Skip to content

fix(bmp388): correct timestamp_sample to integration midpoint#26920

Merged
dakejahl merged 1 commit intoPX4:mainfrom
dakejahl:dakejahl/bmp388-timestamp-fix
Mar 31, 2026
Merged

fix(bmp388): correct timestamp_sample to integration midpoint#26920
dakejahl merged 1 commit intoPX4:mainfrom
dakejahl:dakejahl/bmp388-timestamp-fix

Conversation

@dakejahl
Copy link
Copy Markdown
Contributor

Summary

The BMP388/BMP390 pressure measurement is integrated over a configurable window (e.g. 37ms at 16x oversampling). The current code uses the SPI read time as timestamp_sample, which corresponds to the end of the integration window. This introduces a systematic timing bias equal to half the measurement time (~18.5ms at 16x oversampling).

This PR corrects timestamp_sample to the integration midpoint by subtracting measurement_time / 2, with a guard against unsigned underflow.

This improves time alignment for all downstream consumers (EKF baro fusion, logging, etc.).

Changes

  • src/drivers/barometer/bmp388/bmp388.cpp: Replace hrt_absolute_time() with midpoint-corrected timestamp

Test plan

  • Before/after flight logs comparing baro timestamp alignment
  • Verify EKF baro innovation statistics are equal or improved

The BMP388 pressure measurement is integrated over a configurable
window (e.g. 37ms at 16x oversampling). The previous code used the
read time as timestamp_sample, which is the end of the integration
window. Correct to the midpoint by subtracting half the measurement
time, with a guard against unsigned underflow.
@dakejahl
Copy link
Copy Markdown
Contributor Author

dakejahl commented Mar 31, 2026

I will follow up on this PR with fixes for every baro and mag driver.

Related to #26921

@dakejahl dakejahl merged commit 0deb6b3 into PX4:main Mar 31, 2026
73 checks passed
@dakejahl dakejahl deleted the dakejahl/bmp388-timestamp-fix branch March 31, 2026 23:35
hamishwillee pushed a commit that referenced this pull request Apr 1, 2026
The BMP388 pressure measurement is integrated over a configurable
window (e.g. 37ms at 16x oversampling). The previous code used the
read time as timestamp_sample, which is the end of the integration
window. Correct to the midpoint by subtracting half the measurement
time, with a guard against unsigned underflow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants