Copter: add allows_autotune function to Mode class

This commit is contained in:
Tatsuya Yamaguchi 2020-02-11 11:06:57 +09:00 committed by Peter Barker
parent 2b89ac625f
commit f4eed612d7
2 changed files with 7 additions and 5 deletions

View File

@ -61,6 +61,7 @@ public:
virtual bool in_guided_mode() const { return false; } virtual bool in_guided_mode() const { return false; }
virtual bool logs_attitude() const { return false; } virtual bool logs_attitude() const { return false; }
virtual bool allows_save_trim() const { return false; } virtual bool allows_save_trim() const { return false; }
virtual bool allows_autotune() const { return false; }
// return a string for this flightmode // return a string for this flightmode
virtual const char *name() const = 0; virtual const char *name() const = 0;
@ -326,6 +327,7 @@ public:
bool has_user_takeoff(bool must_navigate) const override { bool has_user_takeoff(bool must_navigate) const override {
return !must_navigate; return !must_navigate;
} }
bool allows_autotune() const override { return true; }
protected: protected:
@ -933,6 +935,7 @@ public:
bool allows_arming(bool from_gcs) const override { return true; }; bool allows_arming(bool from_gcs) const override { return true; };
bool is_autopilot() const override { return false; } bool is_autopilot() const override { return false; }
bool has_user_takeoff(bool must_navigate) const override { return true; } bool has_user_takeoff(bool must_navigate) const override { return true; }
bool allows_autotune() const override { return true; }
#if PRECISION_LANDING == ENABLED #if PRECISION_LANDING == ENABLED
void set_precision_loiter_enabled(bool value) { _precision_loiter_enabled = value; } void set_precision_loiter_enabled(bool value) { _precision_loiter_enabled = value; }
@ -975,6 +978,7 @@ public:
bool allows_arming(bool from_gcs) const override { return true; }; bool allows_arming(bool from_gcs) const override { return true; };
bool is_autopilot() const override { return false; } bool is_autopilot() const override { return false; }
bool has_user_takeoff(bool must_navigate) const override { return true; } bool has_user_takeoff(bool must_navigate) const override { return true; }
bool allows_autotune() const override { return true; }
protected: protected:
@ -1239,6 +1243,7 @@ public:
bool allows_arming(bool from_gcs) const override { return true; }; bool allows_arming(bool from_gcs) const override { return true; };
bool is_autopilot() const override { return false; } bool is_autopilot() const override { return false; }
bool allows_save_trim() const override { return true; } bool allows_save_trim() const override { return true; }
bool allows_autotune() const override { return true; }
protected: protected:

View File

@ -23,11 +23,8 @@ bool AutoTune::init()
*/ */
bool AutoTune::start() bool AutoTune::start()
{ {
// only allow flip from Stabilize, AltHold, PosHold or Loiter modes // only allow AutoTune from some flight modes, for example Stabilize, AltHold, PosHold or Loiter modes
if (copter.flightmode != &copter.mode_stabilize && if (!copter.flightmode->allows_autotune()) {
copter.flightmode != &copter.mode_althold &&
copter.flightmode != &copter.mode_loiter &&
copter.flightmode != &copter.mode_poshold) {
return false; return false;
} }