Browse Source

Update first jupyter blog post style to match cobalt and reimport

cobalt
Nathan Bergey 3 months ago
parent
commit
c31e8bd1c6
  1. 3
      _cobalt.yml
  2. BIN
      source/_posts/magnetometer_calibration/post_files/post_11_0.png
  3. BIN
      source/_posts/magnetometer_calibration/post_files/post_24_0.png
  4. BIN
      source/_posts/magnetometer_calibration/post_files/post_25_0.png
  5. BIN
      source/_posts/magnetometer_calibration/post_files/post_26_0.png
  6. BIN
      source/_posts/magnetometer_calibration/post_files/post_28_0.png
  7. BIN
      source/_posts/magnetometer_calibration/post_files/post_29_0.png
  8. BIN
      source/_posts/magnetometer_calibration/post_files/post_31_0.png
  9. BIN
      source/_posts/magnetometer_calibration/post_files/post_32_0.png
  10. BIN
      source/_posts/magnetometer_calibration/post_files/post_5_0.png
  11. BIN
      source/_posts/magnetometer_calibration/post_files/post_6_0.png
  12. BIN
      source/_posts/magnetometer_calibration/post_files/post_7_0.png
  13. BIN
      source/_posts/magnetometer_calibration/post_files/post_8_0.png
  14. BIN
      source/_posts/magnetometer_calibration/post_files/post_9_0.png
  15. 0
      src/2019/magnetometer_calibration/img/L-12_ground_calibration.jpg
  16. 0
      src/2019/magnetometer_calibration/img/L-12_liftoff.jpg
  17. 0
      src/2019/magnetometer_calibration/img/L-12_overview.png
  18. BIN
      src/2019/magnetometer_calibration/post_files/post_11_0.png
  19. BIN
      src/2019/magnetometer_calibration/post_files/post_24_0.png
  20. BIN
      src/2019/magnetometer_calibration/post_files/post_26_0.png
  21. BIN
      src/2019/magnetometer_calibration/post_files/post_29_0.png
  22. BIN
      src/2019/magnetometer_calibration/post_files/post_32_0.png
  23. BIN
      src/2019/magnetometer_calibration/post_files/post_9_0.png
  24. 5
      src/_includes/marginnote.liquid
  25. 11
      src/_layouts/post.liquid
  26. 8
      src/css/ext.css
  27. 51
      src/posts/magnetometer_calibration.md

3
_cobalt.yml

@ -9,3 +9,6 @@ posts:
rss: rss.xml
default:
permalink: /{{year}}/{{slug}}/
syntax_highlight:
theme: "Solarized (light)"
enabled: true

BIN
source/_posts/magnetometer_calibration/post_files/post_11_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 359 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_24_0.png

Before

Width: 1408  |  Height: 503  |  Size: 85 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_25_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 389 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_26_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 391 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_28_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 290 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_29_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 290 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_31_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 351 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_32_0.png

Before

Width: 1408  |  Height: 1377  |  Size: 354 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_5_0.png

Before

Width: 1408  |  Height: 500  |  Size: 83 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_6_0.png

Before

Width: 1408  |  Height: 500  |  Size: 83 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_7_0.png

Before

Width: 1408  |  Height: 500  |  Size: 83 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_8_0.png

Before

Width: 1408  |  Height: 500  |  Size: 83 KiB

BIN
source/_posts/magnetometer_calibration/post_files/post_9_0.png

Before

Width: 1408  |  Height: 503  |  Size: 85 KiB

0
source/_posts/magnetometer_calibration/img/L-12_ground_calibration.jpg → src/2019/magnetometer_calibration/img/L-12_ground_calibration.jpg

Before

Width: 1836  |  Height: 1836  |  Size: 702 KiB

After

Width: 1836  |  Height: 1836  |  Size: 702 KiB

0
source/_posts/magnetometer_calibration/img/L-12_liftoff.jpg → src/2019/magnetometer_calibration/img/L-12_liftoff.jpg

Before

Width: 992  |  Height: 992  |  Size: 147 KiB

After

Width: 992  |  Height: 992  |  Size: 147 KiB

0
source/_posts/magnetometer_calibration/img/L-12_overview.png → src/2019/magnetometer_calibration/img/L-12_overview.png

Before

Width: 1169  |  Height: 433  |  Size: 55 KiB

After

Width: 1169  |  Height: 433  |  Size: 55 KiB

BIN
src/2019/magnetometer_calibration/post_files/post_11_0.png

After

Width: 1413  |  Height: 1377  |  Size: 367 KiB

BIN
src/2019/magnetometer_calibration/post_files/post_24_0.png

After

Width: 1408  |  Height: 503  |  Size: 84 KiB

BIN
src/2019/magnetometer_calibration/post_files/post_26_0.png

After

Width: 1413  |  Height: 1377  |  Size: 399 KiB

BIN
src/2019/magnetometer_calibration/post_files/post_29_0.png

After

Width: 1413  |  Height: 1377  |  Size: 297 KiB

BIN
src/2019/magnetometer_calibration/post_files/post_32_0.png

After

Width: 1413  |  Height: 1377  |  Size: 360 KiB

BIN
src/2019/magnetometer_calibration/post_files/post_9_0.png

After

Width: 1408  |  Height: 503  |  Size: 84 KiB

5
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 %}<label for="{{ mnid }}" class="margin-toggle">&#8853;</label>
<input type="checkbox" id="{{ mnid }}" class="margin-toggle"/>
<span class="marginnote">
{{ marginnote }}
</span>

11
src/_layouts/post.liquid

@ -12,6 +12,17 @@
<meta property="og:image" content="{{site.base_url}}/{{page.permalink}}{{page.data.header_image}}">
{% endif %}
{% if page.data.mathjax %}
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
<script id="MathJax-script" async src="/js/mathjax/tex-svg.js"></script>
{% endif %}
</head>
<body>
{% include "header.liquid" %}

8
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;
}
}
article thead th { border-bottom: 1px solid #aaa; }
article pre { padding: 2em; }

51
source/_posts/magnetometer_calibration.md → 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<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`
{% 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
<figure class="fullwidth">
<img src="post_files/post_9_0.png">
<img src="post_files/post_9_0.png" />
</figure>
@ -82,7 +95,7 @@ This is because we have a couple of problems. One is that the effective _center_
<figure class="">
<img src="post_files/post_11_0.png">
<img src="post_files/post_11_0.png" />
</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
https://teslabs.com/articles/magnetometer-calibration/
<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?
<figure class="fullwidth">
<img src="post_files/post_24_0.png">
<img src="post_files/post_24_0.png" />
</figure>
@ -196,7 +209,7 @@ Again in 3D we can see a much closer to spherical data:
<figure class="">
<img src="post_files/post_26_0.png">
<img src="post_files/post_26_0.png" />
</figure>
@ -206,7 +219,7 @@ We can now take our calibration matrix and apply it to real flight data! Here is
<figure class="">
<img src="post_files/post_29_0.png">
<img src="post_files/post_29_0.png" />
</figure>
@ -219,7 +232,7 @@ So now lets calibrate the flight data!
<figure class="fullwidth">
<img src="post_files/post_32_0.png">
<img src="post_files/post_32_0.png" />
</figure>
@ -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
<https://git.natronics.org/natronics/psas-magnetometer-calibration>
Loading…
Cancel
Save