2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-08-04 03:04:18 -03:00
|
|
|
// last status (deployed or retracted) used to check for changes, initialised to startup state of landing gear
|
|
|
|
static bool last_deploy_status = landinggear.deployed();
|
2015-01-06 22:51:06 -04:00
|
|
|
|
2017-08-04 03:04:18 -03:00
|
|
|
// send event message to datalog if status has changed
|
|
|
|
if (landinggear.deployed() != last_deploy_status) {
|
|
|
|
if (landinggear.deployed()) {
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::LANDING_GEAR_DEPLOYED);
|
2017-08-04 03:04:18 -03:00
|
|
|
} else {
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::LANDING_GEAR_RETRACTED);
|
2015-01-06 11:51:51 -04:00
|
|
|
}
|
|
|
|
}
|
2017-08-04 03:04:18 -03:00
|
|
|
|
|
|
|
last_deploy_status = landinggear.deployed();
|
2018-11-09 00:46:30 -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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|