mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 22:40:27 +08:00
fix(optical_flow): report actual integration timespan in PAW3902/PAA3905 (#27418)
* fix(optical_flow): report actual integration timespan in PAW3902/PAA3905 The chip accumulates delta_x/delta_y in its burst registers until the Motion_Burst register is read, which clears the accumulator. The drivers previously reported a hardcoded mode-dependent SAMPLE_INTERVAL_MODE_X as the integration timespan regardless of how long ago the last burst read happened. This is wrong any time reads span more than one frame period - most commonly when the Motion DRDY pin doesn't fire (chip detected no motion) and the backup watchdog fires the read kBackupScheduleIntervalUs (20 ms) later instead of every frame. Downstream, VehicleOpticalFlow uses integration_timespan_us to size the gyro integration window used for body-rate compensation, and ekf2's _flow_gyro_bias estimator compares that gyro against the IMU at the matched delayed time. A wrong window length misaligns the gyro compensation with what the chip actually saw, and slowly biases _flow_gyro_bias - contaminating motion-reported fusions on the correctly-timed DRDY path too. Replace the hardcoded value with the actual interval between consecutive successful burst reads (clamped to a sane range). _timestamp_sample_last is reset on driver Reset() and updated on every successful burst read regardless of publish, since the chip clears its accumulator on every read. * refactor(optical_flow): use _ms literals for integration_timespan_us clamp Replace raw 1000/200000 microsecond bounds with 1_ms/200_ms to match the existing time_literals convention already used elsewhere in these drivers. No behavior change. Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> --------- Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
1 parent
659ab6b400
commit
c894945f15
4 files changed
+30
No files matched your search
@@ -89,6 +89,7 @@ bool PAA3905::Reset()
|
||||
_state = STATE::RESET;
|
||||
DataReadyInterruptDisable();
|
||||
_drdy_timestamp_sample.store(0);
|
||||
_timestamp_sample_last = 0;
|
||||
ScheduleClear();
|
||||
ScheduleNow();
|
||||
return true;
|
||||
@@ -391,6 +392,15 @@ void PAA3905::RunImpl()
|
||||
break;
|
||||
}
|
||||
|
||||
// override the per-mode default with the actual interval between burst reads
|
||||
// (the chip accumulates delta_x/delta_y until Motion_Burst is read), so the
|
||||
// gyro integration window downstream lines up with what the chip actually saw.
|
||||
if (_timestamp_sample_last != 0 && timestamp_sample > _timestamp_sample_last) {
|
||||
const hrt_abstime dt = timestamp_sample - _timestamp_sample_last;
|
||||
sensor_optical_flow.integration_timespan_us = math::constrain(static_cast<uint32_t>(dt),
|
||||
static_cast<uint32_t>(1_ms), static_cast<uint32_t>(200_ms));
|
||||
}
|
||||
|
||||
// motion in burst transfer
|
||||
const bool motion_reported = (buffer.data.Motion & Motion_Bit::MotionOccurred);
|
||||
|
||||
@@ -481,6 +491,10 @@ void PAA3905::RunImpl()
|
||||
_raw_data_sum_prev = buffer.data.RawData_Sum;
|
||||
_quality_prev = buffer.data.SQUAL;
|
||||
|
||||
// chip clears its delta accumulator on every Motion_Burst read,
|
||||
// regardless of whether we publish, so track every successful read.
|
||||
_timestamp_sample_last = timestamp_sample;
|
||||
|
||||
} else {
|
||||
perf_count(_bad_transfer_perf);
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ private:
|
||||
hrt_abstime _reset_timestamp{0};
|
||||
hrt_abstime _last_publish{0};
|
||||
hrt_abstime _last_motion{0};
|
||||
hrt_abstime _timestamp_sample_last{0};
|
||||
|
||||
int16_t _delta_x_raw_prev{0};
|
||||
int16_t _delta_y_raw_prev{0};
|
||||
|
||||
@@ -89,6 +89,7 @@ bool PAW3902::Reset()
|
||||
_state = STATE::RESET;
|
||||
DataReadyInterruptDisable();
|
||||
_drdy_timestamp_sample.store(0);
|
||||
_timestamp_sample_last = 0;
|
||||
ScheduleClear();
|
||||
ScheduleNow();
|
||||
return true;
|
||||
@@ -394,6 +395,15 @@ void PAW3902::RunImpl()
|
||||
break;
|
||||
}
|
||||
|
||||
// override the per-mode default with the actual interval between burst reads
|
||||
// (the chip accumulates delta_x/delta_y until Motion_Burst is read), so the
|
||||
// gyro integration window downstream lines up with what the chip actually saw.
|
||||
if (_timestamp_sample_last != 0 && timestamp_sample > _timestamp_sample_last) {
|
||||
const hrt_abstime dt = timestamp_sample - _timestamp_sample_last;
|
||||
sensor_optical_flow.integration_timespan_us = math::constrain(static_cast<uint32_t>(dt),
|
||||
static_cast<uint32_t>(1_ms), static_cast<uint32_t>(200_ms));
|
||||
}
|
||||
|
||||
// motion in burst transfer
|
||||
const bool motion_reported = (buffer.data.Motion & Motion_Bit::MOT);
|
||||
|
||||
@@ -484,6 +494,10 @@ void PAW3902::RunImpl()
|
||||
_raw_data_sum_prev = buffer.data.RawData_Sum;
|
||||
_quality_prev = buffer.data.SQUAL;
|
||||
|
||||
// chip clears its delta accumulator on every Motion_Burst read,
|
||||
// regardless of whether we publish, so track every successful read.
|
||||
_timestamp_sample_last = timestamp_sample;
|
||||
|
||||
} else {
|
||||
perf_count(_bad_transfer_perf);
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ private:
|
||||
hrt_abstime _reset_timestamp{0};
|
||||
hrt_abstime _last_publish{0};
|
||||
hrt_abstime _last_motion{0};
|
||||
hrt_abstime _timestamp_sample_last{0};
|
||||
|
||||
int16_t _delta_x_raw_prev{0};
|
||||
int16_t _delta_y_raw_prev{0};
|
||||
|
||||
Reference in new issue
Block a user