From 4d8053afc91a0f36973a3352b115b83689acf66c Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Mon, 24 Oct 2016 22:16:11 -0700 Subject: [PATCH] Compass: Rework compass calibrator Summary of significant changes: -Autsave doesn't depend on STREAM_EXTRA3 -Don't risk only saving one compass on copter if CAL_ALWAYS_REBOOT is set -Only calibrate compasses that are both health and marked for use (there was a inconsistency in handling the mask) -Fix incorrect failure reporting on DO_ACCEPT_MAG_CAL with a mask of 0 if a channel was specifically not started -Fix not starting the buzzer if the delay is set to 0 seconds -Always send MAG_CAL_REPORT until its acknowledged -Correct the field in MAG_CAL_REPORT for autosave to indicate if the compass had actually been saved, rather then being scheduled to be saved -Remmove unused public interfaces --- libraries/AP_Compass/AP_Compass.cpp | 1 - libraries/AP_Compass/AP_Compass.h | 31 ++-- .../AP_Compass/AP_Compass_Calibration.cpp | 154 +++++++++--------- libraries/AP_Compass/CompassCalibrator.cpp | 3 +- libraries/AP_Compass/CompassCalibrator.h | 4 +- 5 files changed, 90 insertions(+), 103 deletions(-) diff --git a/libraries/AP_Compass/AP_Compass.cpp b/libraries/AP_Compass/AP_Compass.cpp index 015fc06a1f..4d8db95e30 100644 --- a/libraries/AP_Compass/AP_Compass.cpp +++ b/libraries/AP_Compass/AP_Compass.cpp @@ -383,7 +383,6 @@ Compass::Compass(void) : for (uint8_t i=0; idelay(1000); hal.scheduler->reboot(false); } } bool -Compass::start_calibration(uint8_t i, bool retry, bool autosave, float delay, bool autoreboot) +Compass::_start_calibration(uint8_t i, bool retry, float delay) { if (!healthy(i)) { return false; } - memset(_reports_sent,0,sizeof(_reports_sent)); - if (!is_calibrating() && delay > 0.5f) { + if (!use_for_yaw(i)) { + return false; + } + if (!is_calibrating()) { AP_Notify::events.initiated_compass_cal = 1; } if (i == get_primary() && _state[i].external != 0) { @@ -57,8 +61,8 @@ Compass::start_calibration(uint8_t i, bool retry, bool autosave, float delay, bo // lot noisier _calibrator[i].set_tolerance(_calibration_threshold*2); } - _calibrator[i].start(retry, autosave, delay); - _compass_cal_autoreboot = autoreboot; + _cal_saved[i] = false; + _calibrator[i].start(retry, delay); // disable compass learning both for calibration and after completion _learn.set_and_save(0); @@ -67,26 +71,15 @@ Compass::start_calibration(uint8_t i, bool retry, bool autosave, float delay, bo } bool -Compass::start_calibration_mask(uint8_t mask, bool retry, bool autosave, float delay, bool autoreboot) +Compass::_start_calibration_mask(uint8_t mask, bool retry, bool autosave, float delay, bool autoreboot) { + _cal_autosave = autosave; + _compass_cal_autoreboot = autoreboot; + for (uint8_t i=0; i