Solving for the soft and hard iron IMU magnetometer calbiration on a
amateur student rocket launched by Portland State Aerospace Society.
data:
mathjax: True
---
---
For a number of years I was involved with a university rocketry club called PSAS{% sidenote %}[Portland State Aerospace Society](http://psas.pdx.edu), a student aerospace engineering project at Portland State University. They build ultra-low-cost, open source rockets that feature very sophisticated amateur rocket avionics systems.{% endsidenote %}. One of the things I really liked to do was play with the data from the launches and learn how rockets and flight electronics work.
# PSAS Magnetometer Calibration
_Published in November 2019_
For a number of years I was involved with a university rocketry club called PSAS{% capture sidenote %}[Portland State Aerospace Society](http://psas.pdx.edu), a student aerospace engineering project at Portland State University. They build ultra-low-cost, open source rockets that feature very sophisticated amateur rocket avionics systems.{% endcapture %}{% include "sidenote.liquid" %}. One of the things I really liked to do was play with the data from the launches and learn how rockets and flight electronics work.
Our rockets carry an instrument on them called an **IMU** (Inertial Measument Unit). An IMU typically measures both acceleration and rotation-rate of an object in all directions so with some clever math you can recreate the exact position, velocity, and orientation of the rocket over time. This is the only way to know where something is in space, and very important for rockets. IMUs have a problem though: they're not very precise.
Our rockets carry an instrument on them called an **IMU** (Inertial Measument Unit). An IMU typically measures both acceleration and rotation-rate of an object in all directions so with some clever math you can recreate the exact position, velocity, and orientation of the rocket over time. This is the only way to know where something is in space, and very important for rockets. IMUs have a problem though: they're not very precise.
Since our IMU is fixed to the rocket, {% marginnote %}![diagram of the rocket on it's side showing the layout of the internal components](img/L-12_overview.png) Overview of the rocket "LV2.3". The IMU is near the primary flight computer.{% endmarginnote %} which direction is "up" or "left", etc. relative to the Earth changes constantly as the rocket flies about. In order for the data to be useful we need to know which way we are pointed, which is why IMUs always have some kind of gryoscope to account for rotation. Our particular IMU has rate-gyroscopes that can sense rotation rate, and so we integrate that once to get orientation. Since any integration will give an estimate that drifts from the true value over time, our IMU also includes a 3-axis _magnetometer_ as well.
Since our IMU is fixed to the rocket, {% capture marginnote %}![diagram of the rocket on it's side showing the layout of the internal components](img/L-12_overview.png) Overview of the rocket "LV2.3". The IMU is near the primary flight computer.{% endcapture %}{% include "marginnote.liquid" %} which direction is "up" or "left", etc. relative to the Earth changes constantly as the rocket flies about. In order for the data to be useful we need to know which way we are pointed, which is why IMUs always have some kind of gryoscope to account for rotation. Our particular IMU has rate-gyroscopes that can sense rotation rate, and so we integrate that once to get orientation. Since any integration will give an estimate that drifts from the true value over time, our IMU also includes a 3-axis _magnetometer_ as well.
## 9DOF IMU
## 9DOF IMU
This makes what is often what is refered to as a "9DOF" IMU, because it has "nine degrees of freedom". That would be _x, y, z_ accleration, _x, y, z_ rotation-rate, and _x, y, z_ magnetic field. The reason to have a magnetometer is so you can use Earth's own magnetic field as a kind of guide to the orientation of the rocket. This doesn't instantly solve all problems in life, sadly. But it provides a good reference for the rough orientation of the rocket that can be used to produce a real-time estimate of rate-gyroscape drift, or 'bias', as we fly.
This makes what is often what is refered to as a "9DOF" IMU, because it has "nine degrees of freedom". That would be _x, y, z_ accleration, _x, y, z_ rotation-rate, and _x, y, z_ magnetic field. The reason to have a magnetometer is so you can use Earth's own magnetic field as a kind of guide to the orientation of the rocket. This doesn't instantly solve all problems in life, sadly. But it provides a good reference for the rough orientation of the rocket that can be used to produce a real-time estimate of rate-gyroscape drift, or 'bias', as we fly.
The magnetic field sensor in the rocket is sensitive, but because the Earth's field is so weak it's easily overwhelmed by local effects (metal screws, magnetic fields from nearby wires, etc.). In order to get good orientation data we need to undo{% marginnote %}![photo of two men awkwardly holding a large rocket body and an angle](img/L-12_ground_calibration.jpg) Members of the PSAS ground crew lifting and aranging the rocket around as many different orientations as possible before the flight.{% endmarginnote %} these local effects.
The magnetic field sensor in the rocket is sensitive, but because the Earth's field is so weak it's easily overwhelmed by local effects (metal screws, magnetic fields from nearby wires, etc.). In order to get good orientation data we need to undo{% capture marginnote %}![photo of two men awkwardly holding a large rocket body and an angle](img/L-12_ground_calibration.jpg) Members of the PSAS ground crew lifting and aranging the rocket around as many different orientations as possible before the flight.{% endcapture %}{% include "marginnote.liquid" %} these local effects.
So a little before the flight we took the nearly complete rocket, powered the electronics up, picked it up and tried to move it around in every direction.
So a little before the flight we took the nearly complete rocket, powered the electronics up, picked it up and tried to move it around in every direction.
@ -29,13 +42,13 @@ What do we expect good magnetometer data to look like? The Earth's magnetic fiel
## Earth's Field Strength
## Earth's Field Strength
But what is the strength of Earth's magnetic field? It varies over time and over the surface of the Earth. We know where we launched from{% sidenote %}
Latitude: `43.79613280°` N
Longitude: `120.65175340°` W
Elevation: `1390.0` m Mean Sea Level
{% endsidenote %} and the date, so we can look up{% sidenote %}[NOAA's magnetic field calculator](https://www.ngdc.noaa.gov/geomag/magfield.shtml)
But what is the strength of Earth's magnetic field? It varies over time and over the surface of the Earth. We know where we launched from{% capture sidenote %}
Latitude: `43.79613280°` N<br>
Longitude: `120.65175340°` W<br>
Elevation: `1390.0` m Mean Sea Level<br>
{% endcapture %}{% include "sidenote.liquid" %} and the date, so we can look up{% capture sidenote %}[NOAA's magnetic field calculator](https://www.ngdc.noaa.gov/geomag/magfield.shtml)
Model Used: `WMM2015`
Model Used: `WMM2015`
{% endsidenote %} what the expected magnetic field should be:
{% endcapture %}{% include "sidenote.liquid" %} what the expected magnetic field should be:
Its direction:
Its direction:
@ -74,7 +87,7 @@ Looking over time at the _x, y, z_ values of the magnetometer and the mangitue c
<figureclass="fullwidth">
<figureclass="fullwidth">
<imgsrc="post_files/post_9_0.png">
<imgsrc="post_files/post_9_0.png"/>
</figure>
</figure>
@ -82,7 +95,7 @@ This is because we have a couple of problems. One is that the effective _center_
<figureclass="">
<figureclass="">
<imgsrc="post_files/post_11_0.png">
<imgsrc="post_files/post_11_0.png"/>
</figure>
</figure>
@ -98,7 +111,7 @@ This is the simpler of the two, one can essentially find the midrange value of a
Finding the soft iron correction is a bit trickier because we want to fit an matching elongated ellipsoid to the data, and then once we have an approximation for that ellipsoid apply stretch to the data to undo the elongation and get it back to a sphere. Luckily an algorithm for this has been worked out. For a detailed breakdown see
Finding the soft iron correction is a bit trickier because we want to fit an matching elongated ellipsoid to the data, and then once we have an approximation for that ellipsoid apply stretch to the data to undo the elongation and get it back to a sphere. Luckily an algorithm for this has been worked out. For a detailed breakdown see