2015-12-22 19:12:15 -04:00
|
|
|
#include "Copter.h"
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2015-12-24 01:08:00 -04:00
|
|
|
if (pre_arm_checks(display_fail)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
set_pre_arm_check(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// performs pre-arm checks and arming checks
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::all_checks_passing(bool arming_from_gcs)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
|
|
|
if (pre_arm_checks(true)) {
|
|
|
|
set_pre_arm_check(true);
|
2016-01-21 22:59:47 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
return copter.ap.pre_arm_check && arm_checks(true, arming_from_gcs);
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// perform pre-arm checks and set ap.pre_arm_check flag
|
|
|
|
// return true if the checks pass successfully
|
2017-01-09 03:45:48 -04:00
|
|
|
// NOTE: this does *NOT* call AP_Arming::pre_arm_checks() yet!
|
|
|
|
bool AP_Arming_Copter::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.
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.check_if_auxsw_mode_used(AUXSW_MOTOR_INTERLOCK) && copter.check_if_auxsw_mode_used(AUXSW_MOTOR_ESTOP)){
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Interlock/E-Stop Conflict");
|
|
|
|
}
|
|
|
|
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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Motor Interlock Enabled");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// exit immediately if we've already successfully performed the pre-arm check
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.ap.pre_arm_check) {
|
2015-12-22 19:12:15 -04:00
|
|
|
// run gps checks because results may change and affect LED colour
|
|
|
|
// no need to display failures because arm_checks will do that if the pilot tries to arm
|
|
|
|
pre_arm_gps_checks(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// succeed if pre arm checks are disabled
|
2017-01-09 03:45:48 -04:00
|
|
|
if (checks_to_perform == ARMING_CHECK_NONE) {
|
2015-12-22 19:12:15 -04:00
|
|
|
set_pre_arm_check(true);
|
|
|
|
set_pre_arm_rc_check(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-13 12:51:55 -03:00
|
|
|
return barometer_checks(display_failure)
|
|
|
|
& rc_calibration_checks(display_failure)
|
|
|
|
& compass_checks(display_failure)
|
|
|
|
& gps_checks(display_failure)
|
|
|
|
& fence_checks(display_failure)
|
|
|
|
& ins_checks(display_failure)
|
|
|
|
& board_voltage_checks(display_failure)
|
2017-01-19 22:57:40 -04:00
|
|
|
& logging_checks(display_failure)
|
2016-10-13 12:51:55 -03:00
|
|
|
& parameter_checks(display_failure)
|
2016-12-13 22:30:36 -04:00
|
|
|
& motor_checks(display_failure)
|
2016-10-13 12:51:55 -03:00
|
|
|
& pilot_throttle_checks(display_failure);
|
2016-08-15 09:02:48 -03:00
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::rc_calibration_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2015-12-22 19:12:15 -04:00
|
|
|
// pre-arm rc checks a prerequisite
|
2017-01-19 22:28:36 -04:00
|
|
|
pre_arm_rc_checks(display_failure);
|
2017-03-24 02:37:29 -03:00
|
|
|
return copter.ap.pre_arm_rc_check;
|
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
|
|
|
{
|
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
|
|
|
// barometer health check
|
2015-12-24 01:08:00 -04:00
|
|
|
if (!barometer.all_healthy()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Barometer not healthy");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// 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.
|
2016-12-30 00:52:53 -04:00
|
|
|
nav_filter_status filt_status = _inav.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) {
|
2016-12-30 00:52:53 -04:00
|
|
|
if (fabsf(_inav.get_altitude() - copter.baro_alt) > PREARM_MAX_ALT_DISPARITY_CM) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Altitude disparity");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-15 09:02:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
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.
|
|
|
|
if (!_compass.configured()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Compass not calibrated");
|
|
|
|
}
|
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::gps_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2015-12-22 19:12:15 -04:00
|
|
|
// check GPS
|
|
|
|
if (!pre_arm_gps_checks(display_failure)) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-15 09:02:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::fence_checks(bool display_failure)
|
2016-08-15 09:02:48 -03:00
|
|
|
{
|
2015-12-22 19:12:15 -04:00
|
|
|
#if AC_FENCE == ENABLED
|
|
|
|
// check fence is initialised
|
2017-03-23 23:03:15 -03:00
|
|
|
const char *fail_msg = nullptr;
|
|
|
|
if (!copter.fence.pre_arm_check(fail_msg)) {
|
|
|
|
if (display_failure && fail_msg != nullptr) {
|
|
|
|
GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_CRITICAL, "PreArm: %s", fail_msg);
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2016-08-15 09:02:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
2015-12-22 19:12:15 -04: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()) {
|
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: gyros still settling");
|
|
|
|
}
|
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-03-20 14:57:38 -03:00
|
|
|
#if HAL_HAVE_BOARD_VOLTAGE
|
2015-12-22 19:12:15 -04:00
|
|
|
// check board voltage
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_VOLTAGE)) {
|
2015-12-24 01:08:00 -04:00
|
|
|
if (hal.analogin->board_voltage() < BOARD_VOLTAGE_MIN || hal.analogin->board_voltage() > BOARD_VOLTAGE_MAX) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Check Board Voltage");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-03-20 14:57:38 -03:00
|
|
|
#endif
|
2015-12-22 19:12:15 -04:00
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
Parameters &g = copter.g;
|
|
|
|
|
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)) {
|
|
|
|
if (copter.failsafe.battery || (!copter.ap.usb_connected && copter.battery.exhausted(g.fs_batt_voltage, g.fs_batt_mah))) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Check Battery");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// ensure ch7 and ch8 have different functions
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.check_duplicate_auxsw()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Duplicate Aux Switch Options");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Check FS_THR_VALUE");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// lean angle parameter check
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.aparm.angle_max < 1000 || copter.aparm.angle_max > 8000) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Check ANGLE_MAX");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// acro balance parameter check
|
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())) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: ACRO_BAL_ROLL/PITCH");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-27 07:55:35 -03:00
|
|
|
#if RANGEFINDER_ENABLED == ENABLED && OPTFLOW == ENABLED
|
2015-12-22 19:12:15 -04:00
|
|
|
// check range finder if optflow enabled
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.optflow.enabled() && !copter.rangefinder.pre_arm_check()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: check range finder");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2016-08-22 04:13:46 -03:00
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
// check helicopter parameters
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!copter.motors->parameter_check(display_failure)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // HELI_FRAME
|
2016-03-19 03:26:10 -03:00
|
|
|
|
|
|
|
// check for missing terrain data
|
2016-04-28 01:57:52 -03:00
|
|
|
if (!pre_arm_terrain_check(display_failure)) {
|
2016-03-19 03:26:10 -03:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-21 09:42:32 -03:00
|
|
|
|
|
|
|
// check adsb avoidance failsafe
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.failsafe.adsb) {
|
2016-07-21 09:42:32 -03:00
|
|
|
if (display_failure) {
|
2016-08-12 16:52:49 -03:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: ADSB threat detected");
|
2016-07-21 09:42:32 -03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-08 03:44:02 -04:00
|
|
|
|
|
|
|
// check for something close to vehicle
|
|
|
|
if (!pre_arm_proximity_check(display_failure)) {
|
|
|
|
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()) {
|
2016-12-13 22:30:36 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: check firmware or FRAME_CLASS");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Collective below Failsafe");
|
|
|
|
#else
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Throttle below Failsafe");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// perform pre_arm_rc_checks checks and set ap.pre_arm_rc_check flag
|
2017-01-19 22:28:36 -04:00
|
|
|
void AP_Arming_Copter::pre_arm_rc_checks(const bool display_failure)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
|
|
|
// exit immediately if we've already successfully performed the pre-arm rc check
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.ap.pre_arm_rc_check) {
|
2015-12-22 19:12:15 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set rc-checks to success if RC checks are disabled
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform != ARMING_CHECK_ALL) && !(checks_to_perform & ARMING_CHECK_RC)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
set_pre_arm_rc_check(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-19 22:04:22 -04:00
|
|
|
const RC_Channel *channels[] = {
|
|
|
|
copter.channel_roll,
|
|
|
|
copter.channel_pitch,
|
|
|
|
copter.channel_throttle,
|
|
|
|
copter.channel_yaw
|
|
|
|
};
|
2017-01-19 22:28:36 -04:00
|
|
|
const char *channel_names[] = { "Roll", "Pitch", "Throttle", "Yaw" };
|
2017-01-19 22:04:22 -04:00
|
|
|
|
|
|
|
for (uint8_t i=0; i<ARRAY_SIZE(channels);i++) {
|
|
|
|
const RC_Channel *channel = channels[i];
|
2017-01-19 22:28:36 -04:00
|
|
|
const char *channel_name = channel_names[i];
|
2017-01-19 22:40:42 -04:00
|
|
|
// check if radio has been calibrated
|
|
|
|
if (!channel->min_max_configured()) {
|
|
|
|
if (display_failure) {
|
2017-03-24 02:37:29 -03:00
|
|
|
copter.gcs_send_text_fmt(MAV_SEVERITY_CRITICAL,"PreArm: RC %s not configured", channel_name);
|
2017-01-19 22:40:42 -04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-01-19 22:04:22 -04:00
|
|
|
if (channel->get_radio_min() > 1300) {
|
2017-01-19 22:28:36 -04:00
|
|
|
if (display_failure) {
|
|
|
|
copter.gcs_send_text_fmt(MAV_SEVERITY_CRITICAL,"PreArm: %s radio min too high", channel_name);
|
|
|
|
}
|
2017-01-19 22:04:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (channel->get_radio_max() < 1700) {
|
2017-01-19 22:28:36 -04:00
|
|
|
if (display_failure) {
|
|
|
|
copter.gcs_send_text_fmt(MAV_SEVERITY_CRITICAL,"PreArm: %s radio max too low", channel_name);
|
|
|
|
}
|
2017-01-19 22:04:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (i == 2) {
|
|
|
|
// skip checking trim for throttle as older code did not check it
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (channel->get_radio_trim() < channel->get_radio_min()) {
|
2017-01-19 22:28:36 -04:00
|
|
|
if (display_failure) {
|
|
|
|
copter.gcs_send_text_fmt(MAV_SEVERITY_CRITICAL,"PreArm: %s radio trim below min", channel_name);
|
|
|
|
}
|
2017-01-19 22:04:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (channel->get_radio_trim() > channel->get_radio_max()) {
|
2017-01-19 22:28:36 -04:00
|
|
|
if (display_failure) {
|
|
|
|
copter.gcs_send_text_fmt(MAV_SEVERITY_CRITICAL,"PreArm: %s radio trim above max", channel_name);
|
|
|
|
}
|
2017-01-19 22:04:22 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we've gotten this far rc is ok
|
|
|
|
set_pre_arm_rc_check(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// performs pre_arm gps related checks and returns true if passed
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::pre_arm_gps_checks(bool display_failure)
|
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()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Waiting for Nav Checks");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if flight mode requires GPS
|
2017-03-23 23:03:15 -03:00
|
|
|
bool mode_requires_gps = copter.mode_requires_GPS(copter.control_mode);
|
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
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure GPS is ok
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!copter.position_ok()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
const char *reason = ahrs.prearm_failure_reason();
|
|
|
|
if (reason) {
|
|
|
|
GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_CRITICAL, "PreArm: %s", reason);
|
|
|
|
} else {
|
2017-03-23 23:03:15 -03:00
|
|
|
if (!mode_requires_gps && fence_requires_gps) {
|
|
|
|
// clarify to user why they need GPS in non-GPS flight mode
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Fence enabled, need 3D Fix");
|
|
|
|
} else {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Need 3D Fix");
|
|
|
|
}
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
AP_Notify::flags.pre_arm_gps_check = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check EKF compass variance is below failsafe threshold
|
|
|
|
float vel_variance, pos_variance, hgt_variance, tas_variance;
|
|
|
|
Vector3f mag_variance;
|
|
|
|
Vector2f offset;
|
2016-12-30 00:52:53 -04:00
|
|
|
_ahrs_navekf.get_variances(vel_variance, pos_variance, hgt_variance, mag_variance, tas_variance, offset);
|
2017-01-09 03:45:48 -04:00
|
|
|
if (mag_variance.length() >= copter.g.fs_ekf_thresh) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: EKF compass variance");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check home and EKF origin are not too far
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.far_from_EKF_origin(ahrs.get_home())) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: EKF-home variance");
|
|
|
|
}
|
|
|
|
AP_Notify::flags.pre_arm_gps_check = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: High GPS HDOP");
|
|
|
|
}
|
|
|
|
AP_Notify::flags.pre_arm_gps_check = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:59:07 -04:00
|
|
|
// call parent gps checks
|
|
|
|
if (!AP_Arming::gps_checks(display_failure)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// 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
|
2016-12-30 00:52:53 -04:00
|
|
|
nav_filter_status filt_status = _inav.get_filter_status();
|
2015-12-22 19:12:15 -04:00
|
|
|
|
|
|
|
return filt_status.flags.attitude;
|
|
|
|
}
|
|
|
|
|
2016-03-19 03:26:10 -03:00
|
|
|
// check we have required terrain data
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::pre_arm_terrain_check(bool display_failure)
|
2016-03-19 03:26:10 -03:00
|
|
|
{
|
2016-04-21 22:58:36 -03:00
|
|
|
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
|
2016-03-19 03:26:10 -03:00
|
|
|
// succeed if not using terrain data
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!copter.terrain_use()) {
|
2016-03-19 03:26:10 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-28 01:57:52 -03:00
|
|
|
// check if terrain following is enabled, using a range finder but RTL_ALT is higher than rangefinder's max range
|
|
|
|
// To-Do: modify RTL return path to fly at or above the RTL_ALT and remove this check
|
2017-02-09 07:30:59 -04:00
|
|
|
|
|
|
|
if (copter.rangefinder_state.enabled && (copter.g.rtl_altitude > copter.rangefinder.max_distance_cm_orient(ROTATION_PITCH_270))) {
|
2016-04-28 01:57:52 -03:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: RTL_ALT above rangefinder max range");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-19 03:26:10 -03:00
|
|
|
// show terrain statistics
|
|
|
|
uint16_t terr_pending, terr_loaded;
|
2017-01-09 03:45:48 -04:00
|
|
|
copter.terrain.get_statistics(terr_pending, terr_loaded);
|
2016-04-28 01:57:52 -03:00
|
|
|
bool have_all_data = (terr_pending <= 0);
|
|
|
|
if (!have_all_data && display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: Waiting for Terrain data");
|
|
|
|
}
|
|
|
|
return have_all_data;
|
2016-04-21 22:58:36 -03:00
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
2016-03-19 03:26:10 -03:00
|
|
|
}
|
|
|
|
|
2016-11-08 03:44:02 -04:00
|
|
|
// check nothing is too close to vehicle
|
2016-12-26 04:04:13 -04:00
|
|
|
bool AP_Arming_Copter::pre_arm_proximity_check(bool display_failure)
|
2016-11-08 03:44:02 -04:00
|
|
|
{
|
|
|
|
#if PROXIMITY_ENABLED == ENABLED
|
|
|
|
|
|
|
|
// return true immediately if no sensor present
|
2016-12-26 04:04:13 -04:00
|
|
|
if (copter.g2.proximity.get_status() == AP_Proximity::Proximity_NotConnected) {
|
2016-11-08 03:44:02 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return false if proximity sensor unhealthy
|
2016-12-26 04:04:13 -04:00
|
|
|
if (copter.g2.proximity.get_status() < AP_Proximity::Proximity_Good) {
|
2016-11-08 03:44:02 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"PreArm: check proximity sensor");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if (distance <= 0.6f) {
|
|
|
|
if (display_failure) {
|
|
|
|
GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_CRITICAL, "PreArm: Proximity %d deg, %4.2fm", (int)angle_deg, (double)distance);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-01-02 20:36:26 -04:00
|
|
|
#endif
|
2016-11-08 03:44:02 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
2017-01-09 03:45:48 -04:00
|
|
|
bool AP_Arming_Copter::arm_checks(bool display_failure, bool arming_from_gcs)
|
2015-12-22 19:12:15 -04:00
|
|
|
{
|
|
|
|
#if LOGGING_ENABLED == ENABLED
|
|
|
|
// start dataflash
|
2017-01-09 03:45:48 -04:00
|
|
|
copter.start_logging();
|
2015-12-22 19:12:15 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// check accels and gyro are healthy
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_INS)) {
|
2015-12-29 00:36:11 -04:00
|
|
|
//check if accelerometers have calibrated and require reboot
|
2016-12-30 00:52:53 -04:00
|
|
|
if (_ins.accel_cal_requires_reboot()) {
|
2015-12-29 00:36:11 -04:00
|
|
|
if (display_failure) {
|
2017-03-24 02:37:29 -03:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL, "PreArm: Accels calibrated requires reboot");
|
2015-12-29 00:36:11 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-30 00:52:53 -04:00
|
|
|
if (!_ins.get_accel_health_all()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
2017-03-24 02:37:29 -03:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Accels not healthy");
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-30 00:52:53 -04:00
|
|
|
if (!_ins.get_gyro_health_all()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Gyros not healthy");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get ekf attitude (if bad, it's usually the gyro biases)
|
|
|
|
if (!pre_arm_ekf_attitude_check()) {
|
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: gyros still settling");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// always check if inertial nav has started and is ready
|
2015-12-24 01:08:00 -04:00
|
|
|
if (!ahrs.healthy()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Waiting for Nav Checks");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-01 04:11:07 -03:00
|
|
|
// check compass health
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!_compass.healthy()) {
|
2016-11-01 04:11:07 -03:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Compass not healthy");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
if (_compass.is_calibrating()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Compass calibration running");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-29 00:40:04 -04:00
|
|
|
//check if compass has calibrated and requires reboot
|
2017-01-09 03:45:48 -04:00
|
|
|
if (_compass.compass_cal_requires_reboot()) {
|
2015-12-29 00:40:04 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL, "PreArm: Compass calibrated requires reboot");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
control_mode_t control_mode = copter.control_mode;
|
|
|
|
|
2015-12-22 19:12:15 -04:00
|
|
|
// always check if the current mode allows arming
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!copter.mode_allows_arming(control_mode, arming_from_gcs)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Mode not armable");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// always check gps
|
|
|
|
if (!pre_arm_gps_checks(display_failure)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-13 22:30:36 -04:00
|
|
|
// always check motors
|
|
|
|
if (!motor_checks(display_failure)) {
|
|
|
|
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
|
2017-01-09 03:45:48 -04:00
|
|
|
if (copter.ap.using_interlock && copter.motors->get_interlock()) {
|
2015-12-22 19:12:15 -04:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Motor Interlock Enabled");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we are not using Emergency Stop switch option, force Estop false to ensure motors
|
|
|
|
// can run normally
|
2017-01-09 03:45:48 -04:00
|
|
|
if (!copter.check_if_auxsw_mode_used(AUXSW_MOTOR_ESTOP)){
|
|
|
|
copter.set_motor_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
|
2017-01-09 03:45:48 -04:00
|
|
|
} else if (copter.check_if_auxsw_mode_used(AUXSW_MOTOR_ESTOP) && copter.ap.motor_emergency_stop){
|
2015-12-22 19:12:15 -04:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Motor Emergency Stopped");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// succeed if arming checks are disabled
|
2017-01-09 03:45:48 -04:00
|
|
|
if (checks_to_perform == ARMING_CHECK_NONE) {
|
2015-12-22 19:12:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// baro checks
|
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
|
|
|
// baro health check
|
|
|
|
if (!barometer.all_healthy()) {
|
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Barometer not healthy");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// 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.
|
2016-12-30 00:52:53 -04:00
|
|
|
nav_filter_status filt_status = _inav.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);
|
2016-12-30 00:52:53 -04:00
|
|
|
if (using_baro_ref && (fabsf(_inav.get_altitude() - copter.baro_alt) > PREARM_MAX_ALT_DISPARITY_CM)) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Altitude disparity");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if AC_FENCE == ENABLED
|
|
|
|
// check vehicle is within fence
|
2017-03-23 23:03:15 -03:00
|
|
|
const char *fail_msg = nullptr;
|
|
|
|
if (!copter.fence.pre_arm_check(fail_msg)) {
|
|
|
|
if (display_failure && fail_msg != nullptr) {
|
|
|
|
GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_CRITICAL, "Arm: %s", fail_msg);
|
2015-12-22 19:12:15 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Leaning");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check battery voltage
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_VOLTAGE)) {
|
|
|
|
if (copter.failsafe.battery || (!copter.ap.usb_connected && copter.battery.exhausted(copter.g.fs_batt_voltage, copter.g.fs_batt_mah))) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Check Battery");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 03:26:10 -03:00
|
|
|
// check for missing terrain data
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((checks_to_perform == ARMING_CHECK_ALL) || (checks_to_perform & ARMING_CHECK_PARAMETERS)) {
|
2016-04-28 01:57:52 -03:00
|
|
|
if (!pre_arm_terrain_check(display_failure)) {
|
2016-03-19 03:26:10 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 09:42:32 -03:00
|
|
|
// check adsb
|
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) {
|
2016-07-21 09:42:32 -03:00
|
|
|
if (display_failure) {
|
2016-08-12 16:52:49 -03:00
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: ADSB threat detected");
|
2016-07-21 09:42:32 -03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Collective below Failsafe");
|
|
|
|
#else
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Throttle below Failsafe");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check throttle is not too high - skips checks if arming from GCS in Guided
|
2016-08-01 05:44:12 -03:00
|
|
|
if (!(arming_from_gcs && (control_mode == GUIDED || control_mode == 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) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Collective too high");
|
|
|
|
#else
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Throttle too high");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// in manual modes throttle must be at zero
|
2017-01-09 03:45:48 -04:00
|
|
|
if ((copter.mode_has_manual_throttle(control_mode) || control_mode == DRIFT) && copter.channel_throttle->get_control_in() > 0) {
|
2015-12-22 19:12:15 -04:00
|
|
|
if (display_failure) {
|
|
|
|
#if FRAME_CONFIG == HELI_FRAME
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Collective too high");
|
|
|
|
#else
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Throttle too high");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if safety switch has been pushed
|
|
|
|
if (hal.util->safety_switch_state() == AP_HAL::Util::SAFETY_DISARMED) {
|
|
|
|
if (display_failure) {
|
|
|
|
gcs_send_text(MAV_SEVERITY_CRITICAL,"Arm: Safety Switch");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we've gotten this far all is ok
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-09 03:45:48 -04:00
|
|
|
|
|
|
|
enum HomeState AP_Arming_Copter::home_status() const
|
|
|
|
{
|
|
|
|
return copter.ap.home_state;
|
|
|
|
}
|
|
|
|
|
2016-12-26 04:03:40 -04:00
|
|
|
void AP_Arming_Copter::set_pre_arm_check(bool b)
|
|
|
|
{
|
|
|
|
if(copter.ap.pre_arm_check != b) {
|
|
|
|
copter.ap.pre_arm_check = b;
|
|
|
|
AP_Notify::flags.pre_arm_check = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AP_Arming_Copter::set_pre_arm_rc_check(bool b)
|
|
|
|
{
|
|
|
|
if(copter.ap.pre_arm_rc_check != b) {
|
|
|
|
copter.ap.pre_arm_rc_check = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 03:45:48 -04:00
|
|
|
void AP_Arming_Copter::gcs_send_text(MAV_SEVERITY severity, const char *str)
|
|
|
|
{
|
|
|
|
copter.gcs_send_text(severity, str);
|
|
|
|
}
|