ardupilot/libraries/AP_Arming/AP_Arming.h

167 lines
5.0 KiB
C
Raw Normal View History

#pragma once
#include <AP_HAL/AP_HAL.h>
#include <AP_Param/AP_Param.h>
#include <AP_InertialSensor/AP_InertialSensor.h>
#include <RC_Channel/RC_Channel.h>
class AP_Arming {
public:
2018-06-25 00:42:39 -03:00
AP_Arming();
/* Do not allow copies */
AP_Arming(const AP_Arming &other) = delete;
AP_Arming &operator=(const AP_Arming&) = delete;
2019-05-06 00:33:15 -03:00
static AP_Arming *get_singleton();
enum ArmingChecks {
2019-04-10 04:32:30 -03:00
ARMING_CHECK_ALL = (1U << 0),
ARMING_CHECK_BARO = (1U << 1),
ARMING_CHECK_COMPASS = (1U << 2),
ARMING_CHECK_GPS = (1U << 3),
ARMING_CHECK_INS = (1U << 4),
ARMING_CHECK_PARAMETERS = (1U << 5),
ARMING_CHECK_RC = (1U << 6),
ARMING_CHECK_VOLTAGE = (1U << 7),
ARMING_CHECK_BATTERY = (1U << 8),
ARMING_CHECK_AIRSPEED = (1U << 9),
ARMING_CHECK_LOGGING = (1U << 10),
ARMING_CHECK_SWITCH = (1U << 11),
ARMING_CHECK_GPS_CONFIG = (1U << 12),
ARMING_CHECK_SYSTEM = (1U << 13),
ARMING_CHECK_MISSION = (1U << 14),
ARMING_CHECK_RANGEFINDER = (1U << 15),
};
enum class Method {
RUDDER,
MAVLINK,
AUXSWITCH,
MOTORTEST,
2019-07-22 20:34:25 -03:00
SCRIPTING,
};
enum class Required {
2013-12-19 20:59:05 -04:00
NO = 0,
YES_MIN_PWM = 1,
YES_ZERO_PWM = 2
};
2019-04-10 04:32:30 -03:00
void init(void);
// these functions should not be used by Copter which holds the armed state in the motors library
Required arming_required();
virtual bool arm(AP_Arming::Method method, bool do_arming_checks=true);
virtual bool disarm();
2013-12-11 01:09:11 -04:00
bool is_armed();
// get bitmask of enabled checks
2013-12-11 01:09:11 -04:00
uint16_t get_enabled_checks();
// pre_arm_checks() is virtual so it can be modified in a vehicle specific subclass
virtual bool pre_arm_checks(bool report);
// some arming checks have side-effects, or require some form of state
// change to have occurred, and thus should not be done as pre-arm
// checks. Those go here:
virtual bool arm_checks(AP_Arming::Method method);
// get expected magnetic field strength
uint16_t compass_magfield_expected() const;
2018-09-08 00:30:21 -03:00
// rudder arming support
enum class RudderArming {
IS_DISABLED = 0, // DISABLED leaks in from vehicle defines.h
ARMONLY = 1,
ARMDISARM = 2
2018-09-08 00:30:21 -03:00
};
RudderArming get_rudder_arming_type() const { return (RudderArming)_rudder_arming.get(); }
2018-09-08 00:30:21 -03:00
static const struct AP_Param::GroupInfo var_info[];
protected:
2017-08-30 17:09:05 -03:00
2015-10-12 02:29:27 -03:00
// Parameters
AP_Int8 require;
2019-04-10 04:32:30 -03:00
AP_Int32 checks_to_perform; // bitmask for which checks are required
AP_Float accel_error_threshold;
2018-09-08 00:30:21 -03:00
AP_Int8 _rudder_arming;
AP_Int32 _required_mission_items;
2015-10-12 02:29:27 -03:00
// internal members
bool armed;
2015-10-12 02:29:27 -03:00
uint32_t last_accel_pass_ms[INS_MAX_INSTANCES];
uint32_t last_gyro_pass_ms[INS_MAX_INSTANCES];
virtual bool barometer_checks(bool report);
bool airspeed_checks(bool report);
bool logging_checks(bool report);
2015-10-16 00:51:46 -03:00
virtual bool ins_checks(bool report);
virtual bool compass_checks(bool report);
virtual bool gps_checks(bool report);
bool battery_checks(bool report);
bool hardware_safety_check(bool report);
virtual bool board_voltage_checks(bool report);
2015-10-16 00:13:53 -03:00
virtual bool rc_calibration_checks(bool report);
bool manual_transmitter_checks(bool report);
bool mission_checks(bool report);
2019-04-10 04:32:30 -03:00
bool rangefinder_checks(bool report);
2019-03-05 19:09:55 -04:00
bool fence_checks(bool report);
virtual bool system_checks(bool report);
2018-08-11 11:09:57 -03:00
bool can_checks(bool report);
virtual bool proximity_checks(bool report) const;
bool servo_checks(bool report) const;
bool rc_checks_copter_sub(bool display_failure, const RC_Channel *channels[4]) const;
2017-08-01 00:09:27 -03:00
// returns true if a particular check is enabled
bool check_enabled(const enum AP_Arming::ArmingChecks check) const;
// returns a mavlink severity which should be used if a specific check fails
MAV_SEVERITY check_severity(const enum AP_Arming::ArmingChecks check) const;
// handle the case where a check fails
void check_failed(const enum AP_Arming::ArmingChecks check, bool report, const char *fmt, ...) const FMT_PRINTF(4, 5);
void check_failed(bool report, const char *fmt, ...) const FMT_PRINTF(3, 4);
2017-08-01 00:09:27 -03:00
void Log_Write_Arm_Disarm();
private:
2019-05-06 00:33:15 -03:00
static AP_Arming *_singleton;
bool ins_accels_consistent(const AP_InertialSensor &ins);
bool ins_gyros_consistent(const AP_InertialSensor &ins);
enum MIS_ITEM_CHECK {
MIS_ITEM_CHECK_LAND = (1 << 0),
MIS_ITEM_CHECK_VTOL_LAND = (1 << 1),
MIS_ITEM_CHECK_DO_LAND_START = (1 << 2),
MIS_ITEM_CHECK_TAKEOFF = (1 << 3),
MIS_ITEM_CHECK_VTOL_TAKEOFF = (1 << 4),
MIS_ITEM_CHECK_RALLY = (1 << 5),
MIS_ITEM_CHECK_MAX
};
};
2019-05-06 00:33:15 -03:00
namespace AP {
AP_Arming &arming();
};