AP_Soaring: Detect changes in active parameter/switch position.

This commit is contained in:
Samuel Tabor 2019-07-15 11:27:29 +01:00 committed by Andrew Tridgell
parent fdf7eae01c
commit 2260fda4ec
4 changed files with 29 additions and 4 deletions

View File

@ -265,7 +265,7 @@ int16_t GCS_MAVLINK_Plane::vfr_hud_throttle() const
float GCS_MAVLINK_Plane::vfr_hud_climbrate() const
{
#if SOARING_ENABLED == ENABLED
if (plane.g2.soaring_controller.is_active()) {
if (plane.g2.soaring_controller.update_active_state()) {
return plane.g2.soaring_controller.get_vario_reading();
}
#endif

View File

@ -9,9 +9,9 @@
*/
void Plane::update_soaring() {
if (!g2.soaring_controller.is_active()) {
// This also sets the TECS gliding_requested to false.
g2.soaring_controller.set_throttle_suppressed(false);
// Check if soaring is active. Also sets throttle suppressed
// status on active state changes.
if (!g2.soaring_controller.update_active_state()) {
return;
}

View File

@ -355,6 +355,27 @@ bool SoaringController::is_active() const
return RC_Channels::get_radio_in(soar_active_ch-1) >= 1400;
}
bool SoaringController::update_active_state()
{
bool active = is_active();
bool state_changed = !(active == _last_update_active);
if (state_changed) {
if (active) {
// It's active, but wasn't on the last loop.
set_throttle_suppressed(true);
} else {
// It's not active, but was active on the last loop.
set_throttle_suppressed(false);
}
}
_last_update_active = active;
return active;
}
void SoaringController::set_throttle_suppressed(bool suppressed)
{
_throttle_suppressed = suppressed;

View File

@ -52,6 +52,8 @@ class SoaringController {
float _thermalability;
float _expected_sink;
bool _last_update_active;
protected:
AP_Int8 soar_active;
AP_Int8 soar_active_ch;
@ -112,6 +114,8 @@ public:
bool check_drift(Vector2f prev_wp, Vector2f next_wp);
bool update_active_state();
private:
// slow down messages if they are the same. During loiter we could smap the same message. Only show new messages during loiters
LoiterStatus _cruise_criteria_msg_last;