Skip to content

Commit fd47706

Browse files
committed
only allow mag calibration when at least one mag is available and enabled (i.e. not prio=0)
renaming, change log type
1 parent d3bcdf8 commit fd47706

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/modules/commander/mag_calibration.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,36 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
520520

521521
const unsigned int calibration_points_maxcount = worker_data.calibration_sides * worker_data.calibration_points_perside;
522522

523+
uORB::SubscriptionMultiArray<sensor_mag_s, MAX_MAGS> mag_sub{ORB_ID::sensor_mag};
524+
int mag_available_enabled_count = 0;
525+
523526
for (uint8_t cur_mag = 0; cur_mag < MAX_MAGS; cur_mag++) {
524527

525-
uORB::SubscriptionData<sensor_mag_s> mag_sub{ORB_ID(sensor_mag), cur_mag};
528+
if (!mag_sub[cur_mag].advertised()) {
529+
continue;
530+
}
531+
532+
sensor_mag_s mag_data;
526533

527-
if (mag_sub.advertised() && (mag_sub.get().device_id != 0) && (mag_sub.get().timestamp > 0)) {
528-
worker_data.calibration[cur_mag].set_device_id(mag_sub.get().device_id);
534+
if (!mag_sub[cur_mag].copy(&mag_data) || mag_data.device_id == 0) {
535+
continue;
536+
}
537+
538+
int calibration_index = calibration::FindCurrentCalibrationIndex("MAG", mag_data.device_id);
539+
540+
if (calibration_index >= 0) {
541+
int priority = calibration::GetCalibrationParamInt32("MAG", "PRIO", calibration_index);
542+
543+
if (priority != 0) {
544+
++mag_available_enabled_count;
545+
}
546+
547+
} else {
548+
++mag_available_enabled_count;
549+
}
550+
551+
if ((mag_data.device_id != 0) && (mag_data.timestamp > 0)) {
552+
worker_data.calibration[cur_mag].set_device_id(mag_data.device_id);
529553
}
530554

531555
// reset calibration index to match uORB numbering
@@ -547,6 +571,11 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
547571
}
548572
}
549573

574+
if (mag_available_enabled_count <= 0) {
575+
calibration_log_critical(mavlink_log_pub, "Failed: No magnetometer available or enabled");
576+
return calibrate_return_error;
577+
}
578+
550579
if (result == calibrate_return_ok) {
551580
result = calibrate_from_orientation(mavlink_log_pub, // uORB handle to write output
552581
worker_data.side_data_collected, // Sides to calibrate

0 commit comments

Comments
 (0)