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.
This commit is contained in:
Jacob Dahl 2026-04-04 00:02:21 -08:00 committed by GitHub
parent dd2530bb09
commit 047fddbcd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -274,7 +274,7 @@ void VehicleAirData::Run()
const hrt_abstime timestamp_sample = _timestamp_sample_sum[instance] / _data_sum_count[instance]; 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); bool publish = (time_now_us <= timestamp_sample + 1_s);
@ -312,7 +312,12 @@ void VehicleAirData::Run()
_vehicle_air_data_pub.publish(out); _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 // reset
_timestamp_sample_sum[instance] = 0; _timestamp_sample_sum[instance] = 0;