39
39
__version__ = "0.0.0-auto.0"
40
40
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BNO055.git"
41
41
42
- _CHIP_ID = const (0xa0 )
42
+ _CHIP_ID = const (0xA0 )
43
43
44
44
CONFIG_MODE = const (0x00 )
45
45
ACCONLY_MODE = const (0x01 )
51
51
AMG_MODE = const (0x07 )
52
52
IMUPLUS_MODE = const (0x08 )
53
53
COMPASS_MODE = const (0x09 )
54
- M4G_MODE = const (0x0a )
55
- NDOF_FMC_OFF_MODE = const (0x0b )
56
- NDOF_MODE = const (0x0c )
54
+ M4G_MODE = const (0x0A )
55
+ NDOF_FMC_OFF_MODE = const (0x0B )
56
+ NDOF_MODE = const (0x0C )
57
57
58
58
_POWER_NORMAL = const (0x00 )
59
59
_POWER_LOW = const (0x01 )
60
60
_POWER_SUSPEND = const (0x02 )
61
61
62
- _MODE_REGISTER = const (0x3d )
62
+ _MODE_REGISTER = const (0x3D )
63
63
_PAGE_REGISTER = const (0x07 )
64
64
_CALIBRATION_REGISTER = const (0x35 )
65
65
_OFFSET_ACCEL_REGISTER = const (0x55 )
66
- _OFFSET_MAGNET_REGISTER = const (0x5b )
66
+ _OFFSET_MAGNET_REGISTER = const (0x5B )
67
67
_OFFSET_GYRO_REGISTER = const (0x61 )
68
68
_RADIUS_ACCEL_REGISTER = const (0x67 )
69
69
_RADIUS_MAGNET_REGISTER = const (0x69 )
70
- _TRIGGER_REGISTER = const (0x3f )
71
- _POWER_REGISTER = const (0x3e )
70
+ _TRIGGER_REGISTER = const (0x3F )
71
+ _POWER_REGISTER = const (0x3E )
72
72
_ID_REGISTER = const (0x00 )
73
73
74
74
75
- class _ScaledReadOnlyStruct (Struct ): # pylint: disable=too-few-public-methods
75
+ class _ScaledReadOnlyStruct (Struct ): # pylint: disable=too-few-public-methods
76
76
def __init__ (self , register_address , struct_format , scale ):
77
- super (_ScaledReadOnlyStruct , self ).__init__ (
78
- register_address , struct_format )
77
+ super (_ScaledReadOnlyStruct , self ).__init__ (register_address , struct_format )
79
78
self .scale = scale
80
79
81
80
def __get__ (self , obj , objtype = None ):
@@ -86,11 +85,12 @@ def __set__(self, obj, value):
86
85
raise NotImplementedError ()
87
86
88
87
89
- class _ReadOnlyUnaryStruct (UnaryStruct ): # pylint: disable=too-few-public-methods
88
+ class _ReadOnlyUnaryStruct (UnaryStruct ): # pylint: disable=too-few-public-methods
90
89
def __set__ (self , obj , value ):
91
90
raise NotImplementedError ()
92
91
93
- class _ModeStruct (Struct ): # pylint: disable=too-few-public-methods
92
+
93
+ class _ModeStruct (Struct ): # pylint: disable=too-few-public-methods
94
94
def __init__ (self , register_address , struct_format , mode ):
95
95
super ().__init__ (register_address , struct_format )
96
96
self .mode = mode
@@ -111,31 +111,31 @@ def __set__(self, obj, value):
111
111
super ().__set__ (obj , set_val )
112
112
obj .mode = last_mode
113
113
114
+
114
115
class BNO055 :
115
116
"""
116
117
Driver for the BNO055 9DOF IMU sensor.
117
118
"""
118
119
119
- _temperature = _ReadOnlyUnaryStruct (0x34 , 'b' )
120
- _acceleration = _ScaledReadOnlyStruct (0x08 , ' <hhh' , 1 / 100 )
121
- _magnetic = _ScaledReadOnlyStruct (0x0e , ' <hhh' , 1 / 16 )
122
- _gyro = _ScaledReadOnlyStruct (0x14 , ' <hhh' , 0.001090830782496456 )
123
- _euler = _ScaledReadOnlyStruct (0x1a , ' <hhh' , 1 / 16 )
124
- _quaternion = _ScaledReadOnlyStruct (0x20 , ' <hhhh' , 1 / ( 1 << 14 ))
125
- _linear_acceleration = _ScaledReadOnlyStruct (0x28 , ' <hhh' , 1 / 100 )
126
- _gravity = _ScaledReadOnlyStruct (0x2e , ' <hhh' , 1 / 100 )
120
+ _temperature = _ReadOnlyUnaryStruct (0x34 , "b" )
121
+ _acceleration = _ScaledReadOnlyStruct (0x08 , " <hhh" , 1 / 100 )
122
+ _magnetic = _ScaledReadOnlyStruct (0x0E , " <hhh" , 1 / 16 )
123
+ _gyro = _ScaledReadOnlyStruct (0x14 , " <hhh" , 0.001090830782496456 )
124
+ _euler = _ScaledReadOnlyStruct (0x1A , " <hhh" , 1 / 16 )
125
+ _quaternion = _ScaledReadOnlyStruct (0x20 , " <hhhh" , 1 / ( 1 << 14 ))
126
+ _linear_acceleration = _ScaledReadOnlyStruct (0x28 , " <hhh" , 1 / 100 )
127
+ _gravity = _ScaledReadOnlyStruct (0x2E , " <hhh" , 1 / 100 )
127
128
128
-
129
- offsets_accelerometer = _ModeStruct (_OFFSET_ACCEL_REGISTER , '<hhh' , CONFIG_MODE )
129
+ offsets_accelerometer = _ModeStruct (_OFFSET_ACCEL_REGISTER , "<hhh" , CONFIG_MODE )
130
130
"""Calibration offsets for the accelerometer"""
131
- offsets_magnetometer = _ModeStruct (_OFFSET_MAGNET_REGISTER , ' <hhh' , CONFIG_MODE )
131
+ offsets_magnetometer = _ModeStruct (_OFFSET_MAGNET_REGISTER , " <hhh" , CONFIG_MODE )
132
132
"""Calibration offsets for the magnetometer"""
133
- offsets_gyroscope = _ModeStruct (_OFFSET_GYRO_REGISTER , ' <hhh' , CONFIG_MODE )
133
+ offsets_gyroscope = _ModeStruct (_OFFSET_GYRO_REGISTER , " <hhh" , CONFIG_MODE )
134
134
"""Calibration offsets for the gyroscope"""
135
135
136
- radius_accelerometer = _ModeStruct (_RADIUS_ACCEL_REGISTER , '<h' , CONFIG_MODE )
136
+ radius_accelerometer = _ModeStruct (_RADIUS_ACCEL_REGISTER , "<h" , CONFIG_MODE )
137
137
"""Radius for accelerometer (cm?)"""
138
- radius_magnetometer = _ModeStruct (_RADIUS_MAGNET_REGISTER , '<h' , CONFIG_MODE )
138
+ radius_magnetometer = _ModeStruct (_RADIUS_MAGNET_REGISTER , "<h" , CONFIG_MODE )
139
139
"""Radius for magnetometer (cm?)"""
140
140
141
141
def __init__ (self , i2c , address = 0x28 ):
@@ -161,16 +161,15 @@ def _write_register(self, register, value):
161
161
def _read_register (self , register ):
162
162
self .buffer [0 ] = register
163
163
with self .i2c_device as i2c :
164
- i2c .write_then_readinto (self .buffer , self .buffer ,
165
- out_end = 1 , in_start = 1 )
164
+ i2c .write_then_readinto (self .buffer , self .buffer , out_end = 1 , in_start = 1 )
166
165
return self .buffer [1 ]
167
166
168
167
def _reset (self ):
169
168
"""Resets the sensor to default settings."""
170
169
self .mode = CONFIG_MODE
171
170
try :
172
171
self ._write_register (_TRIGGER_REGISTER , 0x20 )
173
- except OSError : # error due to the chip resetting
172
+ except OSError : # error due to the chip resetting
174
173
pass
175
174
# wait for the chip to reset (650 ms typ.)
176
175
time .sleep (0.7 )
@@ -262,7 +261,6 @@ def use_external_crystal(self, value):
262
261
self .mode = last_mode
263
262
time .sleep (0.01 )
264
263
265
-
266
264
@property
267
265
def temperature (self ):
268
266
"""Measures the temperature of the chip in degrees Celsius."""
@@ -291,7 +289,7 @@ def gyro(self):
291
289
"""Gives the raw gyroscope reading in radians per second.
292
290
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
293
291
"""
294
- if self .mode not in [0x00 , 0x01 , 0x02 , 0x04 , 0x09 , 0x0a ]:
292
+ if self .mode not in [0x00 , 0x01 , 0x02 , 0x04 , 0x09 , 0x0A ]:
295
293
return self ._gyro
296
294
return (None , None , None )
297
295
@@ -300,7 +298,7 @@ def euler(self):
300
298
"""Gives the calculated orientation angles, in degrees.
301
299
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
302
300
"""
303
- if self .mode in [0x09 , 0x0b , 0x0c ]:
301
+ if self .mode in [0x09 , 0x0B , 0x0C ]:
304
302
return self ._euler
305
303
return (None , None , None )
306
304
@@ -309,7 +307,7 @@ def quaternion(self):
309
307
"""Gives the calculated orientation as a quaternion.
310
308
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
311
309
"""
312
- if self .mode in [0x09 , 0x0b , 0x0c ]:
310
+ if self .mode in [0x09 , 0x0B , 0x0C ]:
313
311
return self ._quaternion
314
312
return (None , None , None , None )
315
313
@@ -318,7 +316,7 @@ def linear_acceleration(self):
318
316
"""Returns the linear acceleration, without gravity, in m/s.
319
317
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
320
318
"""
321
- if self .mode in [0x09 , 0x0b , 0x0c ]:
319
+ if self .mode in [0x09 , 0x0B , 0x0C ]:
322
320
return self ._linear_acceleration
323
321
return (None , None , None )
324
322
@@ -327,6 +325,6 @@ def gravity(self):
327
325
"""Returns the gravity vector, without acceleration in m/s.
328
326
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
329
327
"""
330
- if self .mode in [0x09 , 0x0b , 0x0c ]:
328
+ if self .mode in [0x09 , 0x0B , 0x0C ]:
331
329
return self ._gravity
332
330
return (None , None , None )
0 commit comments