@@ -137,70 +137,6 @@ def _raw_to_mg(self, raw):
137
137
138
138
def _raw_to_mdps (self , raw ):
139
139
return self ._int16 ((raw [1 ] << 8 ) | raw [0 ]) * LSM_MDPS_PER_LSB_125DPS * self ._gyro_scale_factor
140
-
141
- def _get_gyro_x_rate (self ):
142
- """
143
- Individual axis read for the Gyroscope's X-axis, in mg
144
- """
145
- # Burst read data registers
146
- raw_bytes = self ._getregs (LSM_REG_OUTX_L_G , 2 )
147
-
148
- # Convert raw data to mdps
149
- return self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [0 ]
150
-
151
- def _get_gyro_y_rate (self ):
152
- """
153
- Individual axis read for the Gyroscope's Y-axis, in mg
154
- """
155
- # Burst read data registers
156
- raw_bytes = self ._getregs (LSM_REG_OUTY_L_G , 2 )
157
-
158
- # Convert raw data to mdps
159
- return self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [1 ]
160
-
161
- def _get_gyro_z_rate (self ):
162
- """
163
- Individual axis read for the Gyroscope's Z-axis, in mg
164
- """
165
- # Burst read data registers
166
- raw_bytes = self ._getregs (LSM_REG_OUTZ_L_G , 2 )
167
-
168
- # Convert raw data to mdps
169
- return self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [2 ]
170
-
171
- def _get_gyro_rates (self ):
172
- """
173
- Retrieves the array of readings from the Gyroscope, in mdps
174
- The order of the values is x, y, z.
175
- """
176
- # Burst read data registers
177
- raw_bytes = self ._getregs (LSM_REG_OUTX_L_G , 6 )
178
-
179
- # Convert raw data to mdps
180
- self .irq_v [1 ][0 ] = self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [0 ]
181
- self .irq_v [1 ][1 ] = self ._raw_to_mdps (raw_bytes [2 :4 ]) - self .gyro_offsets [1 ]
182
- self .irq_v [1 ][2 ] = self ._raw_to_mdps (raw_bytes [4 :6 ]) - self .gyro_offsets [2 ]
183
-
184
- return self .irq_v [1 ]
185
-
186
- def _get_acc_gyro_rates (self ):
187
- """
188
- Get the accelerometer and gyroscope values in mg and mdps in the form of a 2D array.
189
- The first row is the acceleration values, the second row is the gyro values.
190
- The order of the values is x, y, z.
191
- """
192
- # Burst read data registers
193
- raw_bytes = self ._getregs (LSM_REG_OUTX_L_G , 12 )
194
-
195
- # Convert raw data to mg's and mdps
196
- self .irq_v [0 ][0 ] = self ._raw_to_mg (raw_bytes [6 :8 ]) - self .acc_offsets [0 ]
197
- self .irq_v [0 ][1 ] = self ._raw_to_mg (raw_bytes [8 :10 ]) - self .acc_offsets [1 ]
198
- self .irq_v [0 ][2 ] = self ._raw_to_mg (raw_bytes [10 :12 ]) - self .acc_offsets [2 ]
199
- self .irq_v [1 ][0 ] = self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [0 ]
200
- self .irq_v [1 ][1 ] = self ._raw_to_mdps (raw_bytes [2 :4 ]) - self .gyro_offsets [1 ]
201
- self .irq_v [1 ][2 ] = self ._raw_to_mdps (raw_bytes [4 :6 ]) - self .gyro_offsets [2 ]
202
-
203
- return self .irq_v
204
140
205
141
"""
206
142
Public facing API Methods
@@ -300,6 +236,70 @@ def get_acc_rates(self):
300
236
self .irq_v [0 ][2 ] = self ._raw_to_mg (raw_bytes [4 :6 ]) - self .acc_offsets [2 ]
301
237
302
238
return self .irq_v [0 ]
239
+
240
+ def get_gyro_x_rate (self ):
241
+ """
242
+ Individual axis read for the Gyroscope's X-axis, in mg
243
+ """
244
+ # Burst read data registers
245
+ raw_bytes = self ._getregs (LSM_REG_OUTX_L_G , 2 )
246
+
247
+ # Convert raw data to mdps
248
+ return self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [0 ]
249
+
250
+ def get_gyro_y_rate (self ):
251
+ """
252
+ Individual axis read for the Gyroscope's Y-axis, in mg
253
+ """
254
+ # Burst read data registers
255
+ raw_bytes = self ._getregs (LSM_REG_OUTY_L_G , 2 )
256
+
257
+ # Convert raw data to mdps
258
+ return self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [1 ]
259
+
260
+ def get_gyro_z_rate (self ):
261
+ """
262
+ Individual axis read for the Gyroscope's Z-axis, in mg
263
+ """
264
+ # Burst read data registers
265
+ raw_bytes = self ._getregs (LSM_REG_OUTZ_L_G , 2 )
266
+
267
+ # Convert raw data to mdps
268
+ return self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [2 ]
269
+
270
+ def get_gyro_rates (self ):
271
+ """
272
+ Retrieves the array of readings from the Gyroscope, in mdps
273
+ The order of the values is x, y, z.
274
+ """
275
+ # Burst read data registers
276
+ raw_bytes = self ._getregs (LSM_REG_OUTX_L_G , 6 )
277
+
278
+ # Convert raw data to mdps
279
+ self .irq_v [1 ][0 ] = self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [0 ]
280
+ self .irq_v [1 ][1 ] = self ._raw_to_mdps (raw_bytes [2 :4 ]) - self .gyro_offsets [1 ]
281
+ self .irq_v [1 ][2 ] = self ._raw_to_mdps (raw_bytes [4 :6 ]) - self .gyro_offsets [2 ]
282
+
283
+ return self .irq_v [1 ]
284
+
285
+ def get_acc_gyro_rates (self ):
286
+ """
287
+ Get the accelerometer and gyroscope values in mg and mdps in the form of a 2D array.
288
+ The first row is the acceleration values, the second row is the gyro values.
289
+ The order of the values is x, y, z.
290
+ """
291
+ # Burst read data registers
292
+ raw_bytes = self ._getregs (LSM_REG_OUTX_L_G , 12 )
293
+
294
+ # Convert raw data to mg's and mdps
295
+ self .irq_v [0 ][0 ] = self ._raw_to_mg (raw_bytes [6 :8 ]) - self .acc_offsets [0 ]
296
+ self .irq_v [0 ][1 ] = self ._raw_to_mg (raw_bytes [8 :10 ]) - self .acc_offsets [1 ]
297
+ self .irq_v [0 ][2 ] = self ._raw_to_mg (raw_bytes [10 :12 ]) - self .acc_offsets [2 ]
298
+ self .irq_v [1 ][0 ] = self ._raw_to_mdps (raw_bytes [0 :2 ]) - self .gyro_offsets [0 ]
299
+ self .irq_v [1 ][1 ] = self ._raw_to_mdps (raw_bytes [2 :4 ]) - self .gyro_offsets [1 ]
300
+ self .irq_v [1 ][2 ] = self ._raw_to_mdps (raw_bytes [4 :6 ]) - self .gyro_offsets [2 ]
301
+
302
+ return self .irq_v
303
303
304
304
def get_pitch (self ):
305
305
"""
@@ -503,7 +503,7 @@ def calibrate(self, calibration_time:float=1, vertical_axis:int= 2):
503
503
time .sleep (.1 )
504
504
start_time = time .ticks_ms ()
505
505
while time .ticks_ms () < start_time + calibration_time * 1000 :
506
- cur_vals = self ._get_acc_gyro_rates ()
506
+ cur_vals = self .get_acc_gyro_rates ()
507
507
# Accelerometer averages
508
508
avg_vals [0 ][0 ] += cur_vals [0 ][0 ]
509
509
avg_vals [0 ][1 ] += cur_vals [0 ][1 ]
@@ -538,7 +538,7 @@ def _stop_timer(self):
538
538
539
539
def _update_imu_readings (self ):
540
540
# Called every tick through a callback timer
541
- self ._get_gyro_rates ()
541
+ self .get_gyro_rates ()
542
542
delta_pitch = self .irq_v [1 ][0 ] / 1000 / self .timer_frequency
543
543
delta_roll = self .irq_v [1 ][1 ] / 1000 / self .timer_frequency
544
544
delta_yaw = self .irq_v [1 ][2 ] / 1000 / self .timer_frequency
0 commit comments