Copter: make requires_terrain a callback on the flightmode

This will prompt new modes to consider whether failsafe should be active
for terrain.
This commit is contained in:
Peter Barker 2019-09-09 09:08:02 +10:00 committed by Randy Mackay
parent 8bd4f2b097
commit 72e6446204
2 changed files with 11 additions and 6 deletions

View File

@ -216,13 +216,9 @@ void Copter::failsafe_gcs_off_event(void)
// executes terrain failsafe if data is missing for longer than a few seconds
void Copter::failsafe_terrain_check()
{
// trigger with 5 seconds of failures while in AUTO mode
bool valid_mode = (control_mode == Mode::Number::AUTO ||
control_mode == Mode::Number::GUIDED ||
control_mode == Mode::Number::GUIDED_NOGPS ||
control_mode == Mode::Number::RTL);
// trigger within <n> milliseconds of failures while in various modes
bool timeout = (failsafe.terrain_last_failure_ms - failsafe.terrain_first_failure_ms) > FS_TERRAIN_TIMEOUT_MS;
bool trigger_event = valid_mode && timeout;
bool trigger_event = timeout && flightmode->requires_terrain_failsafe();
// check for clearing of event
if (trigger_event != failsafe.terrain) {

View File

@ -69,6 +69,9 @@ public:
virtual bool landing_gear_should_be_deployed() const { return false; }
virtual bool is_landing() const { return false; }
// mode requires terrain to be present to be functional
virtual bool requires_terrain_failsafe() const { return false; }
// functions for reporting to GCS
virtual bool get_wp(Location &loc) { return false; };
virtual int32_t wp_bearing() const { return 0; }
@ -363,6 +366,8 @@ public:
bool is_taking_off() const override;
bool requires_terrain_failsafe() const override { return true; }
// return true if this flight mode supports user takeoff
// must_nagivate is true if mode must also control horizontal position
virtual bool has_user_takeoff(bool must_navigate) const override { return false; }
@ -776,6 +781,8 @@ public:
bool has_user_takeoff(bool must_navigate) const override { return true; }
bool in_guided_mode() const override { return true; }
bool requires_terrain_failsafe() const override { return true; }
void set_angle(const Quaternion &q, float climb_rate_cms, bool use_yaw_rate, float yaw_rate_rads);
bool set_destination(const Vector3f& destination, bool use_yaw = false, float yaw_cd = 0.0, bool use_yaw_rate = false, float yaw_rate_cds = 0.0, bool yaw_relative = false);
bool set_destination(const Location& dest_loc, bool use_yaw = false, float yaw_cd = 0.0, bool use_yaw_rate = false, float yaw_rate_cds = 0.0, bool yaw_relative = false);
@ -1016,6 +1023,8 @@ public:
bool allows_arming(bool from_gcs) const override { return false; };
bool is_autopilot() const override { return true; }
bool requires_terrain_failsafe() const override { return true; }
// for reporting to GCS
bool get_wp(Location &loc) override;