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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!copter.set_mode((control_mode_t)copter.flight_modes[new_pos].get(), MODE_REASON_TX_COMMAND)) {
|
|
|
|
// alert user to mode change failure
|
|
|
|
if (copter.ap.initialised) {
|
|
|
|
AP_Notify::events.user_mode_change_failed = 1;
|
2016-09-23 03:41:10 -03:00
|
|
|
}
|
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
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
// play a tone
|
|
|
|
// alert user to mode change (except if autopilot is just starting up)
|
|
|
|
if (copter.ap.initialised) {
|
|
|
|
AP_Notify::events.user_mode_change = 1;
|
|
|
|
}
|
2010-12-19 12:40:33 -04: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)) {
|
|
|
|
copter.set_simple_mode(2);
|
|
|
|
} else {
|
|
|
|
copter.set_simple_mode(BIT_IS_SET(copter.g.simple_modes, new_pos));
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2013-07-16 10:05:59 -03:00
|
|
|
|
2015-03-10 15:21:31 -03:00
|
|
|
// init_aux_switch_function - initialize aux functions
|
2018-06-04 00:06:32 -03:00
|
|
|
void RC_Channel_Copter::init_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag)
|
2018-02-11 20:39:54 -04:00
|
|
|
{
|
2015-03-10 15:21:31 -03:00
|
|
|
// init channel options
|
|
|
|
switch(ch_option) {
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::SIMPLE_MODE:
|
|
|
|
case AUX_FUNC::RANGEFINDER:
|
|
|
|
case AUX_FUNC::FENCE:
|
|
|
|
case AUX_FUNC::SUPERSIMPLE_MODE:
|
|
|
|
case AUX_FUNC::ACRO_TRAINER:
|
|
|
|
case AUX_FUNC::PARACHUTE_ENABLE:
|
|
|
|
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::RETRACT_MOUNT:
|
|
|
|
case AUX_FUNC::ATTCON_FEEDFWD:
|
|
|
|
case AUX_FUNC::ATTCON_ACCEL_LIM:
|
|
|
|
case AUX_FUNC::MOTOR_INTERLOCK:
|
|
|
|
case AUX_FUNC::AVOID_ADSB:
|
|
|
|
case AUX_FUNC::PRECISION_LOITER:
|
|
|
|
case AUX_FUNC::INVERTED:
|
|
|
|
case AUX_FUNC::WINCH_ENABLE:
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
|
|
|
// the following functions do not need to be initialised:
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::FLIP:
|
|
|
|
case AUX_FUNC::RTL:
|
|
|
|
case AUX_FUNC::SAVE_TRIM:
|
|
|
|
case AUX_FUNC::SAVE_WP:
|
|
|
|
case AUX_FUNC::RESETTOARMEDYAW:
|
|
|
|
case AUX_FUNC::AUTO:
|
|
|
|
case AUX_FUNC::AUTOTUNE:
|
|
|
|
case AUX_FUNC::LAND:
|
|
|
|
case AUX_FUNC::BRAKE:
|
|
|
|
case AUX_FUNC::THROW:
|
|
|
|
case AUX_FUNC::SMART_RTL:
|
|
|
|
case AUX_FUNC::GUIDED:
|
|
|
|
case AUX_FUNC::LOITER:
|
|
|
|
case AUX_FUNC::FOLLOW:
|
|
|
|
case AUX_FUNC::PARACHUTE_RELEASE:
|
|
|
|
case AUX_FUNC::ARMDISARM:
|
|
|
|
case AUX_FUNC::WINCH_CONTROL:
|
|
|
|
case AUX_FUNC::USER_FUNC1:
|
|
|
|
case AUX_FUNC::USER_FUNC2:
|
|
|
|
case AUX_FUNC::USER_FUNC3:
|
|
|
|
case AUX_FUNC::ZIGZAG:
|
|
|
|
case AUX_FUNC::ZIGZAG_SaveWP:
|
2019-04-06 22:55:15 -03:00
|
|
|
case AUX_FUNC::STABILIZE:
|
|
|
|
case AUX_FUNC::POSHOLD:
|
|
|
|
case AUX_FUNC::ALTHOLD:
|
|
|
|
case AUX_FUNC::FLOWHOLD:
|
|
|
|
case AUX_FUNC::CIRCLE:
|
|
|
|
case AUX_FUNC::DRIFT:
|
2018-06-04 00:06:32 -03:00
|
|
|
break;
|
|
|
|
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
|
|
|
|
void RC_Channel_Copter::do_aux_function_change_mode(const control_mode_t mode,
|
|
|
|
const aux_switch_pos_t ch_flag)
|
2018-05-27 05:56:16 -03:00
|
|
|
{
|
2018-06-04 00:06:32 -03:00
|
|
|
switch(ch_flag) {
|
2018-12-20 07:06:51 -04:00
|
|
|
case HIGH: {
|
2018-06-04 00:06:32 -03:00
|
|
|
// engage mode (if not possible we remain in current flight mode)
|
2018-12-20 07:06:51 -04:00
|
|
|
const bool success = copter.set_mode(mode, MODE_REASON_TX_COMMAND);
|
|
|
|
if (copter.ap.initialised) {
|
|
|
|
if (success) {
|
|
|
|
AP_Notify::events.user_mode_change = 1;
|
|
|
|
} else {
|
|
|
|
AP_Notify::events.user_mode_change_failed = 1;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
if (copter.control_mode == mode) {
|
|
|
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
void RC_Channel_Copter::do_aux_function(const aux_func_t ch_option, const aux_switch_pos_t 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
|
2019-01-07 22:01:59 -04:00
|
|
|
if (ch_flag == aux_switch_pos_t::HIGH) {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.set_mode(control_mode_t::FLIP, MODE_REASON_TX_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
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.set_simple_mode(ch_flag == HIGH || ch_flag == MIDDLE);
|
2013-10-05 06:25:03 -03:00
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::SUPERSIMPLE_MODE:
|
2013-10-05 06:25:03 -03:00
|
|
|
// low = simple mode off, middle = simple mode, high = super simple mode
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.set_simple_mode(ch_flag);
|
2012-12-06 04:47:01 -04:00
|
|
|
break;
|
|
|
|
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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:
|
2018-06-04 00:06:32 -03:00
|
|
|
if ((ch_flag == HIGH) && (copter.control_mode <= control_mode_t::ACRO) && (copter.channel_throttle->get_control_in() == 0)) {
|
|
|
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
if (ch_flag == 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
|
2018-06-04 00:06:32 -03:00
|
|
|
if (copter.control_mode == control_mode_t::AUTO || !copter.motors->armed()) {
|
2012-08-16 21:50:02 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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)) {
|
2015-03-24 16:33:13 -03:00
|
|
|
return;
|
|
|
|
}
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.Log_Write_Event(DATA_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
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.Log_Write_Event(DATA_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
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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
|
2018-06-04 00:06:32 -03:00
|
|
|
if ((ch_flag == HIGH) && copter.rangefinder.has_orientation(ROTATION_PITCH_270)) {
|
|
|
|
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::FENCE:
|
2016-12-19 03:08:43 -04:00
|
|
|
#if AC_FENCE == ENABLED
|
2013-07-20 03:00:08 -03:00
|
|
|
// enable or disable the fence
|
2018-06-04 00:06:32 -03:00
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
copter.fence.enable(true);
|
|
|
|
copter.Log_Write_Event(DATA_FENCE_ENABLE);
|
2016-12-18 22:19:03 -04:00
|
|
|
} else {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.fence.enable(false);
|
|
|
|
copter.Log_Write_Event(DATA_FENCE_DISABLE);
|
2013-07-29 04:28:04 -03:00
|
|
|
}
|
2013-07-20 03:00:08 -03:00
|
|
|
#endif
|
2016-12-19 03:08:43 -04:00
|
|
|
break;
|
2013-08-04 06:33:23 -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) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case LOW:
|
|
|
|
copter.g.acro_trainer = ACRO_TRAINER_DISABLED;
|
|
|
|
copter.Log_Write_Event(DATA_ACRO_TRAINER_DISABLED);
|
2013-08-04 06:33:23 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case MIDDLE:
|
|
|
|
copter.g.acro_trainer = ACRO_TRAINER_LEVELING;
|
|
|
|
copter.Log_Write_Event(DATA_ACRO_TRAINER_LEVELING);
|
2013-08-04 06:33:23 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
|
|
|
copter.g.acro_trainer = ACRO_TRAINER_LIMITED;
|
|
|
|
copter.Log_Write_Event(DATA_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
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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:
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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:
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::GUIDED, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::LOITER:
|
2019-03-27 23:23:35 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::LOITER, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::FOLLOW:
|
2019-03-27 23:23:35 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::FOLLOW, ch_flag);
|
|
|
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.parachute.enabled(ch_flag == 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
|
2018-06-04 00:06:32 -03:00
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
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) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case LOW:
|
|
|
|
copter.parachute.enabled(false);
|
|
|
|
copter.Log_Write_Event(DATA_PARACHUTE_DISABLED);
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case MIDDLE:
|
|
|
|
copter.parachute.enabled(true);
|
|
|
|
copter.Log_Write_Event(DATA_PARACHUTE_ENABLED);
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
|
|
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.attitude_control->bf_feedforward(ch_flag == 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
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.attitude_control->accel_limiting(ch_flag == 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::RETRACT_MOUNT:
|
2016-12-19 03:08:43 -04:00
|
|
|
#if MOUNT == ENABLE
|
2015-03-24 16:33:13 -03:00
|
|
|
switch (ch_flag) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
|
|
|
copter.camera_mount.set_mode(MAV_MOUNT_MODE_RETRACT);
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case LOW:
|
|
|
|
copter.camera_mount.set_mode_to_default();
|
2015-03-24 16:33:13 -03:00
|
|
|
break;
|
|
|
|
}
|
2014-07-10 01:00:28 -03:00
|
|
|
#endif
|
2016-12-19 03:08:43 -04:00
|
|
|
break;
|
2014-08-09 01:36:35 -03:00
|
|
|
|
2019-04-03 13:25:47 -03:00
|
|
|
case AUX_FUNC::MOTOR_INTERLOCK:
|
2015-03-24 16:33:13 -03:00
|
|
|
// Turn on when above LOW, because channel will also be used for speed
|
|
|
|
// control signal in tradheli
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.ap.motor_interlock_switch = (ch_flag == HIGH || ch_flag == MIDDLE);
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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::AVOID_ADSB:
|
2018-02-16 10:21:55 -04:00
|
|
|
#if ADSB_ENABLED == ENABLED
|
2016-07-21 09:44:09 -03:00
|
|
|
// enable or disable AP_Avoidance
|
2018-06-04 00:06:32 -03:00
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
copter.avoidance_adsb.enable();
|
|
|
|
copter.Log_Write_Event(DATA_AVOIDANCE_ADSB_ENABLE);
|
2016-12-18 22:19:03 -04:00
|
|
|
} else {
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.avoidance_adsb.disable();
|
|
|
|
copter.Log_Write_Event(DATA_AVOIDANCE_ADSB_DISABLE);
|
2016-07-21 09:44:09 -03:00
|
|
|
}
|
2018-02-16 10:21:55 -04:00
|
|
|
#endif
|
2016-07-21 09:44:09 -03:00
|
|
|
break;
|
2016-11-16 21:40:49 -04: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) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
|
|
|
copter.mode_loiter.set_precision_loiter_enabled(true);
|
2016-11-16 21:40:49 -04:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW:
|
|
|
|
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::ARMDISARM:
|
2017-02-06 02:28:52 -04:00
|
|
|
// arm or disarm the vehicle
|
|
|
|
switch (ch_flag) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
2019-05-05 22:39:57 -03:00
|
|
|
copter.arming.arm(AP_Arming::Method::AUXSWITCH);
|
2018-05-27 05:12:00 -03:00
|
|
|
// remember that we are using an arming switch, for use by set_throttle_zero_flag
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.ap.armed_with_switch = true;
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
2017-02-06 02:28:52 -04:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case LOW:
|
2019-05-05 22:39:57 -03:00
|
|
|
copter.arming.disarm();
|
2017-02-06 02:28:52 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2017-07-26 14:14:40 -03:00
|
|
|
|
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
|
2018-06-04 00:06:32 -03:00
|
|
|
do_aux_function_change_mode(control_mode_t::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) {
|
|
|
|
case HIGH:
|
|
|
|
copter.motors->set_inverted_flight(true);
|
|
|
|
copter.attitude_control->set_inverted_flight(true);
|
|
|
|
copter.heli_flags.inverted_flight = true;
|
|
|
|
break;
|
|
|
|
case MIDDLE:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
case LOW:
|
|
|
|
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) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
2017-10-04 23:21:23 -03:00
|
|
|
// high switch maintains current position
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.g2.winch.release_length(0.0f);
|
|
|
|
copter.Log_Write_Event(DATA_WINCH_LENGTH_CONTROL);
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// all other position relax winch
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.g2.winch.relax();
|
|
|
|
copter.Log_Write_Event(DATA_WINCH_RELAXED);
|
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:
|
2018-02-10 10:23:06 -04:00
|
|
|
#if WINCH_ENABLED == ENABLED
|
2017-10-04 23:21:23 -03:00
|
|
|
switch (ch_flag) {
|
2018-06-04 00:06:32 -03:00
|
|
|
case LOW:
|
2017-10-04 23:21:23 -03:00
|
|
|
// raise winch at maximum speed
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.g2.winch.set_desired_rate(-copter.g2.winch.get_rate_max());
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case HIGH:
|
2017-10-04 23:21:23 -03:00
|
|
|
// lower winch at maximum speed
|
2018-06-04 00:06:32 -03:00
|
|
|
copter.g2.winch.set_desired_rate(copter.g2.winch.get_rate_max());
|
2017-10-04 23:21:23 -03:00
|
|
|
break;
|
2018-06-04 00:06:32 -03:00
|
|
|
case MIDDLE:
|
|
|
|
copter.g2.winch.set_desired_rate(0.0f);
|
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;
|
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
|
|
|
|
do_aux_function_change_mode(control_mode_t::ZIGZAG, ch_flag);
|
|
|
|
#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) {
|
2018-09-29 06:25:31 -03:00
|
|
|
switch (ch_flag) {
|
|
|
|
case LOW:
|
|
|
|
copter.mode_zigzag.save_or_move_to_destination(0);
|
|
|
|
break;
|
|
|
|
case 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;
|
|
|
|
case HIGH:
|
|
|
|
copter.mode_zigzag.save_or_move_to_destination(1);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-07 01:23:33 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2019-04-06 22:55:15 -03:00
|
|
|
case AUX_FUNC::STABILIZE:
|
|
|
|
do_aux_function_change_mode(control_mode_t::STABILIZE, ch_flag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::POSHOLD:
|
|
|
|
#if MODE_POSHOLD_ENABLED == ENABLED
|
|
|
|
do_aux_function_change_mode(control_mode_t::POSHOLD, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::ALTHOLD:
|
|
|
|
do_aux_function_change_mode(control_mode_t::ALT_HOLD, ch_flag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::FLOWHOLD:
|
|
|
|
#if OPTFLOW == ENABLED
|
|
|
|
do_aux_function_change_mode(control_mode_t::FLOWHOLD, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::CIRCLE:
|
|
|
|
#if MODE_CIRCLE_ENABLED == ENABLED
|
|
|
|
do_aux_function_change_mode(control_mode_t::CIRCLE, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::DRIFT:
|
|
|
|
#if MODE_DRIFT_ENABLED == ENABLED
|
|
|
|
do_aux_function_change_mode(control_mode_t::DRIFT, ch_flag);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2018-06-04 00:06:32 -03:00
|
|
|
default:
|
|
|
|
RC_Channel::do_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
2011-01-15 22:37:35 -04:00
|
|
|
}
|
|
|
|
|
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);
|
2013-10-31 23:53:16 -03:00
|
|
|
Log_Write_Event(DATA_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
|
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) {
|
2012-12-19 11:06:20 -04:00
|
|
|
auto_trim_counter--;
|
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
|
|
|
|
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;
|
2012-08-16 21:50:02 -03:00
|
|
|
}
|
|
|
|
}
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|