Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/ArduPlane/afs_plane.cpp
Views: 1798
/*1plane specific AP_AdvancedFailsafe class2*/34#include "Plane.h"56#if AP_ADVANCEDFAILSAFE_ENABLED78/*9setup radio_out values for all channels to termination values10*/11void AP_AdvancedFailsafe_Plane::terminate_vehicle(void)12{13#if HAL_QUADPLANE_ENABLED14if (plane.quadplane.available() && _terminate_action == TERMINATE_ACTION_LAND) {15// perform a VTOL landing16plane.set_mode(plane.mode_qland, ModeReason::FENCE_BREACHED);17return;18}19#endif2021plane.g2.servo_channels.disable_passthrough(true);2223if (_terminate_action == TERMINATE_ACTION_LAND) {24plane.landing.terminate();25} else {26// remove flap slew limiting27SRV_Channels::set_slew_rate(SRV_Channel::k_flap_auto, 0.0, 100, plane.G_Dt);28SRV_Channels::set_slew_rate(SRV_Channel::k_flap, 0.0, 100, plane.G_Dt);2930// aerodynamic termination is the default approach to termination31SRV_Channels::set_output_scaled(SRV_Channel::k_flap_auto, 100.0);32SRV_Channels::set_output_scaled(SRV_Channel::k_flap, 100.0);33SRV_Channels::set_output_scaled(SRV_Channel::k_aileron, SERVO_MAX);34SRV_Channels::set_output_scaled(SRV_Channel::k_rudder, SERVO_MAX);35SRV_Channels::set_output_scaled(SRV_Channel::k_elevator, SERVO_MAX);36if (plane.have_reverse_thrust()) {37// configured for reverse thrust, use TRIM38SRV_Channels::set_output_limit(SRV_Channel::k_throttle, SRV_Channel::Limit::TRIM);39SRV_Channels::set_output_limit(SRV_Channel::k_throttleLeft, SRV_Channel::Limit::TRIM);40SRV_Channels::set_output_limit(SRV_Channel::k_throttleRight, SRV_Channel::Limit::TRIM);41} else {42// use MIN43SRV_Channels::set_output_limit(SRV_Channel::k_throttle, SRV_Channel::Limit::MIN);44SRV_Channels::set_output_limit(SRV_Channel::k_throttleLeft, SRV_Channel::Limit::MIN);45SRV_Channels::set_output_limit(SRV_Channel::k_throttleRight, SRV_Channel::Limit::MIN);46}47SRV_Channels::set_output_limit(SRV_Channel::k_manual, SRV_Channel::Limit::TRIM);48SRV_Channels::set_output_limit(SRV_Channel::k_none, SRV_Channel::Limit::TRIM);49}5051plane.servos_output();5253#if HAL_QUADPLANE_ENABLED54plane.quadplane.afs_terminate();55#endif5657// also disarm to ensure that ignition is cut58plane.arming.disarm(AP_Arming::Method::AFS);59}6061void AP_AdvancedFailsafe_Plane::setup_IO_failsafe(void)62{63// all aux channels64SRV_Channels::set_failsafe_limit(SRV_Channel::k_flap_auto, SRV_Channel::Limit::MAX);65SRV_Channels::set_failsafe_limit(SRV_Channel::k_flap, SRV_Channel::Limit::MAX);66SRV_Channels::set_failsafe_limit(SRV_Channel::k_aileron, SRV_Channel::Limit::MIN);67SRV_Channels::set_failsafe_limit(SRV_Channel::k_rudder, SRV_Channel::Limit::MAX);68SRV_Channels::set_failsafe_limit(SRV_Channel::k_elevator, SRV_Channel::Limit::MAX);69if (plane.have_reverse_thrust()) {70// configured for reverse thrust, use TRIM71SRV_Channels::set_failsafe_limit(SRV_Channel::k_throttle, SRV_Channel::Limit::TRIM);72SRV_Channels::set_failsafe_limit(SRV_Channel::k_throttleLeft, SRV_Channel::Limit::TRIM);73SRV_Channels::set_failsafe_limit(SRV_Channel::k_throttleRight, SRV_Channel::Limit::TRIM);74} else {75// normal throttle, use MIN76SRV_Channels::set_failsafe_limit(SRV_Channel::k_throttle, SRV_Channel::Limit::MIN);77SRV_Channels::set_failsafe_limit(SRV_Channel::k_throttleLeft, SRV_Channel::Limit::MIN);78SRV_Channels::set_failsafe_limit(SRV_Channel::k_throttleRight, SRV_Channel::Limit::MIN);79}80SRV_Channels::set_failsafe_limit(SRV_Channel::k_manual, SRV_Channel::Limit::TRIM);81SRV_Channels::set_failsafe_limit(SRV_Channel::k_none, SRV_Channel::Limit::TRIM);8283#if HAL_QUADPLANE_ENABLED84if (plane.quadplane.available()) {85// setup AP_Motors outputs for failsafe86uint32_t mask = plane.quadplane.motors->get_motor_mask();87hal.rcout->set_failsafe_pwm(mask, plane.quadplane.motors->get_pwm_output_min());88}89#endif90}9192/*93return an AFS_MODE for current control mode94*/95AP_AdvancedFailsafe::control_mode AP_AdvancedFailsafe_Plane::afs_mode(void)96{97if (plane.control_mode->does_auto_throttle()) {98return AP_AdvancedFailsafe::AFS_AUTO;99}100if (plane.control_mode == &plane.mode_manual) {101return AP_AdvancedFailsafe::AFS_MANUAL;102}103return AP_AdvancedFailsafe::AFS_STABILIZED;104}105106//to force entering auto mode when datalink loss107void AP_AdvancedFailsafe_Plane::set_mode_auto(void)108{109plane.set_mode(plane.mode_auto,ModeReason::GCS_FAILSAFE);110}111112#endif // AP_ADVANCEDFAILSAFE_ENABLED113114115