Browse Source

Plane: Use const method on modes classes to mark those that support auto switch to THERMAL mode.

c415-sdk
Samuel Tabor 4 years ago committed by Andrew Tridgell
parent
commit
a8549f5e5f
  1. 9
      ArduPlane/mode.h
  2. 28
      ArduPlane/soaring.cpp

9
ArduPlane/mode.h

@ -80,6 +80,9 @@ public: @@ -80,6 +80,9 @@ public:
// true if mode can have terrain following disabled by switch
virtual bool allows_terrain_disable() const { return false; }
// true if automatic switch to thermal mode is supported.
virtual bool does_automatic_thermal_switch() const {return false; }
// subclasses override this if they require navigation.
virtual void navigate() { return; }
@ -129,6 +132,8 @@ public: @@ -129,6 +132,8 @@ public:
const char *name() const override { return "AUTO"; }
const char *name4() const override { return "AUTO"; }
bool does_automatic_thermal_switch() const override { return true; }
// methods that affect movement of the vehicle in this mode
void update() override;
@ -341,6 +346,8 @@ public: @@ -341,6 +346,8 @@ public:
bool allows_terrain_disable() const override { return true; }
bool does_automatic_thermal_switch() const override { return true; }
// methods that affect movement of the vehicle in this mode
void update() override;
@ -361,6 +368,8 @@ public: @@ -361,6 +368,8 @@ public:
bool allows_terrain_disable() const override { return true; }
bool does_automatic_thermal_switch() const override { return true; }
// methods that affect movement of the vehicle in this mode
void update() override;

28
ArduPlane/soaring.cpp

@ -20,20 +20,16 @@ void Plane::update_soaring() { @@ -20,20 +20,16 @@ void Plane::update_soaring() {
g2.soaring_controller.update_vario();
// Check for throttle suppression change.
switch (control_mode->mode_number()) {
case Mode::Number::AUTO:
case Mode::Number::FLY_BY_WIRE_B:
case Mode::Number::CRUISE:
if (control_mode->does_automatic_thermal_switch()) {
g2.soaring_controller.suppress_throttle();
break;
case Mode::Number::THERMAL:
}
else if (control_mode == &mode_thermal) {
// Never use throttle in THERMAL with soaring active.
g2.soaring_controller.set_throttle_suppressed(true);
break;
default:
}
else {
// In any other mode allow throttle.
g2.soaring_controller.set_throttle_suppressed(false);
break;
}
// Nothing to do if we are in powered flight
@ -41,13 +37,7 @@ void Plane::update_soaring() { @@ -41,13 +37,7 @@ void Plane::update_soaring() {
return;
}
switch (control_mode->mode_number()) {
default:
// nothing to do
break;
case Mode::Number::AUTO:
case Mode::Number::FLY_BY_WIRE_B:
case Mode::Number::CRUISE:
if (control_mode->does_automatic_thermal_switch()) {
// Test for switch into thermalling mode
g2.soaring_controller.update_cruising();
@ -55,12 +45,10 @@ void Plane::update_soaring() { @@ -55,12 +45,10 @@ void Plane::update_soaring() {
gcs().send_text(MAV_SEVERITY_INFO, "Soaring: Thermal detected, entering %s", mode_thermal.name());
set_mode(mode_thermal, ModeReason::SOARING_THERMAL_DETECTED);
}
break;
case Mode::Number::THERMAL:
} else if (control_mode == &mode_thermal) {
// Update thermal mode soaring logic.
mode_thermal.update_soaring();
break;
} // switch control_mode
}
}
#endif // SOARING_ENABLED

Loading…
Cancel
Save