Adding accelerometer calibration test.

This is a calibration test for two tri-axis (x, y, and z) accelerometers
in a ChromeOS device. From one accelerometer, we can obtain digital output
proportional to the linear acceleration in each axis. For example, the
ideal value of a sensor having 12-bit analog-to-digital resolution and
+/- 2G detection range will be 1024 count/g. If we put it on a flat table
we can get (x, y, z) = (0, 0, 1024) at an ideal case. For upside down
we’ll have (x, y, z) = (0, 0, -1024).

Since accelerometer is very sensitive, the digital output will be different
for each query. For example, (34, -29, 998), (-31, 24, 979), (4, 9, 1003), etc.
In addition, temperature or the assembly quality may impact the accuracy
of the accelerometer during manufacturing (ex, position is tilt). To
mitigate this kind of errors, we'll sample several records of raw data
and compute its average value under an ideal environment.
Then store the offset as a calibrated value for future calculation.

For each signal, there is an equation in the driver:
  _input = (_raw * _calibscale / 1024) + _calibbias.

In a horizontal calibration, we'll put accelerometers on a flat
position then sample 100 records of raw data.
In this position, two axes are under 0G and one axis is under 1G.
Then we'll store the difference between the ideal value (0 and -/+1024)
and the average value of 100 samples as '_calibbias'. For '_calibscale',
we'll set it as default value: 1024.

Below is an example of test list. There are some mandatory arguments:

1. orientation: A dict of { signal_name: orientation in gravity }
   indicates which signal is under 0G and which signal is under -/+1G
   during calibration.

2. spec_offset: A tuple of two integers, ex: (128, 230) indicating the
   tolerance for the digital output of sensors under 0G and -/+1G.

3. spec_ideal_values: A tuple of two integers, ex: (0, 1024) indicating the
   ideal value of digital output corresponding to 0G and 1G, respectively

OperatorTest(
    id='AccelerometersCalibration',
    label_zh=u'加速度计校准',
    pytest_name='accelerometers_calibration',
    dargs={'orientation' = {
               'in_accel_x_base': 0,
               'in_accel_y_base': 0,
               'in_accel_z_base': 1,
               'in_accel_x_lid': 0,
               'in_accel_y_lid': 0,
               'in_accel_z_lid': -1},
           'spec_offset': (128, 230),
           'spec_ideal_values': (0, 1024)})

BUG=chrome-os-partner:25929, chrome-os-partner:25930
TEST=manually test on Glimmer
TEST=make lint LINT_WHITELIST="py/test/pytests/accelerometers_calibration.py"

Change-Id: If4e174310421a3dc1e5381f7f53076adbe47ed92
Reviewed-on: https://chromium-review.googlesource.com/189813
Reviewed-by: Heng-ruey Hsu <henryhsu@chromium.org>
Commit-Queue: Bowgo Tsai <bowgotsai@chromium.org>
Tested-by: Bowgo Tsai <bowgotsai@chromium.org>
1 file changed