Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
For a full reference visit the Markdown syntax.
Posted by @ClearMemory041063
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Calibration of three-axis sensors such as accelerometers, gyroscopes and magnetometers presents a unique problem. Such sensors are typically used with trigonometric functions to derive orientation angles. The use of trigonometry relies on the accuracy of the calibration of each axis. The ideal is a sphere, centered at the origin with a radius R= sqrt( X^2+Y^2+Z^2). Raw values from sensors tend not to be centered nor have equal gains (slopes) for each axis. Picture an off-center ellipsoid.
https://en.wikipedia.org/wiki/Ellipsoid
Several approaches are seen in usage.
• Finding a zero-offset vales for each axis and relying on published values for the scale factor.
• Applying a linear regression model to each axis
Linear regression finding best fit of a line through the data:
https://en.wikipedia.org/wiki/Linear_regression
http://seismo.berkeley.edu/~kirchner/eps_120/Toolkits/Toolkit_10.pdf
Multiple linear regression finding the best plane through the data:
http://reliawiki.org/index.php/Multiple_Linear_Regression_Analysis
http://www.hull.ac.uk/php/ecskrb/METRICS/mrg-deriv-5.ppt
Experimentation with both of these methods has produced poor results as they both rely on accurate positioning of the sensor axis relative to a known flux.
We want to find the best sphere through the data:
The math gives six simultaneous non-linear equations in six unknowns to solve. One unknown may be eliminated by setting the gain to one. The Solver function in the Excel data analysis tool pack was used to find the solution from raw accelerometer data.
In any orientation and in a constant field the sum of squares of the three axis should be a constant. Define R as the radius of a sphere. R =sqrt(x^2+Y^2+z^2). The statistical merit is then based on the deviation from this spherical surface.
Raw readings were collected from a three-axis accelerometer attached to a cube. Data were collected as the cube was positioned with each of the six sides facing down. The data were listed in three columns of a spreadsheet, labeled as X, Y and Z. The radius of the sphere for each point calculated in an additional column in the spreadsheet labeled R.
Six cells of the spreadsheet were used to define the three zero-offset values and the three gains for the regression model. The offset values were initialized to zero and the gains were initialized to a value of one.
Three columns labeled X1, Y1, and Z1 were added along with a column labeled R1.
For each row the X1 value= (X-XOffset)* Xgain, Y1=(Y-Yoffset)*Ygain, and Z1=(Z-Zoffset)*Zgain. The value of R1= sqrt(X1^2+Y1^2+Z1^2).
The accelerometer tested produces 16-bit signed integer values. Full scale is 32768 counts. The accelerometer has a range pf +- 2g. Dividing 32768 by 2 gives the target radius of the sensor sphere of 16384.
A new column labeled error was added, with cell values = R1(row)-16384. Another column labeled error^2 is used to calculate the square of the error. And finally a cell to calculate the sum of the error squared column.
The solver function of the data analysis tool pack was then used to minimize the sum of the error squared by varying the offset values and the X and Y gain values.
The offset and gain values derived from this procedure were then coded into the Espruino program used to acquire the accelerometer data and a new set of data were collected while orienting the sensor in the six positions of the attached cube as previously described. The data were posted in a spreadsheet and the radius R was calculated for each data point. Descriptive statistics were performed on the radius R values.
See the attached files:
Aregression.ods
Acallibrated.ods
2 Attachments