Skip to content

Fix fusion modes #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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