2016-02-17 21:25:37 -04:00
|
|
|
#pragma once
|
2014-04-11 03:35:01 -03:00
|
|
|
|
2013-08-29 02:34:34 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-07-08 22:49:26 -03:00
|
|
|
/*
|
|
|
|
Outback Challenge Failsafe module
|
|
|
|
|
|
|
|
Andrew Tridgell and CanberraUAV, August 2012
|
|
|
|
*/
|
|
|
|
|
2023-02-06 01:39:02 -04:00
|
|
|
#include "AP_AdvancedFailsafe_config.h"
|
|
|
|
|
|
|
|
#if AP_ADVANCEDFAILSAFE_ENABLED
|
|
|
|
|
2015-08-11 03:28:41 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
2012-07-08 22:49:26 -03:00
|
|
|
#include <inttypes.h>
|
2021-07-30 09:25:40 -03:00
|
|
|
#include <AP_Common/Location.h>
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2016-07-22 04:35:45 -03:00
|
|
|
class AP_AdvancedFailsafe
|
2012-07-08 22:49:26 -03:00
|
|
|
{
|
|
|
|
public:
|
2014-06-01 21:47:02 -03:00
|
|
|
enum control_mode {
|
2016-07-22 05:14:30 -03:00
|
|
|
AFS_MANUAL = 0,
|
|
|
|
AFS_STABILIZED = 1,
|
|
|
|
AFS_AUTO = 2
|
2014-06-01 21:47:02 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum state {
|
|
|
|
STATE_PREFLIGHT = 0,
|
|
|
|
STATE_AUTO = 1,
|
|
|
|
STATE_DATA_LINK_LOSS = 2,
|
|
|
|
STATE_GPS_LOSS = 3
|
|
|
|
};
|
|
|
|
|
2017-08-30 16:31:31 -03:00
|
|
|
enum terminate_action {
|
|
|
|
TERMINATE_ACTION_TERMINATE = 42,
|
|
|
|
TERMINATE_ACTION_LAND = 43
|
|
|
|
};
|
|
|
|
|
2019-09-14 01:39:28 -03:00
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_AdvancedFailsafe);
|
2019-09-14 01:39:28 -03:00
|
|
|
|
2014-06-01 21:47:02 -03:00
|
|
|
// Constructor
|
2021-07-30 09:25:40 -03:00
|
|
|
AP_AdvancedFailsafe()
|
2014-04-11 03:35:01 -03:00
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
2019-09-14 01:39:28 -03:00
|
|
|
if (_singleton != nullptr) {
|
|
|
|
AP_HAL::panic("AP_Logger must be singleton");
|
|
|
|
}
|
|
|
|
|
|
|
|
_singleton = this;
|
2014-04-11 03:35:01 -03:00
|
|
|
_state = STATE_PREFLIGHT;
|
|
|
|
_terminate.set(0);
|
2019-09-14 01:39:28 -03:00
|
|
|
|
2014-04-11 03:35:01 -03:00
|
|
|
_saved_wp = 0;
|
|
|
|
}
|
|
|
|
|
2019-09-14 01:39:28 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_AdvancedFailsafe *get_singleton(void) {
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2018-03-28 22:31:23 -03:00
|
|
|
bool enabled() { return _enable; }
|
|
|
|
|
2014-09-23 22:03:19 -03:00
|
|
|
// check that everything is OK
|
2022-10-20 22:25:52 -03:00
|
|
|
void check(uint32_t last_valid_rc_ms);
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2014-09-23 22:03:19 -03:00
|
|
|
// generate heartbeat msgs, so external failsafe boards are happy
|
|
|
|
// during sensor calibration
|
|
|
|
void heartbeat(void);
|
|
|
|
|
2016-07-22 05:14:30 -03:00
|
|
|
// return true if we are terminating (deliberately crashing the vehicle)
|
|
|
|
bool should_crash_vehicle(void);
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2017-07-25 03:34:09 -03:00
|
|
|
// enables or disables a GCS based termination, returns true if AFS is in the desired termination state
|
2017-11-09 18:32:59 -04:00
|
|
|
bool gcs_terminate(bool should_terminate, const char *reason);
|
2017-07-25 03:34:09 -03:00
|
|
|
|
2016-07-22 05:14:30 -03:00
|
|
|
// called to set all outputs to termination state
|
|
|
|
virtual void terminate_vehicle(void) = 0;
|
2017-07-19 03:12:12 -03:00
|
|
|
|
|
|
|
// for holding parameters
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2018-09-29 04:34:36 -03:00
|
|
|
|
|
|
|
bool terminating_vehicle_via_landing() const {
|
|
|
|
return _terminate_action == TERMINATE_ACTION_LAND;
|
|
|
|
};
|
|
|
|
|
2016-07-22 05:14:30 -03:00
|
|
|
protected:
|
|
|
|
// setup failsafe values for if FMU firmware stops running
|
|
|
|
virtual void setup_IO_failsafe(void) = 0;
|
|
|
|
|
|
|
|
// return the AFS mapped control mode
|
|
|
|
virtual enum control_mode afs_mode(void) = 0;
|
|
|
|
|
2023-09-07 15:01:23 -03:00
|
|
|
//to force entering auto mode when datalink loss
|
|
|
|
virtual void set_mode_auto(void) = 0;
|
|
|
|
|
2014-06-01 21:47:02 -03:00
|
|
|
enum state _state;
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2014-08-08 00:30:00 -03:00
|
|
|
AP_Int8 _enable;
|
2014-06-01 21:47:02 -03:00
|
|
|
// digital output pins for communicating with the failsafe board
|
|
|
|
AP_Int8 _heartbeat_pin;
|
|
|
|
AP_Int8 _manual_pin;
|
|
|
|
AP_Int8 _terminate_pin;
|
|
|
|
AP_Int8 _terminate;
|
|
|
|
AP_Int8 _terminate_action;
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2014-06-01 21:47:02 -03:00
|
|
|
// waypoint numbers to jump to on failsafe conditions
|
|
|
|
AP_Int8 _wp_comms_hold;
|
|
|
|
AP_Int8 _wp_gps_loss;
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2014-04-11 03:35:01 -03:00
|
|
|
AP_Float _qnh_pressure;
|
|
|
|
AP_Int32 _amsl_limit;
|
|
|
|
AP_Int32 _amsl_margin_gps;
|
2016-04-22 20:03:46 -03:00
|
|
|
AP_Float _rc_fail_time_seconds;
|
2023-09-12 05:51:49 -03:00
|
|
|
AP_Float _gcs_fail_time_seconds;
|
2014-08-17 05:06:42 -03:00
|
|
|
AP_Int8 _max_gps_loss;
|
|
|
|
AP_Int8 _max_comms_loss;
|
2016-03-21 16:44:48 -03:00
|
|
|
AP_Int8 _enable_geofence_fs;
|
|
|
|
AP_Int8 _enable_RC_fs;
|
|
|
|
AP_Int8 _rc_term_manual_only;
|
|
|
|
AP_Int8 _enable_dual_loss;
|
2019-08-21 02:58:41 -03:00
|
|
|
AP_Int16 _max_range_km;
|
2014-04-11 03:35:01 -03:00
|
|
|
|
2014-06-01 21:47:02 -03:00
|
|
|
bool _heartbeat_pin_value;
|
2012-07-08 22:49:26 -03:00
|
|
|
|
2014-06-01 21:47:02 -03:00
|
|
|
// saved waypoint for resuming mission
|
|
|
|
uint8_t _saved_wp;
|
2014-08-17 05:06:42 -03:00
|
|
|
|
|
|
|
// number of times we've lost GPS
|
|
|
|
uint8_t _gps_loss_count;
|
|
|
|
|
|
|
|
// number of times we've lost data link
|
|
|
|
uint8_t _comms_loss_count;
|
|
|
|
|
|
|
|
// last comms loss time
|
|
|
|
uint32_t _last_comms_loss_ms;
|
|
|
|
|
|
|
|
// last GPS loss time
|
|
|
|
uint32_t _last_gps_loss_ms;
|
2014-04-11 03:35:01 -03:00
|
|
|
|
2014-04-20 21:35:39 -03:00
|
|
|
// have the failsafe values been setup?
|
|
|
|
bool _failsafe_setup:1;
|
|
|
|
|
2019-08-21 02:58:41 -03:00
|
|
|
Location _first_location;
|
|
|
|
bool _have_first_location;
|
|
|
|
uint32_t _term_range_notice_ms;
|
|
|
|
|
2014-06-01 21:47:02 -03:00
|
|
|
bool check_altlimit(void);
|
2019-08-21 02:58:41 -03:00
|
|
|
|
|
|
|
private:
|
2019-09-14 01:39:28 -03:00
|
|
|
static AP_AdvancedFailsafe *_singleton;
|
|
|
|
|
2019-08-21 02:58:41 -03:00
|
|
|
// update maximum range check
|
|
|
|
void max_range_update();
|
2023-09-04 05:29:57 -03:00
|
|
|
|
|
|
|
AP_Int16 options;
|
|
|
|
enum class Option {
|
|
|
|
CONTINUE_AFTER_RECOVERED = (1U<<0),
|
2023-09-07 15:01:23 -03:00
|
|
|
GCS_FS_ALL_AUTONOMOUS_MODES = (1U<<1),
|
2023-09-04 05:29:57 -03:00
|
|
|
};
|
|
|
|
bool option_is_set(Option option) const {
|
|
|
|
return (options.get() & int16_t(option)) != 0;
|
|
|
|
}
|
2012-07-08 22:49:26 -03:00
|
|
|
};
|
2019-09-14 01:39:28 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_AdvancedFailsafe *advancedfailsafe();
|
|
|
|
};
|
2023-02-06 01:39:02 -04:00
|
|
|
|
|
|
|
#endif // AP_ADVANCEDFAILSAFE_ENABLED
|