CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduCopter/landing_gear.cpp
Views: 1798
1
#include "Copter.h"
2
3
#if AP_LANDINGGEAR_ENABLED
4
5
// Run landing gear controller at 10Hz
6
void Copter::landinggear_update()
7
{
8
// exit immediately if no landing gear output has been enabled
9
if (!SRV_Channels::function_assigned(SRV_Channel::k_landing_gear_control)) {
10
return;
11
}
12
13
// support height based triggering using rangefinder or altitude above ground
14
int32_t height_cm = flightmode->get_alt_above_ground_cm();
15
16
// use rangefinder if available
17
#if AP_RANGEFINDER_ENABLED
18
switch (rangefinder.status_orient(ROTATION_PITCH_270)) {
19
case RangeFinder::Status::NotConnected:
20
case RangeFinder::Status::NoData:
21
// use altitude above home for non-functioning rangefinder
22
break;
23
24
case RangeFinder::Status::OutOfRangeLow:
25
// altitude is close to zero (gear should deploy)
26
height_cm = 0;
27
break;
28
29
case RangeFinder::Status::OutOfRangeHigh:
30
case RangeFinder::Status::Good:
31
// use last good reading
32
height_cm = rangefinder_state.alt_cm_filt.get();
33
break;
34
}
35
#endif // AP_RANGEFINDER_ENABLED
36
37
landinggear.update(height_cm * 0.01f); // convert cm->m for update call
38
}
39
40
#endif // AP_LANDINGGEAR_ENABLED
41
42