From 0deb6b33eedbc898d93a00c1217d6676ddd84104 Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Tue, 31 Mar 2026 15:35:36 -0800 Subject: [PATCH] fix(bmp388): correct timestamp_sample to integration midpoint (#26920) 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. --- src/drivers/barometer/bmp388/bmp388.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/drivers/barometer/bmp388/bmp388.cpp b/src/drivers/barometer/bmp388/bmp388.cpp index 464d9b5829..4fa7722918 100644 --- a/src/drivers/barometer/bmp388/bmp388.cpp +++ b/src/drivers/barometer/bmp388/bmp388.cpp @@ -171,8 +171,12 @@ BMP388::collect() perf_begin(_sample_perf); - /* this should be fairly close to the end of the conversion, so the best approximation of the time */ - const hrt_abstime timestamp_sample = hrt_absolute_time(); + /* Correct for measurement integration delay: the pressure was + * integrated over the preceding measurement_time window, so the + * effective sample midpoint is half the measurement time before now. */ + const hrt_abstime now = hrt_absolute_time(); + const hrt_abstime half_meas = get_measurement_time() / 2; + const hrt_abstime timestamp_sample = (now > half_meas) ? (now - half_meas) : now; if (!get_sensor_data(sensor_comp, &data)) { perf_count(_comms_errors);