Updated SensESP code for saving Magnetic Calibration #22
Replies: 11 comments 6 replies
-
Great improvement, Bjarne! Just installed in on an ESP32, and it works. Will do some testing to test its behavior. |
Beta Was this translation helpful? Give feedback.
-
With this progress, new ideas pop up!
These are just thoughts for further improvements. Already very impressed by the work done and very happy with it. |
Beta Was this translation helpful? Give feedback.
-
Small comment on the code: in line 113 of the example code (fx8700_heading_example.cpp), a ; is needed at the end of the line. I don't know how to fix this. |
Beta Was this translation helpful? Give feedback.
-
Found it: had to add the following line: |
Beta Was this translation helpful? Give feedback.
-
Having forked and cloned the SignalK-Orientation repo and successfully uploaded it to a ESP32dev board, I have a question: |
Beta Was this translation helpful? Give feedback.
-
There are a few new additions to the OrientationSensorFusion-ESP and SignalK-Orientation libraries that should help with magnetic calibration. The Orientation interface now has Get___() methods for several internal variables of the calibration subsystem. These report the
These help decide whether calibration is good, but do not directly report magnetic interference (I'm still working on that). If you have a look at the I would like eventually to wrap all three up into a single parameter (so we don't need 3 separate instruments to display the values) but haven't thought yet about how to make that work well. One additional change: in the web interface, if you enter a -1 and Save, then the magnetic calibration is erased from EEPROM. Entering a 1 and Save will save the current calibration in EEPROM, just as before. I haven't updated the online prompt to reflect this new behaviour. Now you can experiment with creating/deleting magnetic calibrations, and how they affect the fit parameters. A reboot of the system is needed to load a saved calibration. |
Beta Was this translation helpful? Give feedback.
-
Great stuff, Bjarne!
Just tried it out and it works really good.
Met vriendelijke groet,
Daniel Goedhuis
06-52 52 50 62
… Op 23 jan. 2021, om 19:31 heeft Bjarne Hansen ***@***.***> het volgende geschreven:
There are a few new additions to the OrientationSensorFusion-ESP and SignalK-Orientation libraries that should help with magnetic calibration. The Orientation interface now has Get___() methods for several internal variables of the calibration subsystem. These report the
quality of fit for current and prospective calibrations. These are numbers ranging [0..100], lower is better fit, and a value less than 3.5 is considered a good calibration.
order of calibration algorithm. This indicates complexity of the calibration algorithm and has possible values of 0 (no calibration), 4, 7, and 10 (most sophisticated).
Geomagnetic field strength
These help decide whether calibration is good, but do not directly report magnetic interference (I'm still working on that).
If you have a look at the examples/example_main.cpp in the SignalK-Orientation library, it has three new paths reporting these values, and there are comments in that file about what they mean.
<https://user-images.githubusercontent.com/68290965/105610703-dd407080-5d65-11eb-8d0f-07a8e2ef6d7f.png>
I would like eventually to wrap all three up into a single parameter (so we don't need 3 separate instruments to display the values) but haven't thought yet about how to make that work well.
One additional change: in the web interface, if you enter a -1 and Save, then the magnetic calibration is erased from EEPROM. Entering a 1 and Save will save the current calibration in EEPROM, just as before. I haven't updated the online prompt to reflect this new behaviour. Now you can experiment with creating/deleting magnetic calibrations, and how they affect the fit parameters. A reboot of the system is needed to load a saved calibration.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#22 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADRLPPXYHMIWE66X3PD3CITS3MIXFANCNFSM4WFVWBNA>.
|
Beta Was this translation helpful? Give feedback.
-
OK - I believe the last piece of the calibration puzzle is in place... I updated the SignalK-Orientation project How it WorksA digital input pin is read periodically and if its state changes, the next consumer (debounce transform) is notified. I set the switch read interval and debounce period fairly long, as we don't need quick response for this function and this way an accidental quick push on the switch won't cause one to lose an existing calibration. With the settings I used, the switch needs to be held just under 500ms before it takes action. The debounce transform sends its output to a lambda consumer function, which I defined as a call to the orientation library's I chose to wire up a physical button that grounds a GPIO pin when pushed, so the GPIO has its pull-up resistor enabled. There's no reason one couldn't use a pull-down on the GPIO and tie the switch to logic high instead - just adjust the code that sets up the digital input. Also (forgive me if I'm repeating something you already know) for good noise immunity and CPU protection in a device to be used in the field, I recommend putting a few passive components on the switch circuit. This is particularly a good idea if the wire length between the CPU and the switch is longer than, say, 10 cm or there's a chance of zapping the switch with static electricity. There's quite a few configurations commonly used for input protection - what I'll probably use is a series resistor between the switch and the GPIO pin of about 1000 ohms (the pull-up/pull-down resistance for ESP32 pins is 45 k, so 1 k will overcome that nicely), and then an ESD protection diode rated between 3V3 and 5V0 between the GPIO pin and board ground. An alternative is to use a small-value capacitor instead of the ESD diode - a 100 nF cap would be fine, as the RC time constant together with the 1k resistor will be plenty short. Anyway, just a suggestion... |
Beta Was this translation helpful? Give feedback.
-
I've done some testing on Magnetic Interference, to find a good indicator of when a calibration might not be valid due to changes in the magnetic environment of the sensor. See the wiki page here: https://github.com/BjarneBitscrambler/OrientationSensorFusion-ESP/wiki/Magnetic-Interference for more details. Consequently I've added a couple functions that report the level of magnetic interference - one of them directly, and the second one that can be used to infer interference when it changes. These are:
These functions are available right now in the OrientationSensorFusion-ESP library. I'm going to experiment in the SignalK-Orientation library to see whether it makes sense to package these parameters up in a single JSON packet that can be sent to a custom SignalK widget for display. One can of course just display the parameters individually without any further changes. |
Beta Was this translation helpful? Give feedback.
-
Folks - I've updated the example The heading with the corrections applied is sent to the I've tested it on my ESP8266 and ESP32 devices, and it has been functioning well. Next I'll probably box the PCBs up properly and start doing some more testing. Enjoy! |
Beta Was this translation helpful? Give feedback.
-
Spring is here and it's time to solder and put the orientation sensor in a box. @BjarneBitscrambler do you have any recommendations about the positioning of the sensor board. Can I solder the board to my experiment board or should I keep some distance (cm:s) from the larger board? |
Beta Was this translation helpful? Give feedback.
-
@tedenda and @DanielG86 Just letting you know that I've updated the SensESP orientation code. It now includes the ability to save the current magnetic calibration using the web interface. After saving, you should no longer need to rotate the sensor manually after power-up to get it calibrated: it will automatically load the saved calibration. This is the same feature that was available through the NXP Sensor Fusion Toolbox app, except you won't need to use that app.
Saving the Magnetic Cal
First, get a valid magnetic calibration by manually rotating the sensor in all directions. Once you are satisfied (the sensor should be reporting the expected heading when you point it in a known direction), then access the sensor's web interface:
In this example I am using the Attitude and CompassHeading sensors - if you expand either one you should see a "Values Setting" entry. Click on that and a "Save Magnetic Calibration" button should appear:
Enter the numeral 1 in that value box and click That sends a command via the orientation interface to the fusion code to save the current magnetic calibration in EEPROM. Now whenever the sensor is powered up it will load this calibration.
If the magnetic environment of your sensor changes, you can use the web interface to save a new calibration (once it has been computed through motion of the sensor). The fusion algorithm collects magnetic readings over a 3 minute cycle and checks whether they are consistent with the current calibration. If they are not, then a new calibration is automatically calculated.
I've noticed that if a bad calibration gets saved, it can take several minutes for this re-calculation process to collect enough data and decide to replace the bad calibration. So if you are noticing erroneous headings, go through the random-movements of the sensor to give it more data points to work with.
Getting the Update
Let me know how this works for you. You can find the latest code on the SensESP github, pull request SignalK/SensESP#349 When you update your local code, be aware that I merged in all other SensESP changes from the past approx 1 month, so you may need to do a clean and rebuild to see all the changes. There's also an updated example main.cpp (found in examples/fx8700_heading_example.cpp).
Other Changes
I made two other changes you should know about:
sensesp_app = new SensESPApp(...)
This saved 2496 bytes of heap (RAM). This is also more convenient than entering them in the web interface, though one can still see the settings in the web interface but they become read-only. To change them there, just revert back to using an empty constructor.-D DEBUG_DISABLED
to thebuild-flags = ...
in theplatformio.ini
file. This is not necessary for the ESP32 module, but when using an ESP8266 (e.g. d1_mini) then there isn't enough RAM to run the web interface unless you set this flag at compile time. The disadvantage of using this flag is that you won't see any messages pop up in the serial window, so it's best used once you have finished debugging and know that the executable is running OK. As I said, you don't have to worry about this on the ESP32 as it has more RAM.I don't know if/when the PR will be accepted by Matti. He's reluctant to make any sensor changes until they figure out how best to isolate SensESP from changes to sensors. In the meantime, you should be able to access this updated code by linking though the PR itself.
Beta Was this translation helpful? Give feedback.
All reactions