@@ -91,6 +91,16 @@ class BNO055:
91
91
Driver for the BNO055 9DOF IMU sensor.
92
92
"""
93
93
94
+ _temperature = _ReadOnlyUnaryStruct (0x34 , 'b' )
95
+ _acceleration = _ScaledReadOnlyStruct (0x08 , '<hhh' , 1 / 100 )
96
+ _magnetic = _ScaledReadOnlyStruct (0x0e , '<hhh' , 1 / 16 )
97
+ _gyro = _ScaledReadOnlyStruct (0x14 , '<hhh' , 0.001090830782496456 )
98
+ _euler = _ScaledReadOnlyStruct (0x1a , '<hhh' , 1 / 16 )
99
+ _quaternion = _ScaledReadOnlyStruct (0x20 , '<hhhh' , 1 / (1 << 14 ))
100
+ _linear_acceleration = _ScaledReadOnlyStruct (0x28 , '<hhh' , 1 / 100 )
101
+ _gravity = _ScaledReadOnlyStruct (0x2e , '<hhh' , 1 / 100 )
102
+
103
+
94
104
def __init__ (self , i2c , address = 0x28 ):
95
105
self .i2c_device = I2CDevice (i2c , address )
96
106
self .buffer = bytearray (2 )
@@ -217,62 +227,103 @@ def use_external_crystal(self, value):
217
227
@property
218
228
def temperature (self ):
219
229
"""Measures the temperature of the chip in degrees Celsius."""
220
- return _ReadOnlyUnaryStruct (0x34 , 'b' )
230
+ return self ._temperature
231
+
232
+ @temperature .setter
233
+ def temperature (self ):
234
+ self ._temperature = _ReadOnlyUnaryStruct (0x34 , 'b' )
221
235
222
236
@property
223
237
def acceleration (self ):
224
238
"""Gives the raw accelerometer readings, in m/s."""
225
239
if self .mode not in [0 , 2 , 3 , 6 ]:
226
- return _ScaledReadOnlyStruct ( 0x08 , '<hhh' , 1 / 100 )
240
+ return self . _acceleration
227
241
else :
228
242
return (None , None , None )
243
+
244
+ @acceleration .setter
245
+ def acceleration (self ):
246
+ self ._acceleration = _ScaledReadOnlyStruct (0x08 , '<hhh' , 1 / 100 )
247
+
229
248
230
249
@property
231
250
def magnetic (self ):
232
251
"""Gives the raw magnetometer readings in microteslas."""
233
252
if self .mode not in [0 , 3 , 5 , 8 ]:
234
- return _ScaledReadOnlyStruct (0x0e , '<hhh' , 1 / 16 )
253
+ return self ._magnetic
254
+
235
255
else :
236
256
return (None , None , None )
237
257
258
+ @magnetic .setter
259
+ def magnetic (self ):
260
+ self ._magnetic = _ScaledReadOnlyStruct (0x0e , '<hhh' , 1 / 16 )
261
+
262
+
238
263
@property
239
264
def gyro (self ):
240
265
"""Gives the raw gyroscope reading in radians per second."""
241
266
if self .mode not in [0 , 1 , 2 , 4 , 9 , 10 ]:
242
- return _ScaledReadOnlyStruct ( 0x14 , '<hhh' , 0.001090830782496456 )
267
+ return self . _gyro
243
268
244
269
else :
245
270
return (None , None , None )
246
271
272
+ @gyro .setter
273
+ def gyro (self ):
274
+ self ._gyro = _ScaledReadOnlyStruct (0x14 , '<hhh' , 0.001090830782496456 )
275
+
276
+
247
277
@property
248
278
def euler (self ):
249
279
"""Gives the calculated orientation angles, in degrees."""
250
- if self .mode in [9 , 11 , 12 , 0x0c ]:
280
+ if self .mode in [9 , 11 , 12 ]:
251
281
252
- return _ScaledReadOnlyStruct ( 0x1a , '<hhh' , 1 / 16 )
282
+ return self . _euler
253
283
else :
254
284
return (None , None , None )
255
-
285
+
286
+ @euler .setter
287
+ def euler (self ):
288
+ self ._euler = _ScaledReadOnlyStruct (0x1a , '<hhh' , 1 / 16 )
289
+
290
+
256
291
@property
257
292
def quaternion (self ):
258
293
"""Gives the calculated orientation as a quaternion."""
259
294
if self .mode in [9 , 11 , 12 ]:
260
- return _ScaledReadOnlyStruct ( 0x20 , '<hhhh' , 1 / ( 1 << 14 ))
295
+ return self . _quaternion
261
296
else :
262
297
return (None , None , None , None )
263
298
299
+ @quaternion .setter
300
+ def quaternion (self ):
301
+ self ._quaternion = _ScaledReadOnlyStruct (0x20 , '<hhhh' , 1 / (1 << 14 ))
302
+
303
+
264
304
@property
265
305
def linear_acceleration (self ):
266
306
"""Returns the linear acceleration, without gravity, in m/s."""
267
307
if self .mode in [9 , 11 , 12 ]:
268
- return _ScaledReadOnlyStruct (0x28 , '<hhh' , 1 / 100 )
308
+ return self ._linear_acceleration
309
+
269
310
else :
270
311
return (None , None , None )
271
312
313
+ @linear_acceleration .setter
314
+ def linear_acceleration (self ):
315
+ self ._linear_acceleration = _ScaledReadOnlyStruct (0x28 , '<hhh' , 1 / 100 )
316
+
317
+
272
318
@property
273
319
def gravity (self ):
274
320
"""Returns the gravity vector, without acceleration in m/s."""
275
321
if self .mode in [9 , 11 , 12 ]:
276
- return _ScaledReadOnlyStruct (0x2e , '<hhh' , 1 / 100 )
322
+ return self ._gravity
323
+
277
324
else :
278
325
return (None , None , None )
326
+
327
+ @gravity .setter
328
+ def gravity (self ):
329
+ self ._gravity = _ScaledReadOnlyStruct (0x2e , '<hhh' , 1 / 100 )
0 commit comments