tim-balloon / TIMflight

Flight MCP repo
0 stars 0 forks source link

Magnetometer Calibration #82

Open shubhagrawal30 opened 5 months ago

shubhagrawal30 commented 5 months ago

Overview

This is an attempt to finalize a well-documented procedure for calibrating the magnetometer, detailing needs and insights discovered from testing at the UA MIL. It exists as a GitHub Issue as we need to make sure that our sensors, pointing, and commanding code are compliant with our nominal procedure. Some of the information listed in this issue is speculative and based on our best guess of what the current BLAST flight code is attempting to do.

Current mcp behavior

We use a three-axis (say, Z towards the pivot, X "towards" boresight) magnetometer that measures fields from -2 to 2 G, mounted on the outer frame's static sunshield. During the flight, the two dominant sources the magnetometer is sensitive to are the gondola and the Earth.

Calibration on the ground, close to flight at LDB, seems to involve rotating the gondola through full rotations, and extracting the constant offset in X, Y, and Z components of the gondola (say B_x, B_y, B_z), as well as the "amplitude" of the Earth's magnetic field (say, A_x, ...). These are #DEFINE#s in magnetometer.h for Z or command-able fields for X & Y.

In pointing.c:MagConvert, the WMM is used to figure out the "declination" and the "dip" of the magnetic field given our known lat, long, and altitude. To get azimuth, we compare this declination to the angle of the XY vector formed by linearly scaled versions of the magnetometer readings. We subtract the offset B and then divide by the slope A.

Suggested changes and questions

  1. Subtracting the offset term B* makes sense, getting rid of the gondola's magnetic field. The scaling term A does not. The best explanation could be the past magnetometer(s) used had different sensitivities along different axes. For us, the scaling does not help, atan2 is similar precise over its domain, and A_x and A_y should be the same value, unless the pivot axis precesses by a lot. remove scaling by magx_m and like in pointing.c*.
  2. Currently, the command-able fields for X and Y are not A_*, B_* directly. Rather, we set the maximum and minimum of the curves we obtain on the ground when performing the calibration operation, and the code calculates A_*, B_*. This makes A_*, B_* related and toughens removing the scaling. make the gondola field offset the command-able term.
  3. Cannot see a reason to not have the Z axis offset also be command-able.

Acceptance

A coherent procedure that several of us agree is the right thing to do pre-flight, corresponding code changes code in magnetometer. and pointing., and changes to command-able fields to ensure the sufficient flexibility during operations.

evanmayer commented 5 months ago

Glad we have a code-change issue for this. For docs, I have been working on writing up some docs for this process, with a simple simulated example to help explain it. We should have something like this for each sensor, so if we take this as an example, I have folders ready for the other sensors.

https://github.com/tim-balloon/TIM-software-primer/blob/main/sensor_calibration/magnetometer/mag.md