Copter: add allows_flip function to Mode class

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

View File

@ -62,6 +62,7 @@ public:
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; } virtual bool allows_autotune() const { return false; }
virtual bool allows_flip() 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;
@ -278,6 +279,7 @@ public:
// whether an air-mode aux switch has been toggled // whether an air-mode aux switch has been toggled
void air_mode_aux_changed(); void air_mode_aux_changed();
bool allows_save_trim() const override { return true; } bool allows_save_trim() const override { return true; }
bool allows_flip() const override { return true; }
protected: protected:
@ -328,6 +330,7 @@ public:
return !must_navigate; return !must_navigate;
} }
bool allows_autotune() const override { return true; } bool allows_autotune() const override { return true; }
bool allows_flip() const override { return true; }
protected: protected:
@ -723,6 +726,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_flip() const override { return true; }
static const struct AP_Param::GroupInfo var_info[]; static const struct AP_Param::GroupInfo var_info[];
@ -1244,6 +1248,7 @@ public:
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; } bool allows_autotune() const override { return true; }
bool allows_flip() const override { return true; }
protected: protected:

View File

@ -35,11 +35,8 @@
// flip_init - initialise flip controller // flip_init - initialise flip controller
bool ModeFlip::init(bool ignore_checks) bool ModeFlip::init(bool ignore_checks)
{ {
// only allow flip from ACRO, Stabilize, AltHold or Drift flight modes // only allow flip from some flight modes, for example ACRO, Stabilize, AltHold or FlowHold flight modes
if (copter.flightmode != &copter.mode_acro && if (!copter.flightmode->allows_flip()) {
copter.flightmode != &copter.mode_stabilize &&
copter.flightmode != &copter.mode_althold &&
copter.flightmode != &copter.mode_flowhold) {
return false; return false;
} }