2015-12-22 19:12:15 -04:00
|
|
|
#include "Copter.h"
|
|
|
|
|
2020-05-31 08:47:48 -03:00
|
|
|
#if HAL_MAX_CAN_PROTOCOL_DRIVERS
|
2019-10-30 22:40:10 -03:00
|
|
|
#include <AP_ToshibaCAN/AP_ToshibaCAN.h>
|
|
|
|
#endif
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// performs pre-arm checks. expects to be called at 1hz.
|
2017-01-09 03:45:48 -04:00
|
|
|
void AP_Arming_Copter::update(void)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
|
|
|
// perform pre-arm checks & display failures every 30 seconds
|
|
|
|
static uint8_t pre_arm_display_counter = PREARM_DISPLAY_PERIOD/2;
|
|
|
|
pre_arm_display_counter++;
|
|
|
|
bool display_fail = false;
|
|
|
|
if (pre_arm_display_counter >= PREARM_DISPLAY_PERIOD) {
|
|
|
|
display_fail = true;
|
|
|
|
pre_arm_display_counter = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-05 22:39:57 -03:00
|
|
|
pre_arm_checks(display_fail);
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2019-05-05 22:39:57 -03:00
|
|
|
bool AP_Arming_Copter::pre_arm_checks(bool display_failure)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
2019-05-05 22:39:57 -03:00
|
|
|
const bool passed = run_pre_arm_checks(display_failure);
|
|
|
|
set_pre_arm_check(passed);
|
|
|
|
return passed;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2017-09-03 23:10:14 -03:00
|
|
|
// perform pre-arm checks
|
2015-12-22 19:12:15 -04:00
|
|
|
// return true if the checks pass successfully
|
2019-05-05 22:39:57 -03:00
|
|
|
bool AP_Arming_Copter::run_pre_arm_checks(bool display_failure)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
|
|
|
// exit immediately if already armed
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.motors->armed()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if motor interlock and Emergency Stop aux switches are used
|
|
|
|
// at the same time. This cannot be allowed.
|
2019-04-03 13:25:47 -03:00
|
|
|
if (rc().find_channel_for_option(RC_Channel::AUX_FUNC::MOTOR_INTERLOCK) &&
|
|
|
|
rc().find_channel_for_option(RC_Channel::AUX_FUNC::MOTOR_ESTOP)){
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(display_failure, "Interlock/E-Stop Conflict");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if motor interlock aux switch is in use
|
|
|
|
// if it is, switch needs to be in disabled position to arm
|
|
|
|
// otherwise exit immediately. This check to be repeated,
|
|
|
|
// as state can change at any time.
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.ap.using_interlock && copter.ap.motor_interlock_switch) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(display_failure, "Motor Interlock Enabled");
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:54:06 -04:00
|
|
|
// if pre arm checks are disabled run only the mandatory checks
|
2019-10-04 18:51:22 -03:00
|
|
|
if (checks_to_perform == 0) {
|
2019-11-29 00:54:06 -04:00
|
|
|
return mandatory_checks(display_failure);
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2021-02-19 08:23:07 -04:00
|
|
|
return parameter_checks(display_failure)
|
2016-12-13 22:30:36 -04:00
|
|
|
& motor_checks(display_failure)
|
2019-06-05 07:47:32 -03:00
|
|
|
& pilot_throttle_checks(display_failure)
|
2020-01-15 18:30:46 -04:00
|
|
|
& oa_checks(display_failure)
|
2020-07-24 05:38:42 -03:00
|
|
|
& gcs_failsafe_check(display_failure)
|
|
|
|
& winch_checks(display_failure)
|
2020-08-18 03:07:21 -03:00
|
|
|
& alt_checks(display_failure)
|
2020-07-24 05:38:42 -03:00
|
|
|
& AP_Arming::pre_arm_checks(display_failure);
|
2016-08-15 09:02:48 -03:00
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::barometer_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2017-07-15 04:22:26 -03:00
|
|
|
if (!AP_Arming::barometer_checks(display_failure)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = true;
|
2015-12-22 19:12:15 -04:00
|
|
|
// check Baro
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_BARO)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
// Check baro & inav alt are within 1m if EKF is operating in an absolute position mode.
|
|
|
|
// Do not check if intending to operate in a ground relative height mode as EKF will output a ground relative height
|
|
|
|
// that may differ from the baro height due to baro drift.
|
2018-06-25 00:42:17 -03:00
|
|
|
nav_filter_status filt_status = copter.inertial_nav.get_filter_status();
|
2015-12-22 19:12:15 -04:00
|
|
|
bool using_baro_ref = (!filt_status.flags.pred_horiz_pos_rel && filt_status.flags.pred_horiz_pos_abs);
|
|
|
|
if (using_baro_ref) {
|
2018-06-25 00:42:17 -03:00
|
|
|
if (fabsf(copter.inertial_nav.get_altitude() - copter.baro_alt) > PREARM_MAX_ALT_DISPARITY_CM) {
|
2017-08-09 08:36:19 -03:00
|
|
|
check_failed(ARMING_CHECK_BARO, display_failure, "Altitude disparity");
|
2017-07-15 04:22:26 -03:00
|
|
|
ret = false;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-15 04:22:26 -03:00
|
|
|
return ret;
|
2016-08-15 09:02:48 -03:00
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::compass_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2016-08-17 08:21:05 -03:00
|
|
|
bool ret = AP_Arming::compass_checks(display_failure);
|
2015-12-29 00:40:04 -04:00
|
|
|
|
2016-08-17 08:21:05 -03:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_COMPASS)) {
|
|
|
|
// check compass offsets have been set. AP_Arming only checks
|
|
|
|
// this if learning is off; Copter *always* checks.
|
2019-11-20 01:06:54 -04:00
|
|
|
char failure_msg[50] = {};
|
|
|
|
if (!AP::compass().configured(failure_msg, ARRAY_SIZE(failure_msg))) {
|
|
|
|
check_failed(ARMING_CHECK_COMPASS, display_failure, "%s", failure_msg);
|
2016-08-17 08:21:05 -03:00
|
|
|
ret = false;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 08:21:05 -03:00
|
|
|
return ret;
|
2016-08-15 09:02:48 -03:00
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::ins_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2016-08-17 00:14:56 -03:00
|
|
|
bool ret = AP_Arming::ins_checks(display_failure);
|
2016-07-27 22:22:39 -03:00
|
|
|
|
2016-08-17 00:14:56 -03:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_INS)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
|
|
|
|
// get ekf attitude (if bad, it's usually the gyro biases)
|
|
|
|
if (!pre_arm_ekf_attitude_check()) {
|
2018-10-02 19:25:54 -03:00
|
|
|
check_failed(ARMING_CHECK_INS, display_failure, "EKF attitude is bad");
|
2016-08-17 00:14:56 -03:00
|
|
|
ret = false;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
2016-08-17 00:14:56 -03:00
|
|
|
|
|
|
|
return ret;
|
2016-08-15 09:02:48 -03:00
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::board_voltage_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2017-07-15 04:39:15 -03:00
|
|
|
if (!AP_Arming::board_voltage_checks(display_failure)) {
|
|
|
|
return false;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// check battery voltage
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_VOLTAGE)) {
|
2018-02-28 19:32:16 -04:00
|
|
|
if (copter.battery.has_failsafed()) {
|
2017-08-09 08:36:19 -03:00
|
|
|
check_failed(ARMING_CHECK_VOLTAGE, display_failure, "Battery failsafe");
|
2017-07-26 07:36:57 -03:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2016-08-15 09:02:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::parameter_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2015-12-22 19:12:15 -04:00
|
|
|
// check various parameter values
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_PARAMETERS)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
|
|
|
|
// failsafe parameter checks
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.g.failsafe_throttle) {
|
2015-12-22 19:12:15 -04:00
|
|
|
// check throttle min is above throttle failsafe trigger and that the trigger is above ppm encoder's loss-of-signal value of 900
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.channel_throttle->get_radio_min() <= copter.g.failsafe_throttle_value+10 || copter.g.failsafe_throttle_value < 910) {
|
2017-08-09 08:36:19 -03:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Check FS_THR_VALUE");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-08 01:07:41 -04:00
|
|
|
if (copter.g.failsafe_gcs == FS_GCS_ENABLED_CONTINUE_MISSION) {
|
|
|
|
// FS_GCS_ENABLE == 2 has been removed
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "FS_GCS_ENABLE=2 removed, see FS_OPTIONS");
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
|
|
|
|
// lean angle parameter check
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.aparm.angle_max < 1000 || copter.aparm.angle_max > 8000) {
|
2017-08-09 08:36:19 -03:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Check ANGLE_MAX");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// acro balance parameter check
|
2018-03-19 08:40:33 -03:00
|
|
|
#if MODE_ACRO_ENABLED == ENABLED || MODE_SPORT_ENABLED == ENABLED
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((copter.g.acro_balance_roll > copter.attitude_control->get_angle_roll_p().kP()) || (copter.g.acro_balance_pitch > copter.attitude_control->get_angle_pitch_p().kP())) {
|
2020-02-15 11:55:42 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Check ACRO_BAL_ROLL/PITCH");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-14 17:14:49 -03:00
|
|
|
#endif
|
2015-12-22 19:12:15 -04:00
|
|
|
|
2019-10-02 05:41:02 -03:00
|
|
|
// pilot-speed-up parameter check
|
|
|
|
if (copter.g.pilot_speed_up <= 0) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Check PILOT_SPEED_UP");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
2019-07-03 07:27:26 -03:00
|
|
|
if (copter.g2.frame_class.get() != AP_Motors::MOTOR_FRAME_HELI_QUAD &&
|
|
|
|
copter.g2.frame_class.get() != AP_Motors::MOTOR_FRAME_HELI_DUAL &&
|
|
|
|
copter.g2.frame_class.get() != AP_Motors::MOTOR_FRAME_HELI) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Invalid Heli FRAME_CLASS");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// check helicopter parameters
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!copter.motors->parameter_check(display_failure)) {
|
2017-08-09 08:36:19 -03:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Heli motors checks failed");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-13 12:16:52 -04:00
|
|
|
|
|
|
|
char fail_msg[50];
|
|
|
|
// check input mangager parameters
|
|
|
|
if (!copter.input_manager.parameter_check(fail_msg, ARRAY_SIZE(fail_msg))) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "%s", fail_msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-12 23:42:38 -03:00
|
|
|
// Inverted flight feature disabled for Heli Single and Dual frames
|
2018-06-04 00:06:32 -03:00
|
|
|
if (copter.g2.frame_class.get() != AP_Motors::MOTOR_FRAME_HELI_QUAD &&
|
|
|
|
rc().find_channel_for_option(RC_Channel::aux_func_t::INVERTED) != nullptr) {
|
2019-03-05 18:33:29 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Inverted flight option not supported");
|
2018-05-12 23:42:38 -03:00
|
|
|
return false;
|
|
|
|
}
|
2019-01-26 10:33:32 -04:00
|
|
|
// Ensure an Aux Channel is configured for motor interlock
|
|
|
|
if (rc().find_channel_for_option(RC_Channel::aux_func_t::MOTOR_INTERLOCK) == nullptr) {
|
2019-03-05 18:33:29 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Motor Interlock not configured");
|
2019-01-26 10:33:32 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-03 07:27:26 -03:00
|
|
|
#else
|
|
|
|
if (copter.g2.frame_class.get() == AP_Motors::MOTOR_FRAME_HELI_QUAD ||
|
|
|
|
copter.g2.frame_class.get() == AP_Motors::MOTOR_FRAME_HELI_DUAL ||
|
|
|
|
copter.g2.frame_class.get() == AP_Motors::MOTOR_FRAME_HELI) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Invalid MultiCopter FRAME_CLASS");
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-29 21:04:00 -04:00
|
|
|
|
|
|
|
// checks MOT_PWM_MIN/MAX for acceptable values
|
|
|
|
if (!copter.motors->check_mot_pwm_params()) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Check MOT_PWM_MIN/MAX");
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
#endif // HELI_FRAME
|
2016-03-19 03:26:10 -03:00
|
|
|
|
2019-12-11 23:36:49 -04:00
|
|
|
// checks when using range finder for RTL
|
2020-10-01 08:45:40 -03:00
|
|
|
#if MODE_RTL_ENABLED == ENABLED
|
2019-12-11 23:36:49 -04:00
|
|
|
if (copter.mode_rtl.get_alt_type() == ModeRTL::RTLAltType::RTL_ALTTYPE_TERRAIN) {
|
|
|
|
// get terrain source from wpnav
|
2021-02-02 23:07:23 -04:00
|
|
|
const char *failure_template = "RTL_ALT_TYPE is above-terrain but %s";
|
2019-12-11 23:36:49 -04:00
|
|
|
switch (copter.wp_nav->get_terrain_source()) {
|
|
|
|
case AC_WPNav::TerrainSource::TERRAIN_UNAVAILABLE:
|
2021-02-02 23:07:23 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, failure_template, "no terrain data");
|
2019-12-11 23:36:49 -04:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case AC_WPNav::TerrainSource::TERRAIN_FROM_RANGEFINDER:
|
|
|
|
if (!copter.rangefinder_state.enabled || !copter.rangefinder.has_orientation(ROTATION_PITCH_270)) {
|
2021-02-02 23:07:23 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, failure_template, "no rangefinder");
|
2019-12-11 23:36:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// check if RTL_ALT is higher than rangefinder's max range
|
|
|
|
if (copter.g.rtl_altitude > copter.rangefinder.max_distance_cm_orient(ROTATION_PITCH_270)) {
|
2021-02-02 23:07:23 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, failure_template, "RTL_ALT>RNGFND_MAX_CM");
|
2019-12-11 23:36:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AC_WPNav::TerrainSource::TERRAIN_FROM_TERRAINDATABASE:
|
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
|
|
|
if (!copter.terrain.enabled()) {
|
2021-02-02 23:07:23 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, failure_template, "terrain disabled");
|
2019-12-11 23:36:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// check terrain data is loaded
|
|
|
|
uint16_t terr_pending, terr_loaded;
|
|
|
|
copter.terrain.get_statistics(terr_pending, terr_loaded);
|
|
|
|
if (terr_pending != 0) {
|
2021-02-02 23:07:23 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, failure_template, "waiting for terrain data");
|
2019-12-11 23:36:49 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2021-02-02 23:07:23 -04:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, failure_template, "terrain disabled");
|
2019-12-11 23:36:49 -04:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2016-03-19 03:26:10 -03:00
|
|
|
}
|
2020-10-01 08:45:40 -03:00
|
|
|
#endif
|
2016-07-21 09:42:32 -03:00
|
|
|
|
|
|
|
// check adsb avoidance failsafe
|
2020-09-19 05:37:52 -03:00
|
|
|
#if HAL_ADSB_ENABLED
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.failsafe.adsb) {
|
2017-08-09 08:36:19 -03:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "ADSB threat detected");
|
2016-07-21 09:42:32 -03:00
|
|
|
return false;
|
|
|
|
}
|
2018-02-16 10:21:55 -04:00
|
|
|
#endif
|
2016-11-08 03:44:02 -04:00
|
|
|
|
2019-01-09 22:26:15 -04:00
|
|
|
// ensure controllers are OK with us arming:
|
|
|
|
char failure_msg[50];
|
|
|
|
if (!copter.pos_control->pre_arm_checks("PSC", failure_msg, ARRAY_SIZE(failure_msg))) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Bad parameter: %s", failure_msg);
|
2017-11-15 07:59:08 -04:00
|
|
|
return false;
|
2019-01-09 22:26:15 -04:00
|
|
|
}
|
|
|
|
if (!copter.attitude_control->pre_arm_checks("ATC", failure_msg, ARRAY_SIZE(failure_msg))) {
|
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Bad parameter: %s", failure_msg);
|
2017-11-15 07:59:08 -04:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2016-08-15 09:02:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-13 22:30:36 -04:00
|
|
|
// check motor setup was successful
|
2017-01-09 01:43:39 -04:00
|
|
|
bool AP_Arming_Copter::motor_checks(bool display_failure)
|
2016-12-13 22:30:36 -04:00
|
|
|
{
|
|
|
|
// check motors initialised correctly
|
2017-01-09 01:43:39 -04:00
|
|
|
if (!copter.motors->initialised_ok()) {
|
2020-02-15 11:55:42 -04:00
|
|
|
check_failed(display_failure, "Check firmware or FRAME_CLASS");
|
2016-12-13 22:30:36 -04:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-10 05:03:32 -03:00
|
|
|
|
2020-08-09 21:34:28 -03:00
|
|
|
// servo_test check
|
2020-08-03 23:38:55 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
2020-08-09 21:34:28 -03:00
|
|
|
if (copter.motors->servo_test_running()) {
|
2020-08-03 23:38:55 -03:00
|
|
|
check_failed(display_failure, "Servo Test is still running");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-19 22:04:02 -04:00
|
|
|
// further checks enabled with parameters
|
|
|
|
if (!check_enabled(ARMING_CHECK_PARAMETERS)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-10 05:03:32 -03:00
|
|
|
// if this is a multicopter using ToshibaCAN ESCs ensure MOT_PMW_MIN = 1000, MOT_PWM_MAX = 2000
|
2020-05-31 08:47:48 -03:00
|
|
|
#if HAL_MAX_CAN_PROTOCOL_DRIVERS && (FRAME_CONFIG != HELI_FRAME)
|
2019-08-10 05:03:32 -03:00
|
|
|
bool tcan_active = false;
|
2019-10-30 22:40:10 -03:00
|
|
|
uint8_t tcan_index = 0;
|
2019-08-10 05:03:32 -03:00
|
|
|
const uint8_t num_drivers = AP::can().get_num_drivers();
|
|
|
|
for (uint8_t i = 0; i < num_drivers; i++) {
|
2020-05-31 08:47:48 -03:00
|
|
|
if (AP::can().get_driver_type(i) == AP_CANManager::Driver_Type_ToshibaCAN) {
|
2019-08-10 05:03:32 -03:00
|
|
|
tcan_active = true;
|
2019-10-30 22:40:10 -03:00
|
|
|
tcan_index = i;
|
2019-08-10 05:03:32 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tcan_active) {
|
2019-11-19 22:04:02 -04:00
|
|
|
// check motor range parameters
|
2019-08-10 05:03:32 -03:00
|
|
|
if (copter.motors->get_pwm_output_min() != 1000) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(display_failure, "TCAN ESCs require MOT_PWM_MIN=1000");
|
2019-08-10 05:03:32 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (copter.motors->get_pwm_output_max() != 2000) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(display_failure, "TCAN ESCs require MOT_PWM_MAX=2000");
|
2019-08-10 05:03:32 -03:00
|
|
|
return false;
|
|
|
|
}
|
2019-10-30 22:40:10 -03:00
|
|
|
|
|
|
|
// check we have an ESC present for every SERVOx_FUNCTION = motorx
|
|
|
|
// find and report first missing ESC, extra ESCs are OK
|
|
|
|
AP_ToshibaCAN *tcan = AP_ToshibaCAN::get_tcan(tcan_index);
|
|
|
|
const uint16_t motors_mask = copter.motors->get_motor_mask();
|
|
|
|
const uint16_t esc_mask = tcan->get_present_mask();
|
|
|
|
uint8_t escs_missing = 0;
|
|
|
|
uint8_t first_missing = 0;
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
uint32_t bit = 1UL << i;
|
|
|
|
if (((motors_mask & bit) > 0) && ((esc_mask & bit) == 0)) {
|
|
|
|
escs_missing++;
|
|
|
|
if (first_missing == 0) {
|
|
|
|
first_missing = i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (escs_missing > 0) {
|
|
|
|
check_failed(display_failure, "TCAN missing %d escs, check #%d", (int)escs_missing, (int)first_missing);
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-10 05:03:32 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-13 22:30:36 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::pilot_throttle_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2015-12-22 19:12:15 -04:00
|
|
|
// check throttle is above failsafe throttle
|
|
|
|
// this is near the bottom to allow other failures to be displayed before checking pilot throttle
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_RC)) {
|
|
|
|
if (copter.g.failsafe_throttle != FS_THR_DISABLED && copter.channel_throttle->get_radio_in() < copter.g.failsafe_throttle_value) {
|
2017-08-09 08:36:19 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
const char *failmsg = "Collective below Failsafe";
|
|
|
|
#else
|
|
|
|
const char *failmsg = "Throttle below Failsafe";
|
|
|
|
#endif
|
2019-08-04 22:38:38 -03:00
|
|
|
check_failed(ARMING_CHECK_RC, display_failure, "%s", failmsg);
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-05 07:47:32 -03:00
|
|
|
bool AP_Arming_Copter::oa_checks(bool display_failure)
|
|
|
|
{
|
|
|
|
#if AC_OAPATHPLANNER_ENABLED == ENABLED
|
|
|
|
char failure_msg[50];
|
|
|
|
if (copter.g2.oa.pre_arm_check(failure_msg, ARRAY_SIZE(failure_msg))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// display failure
|
|
|
|
if (strlen(failure_msg) == 0) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(display_failure, "%s", "Check Object Avoidance");
|
2019-06-05 07:47:32 -03:00
|
|
|
} else {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(display_failure, "%s", failure_msg);
|
2019-06-05 07:47:32 -03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-20 03:24:33 -03:00
|
|
|
bool AP_Arming_Copter::rc_calibration_checks(bool display_failure)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
2017-01-19 22:04:22 -04:00
|
|
|
const RC_Channel *channels[] = {
|
|
|
|
copter.channel_roll,
|
|
|
|
copter.channel_pitch,
|
|
|
|
copter.channel_throttle,
|
|
|
|
copter.channel_yaw
|
|
|
|
};
|
2015-12-22 19:12:15 -04:00
|
|
|
|
2017-09-04 01:16:40 -03:00
|
|
|
copter.ap.pre_arm_rc_check = rc_checks_copter_sub(display_failure, channels)
|
|
|
|
& AP_Arming::rc_calibration_checks(display_failure);
|
|
|
|
|
2017-08-20 03:24:33 -03:00
|
|
|
return copter.ap.pre_arm_rc_check;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// performs pre_arm gps related checks and returns true if passed
|
2017-07-15 04:53:00 -03:00
|
|
|
bool AP_Arming_Copter::gps_checks(bool display_failure)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
2017-03-23 23:03:15 -03:00
|
|
|
// check if fence requires GPS
|
|
|
|
bool fence_requires_gps = false;
|
2015-12-22 19:12:15 -04:00
|
|
|
#if AC_FENCE == ENABLED
|
2017-03-23 23:03:15 -03:00
|
|
|
// if circular or polygon fence is enabled we need GPS
|
|
|
|
fence_requires_gps = (copter.fence.get_enabled_fences() & (AC_FENCE_TYPE_CIRCLE | AC_FENCE_TYPE_POLYGON)) > 0;
|
2015-12-22 19:12:15 -04:00
|
|
|
#endif
|
|
|
|
|
2021-03-03 04:50:09 -04:00
|
|
|
// check if flight mode requires GPS
|
|
|
|
bool mode_requires_gps = copter.flightmode->requires_GPS();
|
|
|
|
|
|
|
|
// call parent gps checks
|
|
|
|
if (mode_requires_gps || fence_requires_gps) {
|
|
|
|
if (!AP_Arming::gps_checks(display_failure)) {
|
|
|
|
AP_Notify::flags.pre_arm_gps_check = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// run mandatory gps checks first
|
|
|
|
if (!mandatory_gps_checks(display_failure)) {
|
|
|
|
AP_Notify::flags.pre_arm_gps_check = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// return true if GPS is not required
|
2017-03-23 23:03:15 -03:00
|
|
|
if (!mode_requires_gps && !fence_requires_gps) {
|
2015-12-22 19:12:15 -04:00
|
|
|
AP_Notify::flags.pre_arm_gps_check = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true immediately if gps check is disabled
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!(checks_to_perform == ARMING_CHECK_ALL || checks_to_perform & ARMING_CHECK_GPS)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
AP_Notify::flags.pre_arm_gps_check = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// warn about hdop separately - to prevent user confusion with no gps lock
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.gps.get_hdop() > copter.g.gps_hdop_good) {
|
2019-03-05 18:33:29 -04:00
|
|
|
check_failed(ARMING_CHECK_GPS, display_failure, "High GPS HDOP");
|
2019-11-29 00:54:06 -04:00
|
|
|
AP_Notify::flags.pre_arm_gps_check = false;
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got here all must be ok
|
|
|
|
AP_Notify::flags.pre_arm_gps_check = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check ekf attitude is acceptable
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::pre_arm_ekf_attitude_check()
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
|
|
|
// get ekf filter status
|
2018-06-25 00:42:17 -03:00
|
|
|
nav_filter_status filt_status = copter.inertial_nav.get_filter_status();
|
2015-12-22 19:12:15 -04:00
|
|
|
|
|
|
|
return filt_status.flags.attitude;
|
|
|
|
}
|
|
|
|
|
2016-11-08 03:44:02 -04:00
|
|
|
// check nothing is too close to vehicle
|
2019-05-29 23:31:06 -03:00
|
|
|
bool AP_Arming_Copter::proximity_checks(bool display_failure) const
|
2016-11-08 03:44:02 -04:00
|
|
|
{
|
2021-03-25 05:08:44 -03:00
|
|
|
#if HAL_PROXIMITY_ENABLED
|
2016-11-08 03:44:02 -04:00
|
|
|
|
2019-05-29 23:31:06 -03:00
|
|
|
if (!AP_Arming::proximity_checks(display_failure)) {
|
|
|
|
return false;
|
2016-11-08 03:44:02 -04:00
|
|
|
}
|
|
|
|
|
2019-05-29 23:31:06 -03:00
|
|
|
if (!((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_PARAMETERS))) {
|
|
|
|
// check is disabled
|
|
|
|
return true;
|
2016-11-08 03:44:02 -04:00
|
|
|
}
|
|
|
|
|
2016-12-20 02:06:22 -04:00
|
|
|
// get closest object if we might use it for avoidance
|
2017-01-02 20:36:26 -04:00
|
|
|
#if AC_AVOID_ENABLED == ENABLED
|
2016-11-08 03:44:02 -04:00
|
|
|
float angle_deg, distance;
|
2016-12-26 04:04:13 -04:00
|
|
|
if (copter.avoid.proximity_avoidance_enabled() && copter.g2.proximity.get_closest_object(angle_deg, distance)) {
|
2016-11-08 03:44:02 -04:00
|
|
|
// display error if something is within 60cm
|
2018-12-23 05:37:34 -04:00
|
|
|
const float tolerance = 0.6f;
|
|
|
|
if (distance <= tolerance) {
|
2020-09-30 02:17:20 -03:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Proximity %d deg, %4.2fm (want > %0.1fm)", (int)angle_deg, (double)distance, (double)tolerance);
|
2016-11-08 03:44:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 20:36:26 -04:00
|
|
|
#endif
|
2016-11-08 03:44:02 -04:00
|
|
|
|
|
|
|
#endif
|
2018-12-23 05:04:49 -04:00
|
|
|
return true;
|
2016-11-08 03:44:02 -04:00
|
|
|
}
|
|
|
|
|
2019-11-29 00:54:06 -04:00
|
|
|
// performs mandatory gps checks. returns true if passed
|
|
|
|
bool AP_Arming_Copter::mandatory_gps_checks(bool display_failure)
|
|
|
|
{
|
2021-01-21 00:16:29 -04:00
|
|
|
// check if flight mode requires GPS
|
|
|
|
bool mode_requires_gps = copter.flightmode->requires_GPS();
|
|
|
|
|
2019-11-29 00:54:06 -04:00
|
|
|
// always check if inertial nav has started and is ready
|
|
|
|
const AP_AHRS_NavEKF &ahrs = AP::ahrs_navekf();
|
2020-08-11 02:04:10 -03:00
|
|
|
char failure_msg[50] = {};
|
2021-01-21 00:16:29 -04:00
|
|
|
if (!ahrs.pre_arm_check(mode_requires_gps, failure_msg, sizeof(failure_msg))) {
|
2020-10-06 02:20:54 -03:00
|
|
|
check_failed(display_failure, "AHRS: %s", failure_msg);
|
2019-11-29 00:54:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if fence requires GPS
|
|
|
|
bool fence_requires_gps = false;
|
|
|
|
#if AC_FENCE == ENABLED
|
|
|
|
// if circular or polygon fence is enabled we need GPS
|
|
|
|
fence_requires_gps = (copter.fence.get_enabled_fences() & (AC_FENCE_TYPE_CIRCLE | AC_FENCE_TYPE_POLYGON)) > 0;
|
|
|
|
#endif
|
|
|
|
|
2020-04-15 23:09:36 -03:00
|
|
|
if (mode_requires_gps) {
|
|
|
|
if (!copter.position_ok()) {
|
2020-08-11 02:04:10 -03:00
|
|
|
// vehicle level position estimate checks
|
2020-07-10 19:34:22 -03:00
|
|
|
check_failed(display_failure, "Need Position Estimate");
|
2020-04-15 23:09:36 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fence_requires_gps) {
|
|
|
|
if (!copter.position_ok()) {
|
2019-11-29 00:54:06 -04:00
|
|
|
// clarify to user why they need GPS in non-GPS flight mode
|
2020-07-10 19:34:22 -03:00
|
|
|
check_failed(display_failure, "Fence enabled, need position estimate");
|
2020-04-15 23:09:36 -03:00
|
|
|
return false;
|
2019-11-29 00:54:06 -04:00
|
|
|
}
|
2020-04-15 23:09:36 -03:00
|
|
|
} else {
|
|
|
|
// return true if GPS is not required
|
|
|
|
return true;
|
2019-11-29 00:54:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for GPS glitch (as reported by EKF)
|
|
|
|
nav_filter_status filt_status;
|
|
|
|
if (ahrs.get_filter_status(filt_status)) {
|
|
|
|
if (filt_status.flags.gps_glitching) {
|
|
|
|
check_failed(display_failure, "GPS glitching");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 01:26:16 -04:00
|
|
|
// check EKF's compass, position and velocity variances are below failsafe threshold
|
|
|
|
if (copter.g.fs_ekf_thresh > 0.0f) {
|
|
|
|
float vel_variance, pos_variance, hgt_variance, tas_variance;
|
|
|
|
Vector3f mag_variance;
|
|
|
|
ahrs.get_variances(vel_variance, pos_variance, hgt_variance, mag_variance, tas_variance);
|
|
|
|
if (mag_variance.length() >= copter.g.fs_ekf_thresh) {
|
|
|
|
check_failed(display_failure, "EKF compass variance");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (pos_variance >= copter.g.fs_ekf_thresh) {
|
|
|
|
check_failed(display_failure, "EKF position variance");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (vel_variance >= copter.g.fs_ekf_thresh) {
|
|
|
|
check_failed(display_failure, "EKF velocity variance");
|
|
|
|
return false;
|
|
|
|
}
|
2019-11-29 00:54:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// check home and EKF origin are not too far
|
|
|
|
if (copter.far_from_EKF_origin(ahrs.get_home())) {
|
|
|
|
check_failed(display_failure, "EKF-home variance");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got here all must be ok
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-15 18:30:46 -04:00
|
|
|
// Check GCS failsafe
|
|
|
|
bool AP_Arming_Copter::gcs_failsafe_check(bool display_failure)
|
|
|
|
{
|
|
|
|
if (copter.failsafe.gcs) {
|
|
|
|
check_failed(display_failure, "GCS failsafe on");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-29 00:54:06 -04:00
|
|
|
|
2020-07-24 05:38:42 -03:00
|
|
|
// check winch
|
|
|
|
bool AP_Arming_Copter::winch_checks(bool display_failure) const
|
|
|
|
{
|
|
|
|
#if WINCH_ENABLED == ENABLED
|
|
|
|
// pass if parameter or all arming checks disabled
|
|
|
|
if (((checks_to_perform & ARMING_CHECK_ALL) == 0) && ((checks_to_perform & ARMING_CHECK_PARAMETERS) == 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AP_Winch *winch = AP::winch();
|
|
|
|
if (winch == nullptr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
char failure_msg[50] = {};
|
|
|
|
if (!winch->pre_arm_check(failure_msg, sizeof(failure_msg))) {
|
|
|
|
check_failed(display_failure, "%s", failure_msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-18 03:07:21 -03:00
|
|
|
// performs altitude checks. returns true if passed
|
|
|
|
bool AP_Arming_Copter::alt_checks(bool display_failure)
|
|
|
|
{
|
|
|
|
// always EKF altitude estimate
|
|
|
|
if (!copter.flightmode->has_manual_throttle() && !copter.ekf_alt_ok()) {
|
|
|
|
check_failed(display_failure, "Need Alt Estimate");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// arm_checks - perform final checks before arming
|
|
|
|
// always called just before arming. Return true if ok to arm
|
|
|
|
// has side-effect that logging is started
|
2019-04-22 23:58:51 -03:00
|
|
|
bool AP_Arming_Copter::arm_checks(AP_Arming::Method method)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
2018-06-25 00:42:17 -03:00
|
|
|
const AP_AHRS_NavEKF &ahrs = AP::ahrs_navekf();
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// always check if inertial nav has started and is ready
|
2015-12-24 01:08:00 -04:00
|
|
|
if (!ahrs.healthy()) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(true, "AHRS not healthy");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-12 17:11:48 -04:00
|
|
|
#ifndef ALLOW_ARM_NO_COMPASS
|
2019-07-24 06:48:07 -03:00
|
|
|
// if external source of heading is available, we can skip compass health check
|
|
|
|
if (!ahrs.is_ext_nav_used_for_yaw()) {
|
|
|
|
const Compass &_compass = AP::compass();
|
|
|
|
// check compass health
|
|
|
|
if (!_compass.healthy()) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(true, "Compass not healthy");
|
2019-07-24 06:48:07 -03:00
|
|
|
return false;
|
|
|
|
}
|
2016-11-01 04:11:07 -03:00
|
|
|
}
|
2018-02-12 17:11:48 -04:00
|
|
|
#endif
|
2016-11-01 04:11:07 -03:00
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// always check if the current mode allows arming
|
2020-12-31 20:49:01 -04:00
|
|
|
if (!copter.flightmode->allows_arming(method)) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(true, "Mode not armable");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-13 22:30:36 -04:00
|
|
|
// always check motors
|
2019-04-22 23:58:51 -03:00
|
|
|
if (!motor_checks(true)) {
|
2016-12-13 22:30:36 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// if we are using motor interlock switch and it's enabled, fail to arm
|
2016-08-02 04:07:48 -03:00
|
|
|
// skip check in Throw mode which takes control of the motor interlock
|
2018-05-31 21:32:44 -03:00
|
|
|
if (copter.ap.using_interlock && copter.ap.motor_interlock_switch) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(true, "Motor Interlock Enabled");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we are not using Emergency Stop switch option, force Estop false to ensure motors
|
|
|
|
// can run normally
|
2019-04-03 13:25:47 -03:00
|
|
|
if (!rc().find_channel_for_option(RC_Channel::AUX_FUNC::MOTOR_ESTOP)){
|
2019-01-25 14:57:36 -04:00
|
|
|
SRV_Channels::set_emergency_stop(false);
|
2015-12-22 19:12:15 -04:00
|
|
|
// if we are using motor Estop switch, it must not be in Estop position
|
2020-05-02 02:46:33 -03:00
|
|
|
} else if (SRV_Channels::get_emergency_stop()){
|
2020-05-01 10:05:44 -03:00
|
|
|
check_failed(true, "Motor Emergency Stopped");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// succeed if arming checks are disabled
|
2019-10-04 18:51:22 -03:00
|
|
|
if (checks_to_perform == 0) {
|
2015-12-22 19:12:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check lean angle
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_INS)) {
|
|
|
|
if (degrees(acosf(ahrs.cos_roll()*ahrs.cos_pitch()))*100.0f > copter.aparm.angle_max) {
|
2019-04-22 23:58:51 -03:00
|
|
|
check_failed(ARMING_CHECK_INS, true, "Leaning");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 09:42:32 -03:00
|
|
|
// check adsb
|
2020-09-19 05:37:52 -03:00
|
|
|
#if HAL_ADSB_ENABLED
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_PARAMETERS)) {
|
|
|
|
if (copter.failsafe.adsb) {
|
2019-04-22 23:58:51 -03:00
|
|
|
check_failed(ARMING_CHECK_PARAMETERS, true, "ADSB threat detected");
|
2016-07-21 09:42:32 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-02-16 10:21:55 -04:00
|
|
|
#endif
|
2016-07-21 09:42:32 -03:00
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// check throttle
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_RC)) {
|
2017-08-09 08:36:19 -03:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
const char *rc_item = "Collective";
|
|
|
|
#else
|
|
|
|
const char *rc_item = "Throttle";
|
|
|
|
#endif
|
2015-12-22 19:12:15 -04:00
|
|
|
// check throttle is not too low - must be above failsafe throttle
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.g.failsafe_throttle != FS_THR_DISABLED && copter.channel_throttle->get_radio_in() < copter.g.failsafe_throttle_value) {
|
2019-04-22 23:58:51 -03:00
|
|
|
check_failed(ARMING_CHECK_RC, true, "%s below failsafe", rc_item);
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check throttle is not too high - skips checks if arming from GCS in Guided
|
2020-01-30 03:29:36 -04:00
|
|
|
if (!(method == AP_Arming::Method::MAVLINK && (copter.flightmode->mode_number() == Mode::Number::GUIDED || copter.flightmode->mode_number() == Mode::Number::GUIDED_NOGPS))) {
|
2015-12-22 19:12:15 -04:00
|
|
|
// above top of deadband is too always high
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.get_pilot_desired_climb_rate(copter.channel_throttle->get_control_in()) > 0.0f) {
|
2019-04-22 23:58:51 -03:00
|
|
|
check_failed(ARMING_CHECK_RC, true, "%s too high", rc_item);
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// in manual modes throttle must be at zero
|
2019-03-27 14:56:30 -03:00
|
|
|
#if FRAME_CONFIG != HELI_FRAME
|
2020-01-30 03:29:36 -04:00
|
|
|
if ((copter.flightmode->has_manual_throttle() || copter.flightmode->mode_number() == Mode::Number::DRIFT) && copter.channel_throttle->get_control_in() > 0) {
|
2019-04-22 23:58:51 -03:00
|
|
|
check_failed(ARMING_CHECK_RC, true, "%s too high", rc_item);
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-27 14:56:30 -03:00
|
|
|
#endif
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if safety switch has been pushed
|
|
|
|
if (hal.util->safety_switch_state() == AP_HAL::Util::SAFETY_DISARMED) {
|
2019-10-04 18:51:22 -03:00
|
|
|
check_failed(true, "Safety Switch");
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-03 00:02:49 -03:00
|
|
|
// superclass method should always be the last thing called; it
|
|
|
|
// has side-effects which would need to be cleaned up if one of
|
|
|
|
// our arm checks failed
|
2018-06-24 23:09:23 -03:00
|
|
|
return AP_Arming::arm_checks(method);
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
2017-01-09 03:45:48 -04:00
|
|
|
|
2019-11-29 00:54:06 -04:00
|
|
|
// mandatory checks that will be run if ARMING_CHECK is zero or arming forced
|
|
|
|
bool AP_Arming_Copter::mandatory_checks(bool display_failure)
|
|
|
|
{
|
|
|
|
// call mandatory gps checks and update notify status because regular gps checks will not run
|
2020-08-18 03:07:21 -03:00
|
|
|
bool result = mandatory_gps_checks(display_failure);
|
2019-11-29 00:54:06 -04:00
|
|
|
AP_Notify::flags.pre_arm_gps_check = result;
|
2020-08-18 03:07:21 -03:00
|
|
|
|
|
|
|
// call mandatory alt check
|
|
|
|
if (!alt_checks(display_failure)) {
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 00:54:06 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-26 04:03:40 -04:00
|
|
|
void AP_Arming_Copter::set_pre_arm_check(bool b)
|
|
|
|
{
|
2017-09-03 23:10:14 -03:00
|
|
|
copter.ap.pre_arm_check = b;
|
|
|
|
AP_Notify::flags.pre_arm_check = b;
|
2016-12-26 04:03:40 -04:00
|
|
|
}
|
2019-05-29 20:37:28 -03:00
|
|
|
|
|
|
|
bool AP_Arming_Copter::arm(const AP_Arming::Method method, const bool do_arming_checks)
|
|
|
|
{
|
|
|
|
static bool in_arm_motors = false;
|
|
|
|
|
|
|
|
// exit immediately if already in this function
|
|
|
|
if (in_arm_motors) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
in_arm_motors = true;
|
|
|
|
|
|
|
|
// return true if already armed
|
|
|
|
if (copter.motors->armed()) {
|
|
|
|
in_arm_motors = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AP_Arming::arm(method, do_arming_checks)) {
|
|
|
|
AP_Notify::events.arming_failed = true;
|
|
|
|
in_arm_motors = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// let logger know that we're armed (it may open logs e.g.)
|
|
|
|
AP::logger().set_vehicle_armed(true);
|
|
|
|
|
|
|
|
// disable cpu failsafe because initialising everything takes a while
|
|
|
|
copter.failsafe_disable();
|
|
|
|
|
|
|
|
// notify that arming will occur (we do this early to give plenty of warning)
|
|
|
|
AP_Notify::flags.armed = true;
|
|
|
|
// call notify update a few times to ensure the message gets out
|
|
|
|
for (uint8_t i=0; i<=10; i++) {
|
|
|
|
AP::notify().update();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HIL_MODE != HIL_MODE_DISABLED || CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Arming motors");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Remember Orientation
|
|
|
|
// --------------------
|
|
|
|
copter.init_simple_bearing();
|
|
|
|
|
|
|
|
AP_AHRS_NavEKF &ahrs = AP::ahrs_navekf();
|
|
|
|
|
|
|
|
copter.initial_armed_bearing = ahrs.yaw_sensor;
|
|
|
|
|
|
|
|
if (!ahrs.home_is_set()) {
|
|
|
|
// Reset EKF altitude if home hasn't been set yet (we use EKF altitude as substitute for alt above home)
|
|
|
|
ahrs.resetHeightDatum();
|
2019-10-25 03:06:05 -03:00
|
|
|
AP::logger().Write_Event(LogEvent::EKF_ALT_RESET);
|
2019-05-29 20:37:28 -03:00
|
|
|
|
|
|
|
// we have reset height, so arming height is zero
|
|
|
|
copter.arming_altitude_m = 0;
|
|
|
|
} else if (!ahrs.home_is_locked()) {
|
|
|
|
// Reset home position if it has already been set before (but not locked)
|
|
|
|
if (!copter.set_home_to_current_location(false)) {
|
|
|
|
// ignore failure
|
|
|
|
}
|
|
|
|
|
|
|
|
// remember the height when we armed
|
|
|
|
copter.arming_altitude_m = copter.inertial_nav.get_altitude() * 0.01;
|
|
|
|
}
|
|
|
|
copter.update_super_simple_bearing(false);
|
|
|
|
|
|
|
|
// Reset SmartRTL return location. If activated, SmartRTL will ultimately try to land at this point
|
|
|
|
#if MODE_SMARTRTL_ENABLED == ENABLED
|
|
|
|
copter.g2.smart_rtl.set_home(copter.position_ok());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// enable gps velocity based centrefugal force compensation
|
|
|
|
ahrs.set_correct_centrifugal(true);
|
|
|
|
hal.util->set_soft_armed(true);
|
|
|
|
|
|
|
|
#if SPRAYER_ENABLED == ENABLED
|
|
|
|
// turn off sprayer's test if on
|
|
|
|
copter.sprayer.test_pump(false);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// enable output to motors
|
|
|
|
copter.enable_motor_output();
|
|
|
|
|
|
|
|
// finally actually arm the motors
|
|
|
|
copter.motors->armed(true);
|
|
|
|
|
|
|
|
// log flight mode in case it was changed while vehicle was disarmed
|
2020-01-30 03:29:36 -04:00
|
|
|
AP::logger().Write_Mode((uint8_t)copter.flightmode->mode_number(), copter.control_mode_reason);
|
2019-05-29 20:37:28 -03:00
|
|
|
|
|
|
|
// re-enable failsafe
|
|
|
|
copter.failsafe_enable();
|
|
|
|
|
|
|
|
// perf monitor ignores delay due to arming
|
|
|
|
AP::scheduler().perf_info.ignore_this_loop();
|
|
|
|
|
|
|
|
// flag exiting this function
|
|
|
|
in_arm_motors = false;
|
|
|
|
|
|
|
|
// Log time stamp of arming event
|
|
|
|
copter.arm_time_ms = millis();
|
|
|
|
|
|
|
|
// Start the arming delay
|
|
|
|
copter.ap.in_arming_delay = true;
|
|
|
|
|
|
|
|
// assumed armed without a arming, switch. Overridden in switches.cpp
|
|
|
|
copter.ap.armed_with_switch = false;
|
|
|
|
|
|
|
|
// return success
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// arming.disarm - disarm motors
|
2021-01-05 20:15:48 -04:00
|
|
|
bool AP_Arming_Copter::disarm(const AP_Arming::Method method, bool do_disarm_checks)
|
2019-05-29 20:37:28 -03:00
|
|
|
{
|
|
|
|
// return immediately if we are already disarmed
|
|
|
|
if (!copter.motors->armed()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-05 20:15:48 -04:00
|
|
|
// do not allow disarm via mavlink if we think we are flying:
|
|
|
|
if (do_disarm_checks &&
|
|
|
|
method == AP_Arming::Method::MAVLINK &&
|
|
|
|
!copter.ap.land_complete) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AP_Arming::disarm(method, do_disarm_checks)) {
|
2019-05-29 20:37:28 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HIL_MODE != HIL_MODE_DISABLED || CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Disarming motors");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AP_AHRS_NavEKF &ahrs = AP::ahrs_navekf();
|
|
|
|
|
|
|
|
// save compass offsets learned by the EKF if enabled
|
|
|
|
Compass &compass = AP::compass();
|
|
|
|
if (ahrs.use_compass() && compass.get_learn_type() == Compass::LEARN_EKF) {
|
|
|
|
for(uint8_t i=0; i<COMPASS_MAX_INSTANCES; i++) {
|
|
|
|
Vector3f magOffsets;
|
|
|
|
if (ahrs.getMagOffsets(i, magOffsets)) {
|
|
|
|
compass.set_and_save_offsets(i, magOffsets);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if AUTOTUNE_ENABLED == ENABLED
|
|
|
|
// save auto tuned parameters
|
|
|
|
if (copter.flightmode == &copter.mode_autotune) {
|
|
|
|
copter.mode_autotune.save_tuning_gains();
|
|
|
|
} else {
|
|
|
|
copter.mode_autotune.reset();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// we are not in the air
|
|
|
|
copter.set_land_complete(true);
|
|
|
|
copter.set_land_complete_maybe(true);
|
|
|
|
|
|
|
|
// send disarm command to motors
|
|
|
|
copter.motors->armed(false);
|
|
|
|
|
|
|
|
#if MODE_AUTO_ENABLED == ENABLED
|
|
|
|
// reset the mission
|
|
|
|
copter.mode_auto.mission.reset();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AP::logger().set_vehicle_armed(false);
|
|
|
|
|
|
|
|
// disable gps velocity based centrefugal force compensation
|
|
|
|
ahrs.set_correct_centrifugal(false);
|
|
|
|
hal.util->set_soft_armed(false);
|
|
|
|
|
|
|
|
copter.ap.in_arming_delay = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|