Skip to content

Commit 99d4933

Browse files
committed
AP_InertialSensor: bound the non-primary beat on Invensense v1
Unlike the v3 IMUs, where the sensor ODR is programmed to the backend rate, the v1 FIFO fills at the 8kHz sensor rate when fast sampling and the backend rate is a software decimation. Reading a non-primary at 2x loop rate left 20 samples in the FIFO between beats, and with bus latency on top it reached the depth at which _read_fifo() already expects corrupt samples: an MPU6000 in the second slot gave a continuous stream of "stop at 8 of 48" and temperature resets. Hold a fast-sampling non-primary at 1kHz, one read buffer of samples per beat, so the FIFO stays well clear of that depth. The 2x loop rate scaling now only applies without fast sampling, where the FIFO fills at the backend rate as it does on v3.
1 parent cca21b0 commit 99d4933

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

libraries/AP_InertialSensor/AP_InertialSensor_Invensense.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ extern const AP_HAL::HAL& hal;
7474
#define MPU_SAMPLE_SIZE 14
7575
#define MPU_FIFO_BUFFER_LEN 8
7676

77+
// rate the FIFO is filled at when fast sampling, independent of the backend rate
78+
#define MPU_FAST_SAMPLE_RATE_HZ 8000
79+
7780
#define int16_val(v, idx) ((int16_t)(((uint16_t)v[2*idx] << 8) | v[2*idx+1]))
7881
#define uint16_val(v, idx)(((uint16_t)v[2*idx] << 8) | v[2*idx+1])
7982

@@ -490,6 +493,11 @@ void AP_InertialSensor_Invensense::set_primary(bool _is_primary)
490493
if (_imu.is_dynamic_fifo_enabled(gyro_instance)) {
491494
if (_is_primary) {
492495
_dev->adjust_periodic_callback(periodic_handle, 1000000UL / _gyro_backend_rate_hz);
496+
} else if (_fast_sampling) {
497+
// unlike the v3 IMUs the FIFO fills at the 8kHz sensor rate rather than the backend rate,
498+
// so keep a non-primary at one _fifo_buffer of samples per beat to stay well clear of the
499+
// depth beyond which _read_fifo() finds corrupt samples
500+
_dev->adjust_periodic_callback(periodic_handle, 1000000UL / (MPU_FAST_SAMPLE_RATE_HZ / MPU_FIFO_BUFFER_LEN));
493501
} else {
494502
// scale down non-primary to 2x loop rate, but no greater than the default sampling rate
495503
_dev->adjust_periodic_callback(periodic_handle,

0 commit comments

Comments
 (0)