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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve magnetometer consistency check #12334

Merged
merged 5 commits into from
Aug 7, 2019
Merged

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented Jun 26, 2019

Describe problem solved by the proposed pull request
Fixes #12272

Describe your preferred solution
Instead of comparing each vector component of the 3D filed vectors of each additional megnetometer against the primary one we calculate the angle between the vectors. This allows to check if the sensor orientation is set correctly and the magnetometers mounts are not completely misaligned. It should result in less false positives because of small magnetometer amplitude differences between internal and external compass since we had a lot of false positives preventing people to fly with perfectly fine setups.

There's also some refactoring going on:

  • There were early returns one of which lead to not unsubscribing from the sensors topic and leaking file descriptors.
  • matrix namespace can be used globally in the cpp source to safe repetitive code
  • we should shift towards consistent camelCase function names in our C++ classes, that improves readability against variables

Test data / coverage
Not yet tested. Tests to come.
EDIT: I did bench tests and it works great 馃帀 :

  • I strapped a GPS module (with external mag) to a pixhawk 4 with foam in between to avoid mag interference because of the pxihawk 4 metal case.
  • I did the compass calibration.
  • I armed with all the circuit breakers because it's only a board. It worked every time with this fixed setup.
  • I took the GPS module and external compass off and tilted it a bit. From 30掳 (default) on in any direction it denies to arm and shows you what the inconsistency error in degree is such that the user gets a feel if it's 180掳 or 31掳.
    QGC1
    QGC2
  • I put the mag back where the calibration was done and it works fine again

Describe possible alternatives
closes #12327

Additional context
Add any other related context or media.

@MaEtUgR MaEtUgR added the bug label Jun 26, 2019
@MaEtUgR MaEtUgR self-assigned this Jun 26, 2019
@dagar
Copy link
Member

dagar commented Jun 26, 2019

There were early returns one of which lead to not unsubscribing from the sensors topic and leaking file descriptors.

All of that orb usage can be updated to stack allocated uORB::Subscription, which cleans itself up via RAII and doesn't even use file descriptors internally. I can do it in a followup PR.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jun 26, 2019

@dagar Great, @bkueng mentioned that to me when I quickly asked him 馃憤
I started testing this pr and will follow up with the results.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jun 26, 2019

I successfully benchtested this PR, comments in description and improved the output for the user in case the check fails.

@MaEtUgR MaEtUgR changed the title Mag consistency check Improve magnetometer consistency check Jun 26, 2019
@dagar
Copy link
Member

dagar commented Jun 26, 2019

The updated output is quite nice, but still feels one step away from being actionable for a user. Could we just keep all the angle errors (mag_inconsistency_angle[MAG_COUNT_MAX]) and report which mags exceed the threshold? That way we'd have more detail in the log (sensor_preflight) and the user could decide to disable a particular mag if necessary (we'd have to be careful with the reported numbering).

Preflight Fail: Compass X %.0f掳 inconsistent with primary (Y)"

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jun 27, 2019

I force-pushed to switch the printf value from double to int since it anyways doesn't have a decimal place printed: https://github.com/PX4/Firmware/compare/0216cdd624c2394aed31ed4b03cb5c5cbbbf8d54..a4a6593370fe39536bb19190382d7430e3fb50f1

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jun 27, 2019

The updated output is quite nice, but still feels one step away from being actionable for a user.

@dagar It's the best that was possible with the current architecture. The number of the mag would certainly also be useful but the information is not passed on to the PreflightCheck and I think the voted_sensors check doesn't even know what mag ID it is that gets checked, just the subscription instance and if it's primary or not. Can we improve it further in a next revision?

@dagar
Copy link
Member

dagar commented Jun 27, 2019

Can we improve it further in a next revision?

Yes of course, I don't mean to impede progress, just brainstorming ideas. This is a nice improvement.

@LorenzMeier LorenzMeier requested a review from a team June 27, 2019 22:41
@LorenzMeier
Copy link
Member

@PX4/testflights Please test and please make sure to also test with a magnet if the check still triggers.

@Tony3dr Tony3dr added this to Ready for testing in Test Flights Jun 28, 2019
@priseborough
Copy link
Contributor

A bias vector in the direction of the earth field will be undetected by this method and result in a false negative if the vehicle remains in a constant orientation from boot to flight so this change does reduce the level of protection. One way to close this vulnerability is to require the user to perform a 90 degree yaw rotation as part of the preflight check.

This method does eliminates false positives caused by different t absolute scale factors between magnetometers.

My testing has shown that calibrating a pixracer board when powered via USB results in an incorrect calibration for the internal magnetometer so this is something to be aware of during testing. I have never had the legacy check fail on a correctly calibrated vehicle other than when magnetic interference caused a different readings between internal and external sensors.

Testing of this PR should include rotating either the internal or external mag with a magnet or by setting offsets to check that the check triggers when there is an error, not just testing to show it doesn't trigger.

Taking off near local magnetic anomalies can still result in a rotated field seen by the external and internal mag depending on their relative locations and result in a check fail even for sensors that are correctly calibrated. A way to resolve a test fail caused by this is to ask the user to pick up and put down the vehicle. If the error clears when the vehicle is picked up, then it is unlikely to be a calibration error, so we could add logic that if the check passes for longer than TBD seconds (long enough to pick up the vehicle) then it latches to passed.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jun 28, 2019

A bias vector in the direction of the earth field will be undetected by this method

I'm aware of this, The goal was to bring down the false positives that I've seen people really struggling with while keeping a useful safety check to see if the values make sense or the setup is completely screwed up e.g. wrong sensor rotation.

My testing has shown that calibrating a pixracer board when powered via USB results in an incorrect calibration

I've seen small differences in calibration that intermittently pass and fail the 0.15 threshold on all components when calibrating with the USB cable plugged. We have to face the fact that people including me will also in future calibrate using a USB cable. The accuracy will be reduced by that and your ideas about separating scale and offset calibration plus learning the offsets over time are in my opinion very valuable and we should look into them.

I have never had the legacy check fail on a correctly calibrated vehicle other than when magnetic interference caused a different readings between internal and external sensors.

I had this happening: I have a wing and a plane with PX4 and had this problem with both. I calibrated them multiple times with and without USB cable and the check sometimes passed sometimes failed randomly even when I didn't change anything about the setup and just went flying on a different day. The unpleasant surprise of having everything set up on the field just like the day before holding the plane in the hand ready to launch, yaw direction looking good just to have the autopilot randomly failing preflight check lead me to increase the threshold to basically disable the check. Multiple times when this happened I plotted the magnetic field vectors and inspected them. Since the vehicle was properly calibrated the angle between the vectors was always within 15掳 but the amplitude changed for some interference reason. I thought for a long time I'm the only one having this problem until I realized a lot of users experience the same issue.

I asked myself what the point of assuming an exact match of internal and external magnetometer data is if you have an external compass because the internal one is buried in components that generate potentially dynamic interference.

Testing of this PR should include rotating either the internal or external mag with a magnet or by setting offsets to check that the check triggers when there is an error, not just testing to show it doesn't trigger.

I did test rotating the external mag and checking the result. The test reliably failed and passed in all the cases I came up with rotating the external mag around different axes.

EDIT: I don't understand why CI fails... Did I break the uORB tree in some way?

@dannyfpv
Copy link

dannyfpv commented Jul 5, 2019

Tested on Pixhawk 4 v5

Procedure

  • Loaded PR12334, placed close to the GPS, proceeded to arm but vehicle did not arm. (Image below shows the reponse)

Screen Shot 2019-07-05 at 9 58 16 AM

Screen Shot 2019-07-05 at 10 17 50 AM

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 22, 2019

I rebased cleanly to properly run CI again.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 22, 2019

I had to fix the uorb_graph exception rule because the naming changed. Now CI should pass.

@dagar dagar added this to Low priority in Devcall via automation Jul 31, 2019
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 31, 2019

Rebased without conflicts to make CI happy. It was the appveyor version check failing because of shallow clone, see #12555.

@dagar
Copy link
Member

dagar commented Aug 2, 2019

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Aug 5, 2019

I removed the merge commit, rebased, fixed the naming to camel case for the line that recently changed with #12586. Now CI is finally happy. Anyone approving?

@dagar
Copy link
Member

dagar commented Aug 5, 2019

@MaEtUgR small side note - those merge commits (from clicking "Update branch" on github) disappear when we "Rebase and merge" or "Squash and merge".

@davids5 davids5 moved this from Low priority to Currently under discussion in Devcall Aug 7, 2019
@davids5 davids5 moved this from Currently under discussion to Discussed in Devcall Aug 7, 2019
@LorenzMeier LorenzMeier added this to In progress in User Experience (UX) via automation Aug 7, 2019
@mcsauder mcsauder added this to To Do in Release 1.11 Blockers via automation Aug 7, 2019
@davids5 davids5 moved this from To Do to Testing in Release 1.11 Blockers Aug 7, 2019
@LorenzMeier LorenzMeier merged commit 161429f into master Aug 7, 2019
Release 1.11 Blockers automation moved this from Testing to Done Aug 7, 2019
Test Flights automation moved this from Ready for testing to Done Aug 7, 2019
Devcall automation moved this from Discussed to Done Aug 7, 2019
User Experience (UX) automation moved this from In progress to Done Aug 7, 2019
@LorenzMeier LorenzMeier deleted the mag-consistency-check branch August 7, 2019 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Multiple magnetometer inconsistency check needs to be revised
5 participants