@@ -33,17 +33,13 @@ def __init__(self, scl_pin: int, sda_pin: int, addr):
33
33
self .i2c = I2C (id = 1 , scl = Pin (scl_pin ), sda = Pin (sda_pin ), freq = 400000 )
34
34
self .addr = addr
35
35
36
+ # Initialize member variables
37
+ self ._reset_member_variables ()
38
+
36
39
# Transmit and recieve buffers
37
40
self .tb = bytearray (1 )
38
41
self .rb = bytearray (1 )
39
42
40
- # Vector of IMU measurements
41
- self .irq_v = [[0 , 0 , 0 ], [0 , 0 , 0 ]]
42
-
43
- # Scale factors when ranges are changed
44
- self ._acc_scale_factor = 1
45
- self ._gyro_scale_factor = 1
46
-
47
43
# Copies of registers. Bytes and structs share the same memory
48
44
# addresses, so changing one changes the other
49
45
self .reg_ctrl1_xl_byte = bytearray (1 )
@@ -75,19 +71,27 @@ def __init__(self, scl_pin: int, sda_pin: int, addr):
75
71
self .acc_rate ('208Hz' )
76
72
self .gyro_rate ('208Hz' )
77
73
78
- # Initialize offsets to zero
74
+ """
75
+ The following are private helper methods to read and write registers, as well as to convert the read values to the correct unit.
76
+ """
77
+
78
+ def _reset_member_variables (self ):
79
+ # Vector of IMU measurements
80
+ self .irq_v = [[0 , 0 , 0 ], [0 , 0 , 0 ]]
81
+
82
+ # Sensor offsets
79
83
self .gyro_offsets = [0 ,0 ,0 ]
80
84
self .acc_offsets = [0 ,0 ,0 ]
81
85
82
- # Initialize integrators to zero
86
+ # Scale factors when ranges are changed
87
+ self ._acc_scale_factor = 1
88
+ self ._gyro_scale_factor = 1
89
+
90
+ # Angle integrators
83
91
self .running_pitch = 0
84
92
self .running_yaw = 0
85
93
self .running_roll = 0
86
94
87
- """
88
- The following are private helper methods to read and write registers, as well as to convert the read values to the correct unit.
89
- """
90
-
91
95
def _int16 (self , d ):
92
96
return d if d < 0x8000 else d - 0x10000
93
97
@@ -223,6 +227,12 @@ def reset(self, wait_for_reset = True, wait_timeout_ms = 100):
223
227
:return: False if timeout occurred, otherwise True
224
228
:rtype: bool
225
229
"""
230
+ # Stop timer
231
+ self ._stop_timer ()
232
+
233
+ # Reset member variables
234
+ self ._reset_member_variables ()
235
+
226
236
# Set BOOT and SW_RESET bits
227
237
self .reg_ctrl3_c_byte [0 ] = self ._getreg (LSM_REG_CTRL3_C )
228
238
self .reg_ctrl3_c_bits .BOOT = 1
0 commit comments