2016-08-16 07:23:27 -03:00
|
|
|
/*
|
|
|
|
copter specific AP_AdvancedFailsafe class
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Copter.h"
|
|
|
|
|
|
|
|
#if ADVANCED_FAILSAFE == ENABLED
|
|
|
|
|
|
|
|
// Constructor
|
2019-06-14 00:14:06 -03:00
|
|
|
AP_AdvancedFailsafe_Copter::AP_AdvancedFailsafe_Copter(AP_Mission &_mission) :
|
|
|
|
AP_AdvancedFailsafe(_mission)
|
2016-08-16 07:23:27 -03:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
setup radio_out values for all channels to termination values
|
|
|
|
*/
|
|
|
|
void AP_AdvancedFailsafe_Copter::terminate_vehicle(void)
|
|
|
|
{
|
2017-08-30 16:32:00 -03:00
|
|
|
if (_terminate_action == TERMINATE_ACTION_LAND) {
|
2019-10-31 19:32:04 -03:00
|
|
|
copter.set_mode(Mode::Number::LAND, ModeReason::TERMINATE);
|
2017-08-30 16:32:00 -03:00
|
|
|
} else {
|
|
|
|
// stop motors
|
2019-04-09 09:16:58 -03:00
|
|
|
copter.motors->set_desired_spool_state(AP_Motors::DesiredSpoolState::SHUT_DOWN);
|
2017-08-30 16:32:00 -03:00
|
|
|
copter.motors->output();
|
|
|
|
|
|
|
|
// disarm as well
|
2019-05-05 22:39:57 -03:00
|
|
|
copter.arming.disarm();
|
2016-08-16 07:23:27 -03:00
|
|
|
|
2017-08-30 16:32:00 -03:00
|
|
|
// and set all aux channels
|
2019-11-24 21:52:19 -04:00
|
|
|
SRV_Channels::set_output_limit(SRV_Channel::k_heli_rsc, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_output_limit(SRV_Channel::k_heli_tail_rsc, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_output_limit(SRV_Channel::k_engine_run_enable, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_output_limit(SRV_Channel::k_ignition, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_output_limit(SRV_Channel::k_none, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_output_limit(SRV_Channel::k_manual, SRV_Channel::Limit::TRIM);
|
2017-08-30 16:32:00 -03:00
|
|
|
}
|
2016-08-16 07:23:27 -03:00
|
|
|
|
2017-01-30 10:42:21 -04:00
|
|
|
SRV_Channels::output_ch_all();
|
2016-08-16 07:23:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AP_AdvancedFailsafe_Copter::setup_IO_failsafe(void)
|
|
|
|
{
|
|
|
|
// setup failsafe for all aux channels
|
2019-11-24 21:52:19 -04:00
|
|
|
SRV_Channels::set_failsafe_limit(SRV_Channel::k_heli_rsc, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_failsafe_limit(SRV_Channel::k_heli_tail_rsc, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_failsafe_limit(SRV_Channel::k_engine_run_enable, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_failsafe_limit(SRV_Channel::k_ignition, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_failsafe_limit(SRV_Channel::k_none, SRV_Channel::Limit::TRIM);
|
|
|
|
SRV_Channels::set_failsafe_limit(SRV_Channel::k_manual, SRV_Channel::Limit::TRIM);
|
2016-08-16 07:23:27 -03:00
|
|
|
|
|
|
|
#if FRAME_CONFIG != HELI_FRAME
|
|
|
|
// setup AP_Motors outputs for failsafe
|
2017-01-09 03:31:26 -04:00
|
|
|
uint16_t mask = copter.motors->get_motor_mask();
|
|
|
|
hal.rcout->set_failsafe_pwm(mask, copter.motors->get_pwm_output_min());
|
2016-08-16 07:23:27 -03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
return an AFS_MODE for current control mode
|
|
|
|
*/
|
|
|
|
AP_AdvancedFailsafe::control_mode AP_AdvancedFailsafe_Copter::afs_mode(void)
|
|
|
|
{
|
|
|
|
switch (copter.control_mode) {
|
2019-10-31 19:32:04 -03:00
|
|
|
case Mode::Number::AUTO:
|
|
|
|
case Mode::Number::GUIDED:
|
|
|
|
case Mode::Number::RTL:
|
|
|
|
case Mode::Number::LAND:
|
2016-08-16 07:23:27 -03:00
|
|
|
return AP_AdvancedFailsafe::AFS_AUTO;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return AP_AdvancedFailsafe::AFS_STABILIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ADVANCED_FAILSAFE
|