|
|
|
@ -207,32 +207,7 @@ void AP_Compass_MAG3110::_update()
@@ -207,32 +207,7 @@ void AP_Compass_MAG3110::_update()
|
|
|
|
|
|
|
|
|
|
Vector3f raw_field = Vector3f((float)_mag_x, (float)_mag_y, (float)_mag_z) * MAG_SCALE; |
|
|
|
|
|
|
|
|
|
// rotate raw_field from sensor frame to body frame
|
|
|
|
|
rotate_field(raw_field, _compass_instance); |
|
|
|
|
|
|
|
|
|
// publish raw_field (uncorrected point sample) for calibration use
|
|
|
|
|
publish_raw_field(raw_field, _compass_instance); |
|
|
|
|
|
|
|
|
|
// correct raw_field for known errors
|
|
|
|
|
correct_field(raw_field, _compass_instance); |
|
|
|
|
|
|
|
|
|
if (!field_ok(raw_field)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_sem->take(HAL_SEMAPHORE_BLOCK_FOREVER)) { |
|
|
|
|
_mag_x_accum += raw_field.x; |
|
|
|
|
_mag_y_accum += raw_field.y; |
|
|
|
|
_mag_z_accum += raw_field.z; |
|
|
|
|
_accum_count++; |
|
|
|
|
if (_accum_count == 10) { |
|
|
|
|
_mag_x_accum /= 2; |
|
|
|
|
_mag_y_accum /= 2; |
|
|
|
|
_mag_z_accum /= 2; |
|
|
|
|
_accum_count /= 2; |
|
|
|
|
} |
|
|
|
|
_sem->give(); |
|
|
|
|
} |
|
|
|
|
accumulate_sample(raw_field, _compass_instance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -243,23 +218,5 @@ void AP_Compass_MAG3110::read()
@@ -243,23 +218,5 @@ void AP_Compass_MAG3110::read()
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!_sem->take_nonblocking()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_accum_count == 0) { |
|
|
|
|
/* We're not ready to publish*/ |
|
|
|
|
_sem->give(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Vector3f field = Vector3f(_mag_x_accum, _mag_y_accum, _mag_z_accum); |
|
|
|
|
field /= _accum_count; |
|
|
|
|
|
|
|
|
|
_accum_count = 0; |
|
|
|
|
_mag_x_accum = _mag_y_accum = _mag_z_accum = 0; |
|
|
|
|
|
|
|
|
|
_sem->give();
|
|
|
|
|
|
|
|
|
|
publish_filtered_field(field, _compass_instance); |
|
|
|
|
drain_accumulated_samples(_compass_instance); |
|
|
|
|
} |
|
|
|
|