eldruin / lsm303agr-rs

Platform agnostic Rust driver for the LSM303AGR ultra-compact high-performance eCompass module: ultra-low-power 3D accelerometer and 3D magnetometer
Apache License 2.0
18 stars 14 forks source link

Scale measurements #5

Closed robyoung closed 3 years ago

robyoung commented 3 years ago

Depends on #4

This change scales the accelerometer and magnetometer outputs. For the accelerometer this includes being able to set the scaling factor. I have renamed UnscaledMeasurement to Measurement to make it clear that these are now scaled.

Scaling the accelerometer

Scaling the accelerometer data to milli-g is fairly well described in the datasheet. The only area of confusion is around the 16g scaling factor. The STMicroelectronics driver has this very confusing line which is also seen in others. I have chosen to go with the datasheet but I am not 100% sure that is correct.

Scaling the magnetometer

Scaling the magnetometer is a little more obscure. I have taken the 150 value from the here in the microbit-dal but there is very little context as to where that number comes from. The commit that introduced it does not shed any more light on the matter (although it does imply that the value has been determined empirically). I have seen similar scaling factors used in other LSM303 drivers but have not been able to find an explanation or any reference in the datasheet.

robyoung commented 3 years ago

Regarding the failing checks:

robyoung commented 3 years ago

About UnscaledMeasurement/Measurement I think it would be better to keep UnscaledMeasurement as well so that the whole scaling operations can be avoided in scenarios where the scale is fixed. What do you think?

Yea, sounds good. What do you think about separate methods accel_data_unscaled and mag_data_unscaled?

eldruin commented 3 years ago

_unscaled methods sound good. That way the "default" method output is scaled, which would be great. Could you also add an entry to the changelog?