From ffa10ab3623c2a3723d0ef5595bb895f946caef2 Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Tue, 31 Mar 2026 14:48:59 -0800 Subject: [PATCH] fix(lps22hb): correct timestamp_sample to integration midpoint The LPS22HB one-shot measurement is integrated over a ~40ms window (at 25Hz-equivalent internal averaging). The read time corresponds to the end of the integration window. Correct timestamp_sample to the midpoint by subtracting CONVERSION_INTERVAL / 2. --- src/drivers/barometer/lps22hb/LPS22HB.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/drivers/barometer/lps22hb/LPS22HB.cpp b/src/drivers/barometer/lps22hb/LPS22HB.cpp index 3121acc0ef..a29b2189db 100644 --- a/src/drivers/barometer/lps22hb/LPS22HB.cpp +++ b/src/drivers/barometer/lps22hb/LPS22HB.cpp @@ -139,8 +139,12 @@ int LPS22HB::collect() uint8_t TEMP_OUT_H; } report{}; - /* this should be fairly close to the end of the measurement, so the best approximation of the time */ - const hrt_abstime timestamp_sample = hrt_absolute_time(); + /* Correct for measurement integration delay: the one-shot conversion + * was started CONVERSION_INTERVAL ago, so the effective sample + * midpoint is half the conversion interval before now. */ + const hrt_abstime now = hrt_absolute_time(); + const hrt_abstime half_meas = LPS22HB_CONVERSION_INTERVAL / 2; + const hrt_abstime timestamp_sample = (now > half_meas) ? (now - half_meas) : now; int ret = _interface->read(STATUS, (uint8_t *)&report, sizeof(report)); if (ret != OK) {