This project is all about calculating the position of a telescope. I derive absolute orientation using a magnetometer sensor and accelerometer sensor. By absolute orientation, I mean deriving the euler angles
of the telescope. The root problem I'm facing is that the yaw
reading experiences a mostly linear error after pitching the device beyond a specific threshold. (About 50 degrees or so).
To consistently observe the error, a simple experiment can be performed which reliably yields the problem.
- Fix the horizontal axis of the telescope (x-axis) so that it does not move
- Slowly tilt the telescope upwards (along the y-axis)
- Review the
roll
(y) andyaw
(x) readings
After some threshold of roll, the yaw
reading begins to deviate in a linear fashion.
The yaw
reading should remain constant for the duration of the experiment, since there is no movement along the x-axis of the telescope.
In this video, you can see me fix the x-axis and then tilt the assembly upwards. The visual representation on the computer shows the yaw
and roll
values as calculated by the sensor. After a certain threshold, the yellow box shifts significantly to the right.
https://joshcole.dev/telescope-error.mp4
The absolute orientation is described via euler angles derived from a 9DoF sensor cluster. Only 6 axis are integrated, however. The accelerometer and the magnetometer.
Variable | Formula |
---|---|
Pitch | -atan2(-accX, sqrt(accY^2 * accZ^2)) |
Roll | atan2(accY, accZ) |
This formula integrates the accelerometer sensor (gravity) and the magnetometer sensor (compass heading) to produce a tilt-compensated heading. And this calculation is where the error is introduced. Pitch
and Roll
seem to be correct (as far as I can tell).
xHor = magX * cos(pitch) + magY * sin(roll) * sin(pitch) - magZ * cos(roll) * sin(pitch)
yHor = magY * cos(roll) + magZ * sin(roll)
yaw = atan2(yHor, xHor)
The sensor device is affixed to the telescope at a 45 degree angle (relative to earth horizon). On my particular telescope, that is non-negotiable due to the location of the mounting bracket. Since the readings are relative to gravity, I don't expect this to matter. But perhaps it has unforseen implications.
The magnetometer is uncalibrated. In the past, I have attempted to perform a Soft and Hard Iron calibration, with even worse results.
The problem could be one of a few possibilities:
- The mounting angle changes the dynamics of the math.
- The magnetometer is not properly calibrated which affects the calculated values
- The sensors are simply not capable of producing good results at the poles
- Something something gimbal lock
- At some point, the accelerometer or magnetometer (or both) have one or more axis flipped
Can the mounting angle affect the mathematical formulas I'm using? To my knowledge, these angles are gravity-compensated, so I don't understand why the mounting angle would affect the readings.
Can the Hard and Soft iron calibration yield this exact kind of error? What I find interesting is that this error has persisted across multiple devices. I've ran this experiment using a phone as the sensor source, a dedicated circuit, and an off-the-shelf circuit. In all cases, I experienced the same exact problem. Which leads me to question whether calibration is really responsible for the entirety of my error.
Term | Meaning |
---|---|
Accelerometer | A 3d vector (x, y, z) representing the direction of gravity. The unit is generally normalized to m^2 |
Magnetometer | A 3d vector (x, y, z) representing magnetic north. The unit is generally in gauss |
Yaw | X-axis of the telescope |
Roll | Y-axis of the telescope |
Hard Iron Calibration | A procedure to correct the magnetometer based on sensor domain and range |
Soft Iron Calibration | A procedure to correct the magnetometer based on magnetic interference |
9DoF | Nine dimensions of freedom. This represents a sensor comprised of a accelerometer, a magnetometer, and a gyroscope |