Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PX4Magnetometer.cpp: Workaround for sensors not initializing with all the magnetometers #23972

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jlaitine
Copy link
Contributor

This PR is a workaround for two issues I am having with the magnetometers. I am running still on 1.14.3, and I tried to study if there are related fixes in 1.15, but didn't find any. So I am offering this one to upstream as well.

If there are better ways to fix these issues, or if they are somehow fixed already and I missed it, please let me know / reject this PR.

So, I am having 2 issues with magnetometers using the following setup:

2 magnetometers in the drone, one internal (bmm350) and one external (ist8310). BMM350 is started first in the rc scripts, ist8310 is started second.

1st issue:

The magnetometers get initialized with state machines running in a work queue, and the initializing RC script runs in parallel to the work queue. On a slightly faster FMU, the ist8310 magnetometer (started second in the rc script) manages to advertise it's uORB before the bmm350. So on this HW the external mag becomes "MAG_0", while on the slightly slower FMU the bmm350 (which was started first by the RC script) manages to advertise it's uORB first, so on that HW the internal mag becomes "MAG_0". With a very bad luck, the numbering becomes random, that is, it varies from boot to boot which one is 0 and which one is 1. This breaks many things (like calibration) and confuses people.

2nd issue

On a certain drone chassis I want to disable the internal magnetometer. I am doing that by setting parameter "CAL_MAG0_PRIO" to 0 ( now assuming that it happens to be 0, considering the first issue above ).

Now, RC script is still running in parallel with the work queues running the magnetometer initialization. It may happen that the "sensors" module gets started by the RC script before my "MAG_1" publishes it's first data. For some reason, the sensors module is not taking the newly appearing magnetometer into account any more.

** workaround for the issues above **

This patch publishes some initial "0" data right at the time of constructing the magnetometer driver. If the probing of the sensor fails, the orb gets anyhow unadvertised, so there is no extra sensor data lying around in the case the magnetometer is not present.

This also forces the magnetometer numbering to follow the startup order; without advertising the data the orb numbering depends on magnetometer initialization sequence - a magnetometer started later in the init scripts may publish it's first data before some other mag, which was started earlier. This is especially problematic when using the same scripts on different HW platforms which run on different speeds.

…ors not initializing with all the magnetometers

There is some issue with "sensors" module; it only takes into account the magnetometers which have published data
before the module start.

Workaround this issue by publishing some initial "0" data right at the time of constructing the magnetometer driver.
If the probing of the sensor fails, the orb gets anyhow unadvertised, so there is no extra sensor data lying
around in the case the magnetometer is not present.

This also forces the magnetometer numbering to follow the startup order; without advertising the data
the orb numbering depends on magnetometer initialization sequence - a magnetometer started later in the
init scripts may publish it's first data before some other mag, which was started earlier. This is especially
problematic when using the same scripts on different HW platforms which run on different speeds.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
@jlaitine jlaitine force-pushed the workaround_sensors_not_reading_all_mags branch from c87f18e to e714f37 Compare November 19, 2024 11:27
@dakejahl
Copy link
Contributor

This breaks many things (like calibration) and confuses people.

It shouldn't break calibration since the CAL parameters are tied to the DeviceID, eg CAL_MAG0_ID

But I agree it would be nice to have consistent uORB order for log analysis and debugging

@jlaitine
Copy link
Contributor Author

This breaks many things (like calibration) and confuses people.

It shouldn't break calibration since the CAL parameters are tied to the DeviceID, eg CAL_MAG0_ID

But I agree it would be nice to have consistent uORB order for log analysis and debugging

Thanks for the comment, I stand corrected! Maybe the "calibration issues" which have been reported to me were about confusion created by attempting to disable a specific sensor or such on different HWs.

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.

2 participants