Found where the factor comes from

This commit is contained in:
Leonardo Arias Fonseca (¡paz y baile!) 2016-12-31 10:08:50 -06:00
parent c9eb50285f
commit eb54ce864b
No known key found for this signature in database
GPG Key ID: 852F630D0DA3C0E0
2 changed files with 10 additions and 11 deletions

View File

@ -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, &rawY)
binary.Read(buf, binary.LittleEndian, &rawZ) binary.Read(buf, binary.LittleEndian, &rawZ)
// Values copied from Adafruit's library: // Sensitivity values from the mechanical characteristics in the datasheet.
// https://github.com/adafruit/Adafruit_L3GD20_U/blob/master/Adafruit_L3GD20_U.h var sensitivity float32
var factor float32
switch(d.scale) { switch(d.scale) {
case L3GD20HScale250dps: case L3GD20HScale250dps:
factor = 0.00875 sensitivity = 0.00875
case L3GD20HScale500dps: case L3GD20HScale500dps:
factor = 0.0175 sensitivity = 0.0175
case L3GD20HScale2000dps: 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
} }

View File

@ -67,8 +67,8 @@ func TestHMC6352DriverMeasurement(t *testing.T) {
d.Start() d.Start()
x, y, z, err := d.XYZ() x, y, z, err := d.XYZ()
gobottest.Assert(t, err, nil) gobottest.Assert(t, err, nil)
var factor float32 = 0.00875 var sensitivity float32 = 0.00875
gobottest.Assert(t, x, float32(rawX) * factor) gobottest.Assert(t, x, float32(rawX) * sensitivity)
gobottest.Assert(t, y, float32(rawY) * factor) gobottest.Assert(t, y, float32(rawY) * sensitivity)
gobottest.Assert(t, z, float32(rawZ) * factor) gobottest.Assert(t, z, float32(rawZ) * sensitivity)
} }