Sensor Skew and Offset: EllipsoidFit

Sensor Skew and Offset: EllipsoidFit

Discusses EllipsoidFit, software which contains Java classes to fit points to a polynomial expression of an ellipsoid.

Author: Kaleb Kircher

Version: 3.0

4.10.14.3.0

Refactoring History

v1.0 1.7.13.1.0 Kaleb Kircher Authored
v2.0 7.5.13.2.0 Kaleb Kircher Refactored
v3.0 4.10.14.3.0 Kaleb Kircher Refactored

 Copy write: 2012, 2013, 2014 Kircher Engineering, LLC

Associated Code Projects:

Ellipsoid Fit:

Ellipsoid Fit Promotional Graphic

Explore noise, offset and skew associated with magnetic and gravitational fields. EllipsoidFit contains Java classes to fit points to a polynomial expression of an ellipsoid. EllipsoidFit uses an algorithm based on Yury Petrov's Ellipsoid Fit MATLAB script. The algorithm fits points from an ellipsoid to the polynomial expression Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1. The polynomial expression is then solved and the center and radii of the ellipse are determined. 

You can get the open source code from Boki Software through GitHub!

Accuracy and Offset:

For more on sensor accuracy, offset and skew you can refer to this blog article.

Accuracy:

EllipsoidFit is especially applicable to gravitation fields and magnetic fields. I am going to use the acceleration sensor and gravitation field as an example because it is more reliable to work with than the magnetic field, but EllipsoidFit is also capable of compensating for the effects of hard and soft iron on the earths magnetic field. 

Offset occurs when the positive and negative sides of a sensor axis do not produce the same measurements. For instance, an acceleration sensor might measure the gravity of earth as .9 g's on the positive axis and 10.1 g's on the negative axis because it is offset from center by 0.1 g's. We can see this on most Android devices by logging the sensor output. We can see that the Nexus 4's MPU-6050 accelerometer never exactly measures the gravity of earth, which is about 9.78m/s^2. 

 Offset:

Offset is apparent when you look at the results from measuring gravity with the positive side of the accelerometer and the same measurement with the negative side of the accelerometer. In this case, the offset occurs because the center of the Z-axis is shifted slightly towards the positive side, in addition to some error in the accuracy.

Theory:

In the most simple form, the gravitational field of earth can be seen, ideally, as a perfect sphere surrounding the earth. It is actually not a perfect sphere, as gravity at the poles is measured at about 9.82 m/s2 at the Earth's poles and 9.78 m/sat the equator, but close enough for our purposes.

When sensor offset occurs, the gravitation field of earth is not centered, perhaps making the center of the sphere created by the gravitational field look more like this. In this specific case, the center of the acceleration sensors Y-axis would be shifted towards the positive axis. 

When errors in the sensors accuracy occur the sphere is stretched or shrunk on the axis creating an ellipsoid. In this case, the Y-axis is overestimating the measurement of gravity.

Real World:

To a sensor in the real world, the gravitational field of earth looks a lot more like this than a perfect, smooth sphere. Sensor noise and distortions in the gravitational field create a sphere-ish looking cloud of data points that can be used to determine orientation, but they are clearly imperfect estimations.

 

Improving the Sensor Measurement:

Sensor Offset:

In two dimensions, just X and Y, the basic idea is that if you had perfect sensors and you were rotate the phone in such a way that you produced no acceleration and rotated through every possible orientation, the points would draw a perfect sphere with a magnitude equal to the gravity of earth centered at in each axis.

It is possible that the devices accelerometers will draw a circle with a radii equal to of gravity, but with a center that is not equal to 0,0. This situation would mean that the accelerometer values in the axis the circle is offset in is reading higher while pointing in one direction than in the opposite direction.

The Solution to Sensor Offset:

This problem is trivial to correct. The center of the circle just needs to be subtracted from the values of their respective axes. Assuming the gravitational field and sensor offsets are fairly constant, this is an effective solution. 

In three dimensions, the process can be visualized as shifting the measured gravitation field (red) to the ideal gravitational field (green).

Sensor Skew and the Ellipse:

The bad possibility is that the accelerometer values are skewed from a sphere into an ellipse with two different radii (and offset from center). To understand why a skewed ellipse can distort accelerometer data so much, consider that in a sphere the diameter in the x-axis and y-axis are always equal to each other and always orthogonal (90 degrees) to each other. So, as you rotate the device through the axes, the lengths of the axes will remain the same and equal. If the lengths of the axes are equal, the magnitude of the acceleration will always be the same, equal to gravity, as the device is rotated through the axes. That means you can measure the tilt of the device with the accelerometers accurately, for instance (assuming the device is not accelerating).

When the accelerometer values are skewed into an ellipse, the length of one axis is shorter or longer than the other axis. That means that as you rotate the device through the axes the lengths of the axis will be different depending on the measurement of gravity.

The Solution to Sensor Skew:

Eliminating skew from acceleration sensors is not trivial. It involves sampling the entire gravitational field, fitting the data to a polynomial representation of a ellipsoid and then scaling the radii of the ellipsoid back into a sphere. The process, visualized in three space, looks like this. The red sphere is the earth's gravitational field measured by a sensor affected by skew and  offset. The green sphere is earth's gravitational field after the sensor has been compensated.

The skewed red sphere measuring the gravitational field:

The corrected green sphere measuring the gravitational field:

Exploring Offset and Skew:

Ellipsoid Fit:

We have released open source software through BokiSoftware to help explore sensor offset and skew. EllipsoidFit is a collection of Java classes designed to fit points to a polynomial expression of an ellipsoid. EllipsoidFit uses an algorithm based on Yury Petrov's Ellipsoid Fit MATLAB script. The algorithm fits points from an ellipsoid to the polynomial expression Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1. The polynomial expression is then solved and the center and radii of the ellipse are determined. It has useful applications in compensating both accelerometers and magnetometers. You can get EllipsoidFit to try for yourself on GitHub.