diff --git a/_cobalt.yml b/_cobalt.yml index 8a94e64..4e3704a 100644 --- a/_cobalt.yml +++ b/_cobalt.yml @@ -9,3 +9,6 @@ posts: rss: rss.xml default: permalink: /{{year}}/{{slug}}/ +syntax_highlight: + theme: "Solarized (light)" + enabled: true \ No newline at end of file diff --git a/source/_posts/magnetometer_calibration/post_files/post_11_0.png b/source/_posts/magnetometer_calibration/post_files/post_11_0.png deleted file mode 100644 index f719121..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_11_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_24_0.png b/source/_posts/magnetometer_calibration/post_files/post_24_0.png deleted file mode 100644 index 4e552a9..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_24_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_25_0.png b/source/_posts/magnetometer_calibration/post_files/post_25_0.png deleted file mode 100644 index 29f75fc..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_25_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_26_0.png b/source/_posts/magnetometer_calibration/post_files/post_26_0.png deleted file mode 100644 index 10b7872..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_26_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_28_0.png b/source/_posts/magnetometer_calibration/post_files/post_28_0.png deleted file mode 100644 index d00da66..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_28_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_29_0.png b/source/_posts/magnetometer_calibration/post_files/post_29_0.png deleted file mode 100644 index d00da66..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_29_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_31_0.png b/source/_posts/magnetometer_calibration/post_files/post_31_0.png deleted file mode 100644 index f180c67..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_31_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_32_0.png b/source/_posts/magnetometer_calibration/post_files/post_32_0.png deleted file mode 100644 index 9924de8..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_32_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_5_0.png b/source/_posts/magnetometer_calibration/post_files/post_5_0.png deleted file mode 100644 index 12d29ae..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_5_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_6_0.png b/source/_posts/magnetometer_calibration/post_files/post_6_0.png deleted file mode 100644 index 12d29ae..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_6_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_7_0.png b/source/_posts/magnetometer_calibration/post_files/post_7_0.png deleted file mode 100644 index 12d29ae..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_7_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_8_0.png b/source/_posts/magnetometer_calibration/post_files/post_8_0.png deleted file mode 100644 index 12d29ae..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_8_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/post_files/post_9_0.png b/source/_posts/magnetometer_calibration/post_files/post_9_0.png deleted file mode 100644 index 2821da0..0000000 Binary files a/source/_posts/magnetometer_calibration/post_files/post_9_0.png and /dev/null differ diff --git a/source/_posts/magnetometer_calibration/img/L-12_ground_calibration.jpg b/src/2019/magnetometer_calibration/img/L-12_ground_calibration.jpg similarity index 100% rename from source/_posts/magnetometer_calibration/img/L-12_ground_calibration.jpg rename to src/2019/magnetometer_calibration/img/L-12_ground_calibration.jpg diff --git a/source/_posts/magnetometer_calibration/img/L-12_liftoff.jpg b/src/2019/magnetometer_calibration/img/L-12_liftoff.jpg similarity index 100% rename from source/_posts/magnetometer_calibration/img/L-12_liftoff.jpg rename to src/2019/magnetometer_calibration/img/L-12_liftoff.jpg diff --git a/source/_posts/magnetometer_calibration/img/L-12_overview.png b/src/2019/magnetometer_calibration/img/L-12_overview.png similarity index 100% rename from source/_posts/magnetometer_calibration/img/L-12_overview.png rename to src/2019/magnetometer_calibration/img/L-12_overview.png diff --git a/src/2019/magnetometer_calibration/post_files/post_11_0.png b/src/2019/magnetometer_calibration/post_files/post_11_0.png new file mode 100644 index 0000000..0c28711 Binary files /dev/null and b/src/2019/magnetometer_calibration/post_files/post_11_0.png differ diff --git a/src/2019/magnetometer_calibration/post_files/post_24_0.png b/src/2019/magnetometer_calibration/post_files/post_24_0.png new file mode 100644 index 0000000..e86d99f Binary files /dev/null and b/src/2019/magnetometer_calibration/post_files/post_24_0.png differ diff --git a/src/2019/magnetometer_calibration/post_files/post_26_0.png b/src/2019/magnetometer_calibration/post_files/post_26_0.png new file mode 100644 index 0000000..7553d0d Binary files /dev/null and b/src/2019/magnetometer_calibration/post_files/post_26_0.png differ diff --git a/src/2019/magnetometer_calibration/post_files/post_29_0.png b/src/2019/magnetometer_calibration/post_files/post_29_0.png new file mode 100644 index 0000000..06ffabe Binary files /dev/null and b/src/2019/magnetometer_calibration/post_files/post_29_0.png differ diff --git a/src/2019/magnetometer_calibration/post_files/post_32_0.png b/src/2019/magnetometer_calibration/post_files/post_32_0.png new file mode 100644 index 0000000..5077066 Binary files /dev/null and b/src/2019/magnetometer_calibration/post_files/post_32_0.png differ diff --git a/src/2019/magnetometer_calibration/post_files/post_9_0.png b/src/2019/magnetometer_calibration/post_files/post_9_0.png new file mode 100644 index 0000000..c9ea7ec Binary files /dev/null and b/src/2019/magnetometer_calibration/post_files/post_9_0.png differ diff --git a/src/_includes/marginnote.liquid b/src/_includes/marginnote.liquid new file mode 100644 index 0000000..1f7f95b --- /dev/null +++ b/src/_includes/marginnote.liquid @@ -0,0 +1,5 @@ +{% assign mn_slug = marginnote | strip | strip_html | slice: 0, 50 | downcase | replace: '.', '' |replace: ' ', '-' %}{% capture mnid %}sn-{{ mn_slug}}{% endcapture %} + + + {{ marginnote }} + \ No newline at end of file diff --git a/src/_layouts/post.liquid b/src/_layouts/post.liquid index 7bc0da6..079e233 100644 --- a/src/_layouts/post.liquid +++ b/src/_layouts/post.liquid @@ -12,6 +12,17 @@ {% endif %} + {% if page.data.mathjax %} + + + {% endif %} + {% include "header.liquid" %} diff --git a/src/css/ext.css b/src/css/ext.css index 7c8ac59..5cdea6a 100644 --- a/src/css/ext.css +++ b/src/css/ext.css @@ -1,9 +1,11 @@ -footer { padding-top: 10em; } -.illuminated::first-letter { +footer { padding-top: 10em; padding-bottom: 2em; } +article .illuminated::first-letter { font-size: 550%; font-style: italic; padding: 6px 3px; margin-right: 6px; float: left; text-shadow: 1px 1px 3px #999; -} \ No newline at end of file +} +article thead th { border-bottom: 1px solid #aaa; } +article pre { padding: 2em; } \ No newline at end of file diff --git a/source/_posts/magnetometer_calibration.md b/src/posts/magnetometer_calibration.md similarity index 72% rename from source/_posts/magnetometer_calibration.md rename to src/posts/magnetometer_calibration.md index 27832a2..fe7afdb 100644 --- a/source/_posts/magnetometer_calibration.md +++ b/src/posts/magnetometer_calibration.md @@ -1,21 +1,34 @@ --- title: PSAS Magnetometer Calibration -author: Nathan -date: 2019/11/05 +layout: post.liquid +published_date: 2019-11-05 00:00:00 +0000 +slug: magnetometer_calibration +is_draft: false +description: | + 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. -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 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. @@ -29,13 +42,13 @@ What do we expect good magnetometer data to look like? The Earth's magnetic fiel ## 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
+Longitude: `120.65175340°` W
+Elevation: `1390.0` m Mean Sea Level
+{% 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` - {% endsidenote %} what the expected magnetic field should be: + {% endcapture %}{% include "sidenote.liquid" %} what the expected magnetic field should be: Its direction: @@ -74,7 +87,7 @@ Looking over time at the _x, y, z_ values of the magnetometer and the mangitue c
- +
@@ -82,7 +95,7 @@ This is because we have a couple of problems. One is that the effective _center_
- +
@@ -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 -https://teslabs.com/articles/magnetometer-calibration/ + After doing fitting we end up with both a correction matrix and an offset vector. This is both the soft iron and hard iron correction. @@ -186,7 +199,7 @@ After we apply the calibration fix above, do we get a better result?
- +
@@ -196,7 +209,7 @@ Again in 3D we can see a much closer to spherical data:
- +
@@ -206,7 +219,7 @@ We can now take our calibration matrix and apply it to real flight data! Here is
- +
@@ -219,7 +232,7 @@ So now lets calibrate the flight data!
- +
@@ -229,4 +242,4 @@ And it looks like the calibration did a reasonable job. The values now come very This post is written as a [jupyter notebook](https://jupyter.org/) and all its code and data can be viewed as a stand-alone own project here: -https://git.natronics.org/natronics/psas-magnetometer-calibration +