2017-02-26 19:18:38 -04:00
|
|
|
#include "Plane.h"
|
|
|
|
|
2020-09-23 05:16:45 -03:00
|
|
|
#if HAL_SOARING_ENABLED
|
2018-07-29 19:57:55 -03:00
|
|
|
|
2017-02-26 19:18:38 -04:00
|
|
|
/*
|
|
|
|
* ArduSoar support function
|
|
|
|
*
|
|
|
|
* Peter Braswell, Samuel Tabor, Andrey Kolobov, and Iain Guilliard
|
|
|
|
*/
|
|
|
|
void Plane::update_soaring() {
|
|
|
|
|
2019-07-15 07:27:29 -03:00
|
|
|
// Check if soaring is active. Also sets throttle suppressed
|
|
|
|
// status on active state changes.
|
2020-04-05 08:38:19 -03:00
|
|
|
plane.g2.soaring_controller.update_active_state();
|
|
|
|
|
|
|
|
if (!g2.soaring_controller.is_active()) {
|
2017-02-26 19:18:38 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g2.soaring_controller.update_vario();
|
|
|
|
|
|
|
|
// Check for throttle suppression change.
|
2019-01-15 13:46:13 -04:00
|
|
|
switch (control_mode->mode_number()) {
|
|
|
|
case Mode::Number::AUTO:
|
|
|
|
case Mode::Number::FLY_BY_WIRE_B:
|
|
|
|
case Mode::Number::CRUISE:
|
2020-09-07 08:52:43 -03:00
|
|
|
g2.soaring_controller.suppress_throttle();
|
2017-02-26 19:18:38 -04:00
|
|
|
break;
|
2020-09-16 04:46:56 -03:00
|
|
|
case Mode::Number::THERMAL:
|
|
|
|
// Never use throttle in THERMAL with soaring active.
|
2018-10-18 09:51:21 -03:00
|
|
|
g2.soaring_controller.set_throttle_suppressed(true);
|
2017-02-26 19:18:38 -04:00
|
|
|
break;
|
|
|
|
default:
|
2018-10-18 09:51:21 -03:00
|
|
|
// In any other mode allow throttle.
|
|
|
|
g2.soaring_controller.set_throttle_suppressed(false);
|
2017-02-26 19:18:38 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing to do if we are in powered flight
|
|
|
|
if (!g2.soaring_controller.get_throttle_suppressed() && aparm.throttle_max > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
switch (control_mode->mode_number()) {
|
2019-06-05 15:24:17 -03:00
|
|
|
default:
|
|
|
|
// nothing to do
|
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::AUTO:
|
|
|
|
case Mode::Number::FLY_BY_WIRE_B:
|
|
|
|
case Mode::Number::CRUISE:
|
2017-02-26 19:18:38 -04:00
|
|
|
// Test for switch into thermalling mode
|
|
|
|
g2.soaring_controller.update_cruising();
|
|
|
|
|
|
|
|
if (g2.soaring_controller.check_thermal_criteria()) {
|
2020-09-16 04:46:56 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Soaring: Thermal detected, entering %s", mode_thermal.name());
|
|
|
|
set_mode(mode_thermal, ModeReason::SOARING_THERMAL_DETECTED);
|
2017-02-26 19:18:38 -04:00
|
|
|
}
|
2020-10-07 06:54:33 -03:00
|
|
|
break;
|
|
|
|
case Mode::Number::THERMAL:
|
|
|
|
// Update thermal mode soaring logic.
|
|
|
|
mode_thermal.update_soaring();
|
|
|
|
break;
|
2019-06-05 17:04:20 -03:00
|
|
|
} // switch control_mode
|
2020-06-26 14:04:19 -03:00
|
|
|
}
|
2019-06-05 15:24:17 -03:00
|
|
|
|
2018-07-29 19:57:55 -03:00
|
|
|
#endif // SOARING_ENABLED
|