mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-09-25 20:28:26 +08:00
fix(commander): convert the baro timestamp delta to seconds for the home altitude filter (#28415)
The low pass filter smoothing barometric altitude for the in-air home position correction was fed the raw timestamp difference. uORB timestamps are microseconds, but AlphaFilter::setParameters() documents both of its arguments as seconds and the filter is constructed with a 5 second time constant, so the sample interval arrived a million times too large: alpha = dt / (tau + dt) rate dt alpha (before) alpha (intended) 50 Hz 0.0200 s 0.999750 0.003984 100 Hz 0.0100 s 0.999500 0.001996 200 Hz 0.0050 s 0.999001 0.000999 At an alpha of 0.9997 the filter passes essentially every raw sample through, giving an effective time constant of 5 us instead of 5 s, so _lpf_baro.getState() has been effectively unfiltered barometric altitude. That state feeds the in-air home altitude correction: it is offset by _baro_gps_static_offset and then compared against the GNSS altitude, and home.alt is shifted when the two differ by more than kAltitudeDifferenceThreshold. A GNSS velocity integral gates that comparison for consistency. The same conversion is already done correctly for the GNSS integral a few lines below in this file, and for the geoid height filter in EKF2. Note that this does change behaviour: the filter now actually applies its 5 s time constant, so _lpf_baro.getState() lags during a climb by roughly the time constant times the climb rate. _baro_gps_static_offset is captured once when the correction window opens, so that lag does not cancel and it biases baro_alt_corrected while climbing. Reviewers who know this feature should say whether the 5 s constant and the 1 m threshold, both tuned while the filter was effectively a pass-through, still want the same values now that it filters. Assisted-by: Claude:claude-fable-5 Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
This commit is contained in:
@@ -364,7 +364,7 @@ void HomePosition::update(bool set_automatically, bool check_if_changed)
|
||||
const float baro_alt = baro_data.baro_alt_meter;
|
||||
|
||||
if (_last_baro_timestamp != 0) {
|
||||
const float dt = baro_data.timestamp - _last_baro_timestamp;
|
||||
const float dt = 1e-6f * (baro_data.timestamp - _last_baro_timestamp);
|
||||
_lpf_baro.update(baro_alt, dt);
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user