2015-05-13 03:09:36 -03:00
|
|
|
#include "Plane.h"
|
2012-08-01 00:59:20 -03:00
|
|
|
|
2021-09-10 03:28:21 -03:00
|
|
|
#include "quadplane.h"
|
|
|
|
#include "qautotune.h"
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
Mode *Plane::mode_from_mode_num(const enum Mode::Number num)
|
|
|
|
{
|
|
|
|
Mode *ret = nullptr;
|
|
|
|
switch (num) {
|
|
|
|
case Mode::Number::MANUAL:
|
|
|
|
ret = &mode_manual;
|
|
|
|
break;
|
|
|
|
case Mode::Number::CIRCLE:
|
|
|
|
ret = &mode_circle;
|
|
|
|
break;
|
|
|
|
case Mode::Number::STABILIZE:
|
|
|
|
ret = &mode_stabilize;
|
|
|
|
break;
|
|
|
|
case Mode::Number::TRAINING:
|
|
|
|
ret = &mode_training;
|
|
|
|
break;
|
|
|
|
case Mode::Number::ACRO:
|
|
|
|
ret = &mode_acro;
|
|
|
|
break;
|
|
|
|
case Mode::Number::FLY_BY_WIRE_A:
|
|
|
|
ret = &mode_fbwa;
|
|
|
|
break;
|
|
|
|
case Mode::Number::FLY_BY_WIRE_B:
|
|
|
|
ret = &mode_fbwb;
|
|
|
|
break;
|
|
|
|
case Mode::Number::CRUISE:
|
|
|
|
ret = &mode_cruise;
|
|
|
|
break;
|
|
|
|
case Mode::Number::AUTOTUNE:
|
|
|
|
ret = &mode_autotune;
|
|
|
|
break;
|
|
|
|
case Mode::Number::AUTO:
|
|
|
|
ret = &mode_auto;
|
|
|
|
break;
|
|
|
|
case Mode::Number::RTL:
|
|
|
|
ret = &mode_rtl;
|
|
|
|
break;
|
|
|
|
case Mode::Number::LOITER:
|
|
|
|
ret = &mode_loiter;
|
|
|
|
break;
|
|
|
|
case Mode::Number::AVOID_ADSB:
|
2020-09-22 14:00:39 -03:00
|
|
|
#if HAL_ADSB_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
ret = &mode_avoidADSB;
|
|
|
|
break;
|
2020-09-22 14:00:39 -03:00
|
|
|
#endif
|
|
|
|
// if ADSB is not compiled in then fallthrough to guided
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::GUIDED:
|
|
|
|
ret = &mode_guided;
|
|
|
|
break;
|
|
|
|
case Mode::Number::INITIALISING:
|
|
|
|
ret = &mode_initializing;
|
|
|
|
break;
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QSTABILIZE:
|
|
|
|
ret = &mode_qstabilize;
|
|
|
|
break;
|
|
|
|
case Mode::Number::QHOVER:
|
|
|
|
ret = &mode_qhover;
|
|
|
|
break;
|
|
|
|
case Mode::Number::QLOITER:
|
|
|
|
ret = &mode_qloiter;
|
|
|
|
break;
|
|
|
|
case Mode::Number::QLAND:
|
|
|
|
ret = &mode_qland;
|
|
|
|
break;
|
|
|
|
case Mode::Number::QRTL:
|
|
|
|
ret = &mode_qrtl;
|
|
|
|
break;
|
|
|
|
case Mode::Number::QACRO:
|
|
|
|
ret = &mode_qacro;
|
|
|
|
break;
|
2021-09-10 03:28:21 -03:00
|
|
|
#if QAUTOTUNE_ENABLED
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::QAUTOTUNE:
|
|
|
|
ret = &mode_qautotune;
|
|
|
|
break;
|
2021-09-10 03:28:21 -03:00
|
|
|
#endif
|
|
|
|
#endif // HAL_QUADPLANE_ENABLED
|
2019-05-04 06:56:07 -03:00
|
|
|
case Mode::Number::TAKEOFF:
|
|
|
|
ret = &mode_takeoff;
|
|
|
|
break;
|
2020-09-16 04:46:56 -03:00
|
|
|
case Mode::Number::THERMAL:
|
2020-09-23 05:16:45 -03:00
|
|
|
#if HAL_SOARING_ENABLED
|
2020-09-16 04:46:56 -03:00
|
|
|
ret = &mode_thermal;
|
|
|
|
#endif
|
|
|
|
break;
|
2021-09-18 20:15:41 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
|
|
|
case Mode::Number::LOITER_ALT_QLAND:
|
2022-02-03 23:24:05 -04:00
|
|
|
ret = &mode_loiter_qland;
|
2021-09-18 20:15:41 -03:00
|
|
|
break;
|
|
|
|
#endif // HAL_QUADPLANE_ENABLED
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-13 22:10:43 -03:00
|
|
|
void RC_Channels_Plane::read_mode_switch()
|
2011-09-08 22:29:39 -03:00
|
|
|
{
|
2022-07-13 22:10:43 -03:00
|
|
|
if (millis() - plane.failsafe.last_valid_rc_ms > 100) {
|
2014-03-08 01:49:57 -04:00
|
|
|
// only use signals that are less than 0.1s old.
|
|
|
|
return;
|
|
|
|
}
|
2022-07-13 22:10:43 -03:00
|
|
|
RC_Channels::read_mode_switch();
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2022-07-13 22:10:43 -03:00
|
|
|
void RC_Channel_Plane::mode_switch_changed(modeswitch_pos_t new_pos)
|
2014-03-08 01:49:57 -04:00
|
|
|
{
|
2022-07-13 22:10:43 -03:00
|
|
|
if (new_pos < 0 || (uint8_t)new_pos > plane.num_flight_modes) {
|
|
|
|
// should not have been called
|
|
|
|
return;
|
|
|
|
}
|
2011-09-08 22:29:39 -03:00
|
|
|
|
2022-07-13 22:10:43 -03:00
|
|
|
plane.set_mode_by_number((Mode::Number)plane.flight_modes[new_pos].get(), ModeReason::RC_COMMAND);
|
2011-09-08 22:29:39 -03:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:12:14 -03:00
|
|
|
/*
|
|
|
|
called when entering autotune
|
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
void Plane::autotune_start(void)
|
2014-04-12 01:12:14 -03:00
|
|
|
{
|
2022-11-01 10:46:52 -03:00
|
|
|
const bool tune_roll = g2.axis_bitmask.get() & int8_t(AutoTuneAxis::ROLL);
|
|
|
|
const bool tune_pitch = g2.axis_bitmask.get() & int8_t(AutoTuneAxis::PITCH);
|
|
|
|
const bool tune_yaw = g2.axis_bitmask.get() & int8_t(AutoTuneAxis::YAW);
|
|
|
|
if (tune_roll || tune_pitch || tune_yaw) {
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Started autotune");
|
|
|
|
if (tune_roll) {
|
|
|
|
rollController.autotune_start();
|
|
|
|
}
|
|
|
|
if (tune_pitch) {
|
|
|
|
pitchController.autotune_start();
|
|
|
|
}
|
|
|
|
if (tune_yaw) {
|
|
|
|
yawController.autotune_start();
|
|
|
|
}
|
2023-01-26 16:59:58 -04:00
|
|
|
autotuning = true;
|
2022-11-01 10:46:52 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Autotuning %s%s%s", tune_roll?"roll ":"", tune_pitch?"pitch ":"", tune_yaw?"yaw":"");
|
|
|
|
} else {
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "No axis selected for tuning!");
|
|
|
|
}
|
2014-04-12 01:12:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
called when exiting autotune
|
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
void Plane::autotune_restore(void)
|
2014-04-12 01:12:14 -03:00
|
|
|
{
|
|
|
|
rollController.autotune_restore();
|
|
|
|
pitchController.autotune_restore();
|
2021-11-25 04:42:08 -04:00
|
|
|
yawController.autotune_restore();
|
2023-01-26 16:59:58 -04:00
|
|
|
if (autotuning) {
|
|
|
|
autotuning = false;
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Stopped autotune");
|
|
|
|
}
|
2014-04-12 01:12:14 -03:00
|
|
|
}
|
2014-06-05 03:12:10 -03:00
|
|
|
|
2015-06-13 06:16:02 -03:00
|
|
|
/*
|
|
|
|
enable/disable autotune for AUTO modes
|
|
|
|
*/
|
|
|
|
void Plane::autotune_enable(bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
autotune_start();
|
|
|
|
} else {
|
|
|
|
autotune_restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 03:12:10 -03:00
|
|
|
/*
|
|
|
|
are we flying inverted?
|
|
|
|
*/
|
2015-05-13 03:09:36 -03:00
|
|
|
bool Plane::fly_inverted(void)
|
2014-06-05 03:12:10 -03:00
|
|
|
{
|
2019-01-15 13:46:13 -04:00
|
|
|
if (control_mode == &plane.mode_manual) {
|
2018-08-11 08:12:35 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (inverted_flight) {
|
|
|
|
// controlled with aux switch
|
2014-06-05 03:12:10 -03:00
|
|
|
return true;
|
|
|
|
}
|
2019-01-15 13:46:13 -04:00
|
|
|
if (control_mode == &mode_auto && auto_state.inverted_flight) {
|
2014-06-05 03:12:10 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|