2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2022-10-01 07:21:38 -03:00
|
|
|
#if AP_LANDINGGEAR_ENABLED
|
2015-05-29 23:12:49 -03:00
|
|
|
|
2015-01-06 11:51:51 -04:00
|
|
|
// Run landing gear controller at 10Hz
|
2017-06-10 01:11:00 -03:00
|
|
|
void Copter::landinggear_update()
|
|
|
|
{
|
2017-08-04 03:40:55 -03:00
|
|
|
// exit immediately if no landing gear output has been enabled
|
|
|
|
if (!SRV_Channels::function_assigned(SRV_Channel::k_landing_gear_control)) {
|
2017-08-04 03:04:18 -03:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 22:51:06 -04:00
|
|
|
|
2019-02-22 18:39:08 -04:00
|
|
|
// support height based triggering using rangefinder or altitude above ground
|
2019-02-25 23:07:55 -04:00
|
|
|
int32_t height_cm = flightmode->get_alt_above_ground_cm();
|
2018-11-09 22:37:47 -04:00
|
|
|
|
|
|
|
// use rangefinder if available
|
2023-11-07 18:23:41 -04:00
|
|
|
#if AP_RANGEFINDER_ENABLED
|
2018-11-09 22:37:47 -04:00
|
|
|
switch (rangefinder.status_orient(ROTATION_PITCH_270)) {
|
2019-11-01 02:13:55 -03:00
|
|
|
case RangeFinder::Status::NotConnected:
|
|
|
|
case RangeFinder::Status::NoData:
|
2018-11-09 22:37:47 -04:00
|
|
|
// use altitude above home for non-functioning rangefinder
|
|
|
|
break;
|
|
|
|
|
2019-11-01 02:13:55 -03:00
|
|
|
case RangeFinder::Status::OutOfRangeLow:
|
2018-11-09 22:37:47 -04:00
|
|
|
// altitude is close to zero (gear should deploy)
|
2019-02-22 18:39:08 -04:00
|
|
|
height_cm = 0;
|
2018-11-09 22:37:47 -04:00
|
|
|
break;
|
|
|
|
|
2019-11-01 02:13:55 -03:00
|
|
|
case RangeFinder::Status::OutOfRangeHigh:
|
|
|
|
case RangeFinder::Status::Good:
|
2018-11-09 22:37:47 -04:00
|
|
|
// use last good reading
|
2019-02-22 18:39:08 -04:00
|
|
|
height_cm = rangefinder_state.alt_cm_filt.get();
|
2018-11-09 22:37:47 -04:00
|
|
|
break;
|
2018-11-09 00:46:30 -04:00
|
|
|
}
|
2023-11-07 18:23:41 -04:00
|
|
|
#endif // AP_RANGEFINDER_ENABLED
|
2018-11-09 00:46:30 -04:00
|
|
|
|
2019-02-22 18:39:08 -04:00
|
|
|
landinggear.update(height_cm * 0.01f); // convert cm->m for update call
|
2015-01-06 11:51:51 -04:00
|
|
|
}
|
2021-02-06 23:29:33 -04:00
|
|
|
|
2022-10-01 07:21:38 -03:00
|
|
|
#endif // AP_LANDINGGEAR_ENABLED
|