2015-05-29 23:12:49 -03:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
#include "RC_Channel.h"
|
2015-03-13 10:15:27 -03:00
|
|
|
|
2020-11-22 09:24:47 -04:00
|
|
|
|
2019-03-25 20:57:55 -03:00
|
|
|
// defining these two macros and including the RC_Channels_VarInfo header defines the parameter information common to all vehicle types
|
2018-06-04 00:06:32 -03:00
|
|
|
#define RC_CHANNELS_SUBCLASS RC_Channels_Copter
|
|
|
|
#define RC_CHANNEL_SUBCLASS RC_Channel_Copter
|
2012-12-14 17:30:48 -04:00
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
#include <RC_Channel/RC_Channels_VarInfo.h>
|
2010-12-19 12:40:33 -04:00
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
int8_t RC_Channels_Copter::flight_mode_channel_number() const
|
2015-03-17 09:15:52 -03:00
|
|
|
{
|
2018-06-04 00:06:32 -03:00
|
|
|
return copter.g.flight_mode_chan.get();
|
2015-03-10 17:53:30 -03:00
|
|
|
}
|
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
void RC_Channel_Copter::mode_switch_changed(modeswitch_pos_t new_pos)
|
2015-03-17 09:15:52 -03:00
|
|
|
{
|
2018-06-04 00:06:32 -03:00
|
|
|
if (new_pos < 0 || (uint8_t)new_pos > copter.num_flight_modes) {
|
|
|
|
// should not have been called
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-17 00:49:22 -03:00
|
|
|
if (!copter.set_mode((Mode::Number)copter.flight_modes[new_pos].get(), ModeReason::RC_COMMAND)) {
|
2018-06-04 00:06:32 -03:00
|
|
|
return;
|
2016-09-23 03:41:10 -03:00
|
|
|
}
|
2015-03-10 22:20:07 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
if (!rc().find_channel_for_option(AUX_FUNC::SIMPLE_MODE) &&
|
|
|
|
!rc().find_channel_for_option(AUX_FUNC::SUPERSIMPLE_MODE)) {
|
2018-06-04 00:06:32 -03:00
|
|
|
// if none of the Aux Switches are set to Simple or Super Simple Mode then
|
|
|
|
// set Simple Mode using stored parameters from EEPROM
|
|
|
|
if (BIT_IS_SET(copter.g.super_simple, new_pos)) {
|
2020-06-15 10:05:09 -03:00
|
|
|
copter.set_simple_mode(Copter::SimpleMode::SUPERSIMPLE);
|
2018-06-04 00:06:32 -03:00
|
|
|
} else {
|
2020-06-15 10:05:09 -03:00
|
|
|
copter.set_simple_mode(BIT_IS_SET(copter.g.simple_modes, new_pos) ? Copter::SimpleMode::SIMPLE : Copter::SimpleMode::NONE);
|
2018-06-04 00:06:32 -03:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 04:28:04 -03:00
|
|
|
}
|
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
bool RC_Channels_Copter::has_valid_input() const
|
2010-12-19 12:40:33 -04:00
|
|
|
{
|
2018-06-04 00:06:32 -03:00
|
|
|
if (copter.failsafe.radio) {
|
|
|
|
return false;
|
2013-09-26 08:19:39 -03:00
|
|
|
}
|
2018-06-04 00:06:32 -03:00
|
|
|
if (copter.failsafe.radio_counter != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2013-05-17 02:42:28 -03:00
|
|
|
}
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2021-09-17 20:52:34 -03:00
|
|
|
// returns true if throttle arming checks should be run
|
|
|
|
bool RC_Channels_Copter::arming_check_throttle() const {
|
|
|
|
if ((copter.g.throttle_behavior & THR_BEHAVE_FEEDBACK_FROM_MID_STICK) != 0) {
|
|
|
|
// center sprung throttle configured, dont run AP_Arming check
|
|
|
|
// Copter already checks this case in its own arming checks
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return RC_Channels::arming_check_throttle();
|
|
|
|
}
|
|
|
|
|
2020-04-02 17:44:43 -03:00
|
|
|
RC_Channel * RC_Channels_Copter::get_arming_channel(void) const
|
|
|
|
{
|
|
|
|
return copter.channel_yaw;
|
|
|
|
}
|
2013-07-16 10:05:59 -03:00
|
|
|
|
2015-03-10 15:21:31 -03:00
|
|
|
// init_aux_switch_function - initialize aux functions
|
2020-06-02 23:21:50 -03:00
|
|
|
void RC_Channel_Copter::init_aux_function(const aux_func_t ch_option, const AuxSwitchPos ch_flag)
|
2018-02-11 20:39:54 -04:00
|
|
|
{
|
2015-03-10 15:21:31 -03:00
|
|
|
// init channel options
|
|
|
|
switch(ch_option) {
|
2018-06-04 00:06:32 -03:00
|
|
|
// the following functions do not need to be initialised:
|
2019-11-09 01:25:14 -04:00
|
|
|
case AUX_FUNC::ALTHOLD:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::AUTO:
|
|
|
|
case AUX_FUNC::AUTOTUNE:
|
|
|
|
case AUX_FUNC::BRAKE:
|
2019-11-09 01:25:14 -04:00
|
|
|
case AUX_FUNC::CIRCLE:
|
|
|
|
case AUX_FUNC::DRIFT:
|
|
|
|
case AUX_FUNC::FLIP:
|
|
|
|
case AUX_FUNC::FLOWHOLD:
|
|
|
|
case AUX_FUNC::FOLLOW:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::GUIDED:
|
2019-11-09 01:25:14 -04:00
|
|
|
case AUX_FUNC::LAND:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::LOITER:
|
|
|
|
case AUX_FUNC::PARACHUTE_RELEASE:
|
2019-11-09 01:25:14 -04:00
|
|
|
case AUX_FUNC::POSHOLD:
|
|
|
|
case AUX_FUNC::RESETTOARMEDYAW:
|
|
|
|
case AUX_FUNC::RTL:
|
|
|
|
case AUX_FUNC::SAVE_TRIM:
|
|
|
|
case AUX_FUNC::SAVE_WP:
|
|
|
|
case AUX_FUNC::SMART_RTL:
|
|
|
|
case AUX_FUNC::STABILIZE:
|
|
|
|
case AUX_FUNC::THROW:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::USER_FUNC1:
|
|
|
|
case AUX_FUNC::USER_FUNC2:
|
|
|
|
case AUX_FUNC::USER_FUNC3:
|
2019-11-09 01:25:14 -04:00
|
|
|
case AUX_FUNC::WINCH_CONTROL:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ZIGZAG:
|
2020-04-03 01:48:23 -03:00
|
|
|
case AUX_FUNC::ZIGZAG_Auto:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ZIGZAG_SaveWP:
|
2020-08-18 00:31:56 -03:00
|
|
|
case AUX_FUNC::ACRO:
|
2021-07-24 20:25:18 -03:00
|
|
|
case AUX_FUNC::AUTO_RTL:
|
2021-07-27 16:51:19 -03:00
|
|
|
case AUX_FUNC::TURTLE:
|
2021-09-05 08:39:03 -03:00
|
|
|
case AUX_FUNC::SIMPLE_HEADING_RESET:
|
2021-09-13 21:10:39 -03:00
|
|
|
case AUX_FUNC::ARMDISARM_AIRMODE:
|
2019-11-09 01:25:14 -04:00
|
|
|
break;
|
|
|
|
case AUX_FUNC::ACRO_TRAINER:
|
|
|
|
case AUX_FUNC::ATTCON_ACCEL_LIM:
|
|
|
|
case AUX_FUNC::ATTCON_FEEDFWD:
|
|
|
|
case AUX_FUNC::INVERTED:
|
|
|
|
case AUX_FUNC::MOTOR_INTERLOCK:
|
|
|
|
case AUX_FUNC::PARACHUTE_3POS: // we trust the vehicle will be disarmed so even if switch is in release position the chute will not release
|
|
|
|
case AUX_FUNC::PARACHUTE_ENABLE:
|
|
|
|
case AUX_FUNC::PRECISION_LOITER:
|
|
|
|
case AUX_FUNC::RANGEFINDER:
|
|
|
|
case AUX_FUNC::SIMPLE_MODE:
|
|
|
|
case AUX_FUNC::STANDBY:
|
|
|
|
case AUX_FUNC::SUPERSIMPLE_MODE:
|
|
|
|
case AUX_FUNC::SURFACE_TRACKING:
|
|
|
|
case AUX_FUNC::WINCH_ENABLE:
|
2020-06-16 17:01:19 -03:00
|
|
|
case AUX_FUNC::AIRMODE:
|
2021-04-28 06:13:53 -03:00
|
|
|
run_aux_function(ch_option, ch_flag, AuxFuncTriggerSource::INIT);
|
2020-06-16 17:01:19 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
default:
|
|
|
|
RC_Channel::init_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
2013-07-16 10:05:59 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
// do_aux_function_change_mode - change mode based on an aux switch
|
|
|
|
// being moved
|
2019-09-07 20:33:56 -03:00
|
|
|
void RC_Channel_Copter::do_aux_function_change_mode(const Mode::Number mode,
|
2021-04-28 06:13:53 -03:00
|
|
|
const AuxSwitchPos ch_flag)
|
2018-05-27 05:56:16 -03:00
|
|
|
{
|
2018-06-04 00:06:32 -03:00
|
|
|
switch(ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH: {
|
2018-06-04 00:06:32 -03:00
|
|
|
// engage mode (if not possible we remain in current flight mode)
|
2021-08-03 21:30:10 -03:00
|
|
|
copter.set_mode(mode, ModeReason::RC_COMMAND);
|
2018-06-04 00:06:32 -03:00
|
|
|
break;
|
2018-12-20 07:06:51 -04:00
|
|
|
}
|
2018-06-04 00:06:32 -03:00
|
|
|
default:
|
|
|
|
// return to flight mode switch's flight mode if we are currently
|
|
|
|
// in this mode
|
2020-01-30 03:29:36 -04:00
|
|
|
if (copter.flightmode->mode_number() == mode) {
|
2018-06-04 00:06:32 -03:00
|
|
|
rc().reset_mode_switch();
|
|
|
|
}
|
2018-05-27 05:56:16 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:57:55 -03:00
|
|
|
// do_aux_function - implement the function invoked by auxiliary switches
|
2021-02-24 05:48:15 -04:00
|
|
|
bool RC_Channel_Copter::do_aux_function(const aux_func_t ch_option, const AuxSwitchPos ch_flag)
|
2013-05-17 02:42:28 -03:00
|
|
|
{
|
2018-06-04 00:06:32 -03:00
|
|
|
switch(ch_option) {
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::FLIP:
|
2012-12-06 04:47:01 -04:00
|
|
|
// flip if switch is on, positive throttle and we're actually flying
|
2020-06-02 23:21:50 -03:00
|
|
|
if (ch_flag == AuxSwitchPos::HIGH) {
|
2019-10-17 00:49:22 -03:00
|
|
|
copter.set_mode(Mode::Number::FLIP, ModeReason::RC_COMMAND);
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
2012-12-06 04:47:01 -04:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::SIMPLE_MODE:
|
2013-10-05 06:25:03 -03:00
|
|
|
// low = simple mode off, middle or high position turns simple mode on
|
2020-06-15 10:05:09 -03:00
|
|
|
copter.set_simple_mode((ch_flag == AuxSwitchPos::LOW) ? Copter::SimpleMode::NONE : Copter::SimpleMode::SIMPLE);
|
2013-10-05 06:25:03 -03:00
|
|
|
break;
|
|
|
|
|
2020-06-15 10:05:09 -03:00
|
|
|
case AUX_FUNC::SUPERSIMPLE_MODE: {
|
|
|
|
Copter::SimpleMode newmode = Copter::SimpleMode::NONE;
|
|
|
|
switch (ch_flag) {
|
|
|
|
case AuxSwitchPos::LOW:
|
|
|
|
break;
|
|
|
|
case AuxSwitchPos::MIDDLE:
|
|
|
|
newmode = Copter::SimpleMode::SIMPLE;
|
|
|
|
break;
|
|
|
|
case AuxSwitchPos::HIGH:
|
|
|
|
newmode = Copter::SimpleMode::SUPERSIMPLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
copter.set_simple_mode(newmode);
|
2012-12-06 04:47:01 -04:00
|
|
|
break;
|
2020-06-15 10:05:09 -03:00
|
|
|
}
|
2012-12-06 04:47:01 -04:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::RTL:
|
2018-03-19 11:02:14 -03:00
|
|
|
#if MODE_RTL_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::RTL, ch_flag);
|
2018-03-19 11:02:14 -03:00
|
|
|
#endif
|
2012-12-06 04:47:01 -04:00
|
|
|
break;
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::SAVE_TRIM:
|
2020-06-02 23:21:50 -03:00
|
|
|
if ((ch_flag == AuxSwitchPos::HIGH) &&
|
2021-02-07 00:58:50 -04:00
|
|
|
(copter.flightmode->allows_save_trim()) &&
|
2020-06-02 23:21:50 -03:00
|
|
|
(copter.channel_throttle->get_control_in() == 0)) {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.save_trim();
|
2012-12-06 04:47:01 -04:00
|
|
|
}
|
|
|
|
break;
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::SAVE_WP:
|
2018-03-19 11:02:14 -03:00
|
|
|
#if MODE_AUTO_ENABLED == ENABLED
|
2013-10-31 23:42:33 -03:00
|
|
|
// save waypoint when switch is brought high
|
2020-06-02 23:21:50 -03:00
|
|
|
if (ch_flag == RC_Channel::AuxSwitchPos::HIGH) {
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2014-02-27 21:25:51 -04:00
|
|
|
// do not allow saving new waypoints while we're in auto or disarmed
|
2021-08-30 10:30:33 -03:00
|
|
|
if (copter.flightmode == &copter.mode_auto || !copter.motors->armed()) {
|
2021-02-24 05:48:15 -04:00
|
|
|
break;
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
|
|
|
|
2015-03-24 16:33:13 -03:00
|
|
|
// do not allow saving the first waypoint with zero throttle
|
2018-12-11 13:11:49 -04:00
|
|
|
if ((copter.mode_auto.mission.num_commands() == 0) && (copter.channel_throttle->get_control_in() == 0)) {
|
2021-02-24 05:48:15 -04:00
|
|
|
break;
|
2015-03-24 16:33:13 -03:00
|
|
|
}
|
2013-10-30 00:01:46 -03:00
|
|
|
|
2014-02-27 21:25:51 -04:00
|
|
|
// create new mission command
|
2014-03-10 05:36:18 -03:00
|
|
|
AP_Mission::Mission_Command cmd = {};
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2014-02-27 21:25:51 -04:00
|
|
|
// if the mission is empty save a takeoff command
|
2018-12-11 13:11:49 -04:00
|
|
|
if (copter.mode_auto.mission.num_commands() == 0) {
|
2012-08-16 21:50:02 -03:00
|
|
|
// set our location ID to 16, MAV_CMD_NAV_WAYPOINT
|
2014-02-27 21:25:51 -04:00
|
|
|
cmd.id = MAV_CMD_NAV_TAKEOFF;
|
2018-06-04 00:06:32 -03:00
|
|
|
cmd.content.location.alt = MAX(copter.current_loc.alt,100);
|
2014-02-27 21:25:51 -04:00
|
|
|
|
|
|
|
// use the current altitude for the target alt for takeoff.
|
2012-08-16 21:50:02 -03:00
|
|
|
// only altitude will matter to the AP mission script for takeoff.
|
2018-12-11 13:11:49 -04:00
|
|
|
if (copter.mode_auto.mission.add_cmd(cmd)) {
|
2014-02-27 21:25:51 -04:00
|
|
|
// log event
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::SAVEWP_ADD_WP);
|
2014-02-27 21:25:51 -04:00
|
|
|
}
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
|
|
|
|
2014-02-27 21:25:51 -04:00
|
|
|
// set new waypoint to current location
|
2018-06-04 00:06:32 -03:00
|
|
|
cmd.content.location = copter.current_loc;
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2014-02-27 21:25:51 -04:00
|
|
|
// if throttle is above zero, create waypoint command
|
2018-06-04 00:06:32 -03:00
|
|
|
if (copter.channel_throttle->get_control_in() > 0) {
|
2014-02-27 21:25:51 -04:00
|
|
|
cmd.id = MAV_CMD_NAV_WAYPOINT;
|
2016-12-18 22:19:03 -04:00
|
|
|
} else {
|
2015-03-24 16:33:13 -03:00
|
|
|
// with zero throttle, create LAND command
|
2014-02-27 21:25:51 -04:00
|
|
|
cmd.id = MAV_CMD_NAV_LAND;
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// save command
|
2018-12-11 13:11:49 -04:00
|
|
|
if (copter.mode_auto.mission.add_cmd(cmd)) {
|
2014-02-27 21:25:51 -04:00
|
|
|
// log event
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::SAVEWP_ADD_WP);
|
2014-02-27 21:25:51 -04:00
|
|
|
}
|
2012-12-06 04:47:01 -04:00
|
|
|
}
|
2018-03-19 11:02:14 -03:00
|
|
|
#endif
|
2012-12-06 04:47:01 -04:00
|
|
|
break;
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::AUTO:
|
2018-03-19 11:02:14 -03:00
|
|
|
#if MODE_AUTO_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::AUTO, ch_flag);
|
2012-12-06 04:47:01 -04:00
|
|
|
#endif
|
2016-12-19 03:08:43 -04:00
|
|
|
break;
|
2013-01-14 00:58:53 -04:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::RANGEFINDER:
|
2016-04-27 08:37:04 -03:00
|
|
|
// enable or disable the rangefinder
|
2016-04-27 07:55:35 -03:00
|
|
|
#if RANGEFINDER_ENABLED == ENABLED
|
2020-06-02 23:21:50 -03:00
|
|
|
if ((ch_flag == AuxSwitchPos::HIGH) &&
|
|
|
|
copter.rangefinder.has_orientation(ROTATION_PITCH_270)) {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.rangefinder_state.enabled = true;
|
2016-12-18 22:19:03 -04:00
|
|
|
} else {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.rangefinder_state.enabled = false;
|
2013-07-29 04:28:04 -03:00
|
|
|
}
|
2014-07-08 02:41:39 -03:00
|
|
|
#endif
|
2013-01-14 00:58:53 -04:00
|
|
|
break;
|
2013-04-26 06:51:07 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ACRO_TRAINER:
|
2018-03-14 17:14:49 -03:00
|
|
|
#if MODE_ACRO_ENABLED == ENABLED
|
2013-08-04 06:33:23 -03:00
|
|
|
switch(ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::LOW:
|
2019-10-25 03:06:05 -03:00
|
|
|
copter.g.acro_trainer = (uint8_t)ModeAcro::Trainer::OFF;
|
|
|
|
AP::logger().Write_Event(LogEvent::ACRO_TRAINER_OFF);
|
2013-08-04 06:33:23 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
2019-10-25 03:06:05 -03:00
|
|
|
copter.g.acro_trainer = (uint8_t)ModeAcro::Trainer::LEVELING;
|
|
|
|
AP::logger().Write_Event(LogEvent::ACRO_TRAINER_LEVELING);
|
2013-08-04 06:33:23 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2019-10-25 03:06:05 -03:00
|
|
|
copter.g.acro_trainer = (uint8_t)ModeAcro::Trainer::LIMITED;
|
|
|
|
AP::logger().Write_Event(LogEvent::ACRO_TRAINER_LIMITED);
|
2013-08-04 06:33:23 -03:00
|
|
|
break;
|
|
|
|
}
|
2018-03-14 17:14:49 -03:00
|
|
|
#endif
|
2013-08-19 06:09:23 -03:00
|
|
|
break;
|
2016-12-19 03:08:43 -04:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::AUTOTUNE:
|
2016-12-19 03:08:43 -04:00
|
|
|
#if AUTOTUNE_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::AUTOTUNE, ch_flag);
|
2013-10-04 03:49:19 -03:00
|
|
|
#endif
|
2016-12-19 03:08:43 -04:00
|
|
|
break;
|
2013-10-22 01:13:36 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::LAND:
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::LAND, ch_flag);
|
2013-10-22 01:13:36 -03:00
|
|
|
break;
|
2014-01-03 21:39:08 -04:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::GUIDED:
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::GUIDED, ch_flag);
|
2018-06-04 00:06:32 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::LOITER:
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::LOITER, ch_flag);
|
2019-03-27 23:23:35 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::FOLLOW:
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::FOLLOW, ch_flag);
|
2019-03-27 23:23:35 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::PARACHUTE_ENABLE:
|
2016-12-19 03:08:43 -04:00
|
|
|
#if PARACHUTE == ENABLED
|
2015-03-24 16:33:13 -03:00
|
|
|
// Parachute enable/disable
|
2020-06-02 23:21:50 -03:00
|
|
|
copter.parachute.enabled(ch_flag == AuxSwitchPos::HIGH);
|
2016-12-19 03:08:43 -04:00
|
|
|
#endif
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::PARACHUTE_RELEASE:
|
2016-12-19 03:08:43 -04:00
|
|
|
#if PARACHUTE == ENABLED
|
2020-06-02 23:21:50 -03:00
|
|
|
if (ch_flag == AuxSwitchPos::HIGH) {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.parachute_manual_release();
|
2015-03-24 16:33:13 -03:00
|
|
|
}
|
2016-12-19 03:08:43 -04:00
|
|
|
#endif
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::PARACHUTE_3POS:
|
2016-12-19 03:08:43 -04:00
|
|
|
#if PARACHUTE == ENABLED
|
2015-03-24 16:33:13 -03:00
|
|
|
// Parachute disable, enable, release with 3 position switch
|
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::LOW:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.parachute.enabled(false);
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::PARACHUTE_DISABLED);
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.parachute.enabled(true);
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::PARACHUTE_ENABLED);
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.parachute.enabled(true);
|
|
|
|
copter.parachute_manual_release();
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
|
|
|
}
|
2014-04-02 12:20:45 -03:00
|
|
|
#endif
|
2016-12-19 03:08:43 -04:00
|
|
|
break;
|
2014-05-03 15:26:58 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ATTCON_FEEDFWD:
|
2015-03-24 16:33:13 -03:00
|
|
|
// enable or disable feed forward
|
2020-06-02 23:21:50 -03:00
|
|
|
copter.attitude_control->bf_feedforward(ch_flag == AuxSwitchPos::HIGH);
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2014-06-10 03:56:15 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ATTCON_ACCEL_LIM:
|
2015-03-24 16:33:13 -03:00
|
|
|
// enable or disable accel limiting by restoring defaults
|
2020-06-02 23:21:50 -03:00
|
|
|
copter.attitude_control->accel_limiting(ch_flag == AuxSwitchPos::HIGH);
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2016-12-19 03:08:43 -04:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::MOTOR_INTERLOCK:
|
2020-01-07 01:12:54 -04:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
// The interlock logic for ROTOR_CONTROL_MODE_SPEED_PASSTHROUGH is handled
|
|
|
|
// in heli_update_rotor_speed_targets. Otherwise turn on when above low.
|
|
|
|
if (copter.motors->get_rsc_mode() != ROTOR_CONTROL_MODE_SPEED_PASSTHROUGH) {
|
2020-06-02 23:21:50 -03:00
|
|
|
copter.ap.motor_interlock_switch = (ch_flag == AuxSwitchPos::HIGH || ch_flag == AuxSwitchPos::MIDDLE);
|
2020-01-07 01:12:54 -04:00
|
|
|
}
|
|
|
|
#else
|
2020-06-02 23:21:50 -03:00
|
|
|
copter.ap.motor_interlock_switch = (ch_flag == AuxSwitchPos::HIGH || ch_flag == AuxSwitchPos::MIDDLE);
|
2020-01-07 01:12:54 -04:00
|
|
|
#endif
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2015-05-17 00:22:47 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::BRAKE:
|
2018-03-19 11:02:14 -03:00
|
|
|
#if MODE_BRAKE_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::BRAKE, ch_flag);
|
2018-03-19 11:02:14 -03:00
|
|
|
#endif
|
2015-05-17 00:22:47 -03:00
|
|
|
break;
|
2016-03-03 02:27:55 -04:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::THROW:
|
2018-03-14 17:16:16 -03:00
|
|
|
#if MODE_THROW_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::THROW, ch_flag);
|
2018-03-14 17:16:16 -03:00
|
|
|
#endif
|
2016-03-03 02:27:55 -04:00
|
|
|
break;
|
2016-07-21 09:44:09 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::PRECISION_LOITER:
|
2018-02-22 01:23:35 -04:00
|
|
|
#if PRECISION_LANDING == ENABLED && MODE_LOITER_ENABLED == ENABLED
|
2016-11-16 21:40:49 -04:00
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.mode_loiter.set_precision_loiter_enabled(true);
|
2016-11-16 21:40:49 -04:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
2018-06-04 00:06:32 -03:00
|
|
|
// nothing
|
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::LOW:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.mode_loiter.set_precision_loiter_enabled(false);
|
2016-11-16 21:40:49 -04:00
|
|
|
break;
|
|
|
|
}
|
2016-12-05 06:06:08 -04:00
|
|
|
#endif
|
2016-11-16 21:40:49 -04:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::SMART_RTL:
|
2018-03-19 11:02:14 -03:00
|
|
|
#if MODE_SMARTRTL_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::SMART_RTL, ch_flag);
|
2018-03-19 11:02:14 -03:00
|
|
|
#endif
|
2017-07-26 14:14:40 -03:00
|
|
|
break;
|
2018-03-19 11:02:14 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::INVERTED:
|
2017-08-27 20:51:49 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
2018-06-04 00:06:32 -03:00
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.motors->set_inverted_flight(true);
|
|
|
|
copter.attitude_control->set_inverted_flight(true);
|
|
|
|
copter.heli_flags.inverted_flight = true;
|
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
2018-06-04 00:06:32 -03:00
|
|
|
// nothing
|
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::LOW:
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.motors->set_inverted_flight(false);
|
|
|
|
copter.attitude_control->set_inverted_flight(false);
|
|
|
|
copter.heli_flags.inverted_flight = false;
|
|
|
|
break;
|
2017-08-27 20:51:49 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2017-10-04 23:21:23 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::WINCH_ENABLE:
|
2018-02-10 10:23:06 -04:00
|
|
|
#if WINCH_ENABLED == ENABLED
|
2017-10-04 23:21:23 -03:00
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2020-08-06 21:09:58 -03:00
|
|
|
// high switch position stops winch using rate control
|
2020-07-24 05:38:12 -03:00
|
|
|
copter.g2.winch.set_desired_rate(0.0f);
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
|
|
|
case AuxSwitchPos::LOW:
|
2017-10-04 23:21:23 -03:00
|
|
|
// all other position relax winch
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.g2.winch.relax();
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
|
|
|
}
|
2018-02-10 10:23:06 -04:00
|
|
|
#endif
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::WINCH_CONTROL:
|
2020-07-24 05:38:12 -03:00
|
|
|
// do nothing, used to control the rate of the winch and is processed within AP_Winch
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
2018-01-23 08:54:27 -04:00
|
|
|
|
2018-05-25 09:10:53 -03:00
|
|
|
#ifdef USERHOOK_AUXSWITCH
|
2019-06-10 10:42:06 -03:00
|
|
|
case AUX_FUNC::USER_FUNC1:
|
|
|
|
copter.userhook_auxSwitch1(ch_flag);
|
2018-05-25 09:10:53 -03:00
|
|
|
break;
|
2019-04-03 13:25:47 -03:00
|
|
|
|
2019-06-10 10:42:06 -03:00
|
|
|
case AUX_FUNC::USER_FUNC2:
|
|
|
|
copter.userhook_auxSwitch2(ch_flag);
|
2018-05-25 09:10:53 -03:00
|
|
|
break;
|
2019-04-03 13:25:47 -03:00
|
|
|
|
2019-06-10 10:42:06 -03:00
|
|
|
case AUX_FUNC::USER_FUNC3:
|
|
|
|
copter.userhook_auxSwitch3(ch_flag);
|
2018-05-25 09:10:53 -03:00
|
|
|
break;
|
|
|
|
#endif
|
2018-09-07 01:23:33 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ZIGZAG:
|
2018-09-29 06:25:31 -03:00
|
|
|
#if MODE_ZIGZAG_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::ZIGZAG, ch_flag);
|
2018-09-29 06:25:31 -03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::ZIGZAG_SaveWP:
|
2018-09-07 01:23:33 -03:00
|
|
|
#if MODE_ZIGZAG_ENABLED == ENABLED
|
|
|
|
if (copter.flightmode == &copter.mode_zigzag) {
|
2020-04-07 12:23:27 -03:00
|
|
|
// initialize zigzag auto
|
|
|
|
copter.mode_zigzag.init_auto();
|
2018-09-29 06:25:31 -03:00
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::LOW:
|
2020-02-22 09:58:42 -04:00
|
|
|
copter.mode_zigzag.save_or_move_to_destination(ModeZigZag::Destination::A);
|
2018-09-29 06:25:31 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
2019-04-11 01:34:30 -03:00
|
|
|
copter.mode_zigzag.return_to_manual_control(false);
|
2018-09-29 06:25:31 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2020-02-22 09:58:42 -04:00
|
|
|
copter.mode_zigzag.save_or_move_to_destination(ModeZigZag::Destination::B);
|
2018-09-29 06:25:31 -03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-07 01:23:33 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2019-04-06 22:55:15 -03:00
|
|
|
case AUX_FUNC::STABILIZE:
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::STABILIZE, ch_flag);
|
2019-04-06 22:55:15 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::POSHOLD:
|
|
|
|
#if MODE_POSHOLD_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::POSHOLD, ch_flag);
|
2019-04-06 22:55:15 -03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::ALTHOLD:
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::ALT_HOLD, ch_flag);
|
2019-04-06 22:55:15 -03:00
|
|
|
break;
|
|
|
|
|
2020-08-17 20:43:43 -03:00
|
|
|
|
|
|
|
case AUX_FUNC::ACRO:
|
|
|
|
#if MODE_ACRO_ENABLED == ENABLED
|
|
|
|
do_aux_function_change_mode(Mode::Number::ACRO, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2020-04-23 01:14:18 -03:00
|
|
|
case AUX_FUNC::FLOWHOLD:
|
2019-04-06 22:55:15 -03:00
|
|
|
#if OPTFLOW == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::FLOWHOLD, ch_flag);
|
2019-04-06 22:55:15 -03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::CIRCLE:
|
|
|
|
#if MODE_CIRCLE_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::CIRCLE, ch_flag);
|
2019-04-06 22:55:15 -03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::DRIFT:
|
|
|
|
#if MODE_DRIFT_ENABLED == ENABLED
|
2019-09-07 20:33:56 -03:00
|
|
|
do_aux_function_change_mode(Mode::Number::DRIFT, ch_flag);
|
2019-04-06 22:55:15 -03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2019-10-21 04:07:04 -03:00
|
|
|
case AUX_FUNC::STANDBY: {
|
2019-09-28 10:37:57 -03:00
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2019-09-28 10:37:57 -03:00
|
|
|
copter.standby_active = true;
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::STANDBY_ENABLE);
|
2019-09-28 10:37:57 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Stand By Enabled");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
copter.standby_active = false;
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::STANDBY_DISABLE);
|
2019-09-28 10:37:57 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Stand By Disabled");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-23 22:59:22 -03:00
|
|
|
case AUX_FUNC::SURFACE_TRACKING:
|
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::LOW:
|
2019-10-25 08:31:31 -03:00
|
|
|
copter.surface_tracking.set_surface(Copter::SurfaceTracking::Surface::GROUND);
|
2019-08-23 22:59:22 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::MIDDLE:
|
2019-10-25 08:31:31 -03:00
|
|
|
copter.surface_tracking.set_surface(Copter::SurfaceTracking::Surface::NONE);
|
2019-08-23 22:59:22 -03:00
|
|
|
break;
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2019-10-25 08:31:31 -03:00
|
|
|
copter.surface_tracking.set_surface(Copter::SurfaceTracking::Surface::CEILING);
|
2019-08-23 22:59:22 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-04-03 01:48:23 -03:00
|
|
|
|
|
|
|
case AUX_FUNC::ZIGZAG_Auto:
|
|
|
|
#if MODE_ZIGZAG_ENABLED == ENABLED
|
|
|
|
if (copter.flightmode == &copter.mode_zigzag) {
|
|
|
|
switch (ch_flag) {
|
2020-06-02 23:21:50 -03:00
|
|
|
case AuxSwitchPos::HIGH:
|
2020-04-03 01:48:23 -03:00
|
|
|
copter.mode_zigzag.run_auto();
|
|
|
|
break;
|
|
|
|
default:
|
2020-04-07 12:23:27 -03:00
|
|
|
copter.mode_zigzag.suspend_auto();
|
2020-04-03 01:48:23 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2020-05-24 08:26:00 -03:00
|
|
|
|
|
|
|
case AUX_FUNC::AIRMODE:
|
2020-06-16 17:01:19 -03:00
|
|
|
do_aux_function_change_air_mode(ch_flag);
|
|
|
|
#if MODE_ACRO_ENABLED == ENABLED && FRAME_CONFIG != HELI_FRAME
|
|
|
|
copter.mode_acro.air_mode_aux_changed();
|
|
|
|
#endif
|
|
|
|
break;
|
2021-02-24 05:48:15 -04:00
|
|
|
|
2021-07-24 20:25:18 -03:00
|
|
|
case AUX_FUNC::AUTO_RTL:
|
|
|
|
#if MODE_AUTO_ENABLED == ENABLED
|
|
|
|
do_aux_function_change_mode(Mode::Number::AUTO_RTL, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2021-07-27 16:51:19 -03:00
|
|
|
case AUX_FUNC::TURTLE:
|
|
|
|
#if MODE_TURTLE_ENABLED == ENABLED
|
|
|
|
do_aux_function_change_mode(Mode::Number::TURTLE, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
2021-07-24 20:25:18 -03:00
|
|
|
|
2021-09-05 08:39:03 -03:00
|
|
|
case AUX_FUNC::SIMPLE_HEADING_RESET:
|
|
|
|
if (ch_flag == AuxSwitchPos::HIGH) {
|
|
|
|
copter.init_simple_bearing();
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Simple heading reset");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-09-13 21:10:39 -03:00
|
|
|
case AUX_FUNC::ARMDISARM_AIRMODE:
|
|
|
|
RC_Channel::do_aux_function_armdisarm(ch_flag);
|
|
|
|
if (copter.arming.is_armed()) {
|
|
|
|
copter.ap.armed_with_airmode_switch = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
default:
|
2021-02-24 05:48:15 -04:00
|
|
|
return RC_Channel::do_aux_function(ch_option, ch_flag);
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
2021-02-24 05:48:15 -04:00
|
|
|
return true;
|
2011-01-15 22:37:35 -04:00
|
|
|
}
|
|
|
|
|
2020-06-16 17:01:19 -03:00
|
|
|
// change air-mode status
|
|
|
|
void RC_Channel_Copter::do_aux_function_change_air_mode(const AuxSwitchPos ch_flag)
|
|
|
|
{
|
|
|
|
switch (ch_flag) {
|
|
|
|
case AuxSwitchPos::HIGH:
|
|
|
|
copter.air_mode = AirMode::AIRMODE_ENABLED;
|
|
|
|
break;
|
|
|
|
case AuxSwitchPos::MIDDLE:
|
|
|
|
break;
|
|
|
|
case AuxSwitchPos::LOW:
|
|
|
|
copter.air_mode = AirMode::AIRMODE_DISABLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 00:32:38 -04:00
|
|
|
// save_trim - adds roll and pitch trims from the radio to ahrs
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::save_trim()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2012-12-19 11:06:20 -04:00
|
|
|
// save roll and pitch trim
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
float roll_trim = ToRad((float)channel_roll->get_control_in()/100.0f);
|
|
|
|
float pitch_trim = ToRad((float)channel_pitch->get_control_in()/100.0f);
|
2012-12-19 11:06:20 -04:00
|
|
|
ahrs.add_trim(roll_trim, pitch_trim);
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::SAVE_TRIM);
|
2017-07-08 21:56:49 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Trim saved");
|
2012-12-19 11:06:20 -04:00
|
|
|
}
|
2012-09-17 21:03:29 -03:00
|
|
|
|
2012-12-19 11:06:20 -04:00
|
|
|
// auto_trim - slightly adjusts the ahrs.roll_trim and ahrs.pitch_trim towards the current stick positions
|
|
|
|
// meant to be called continuously while the pilot attempts to keep the copter level
|
2020-06-03 00:28:04 -03:00
|
|
|
void Copter::auto_trim_cancel()
|
|
|
|
{
|
|
|
|
auto_trim_counter = 0;
|
|
|
|
AP_Notify::flags.save_trim = false;
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "AutoTrim cancelled");
|
|
|
|
}
|
|
|
|
|
2015-05-29 23:12:49 -03:00
|
|
|
void Copter::auto_trim()
|
2012-12-19 11:06:20 -04:00
|
|
|
{
|
2016-12-18 22:19:03 -04:00
|
|
|
if (auto_trim_counter > 0) {
|
2020-06-03 00:28:04 -03:00
|
|
|
if (copter.flightmode != &copter.mode_stabilize ||
|
|
|
|
!copter.motors->armed()) {
|
|
|
|
auto_trim_cancel();
|
|
|
|
return;
|
|
|
|
}
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2012-12-19 11:06:20 -04:00
|
|
|
// flash the leds
|
2013-08-14 00:07:35 -03:00
|
|
|
AP_Notify::flags.save_trim = true;
|
2012-11-05 00:32:38 -04:00
|
|
|
|
2020-06-03 00:28:04 -03:00
|
|
|
if (!auto_trim_started) {
|
|
|
|
if (ap.land_complete) {
|
|
|
|
// haven't taken off yet
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto_trim_started = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ap.land_complete) {
|
|
|
|
// landed again.
|
|
|
|
auto_trim_cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto_trim_counter--;
|
|
|
|
|
2012-12-19 11:06:20 -04:00
|
|
|
// calculate roll trim adjustment
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
float roll_trim_adjustment = ToRad((float)channel_roll->get_control_in() / 4000.0f);
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2012-12-19 11:06:20 -04:00
|
|
|
// calculate pitch trim adjustment
|
ArduCopter: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:46:59 -03:00
|
|
|
float pitch_trim_adjustment = ToRad((float)channel_pitch->get_control_in() / 4000.0f);
|
2012-08-16 21:50:02 -03:00
|
|
|
|
2012-12-19 11:06:20 -04:00
|
|
|
// add trim to ahrs object
|
|
|
|
// save to eeprom on last iteration
|
|
|
|
ahrs.add_trim(roll_trim_adjustment, pitch_trim_adjustment, (auto_trim_counter == 0));
|
|
|
|
|
|
|
|
// on last iteration restore leds and accel gains to normal
|
2016-12-18 22:19:03 -04:00
|
|
|
if (auto_trim_counter == 0) {
|
2013-08-14 00:07:35 -03:00
|
|
|
AP_Notify::flags.save_trim = false;
|
2020-06-03 00:28:04 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "AutoTrim: Trims saved");
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
|
|
|
}
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|