This is the third post in a series.
- Simple Methods
- Least-Squares and Gauss Newton
- Implementing Gauss-Newton on an ATMEGA (this post)
- Error Analysis
This post is short on explanations, I just wanted to something a bit more useful out. We can implement the Gauss-Newton method directly on an Arduino using this sketch to drive a circuit with an ADXL 335 and two pushbuttons like this:
Once the circuit is wired and the sketch is uploaded, open the serial monitor and move the thing around to 6 or more distinct positions. In each position push the button on pin 2, and hold it still for a second (or until you see the reading print out on the serial monitor. After you’ve collected at least 6 readings, push the button on pin 3 — this will perform the optimization and print your parameters.
See how I do it in this very fuzzy video:
In the last post we saw how we could use the Gauss-Newton method to use any set of sample reading from a still accelerometer to get an accurate calibration. The big problem was the tediousness. We took measurements on an arduino, sent it over the serial connection to a computer, ran scripts on the computer to compute calibration parameters, then reprogrammed the Arduino with the new parameters. Sure most of this could be automated, but it would still require a serial connection to a “real” computer with more than 1K of RAM.
To fix this, we need to implement Gauss-Newton directly on the arduino, but the ATMEGAs 1K to 2K memory limitation makes this challenging. We simply cannot store the big matrices used in the intermediate calculations of the Gauss-Newton method. To get around this, we do two things.
- To reduce the number of data samples we need to store without losing too much information about the distribution of samples, we let the accelerometer sit in each position long enough to collect a few samples (I picked 32), then we average them and computed the variance.
- We never materialize the large matrices, instead just compute the smaller matrices on the fly when they are needed.
Even though it is handheld and held by a hand that had too much coffee, this process gives highly repeatable results. I performed this calibration 20 times and recorded the parameters produced. You can see the data in this spreadsheet. The summary is this: the zero-G parameters on each axis has standard deviations less than 0.03% and the sensitivity parameters all had standard deviations less than 0.2%. Accurate? Maybe 🙂 Repeatable? definitely.
On-Arduino Gauss-Newton Calibration Overall Grades: Accuracy – Great Easiness – Great
In the next post I’ll explain the details behind all of this, then move on to error analysis, saving parameters in EEPROM, and more.