Looking at https://cs.corp.google.com/chromeos_public/src/platform/factory/py/device/accelerometer.py?rcl=cf788b8deaff3b5cef83fb85cb3455d1cb3d67a1&l=272
I noticed you assume accel data comes to user space in 1/1024G, and in
general this code only work for pre ryu devices, running 3.14.
While _calibias is still in 1/1024G for VPD backward compatibility,
this is not true for the raw data since Ryu (3.18) to match iio sysfs
guideline.
Instead, raw data already integrate _calibbias, raw data must be
multiplied by the scale attribute to get the value in m/s^2.
On Fri, Nov 4, 2016 at 12:38 AM, Ting Shen <phoenixshen@google.com> wrote:
> Hi Gwendal,
>
> We've changed the fix value by parsing specs in scan_elements/*_type, this
> CL just merged into Gru factory branch a couple days ago.
> Implementation here:
> https://cs.corp.google.com/chromeos_public/src/platform/factory/py/device/accelerometer.py?rcl=cf788b8deaff3b5cef83fb85cb3455d1cb3d67a1&l=27
> https://cs.corp.google.com/chromeos_public/src/platform/factory/py/device/accelerometer.py?rcl=cf788b8deaff3b5cef83fb85cb3455d1cb3d67a1&l=244
> Not sure if the calculation is correct, could you confirm this?
This is not correct:
cros_ec_accel can_elements/in_accel_<axis>_type returns a constant:
le:s16/16>>0
So scan_type.shift is 0, and line 244 is a noop.
The code in /accelerometer.py does not seems to have modified for
cros_ec sensor stack in 3.18 kernel and beyond
(https://docs.google.com/a/google.com/document/d/1-ZLlS8oJNkFUA0wCNsPukJOZjwVIWOvs9404ihdEm6M/edit?usp=sharing_
- raw data in the iio buffer is not in 1/1024G unit, but when multiply
by scale attribute, will show the acceleration in m/s^2
- raw data already take in account _calibbias, so we should not call
_CalculateCalibratedValue() to get the calibrated value.
For calibration purposes, you want to keep data in the python code in
1/1024 units, so in GetRawDataAverage(), you need to multiply by a
constant C = scale / g * 1024
For instance, when the range is +/-2g, scale is 2g / 2^15, so C = 1/16.
To get uncalibrated data, you can set all _calibbias variables to 0
beforehand, or subtract _calibbias from the results.
Comment 1 by phoenixshen@google.com
, Nov 16 2016