Skip to content

Conversation

bresch
Copy link
Member

@bresch bresch commented Jan 23, 2025

Solved Problem

Constant small accelerations during gravity fusion creates a small tilt error. As a consequence, the accel bias gets incorrectly estimated and the gravity fusion (using this bias estimate) takes more time to correct back the error.

Solution

Stop accel bias estimation while gravity fusion is active.

Additionally:

  • start gravity fusion based on accelerometer LPF instead of a peak hold filter (this was causing the flag to switch on and off all the time due to vibrations/spikes). The innovation filter with a small gate (0.25) is more than enough to avoid fusing quick changes in accelerometer data
  • add a "update_tilt" parameter to declination to force the "tilt Kalman gains" to 0 as we already do in mag fusion
  • do not let the mag heading fusion update the xy gyro biases: incorrect mag data was still able to corrupt the tilt estimate by affecting the gyro biases

Test coverage

EKF replay, unit tests, SITL tests

Before: rapid flag switching
image

After: incorrect acceleration are rejected by he innovation filter and not the control flag
Screenshot from 2025-01-23 15-47-29

@bresch bresch requested review from dagar and haumarco January 23, 2025 15:05
@bresch bresch self-assigned this Jan 23, 2025
@bresch bresch marked this pull request as draft January 24, 2025 07:50
@github-actions github-actions bot added the stale label Feb 24, 2025
@bresch bresch force-pushed the pr-ekf2_grav_fusion_threshold branch from b1b6810 to ef78725 Compare April 9, 2025 09:09
@bresch bresch marked this pull request as ready for review April 9, 2025 09:09
bresch added 6 commits April 9, 2025 11:09
This prevent rapid switching in presence of noise and the innovation
filter is good at rejecting spikes
Gravity fusion uses the bias corrected accelerometer data to correct the
tilt estimate. We should not continue to estimate the accel bias when
this is active as it creates an unwanted feedback loop.
This can destabilize the tilt estimate when the mag field is disturbed
@bresch bresch force-pushed the pr-ekf2_grav_fusion_threshold branch from ef78725 to 0a37ca0 Compare April 9, 2025 09:12
@bresch bresch added EKF2 and removed stale labels Apr 9, 2025
@bresch bresch requested a review from dagar April 9, 2025 09:24
const bool enable_fake_pos = !enable_valid_fake_pos
&& (getTiltVariance() > sq(math::radians(3.f)))
&& !(_params.imu_ctrl & static_cast<int32_t>(ImuCtrl::GravityVector))
&& !_control_status.flags.gravity_vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gravity_vector flag is handled a bit differently where it might be flipping on/off relatively rapidly with the accel threshold. Should we change that behavior so it's more consistent with other aid sources? Alternatively we could check here if gravity fusion hasn't been active for some period of time before finally giving up and starting fake_pos.

_control_status.flags.gravity_vector = (_params.imu_ctrl & static_cast<int32_t>(ImuCtrl::GravityVector))
&& (accel_lpf_norm_good || _control_status.flags.vehicle_at_rest)
&& !isHorizontalAidingActive();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, completely missed the plot in the PR description about the rapid switching.

Are we completely sure additional protection isn't needed so that we only start fake_pos as a last resort given it will reset pos/vel on start?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tilt variance condition (getTiltVariance() > sq(math::radians(3.f))) should make sure the fake position doesn't start immediately when the gravity fusion was healthy and briefly switches off (it should take several seconds to reach 3 degrees of tilt uncertainty).

@dagar dagar added this to PX4 EKF Apr 16, 2025
@dagar dagar moved this to 👀 In review/test in PX4 EKF Apr 16, 2025
@bresch bresch requested a review from dagar April 16, 2025 07:41
Comment on lines +58 to +59
const bool accel_lpf_norm_good = (accel_lpf_norm_sq > sq(lower_accel_limit))
&& (accel_lpf_norm_sq < sq(upper_accel_limit));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the lpf filter not an issue when we still have vibrations? Would using accel_vibration_metric be of any additional benefit or do you think is good enough like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Yes, it could still be problematic, but seemed to be ok on the logs I used in replay. Not sure if the vibration metric can help, but we could lower the cutoff frequency of the filter if we see that it's still sensitive. I'll continue to monitor that in the new flights.

@bresch bresch requested a review from haumarco April 30, 2025 06:24
@bresch bresch merged commit e7250bc into main May 2, 2025
65 of 67 checks passed
@bresch bresch deleted the pr-ekf2_grav_fusion_threshold branch May 2, 2025 08:23
@github-project-automation github-project-automation bot moved this from 👀 In review/test to ✅ Done in PX4 EKF May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants