#include #include #include #include "AP_Compass.h" extern AP_HAL::HAL& hal; void Compass::compass_cal_update() { bool running = false; 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) { if (!healthy(i)) { return false; } memset(_reports_sent,0,sizeof(_reports_sent)); if (!is_calibrating() && delay > 0.5f) { AP_Notify::events.initiated_compass_cal = 1; } if (i == get_primary() && _state[i].external != 0) { _calibrator[i].set_tolerance(_calibration_threshold); } else { // internal compasses or secondary compasses get twice the // threshold. This is because internal compasses tend to be a // lot noisier _calibrator[i].set_tolerance(_calibration_threshold*2); } _calibrator[i].start(retry, autosave, delay); _compass_cal_autoreboot = autoreboot; // disable compass learning both for calibration and after completion _learn.set_and_save(0); return true; } bool Compass::start_calibration_mask(uint8_t mask, bool retry, bool autosave, float delay, bool autoreboot) { for (uint8_t i=0; iget_soft_armed()) { hal.console->println("Disarm for compass calibration"); result = MAV_RESULT_FAILED; break; } if (packet.param1 < 0 || packet.param1 > 255) { result = MAV_RESULT_FAILED; break; } uint8_t mag_mask = packet.param1; bool retry = !is_zero(packet.param2); bool autosave = !is_zero(packet.param3); float delay = packet.param4; bool autoreboot = !is_zero(packet.param5); if (mag_mask == 0) { // 0 means all if (!start_calibration_all(retry, autosave, delay, autoreboot)) { result = MAV_RESULT_FAILED; } } else { if (!start_calibration_mask(mag_mask, retry, autosave, delay, autoreboot)) { result = MAV_RESULT_FAILED; } } break; } case MAV_CMD_DO_ACCEPT_MAG_CAL: { result = MAV_RESULT_ACCEPTED; if(packet.param1 < 0 || packet.param1 > 255) { result = MAV_RESULT_FAILED; break; } uint8_t mag_mask = packet.param1; if (mag_mask == 0) { // 0 means all if(!accept_calibration_all()) { result = MAV_RESULT_FAILED; } break; } if(!accept_calibration_mask(mag_mask)) { result = MAV_RESULT_FAILED; } break; } case MAV_CMD_DO_CANCEL_MAG_CAL: { result = MAV_RESULT_ACCEPTED; if(packet.param1 < 0 || packet.param1 > 255) { result = MAV_RESULT_FAILED; break; } uint8_t mag_mask = packet.param1; if (mag_mask == 0) { // 0 means all cancel_calibration_all(); break; } cancel_calibration_mask(mag_mask); break; } } return result; }