123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #pragma once
- #include <AP_Common/AP_Common.h>
- #include <AP_Param/AP_Param.h>
- #include <AP_Mission/AP_Mission.h>
- #include <AP_RCMapper/AP_RCMapper.h>
- #include <inttypes.h>
- class AP_AdvancedFailsafe
- {
- public:
- enum control_mode {
- AFS_MANUAL = 0,
- AFS_STABILIZED = 1,
- AFS_AUTO = 2
- };
- enum state {
- STATE_PREFLIGHT = 0,
- STATE_AUTO = 1,
- STATE_DATA_LINK_LOSS = 2,
- STATE_GPS_LOSS = 3
- };
- enum terminate_action {
- TERMINATE_ACTION_TERMINATE = 42,
- TERMINATE_ACTION_LAND = 43
- };
-
- AP_AdvancedFailsafe(AP_Mission &_mission) :
- mission(_mission)
- {
- AP_Param::setup_object_defaults(this, var_info);
-
- _state = STATE_PREFLIGHT;
- _terminate.set(0);
-
- _saved_wp = 0;
- }
- bool enabled() { return _enable; }
-
- void check(uint32_t last_heartbeat_ms, bool geofence_breached, uint32_t last_valid_rc_ms);
-
-
- void heartbeat(void);
-
- bool should_crash_vehicle(void);
-
- bool gcs_terminate(bool should_terminate, const char *reason);
-
- virtual void terminate_vehicle(void) = 0;
-
- static const struct AP_Param::GroupInfo var_info[];
- bool terminating_vehicle_via_landing() const {
- return _terminate_action == TERMINATE_ACTION_LAND;
- };
- protected:
-
- virtual void setup_IO_failsafe(void) = 0;
-
- virtual enum control_mode afs_mode(void) = 0;
- enum state _state;
- AP_Mission &mission;
- AP_Int8 _enable;
-
- AP_Int8 _heartbeat_pin;
- AP_Int8 _manual_pin;
- AP_Int8 _terminate_pin;
- AP_Int8 _terminate;
- AP_Int8 _terminate_action;
-
- AP_Int8 _wp_comms_hold;
- AP_Int8 _wp_gps_loss;
- AP_Float _qnh_pressure;
- AP_Int32 _amsl_limit;
- AP_Int32 _amsl_margin_gps;
- AP_Float _rc_fail_time_seconds;
- AP_Int8 _max_gps_loss;
- AP_Int8 _max_comms_loss;
- AP_Int8 _enable_geofence_fs;
- AP_Int8 _enable_RC_fs;
- AP_Int8 _rc_term_manual_only;
- AP_Int8 _enable_dual_loss;
- AP_Int16 _max_range_km;
- bool _heartbeat_pin_value;
-
- uint8_t _saved_wp;
-
-
- uint8_t _gps_loss_count;
-
- uint8_t _comms_loss_count;
-
- uint32_t _last_comms_loss_ms;
-
- uint32_t _last_gps_loss_ms;
-
- bool _failsafe_setup:1;
- Location _first_location;
- bool _have_first_location;
- uint32_t _term_range_notice_ms;
- bool check_altlimit(void);
- private:
-
- void max_range_update();
- };
|