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

Mag calibration improvements and fixes #13623

Merged
merged 4 commits into from
Nov 29, 2019
Merged

Mag calibration improvements and fixes #13623

merged 4 commits into from
Nov 29, 2019

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Nov 28, 2019

Bug fix

Fixes a serious calibration bug in combination with the HMC5883 driver (also used for HMC5983): this driver estimates a scale in MAGIOCCALIBRATE and applies it.
The calibration routine calls MAGIOCCALIBRATE (after resetting the existing calibration), then does the calibration with that scale applied, and then overwrites it, without considering it in any way.

Most other mag drivers only do some measurements and perform some checks in MAGIOCCALIBRATE (but the result is just ignored). So it could be removed completely.

Improve 4 and 2 side calibration

The idea is that an initial 6 sided (factory-) calibration is done, and then a two-sided calibration is sufficient later on.
So this PR changes:

  • if less than 6 sides are calibrated, keep the existing calibration and update the offsets and scales
  • if 2 sides are calibrated, estimate the offsets only (as this is enough if a full calibration was done already, and the problem is not constrained enough to estimate scales and offsets - I got consistently wrong results even if the required calibration is very close to identity).

Tested on different boards, with different number of sides. The results were consistent when repeating the calibration.

See also individual commits.

Fixes a serious bug in combination with the HMC5883 driver (also used for
HMC5983): this driver estimates a scale in MAGIOCCALIBRATE and applies it.
The calibration routine does the calibration with that scale applied, and
then overwrites it, without considering it in any way.

Most other mag drivers only do some measurements and perform some checks
in MAGIOCCALIBRATE (but the result is just ignored).
So it is independent from the number of configured sides.
Previously, each side would take longer if less than 6 sides were
calibrated.

Also fixes a bug: calibration_sides was used before it was updated, leading
to different behavior on consecutive calibrations with <6 sides.
- if less than 6 sides are calibrated, keep the existing calibration and
  update the offsets and scales
- if 2 sides are calibrated, estimate the offsets only (as this is enough
  if a full calibration was done already, and the problem is not
  constrained enough to estimate scales and offsets)
@LorenzMeier
Copy link
Member

Awesome!

@dagar dagar added the bug label Nov 28, 2019
@dagar dagar self-requested a review November 28, 2019 16:29
@dagar
Copy link
Member

dagar commented Nov 28, 2019

For the HMC5883/HMC5983 internal calibrate I was wondering about doing it initially at driver start (stored and applied correctly), and not explicitly with every user driven calibration. Thoughts?

The MAGIOCCALIBRATE interaction during calibration is one of the little things we don't really have a replacement for if we used parameters directly. The calibrate also looks bogus in some of the other drivers (copypasta from the honeywell).

@bkueng
Copy link
Member Author

bkueng commented Nov 29, 2019

I have not looked into the exact details, but I don't think it's worth the effort, simply for the fact that both HMC5883 and HMC5983 are EOL. For others it might be useful though.

@dagar dagar merged commit b973b2c into master Nov 29, 2019
@dagar dagar deleted the mag_calibration_fixes branch November 29, 2019 19:14
@mrpollo mrpollo mentioned this pull request Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants