From eb54ce864bee091bb76d0e840aec117d9e319c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Arias=20Fonseca=20=28=C2=A1paz=20y=20baile!=29?= Date: Sat, 31 Dec 2016 10:08:50 -0600 Subject: [PATCH] Found where the factor comes from --- drivers/i2c/l3gd20h_driver.go | 13 ++++++------- drivers/i2c/l3gd20h_driver_test.go | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/i2c/l3gd20h_driver.go b/drivers/i2c/l3gd20h_driver.go index b2253d87..a986a2ce 100644 --- a/drivers/i2c/l3gd20h_driver.go +++ b/drivers/i2c/l3gd20h_driver.go @@ -120,17 +120,16 @@ func (d *L3GD20HDriver) XYZ() (x float32, y float32, z float32, err error) { binary.Read(buf, binary.LittleEndian, &rawY) binary.Read(buf, binary.LittleEndian, &rawZ) - // Values copied from Adafruit's library: - // https://github.com/adafruit/Adafruit_L3GD20_U/blob/master/Adafruit_L3GD20_U.h - var factor float32 + // Sensitivity values from the mechanical characteristics in the datasheet. + var sensitivity float32 switch(d.scale) { case L3GD20HScale250dps: - factor = 0.00875 + sensitivity = 0.00875 case L3GD20HScale500dps: - factor = 0.0175 + sensitivity = 0.0175 case L3GD20HScale2000dps: - factor = 0.07 + sensitivity = 0.07 } - return float32(rawX) * factor, float32(rawY) * factor, float32(rawZ) * factor, nil + return float32(rawX) * sensitivity, float32(rawY) * sensitivity, float32(rawZ) * sensitivity, nil } diff --git a/drivers/i2c/l3gd20h_driver_test.go b/drivers/i2c/l3gd20h_driver_test.go index 8e90adb2..8a84b6bc 100644 --- a/drivers/i2c/l3gd20h_driver_test.go +++ b/drivers/i2c/l3gd20h_driver_test.go @@ -67,8 +67,8 @@ func TestHMC6352DriverMeasurement(t *testing.T) { d.Start() x, y, z, err := d.XYZ() gobottest.Assert(t, err, nil) - var factor float32 = 0.00875 - gobottest.Assert(t, x, float32(rawX) * factor) - gobottest.Assert(t, y, float32(rawY) * factor) - gobottest.Assert(t, z, float32(rawZ) * factor) + var sensitivity float32 = 0.00875 + gobottest.Assert(t, x, float32(rawX) * sensitivity) + gobottest.Assert(t, y, float32(rawY) * sensitivity) + gobottest.Assert(t, z, float32(rawZ) * sensitivity) }