2018-04-26 22:01:37 -03:00
|
|
|
#include "Plane.h"
|
|
|
|
|
|
|
|
#include "RC_Channel.h"
|
|
|
|
|
|
|
|
// defining these two macros and including the RC_Channels_VarInfo
|
|
|
|
// header defines the parameter information common to all vehicle
|
|
|
|
// types
|
|
|
|
#define RC_CHANNELS_SUBCLASS RC_Channels_Plane
|
|
|
|
#define RC_CHANNEL_SUBCLASS RC_Channel_Plane
|
|
|
|
|
|
|
|
#include <RC_Channel/RC_Channels_VarInfo.h>
|
|
|
|
|
|
|
|
// note that this callback is not presently used on Plane:
|
|
|
|
int8_t RC_Channels_Plane::flight_mode_channel_number() const
|
|
|
|
{
|
|
|
|
return plane.g.flight_mode_channel.get();
|
|
|
|
}
|
2018-08-03 06:56:58 -03:00
|
|
|
|
|
|
|
bool RC_Channels_Plane::has_valid_input() const
|
|
|
|
{
|
|
|
|
if (plane.failsafe.rc_failsafe) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (plane.failsafe.throttle_counter != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-05 01:22:14 -03:00
|
|
|
|
2020-04-02 17:44:24 -03:00
|
|
|
RC_Channel * RC_Channels_Plane::get_arming_channel(void) const
|
|
|
|
{
|
|
|
|
return plane.channel_rudder;
|
|
|
|
}
|
|
|
|
|
2019-03-19 18:09:56 -03:00
|
|
|
void RC_Channel_Plane::do_aux_function_change_mode(const Mode::Number number,
|
|
|
|
const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch(ch_flag) {
|
|
|
|
case HIGH: {
|
|
|
|
// engage mode (if not possible we remain in current flight mode)
|
2019-10-17 00:49:32 -03:00
|
|
|
const bool success = plane.set_mode_by_number(number, ModeReason::RC_COMMAND);
|
2019-03-19 18:09:56 -03:00
|
|
|
if (plane.control_mode != &plane.mode_initializing) {
|
|
|
|
if (success) {
|
|
|
|
AP_Notify::events.user_mode_change = 1;
|
|
|
|
} else {
|
|
|
|
AP_Notify::events.user_mode_change_failed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// return to flight mode switch's flight mode if we are currently
|
|
|
|
// in this mode
|
|
|
|
if (plane.control_mode->mode_number() == number) {
|
|
|
|
// TODO: rc().reset_mode_switch();
|
|
|
|
plane.reset_control_switch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-02 15:06:39 -04:00
|
|
|
void RC_Channel_Plane::do_aux_function_q_assist_state(aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch(ch_flag) {
|
|
|
|
case HIGH:
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "QAssist: Force enabled");
|
|
|
|
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_FORCE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDDLE:
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "QAssist: Enabled");
|
|
|
|
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_ENABLED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOW:
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "QAssist: Disabled");
|
|
|
|
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_DISABLED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 01:22:14 -03:00
|
|
|
void RC_Channel_Plane::init_aux_function(const RC_Channel::aux_func_t ch_option,
|
|
|
|
const RC_Channel::aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch(ch_option) {
|
|
|
|
// the following functions do not need to be initialised:
|
2019-10-26 08:35:55 -03:00
|
|
|
case AUX_FUNC::AUTO:
|
|
|
|
case AUX_FUNC::CIRCLE:
|
2019-12-13 19:25:01 -04:00
|
|
|
case AUX_FUNC::FLAP:
|
2019-10-26 08:35:55 -03:00
|
|
|
case AUX_FUNC::GUIDED:
|
2019-11-09 01:25:27 -04:00
|
|
|
case AUX_FUNC::INVERTED:
|
2019-12-13 19:25:01 -04:00
|
|
|
case AUX_FUNC::LOITER:
|
2019-10-26 08:35:55 -03:00
|
|
|
case AUX_FUNC::MANUAL:
|
2019-03-19 18:09:56 -03:00
|
|
|
case AUX_FUNC::RTL:
|
2019-10-26 08:35:55 -03:00
|
|
|
case AUX_FUNC::TAKEOFF:
|
2018-09-05 01:22:14 -03:00
|
|
|
break;
|
2018-11-09 19:00:20 -04:00
|
|
|
|
2020-01-02 15:06:39 -04:00
|
|
|
case AUX_FUNC::Q_ASSIST:
|
|
|
|
do_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-04-03 13:26:19 -03:00
|
|
|
case AUX_FUNC::REVERSE_THROTTLE:
|
2018-11-09 19:00:20 -04:00
|
|
|
plane.have_reverse_throttle_rc_option = true;
|
|
|
|
// setup input throttle as a range. This is needed as init_aux_function is called
|
|
|
|
// after set_control_channels()
|
|
|
|
if (plane.channel_throttle) {
|
|
|
|
plane.channel_throttle->set_range(100);
|
|
|
|
}
|
|
|
|
// note that we don't call do_aux_function() here as we don't
|
|
|
|
// want to startup with reverse thrust
|
|
|
|
break;
|
|
|
|
|
2018-09-05 01:22:14 -03:00
|
|
|
default:
|
2018-11-09 19:00:20 -04:00
|
|
|
// handle in parent class
|
2018-09-05 01:22:14 -03:00
|
|
|
RC_Channel::init_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do_aux_function - implement the function invoked by auxillary switches
|
|
|
|
void RC_Channel_Plane::do_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag)
|
|
|
|
{
|
|
|
|
switch(ch_option) {
|
2019-04-03 13:26:19 -03:00
|
|
|
case AUX_FUNC::INVERTED:
|
2018-08-11 08:12:35 -03:00
|
|
|
plane.inverted_flight = (ch_flag == HIGH);
|
|
|
|
break;
|
2018-06-10 03:33:06 -03:00
|
|
|
|
2019-04-03 13:26:19 -03:00
|
|
|
case AUX_FUNC::REVERSE_THROTTLE:
|
2018-11-09 19:00:20 -04:00
|
|
|
plane.reversed_throttle = (ch_flag == HIGH);
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "RevThrottle: %s", plane.reversed_throttle?"ENABLE":"DISABLE");
|
|
|
|
break;
|
2019-03-19 18:09:56 -03:00
|
|
|
|
|
|
|
case AUX_FUNC::AUTO:
|
|
|
|
do_aux_function_change_mode(Mode::Number::AUTO, ch_flag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::CIRCLE:
|
|
|
|
do_aux_function_change_mode(Mode::Number::CIRCLE, ch_flag);
|
|
|
|
break;
|
2019-11-23 04:08:50 -04:00
|
|
|
|
|
|
|
case AUX_FUNC::LOITER:
|
|
|
|
do_aux_function_change_mode(Mode::Number::LOITER, ch_flag);
|
|
|
|
break;
|
2019-03-19 18:09:56 -03:00
|
|
|
|
|
|
|
case AUX_FUNC::GUIDED:
|
|
|
|
do_aux_function_change_mode(Mode::Number::GUIDED, ch_flag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::MANUAL:
|
|
|
|
do_aux_function_change_mode(Mode::Number::MANUAL, ch_flag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUX_FUNC::RTL:
|
|
|
|
do_aux_function_change_mode(Mode::Number::RTL, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-10-20 18:40:35 -03:00
|
|
|
case AUX_FUNC::TAKEOFF:
|
|
|
|
do_aux_function_change_mode(Mode::Number::TAKEOFF, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2019-12-13 19:25:01 -04:00
|
|
|
case AUX_FUNC::FLAP:
|
|
|
|
break; // flap input label, nothing to do
|
2019-10-20 18:40:35 -03:00
|
|
|
|
2020-01-02 15:06:39 -04:00
|
|
|
case AUX_FUNC::Q_ASSIST:
|
|
|
|
do_aux_function_q_assist_state(ch_flag);
|
|
|
|
break;
|
|
|
|
|
2018-09-05 01:22:14 -03:00
|
|
|
default:
|
|
|
|
RC_Channel::do_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|