LeJOS supports sensor calibrating using filters. In short series of posts we will look at the calibration filters shipped with leJOS to see how they work and how to use them. This post provides some background that will help you understand how calibration works.
Why and when do you need to calibrate a sensor? Well sometimes the value of a sample just doesn’t mach the value you expected it to have. The value returned by the sensor doesn’t seem right. It might be close to what you expected or it might be way off and of little use to you. There is an error in the measurements of the sensor.
If you both know what value to expect and what value you get then it is possible to quantify the error and to correct for it. You know what value to expect from a well positioned and motionless accelerometer. Bottom line is that you need to have an expected value, or reference value, to be able to correct the error of the sensor.
To make a successful correction of a sample you also need to understand a little bit about the kind of errors to expect. We’ll discuss the most important of them. These are classified by the effect of the error rather than by the cause of the error.
- Offset error. This is the simplest form of an error. This error makes a sensor always report a value that is a fixed amount off the expected value. The error is also the most common, light sensors, Gyro’s, accelerometers they all suffer from offset errors, and sometimes quite a bit too. Offset errors can easily be measured and corrected with the LinearCalibrationFilter.
- Scale error. This error means that changes in the expected value are under- or overrated by the sensor. Scale errors are relatively small in the kind of sensors we use. In theory they are not hard to correct but in reality it is quite difficult to really improve the quality of a sample. Also scale errors can be measured and corrected with the LinearCalibrationFilter.
- Sensor noise. This means that a sensor will give a different value every time even when the expected value is constant. Sensor noise is a bit different from the other errors as it is chaotic by nature and cannot be assumed to be of constant value like the errors discussed before. One can quantify noise but one cannot correct for it. You can however decrease sensor noise by taking the average of multiple samples. The error of the mean of N samples is always less than the error of an individual sample.
There are other sources of errors, like non-linearity errors or misalignment errors, but we will concentrate on the errors discussed above.
You can put the effect of the errors discussed here in one simple formula:
SampleValue = offsetError + scaleError * referenceValue + noise
This formula assumes that offset and scale errors are a constant. For some sensors this assumption is true within certain operating conditions. This goes for range sensors, light sensors and accelerometers. The samples of all these sensors can be improved with the LinearCalibrationFilter. The next post in this series will discuss this filter to calibrate an accelerometer.
Other sensors have errors that seem to wander a bit over time. Gyro sensors have an offset error that drifts randomly over time. the offset error is not a constant. But still it can be predicted to a certain extent and thus it can be corrected for. leJOS offers the OffsetCorectionFilter to correct for drifting offset errors. This filter will be discussed in a later post.