Skip to content

Commit

Permalink
Merge pull request #76 from ViennaMike/fix_fusion_modes
Browse files Browse the repository at this point in the history
Fix fusion modes
  • Loading branch information
evaherrada committed Apr 6, 2021
2 parents e7dc35e + dd0b9e7 commit 4a601ae
Showing 1 changed file with 44 additions and 43 deletions.
87 changes: 44 additions & 43 deletions adafruit_bno055.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,37 +186,38 @@ def _reset(self):
@property
def mode(self):
"""
legend: x=on, -=off
+------------------+-------+---------+------+----------+
| Mode | Accel | Compass | Gyro | Absolute |
+==================+=======+=========+======+==========+
| CONFIG_MODE | - | - | - | - |
+------------------+-------+---------+------+----------+
| ACCONLY_MODE | X | - | - | - |
+------------------+-------+---------+------+----------+
| MAGONLY_MODE | - | X | - | - |
+------------------+-------+---------+------+----------+
| GYRONLY_MODE | - | - | X | - |
+------------------+-------+---------+------+----------+
| ACCMAG_MODE | X | X | - | - |
+------------------+-------+---------+------+----------+
| ACCGYRO_MODE | X | - | X | - |
+------------------+-------+---------+------+----------+
| MAGGYRO_MODE | - | X | X | - |
+------------------+-------+---------+------+----------+
| AMG_MODE | X | X | X | - |
+------------------+-------+---------+------+----------+
| IMUPLUS_MODE | X | - | X | - |
+------------------+-------+---------+------+----------+
| COMPASS_MODE | X | X | - | X |
+------------------+-------+---------+------+----------+
| M4G_MODE | X | X | - | - |
+------------------+-------+---------+------+----------+
| NDOF_FMC_OFF_MODE| X | X | X | X |
+------------------+-------+---------+------+----------+
| NDOF_MODE | X | X | X | X |
+------------------+-------+---------+------+----------+
legend: x=on, -=off (see Table 3-3 in datasheet)
+------------------+-------+---------+------+----------+----------+
| Mode | Accel | Compass | Gyro | Fusion | Fusion |
| | | (Mag) | | Absolute | Relative |
+==================+=======+=========+======+==========+==========+
| CONFIG_MODE | - | - | - | - | - |
+------------------+-------+---------+------+----------+----------+
| ACCONLY_MODE | X | - | - | - | - |
+------------------+-------+---------+------+----------+----------+
| MAGONLY_MODE | - | X | - | - | - |
+------------------+-------+---------+------+----------+----------+
| GYRONLY_MODE | - | - | X | - | - |
+------------------+-------+---------+------+----------+----------+
| ACCMAG_MODE | X | X | - | - | - |
+------------------+-------+---------+------+----------+----------+
| ACCGYRO_MODE | X | - | X | - | - |
+------------------+-------+---------+------+----------+----------+
| MAGGYRO_MODE | - | X | X | - | - |
+------------------+-------+---------+------+----------+----------+
| AMG_MODE | X | X | X | - | - |
+------------------+-------+---------+------+----------+----------+
| IMUPLUS_MODE | X | - | X | - | X |
+------------------+-------+---------+------+----------+----------+
| COMPASS_MODE | X | X | - | X | - |
+------------------+-------+---------+------+----------+----------+
| M4G_MODE | X | X | - | - | X |
+------------------+-------+---------+------+----------+----------+
| NDOF_FMC_OFF_MODE| X | X | X | X | - |
+------------------+-------+---------+------+----------+----------+
| NDOF_MODE | X | X | X | X | - |
+------------------+-------+---------+------+----------+----------+
The default mode is ``NDOF_MODE``.
Expand Down Expand Up @@ -362,7 +363,7 @@ def magnetic(self):
"""Gives the raw magnetometer readings in microteslas.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode not in [0x00, 0x03, 0x05, 0x08]:
if self.mode not in [0x00, 0x01, 0x03, 0x05, 0x08]:
return self._magnetic
return (None, None, None)

Expand All @@ -388,7 +389,7 @@ def euler(self):
"""Gives the calculated orientation angles, in degrees.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0B, 0x0C]:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
return self._euler
return (None, None, None)

Expand All @@ -401,7 +402,7 @@ def quaternion(self):
"""Gives the calculated orientation as a quaternion.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0B, 0x0C]:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
return self._quaternion
return (None, None, None, None)

Expand All @@ -414,7 +415,7 @@ def linear_acceleration(self):
"""Returns the linear acceleration, without gravity, in m/s.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0B, 0x0C]:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
return self._linear_acceleration
return (None, None, None)

Expand All @@ -427,7 +428,7 @@ def gravity(self):
"""Returns the gravity vector, without acceleration in m/s.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0B, 0x0C]:
if self.mode in [0x08, 0x09, 0x0A, 0x0B, 0x0C]:
return self._gravity
return (None, None, None)

Expand Down Expand Up @@ -713,37 +714,37 @@ def _temperature(self):
@property
def _acceleration(self):
resp = struct.unpack("<hhh", self._read_register(0x08, 6))
return tuple([x / 100 for x in resp])
return tuple(x / 100 for x in resp)

@property
def _magnetic(self):
resp = struct.unpack("<hhh", self._read_register(0x0E, 6))
return tuple([x / 16 for x in resp])
return tuple(x / 16 for x in resp)

@property
def _gyro(self):
resp = struct.unpack("<hhh", self._read_register(0x14, 6))
return tuple([x * 0.001090830782496456 for x in resp])
return tuple(x * 0.001090830782496456 for x in resp)

@property
def _euler(self):
resp = struct.unpack("<hhh", self._read_register(0x1A, 6))
return tuple([x / 16 for x in resp])
return tuple(x / 16 for x in resp)

@property
def _quaternion(self):
resp = struct.unpack("<hhhh", self._read_register(0x20, 8))
return tuple([x / (1 << 14) for x in resp])
return tuple(x / (1 << 14) for x in resp)

@property
def _linear_acceleration(self):
resp = struct.unpack("<hhh", self._read_register(0x28, 6))
return tuple([x / 100 for x in resp])
return tuple(x / 100 for x in resp)

@property
def _gravity(self):
resp = struct.unpack("<hhh", self._read_register(0x2E, 6))
return tuple([x / 100 for x in resp])
return tuple(x / 100 for x in resp)

@property
def offsets_accelerometer(self):
Expand Down

0 comments on commit 4a601ae

Please sign in to comment.