@@ -520,12 +520,36 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
520
520
521
521
const unsigned int calibration_points_maxcount = worker_data.calibration_sides * worker_data.calibration_points_perside ;
522
522
523
+ uORB::SubscriptionMultiArray<sensor_mag_s, MAX_MAGS> mag_sub{ORB_ID::sensor_mag};
524
+ int mag_available_enabled_count = 0 ;
525
+
523
526
for (uint8_t cur_mag = 0 ; cur_mag < MAX_MAGS; cur_mag++) {
524
527
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;
526
533
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 );
529
553
}
530
554
531
555
// 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
547
571
}
548
572
}
549
573
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
+
550
579
if (result == calibrate_return_ok) {
551
580
result = calibrate_from_orientation (mavlink_log_pub, // uORB handle to write output
552
581
worker_data.side_data_collected , // Sides to calibrate
0 commit comments