From 047fddbcd8b9fa6d6cee7908c0d2865e005088ef Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Sat, 4 Apr 2026 00:02:21 -0800 Subject: [PATCH] fix(sensors): fix baro publish rate limiter aliasing (#26967) Use timestamp_sample instead of time_now_us for the rate limiter check to sync to the sensor clock rather than the wall clock. Switch from direct timestamp assignment to epoch-advance (_last_publication_timestamp += interval_us) with a catch-up guard to prevent aliasing artifacts when the sensor sample rate is close to the configured publication rate. --- src/modules/sensors/vehicle_air_data/VehicleAirData.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/sensors/vehicle_air_data/VehicleAirData.cpp b/src/modules/sensors/vehicle_air_data/VehicleAirData.cpp index 9c4fe75ece..13c17b197d 100644 --- a/src/modules/sensors/vehicle_air_data/VehicleAirData.cpp +++ b/src/modules/sensors/vehicle_air_data/VehicleAirData.cpp @@ -274,7 +274,7 @@ void VehicleAirData::Run() const hrt_abstime timestamp_sample = _timestamp_sample_sum[instance] / _data_sum_count[instance]; - if (time_now_us >= _last_publication_timestamp[instance] + interval_us) { + if (timestamp_sample >= _last_publication_timestamp[instance] + interval_us) { bool publish = (time_now_us <= timestamp_sample + 1_s); @@ -312,7 +312,12 @@ void VehicleAirData::Run() _vehicle_air_data_pub.publish(out); } - _last_publication_timestamp[instance] = time_now_us; + // epoch-advance to prevent aliasing; catch up if more than one interval behind + _last_publication_timestamp[instance] += interval_us; + + if (timestamp_sample > _last_publication_timestamp[instance] + interval_us) { + _last_publication_timestamp[instance] = timestamp_sample; + } // reset _timestamp_sample_sum[instance] = 0;