Skip to content

Clarify EKF3 Affinity#7499

Open
hunt0r wants to merge 3 commits intoArduPilot:masterfrom
hunt0r:clarify-ekf3-affinity
Open

Clarify EKF3 Affinity#7499
hunt0r wants to merge 3 commits intoArduPilot:masterfrom
hunt0r:clarify-ekf3-affinity

Conversation

@hunt0r
Copy link
Contributor

@hunt0r hunt0r commented Mar 9, 2026

EKF3 affinity is difficult to understand from our wiki docs. This (hopefully!) improves it's clarity.

Reviewers: I determined this from source-diving. Please carefully examine this PR's content for mistakes.

Summary of significant points:

  • The truth is quite complicated, and somewhat sensor-type dependent. This PR adds a disclaimer to warn of that.
  • The concept of "primary" is clarified. We have both "primary" EKF lanes, but also "primary" sensor instances.
  • The 1-1ness of lanes & used IMU instances was inferred, but is now explicitly stated.
  • The example provided was too simple. The new example shows more.

The first commit switches to one-sentence-per-line. I find this style much easier for future reviews/changes. (I did not fix the whole file. That has the downside of leaving us with mixed style in a single file. IMO, any movement towards one-sentence-per-line is improvement.) I will revert this to preserve the "one paragraph per line" style if any reviewer objects.

The second commit fixes some trailing whitespace. I'll drop it if any reviewer objects.

Testing:
Built locally, renders as expected.
image

@cclauss
Copy link
Contributor

cclauss commented Mar 9, 2026

Pre-commit errors fixed in:

@hunt0r
Copy link
Contributor Author

hunt0r commented Mar 9, 2026

Pre-commit errors fixed in:

Cool! But... this is entirely independent from this PR, right? (Fixing typos in files this doesn't touch.)

@cclauss tagging you just in case there's a typo in a PR number or something. 🤷

@hunt0r
Copy link
Contributor Author

hunt0r commented Mar 9, 2026

My comment was meant for reviewers of this pull request... The typos are unrelated, and fixes have been proposed elsewhere. It is a bit bumpy when new pre-commit hooks are added, especially before contributors have done pre-commit install.

No worries for minor turbulence. Hurray for automation!

Should the instructions mention pre-commit? If they do, I missed them. If not, no worries, I imagine that will come in time.

@hunt0r
Copy link
Contributor Author

hunt0r commented Mar 9, 2026

What I have so far is:

# See https://pre-commit.com for more information, specially https://pre-commit.com/#pre-commit-run for manual trigger
# Some example useful invocations:
# pre-commit install: this will install the pre-commit hooks in this file.
# pre-commit run: this is what pre-commit runs by default when committing. This will run all hooks against currently staged files.
# pre-commit run --all-files: run all the hooks against all the files. This is a useful invocation if you are using pre-commit in CI.

I would be happy to add elsewhere if you have suggestions.

Suggestions made in PR form 😄
#7502

If affinity for that sensor-type is disabled, each lane uses the system's "primary" instance of the sensor.
(Affinity being disabled for every sensor-type is the conventional/default choice.)
The initial primary sensor instance is selected by a user-modifiable parameter.
The system may change which sensor instance is its primary, even in-flight, for example in case of a sensor fault.
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is a bit confusing in this context. Yes, the lane can possibly change its primary sensor for some sensors mid-flight, for example, a compass. But I don't think that's true for all sensors.. for example a barometer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had details like this in mind with the note-box "This page [...] is not perfect on the details."

Do you think it's worth describing and then maintaining all the details on this page? If yes, additional commit(s) to fix them & remove the "this page is not perfect on the details" are welcome.

On the flip side: Do you think the page is better as it was before? That path forward also makes sense: Reject this PR and keep the content as it was.

The system may change which sensor instance is its primary, even in-flight, for example in case of a sensor fault.

Because modern-day vehicles may have redundant good quality sensors installed, "affinity" provides a way to have some EKF lanes prefer sensor instances which are not the system-wide primary.
For sensors with affinity enabled, lane-switching should be thought of as sensor-switching.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is over-simplification. It's possible that not all IMUs present in a flight controller perform equally well. Which means lane-switching with affinity enabled isn't just "sensor-switching". If a user hasn't tested all lanes (or at least checked logs for all lanes), they might switch to a worse lane.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it is a simplification. (I hoped "should be thought of" would communicate that... maybe it did?)

Over-simplification suggests it might be worse than some alternative... help me understand what you have in mind?

Also, I think there's no gap in my understanding of the topic, it's merely a discussion about what wording is appropriate. This PR is my attempt to find the right balance, but I'm glad to take it in the direction(s) you'd like!

Do you know github's "Suggest Changes" feature? That would be a great way to specifically communicate what differences you'd like to see, and my "Accept Suggestion" would confirm my agreement/understanding.

Because modern-day vehicles may have redundant good quality sensors installed, "affinity" provides a way to have some EKF lanes prefer sensor instances which are not the system-wide primary.
For sensors with affinity enabled, lane-switching should be thought of as sensor-switching.
The lane error score (used to make a switching decision) takes into account innovations from all sensors used by a lane.
Thus in the case of noisy-but-not-broken non-IMU sensors, affinity might avoid a mishap by simply EKF lane-switching to a less-noisy IMU+sensor combination.
Copy link
Contributor

Choose a reason for hiding this comment

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

The language here is a bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm guessing you're flagging the over-hypenation 😄. Yeah, I didn't have good user-facing language for "misbehaving but not faulted". Suggestions?

I also tried to stay close to the original sentence (language like "avoid a mishap by lane-switching") which might contribute to the confusion. That was primarily motivated by a desire to make a minimum-necessary change, I'm happy with broader rewording if you are.

@hunt0r hunt0r requested a review from rishabsingh3003 March 10, 2026 02:24
@cclauss
Copy link
Contributor

cclauss commented Mar 10, 2026

Please rebase to pick up the typo fixes.

@hunt0r hunt0r force-pushed the clarify-ekf3-affinity branch from 543c994 to 61a4457 Compare March 10, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants