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
|
|
|
// if we are doing an automatic landing procedure, force the landing gear to deploy.
|
|
|
|
// To-Do: should we pause the auto-land procedure to give time for gear to come down?
|
2017-12-06 07:18:34 -04:00
|
|
|
if (flightmode->landing_gear_should_be_deployed()) {
|
2018-08-02 22:25:58 -03:00
|
|
|
landinggear.set_position(AP_LandingGear::LandingGear_Deploy);
|
2017-08-04 03:04:18 -03:00
|
|
|
}
|
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()) {
|
|
|
|
Log_Write_Event(DATA_LANDING_GEAR_DEPLOYED);
|
|
|
|
} else {
|
|
|
|
Log_Write_Event(DATA_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
|
|
|
|
2018-11-09 22:37:47 -04:00
|
|
|
// support height based triggering using rangefinder or altitude above home
|
|
|
|
float height = current_loc.alt * 0.01;
|
|
|
|
|
|
|
|
// use rangefinder if available
|
|
|
|
switch (rangefinder.status_orient(ROTATION_PITCH_270)) {
|
|
|
|
case RangeFinder::RangeFinder_NotConnected:
|
|
|
|
case RangeFinder::RangeFinder_NoData:
|
|
|
|
// use altitude above home for non-functioning rangefinder
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RangeFinder::RangeFinder_OutOfRangeLow:
|
|
|
|
// altitude is close to zero (gear should deploy)
|
|
|
|
height = 0.0f;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RangeFinder::RangeFinder_OutOfRangeHigh:
|
|
|
|
case RangeFinder::RangeFinder_Good:
|
|
|
|
// use last good reading
|
2018-11-09 00:46:30 -04:00
|
|
|
height = rangefinder_state.alt_cm_filt.get() * 0.01;
|
2018-11-09 22:37:47 -04:00
|
|
|
break;
|
2018-11-09 00:46:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
landinggear.update(height);
|
2015-01-06 11:51:51 -04:00
|
|
|
}
|