@@ -343,9 +343,9 @@ def power(self, on:bool=None):
343
343
self ._r_w_reg (LSM6DSO_CTRL1_XL , 0 , 0x0F )
344
344
self ._r_w_reg (LSM6DSO_CTRL2_G , 0 , 0x0F )
345
345
346
- def calibrate (self , calibration_time :float = 3 , vertical_axis :int = 2 , update_time :int = 4 ):
346
+ def calibrate (self , calibration_time :float = 1 , vertical_axis :int = 2 , update_time :int = 4 ):
347
347
"""
348
- Collect readings for 3 seconds and calibrate the IMU based on those readings
348
+ Collect readings for [calibration_time] seconds and calibrate the IMU based on those readings
349
349
Do not move the robot during this time
350
350
Assumes the board to be parallel to the ground. Please use the vertical_axis parameter if that is not correct
351
351
@@ -357,12 +357,12 @@ def calibrate(self, calibration_time:float=3, vertical_axis:int= 2, update_time:
357
357
:type update_time: int
358
358
"""
359
359
self .update_timer .deinit ()
360
- start_time = time .time ()
360
+ start_time = time .ticks_ms ()
361
361
self .acc_offsets = [0 ,0 ,0 ]
362
362
self .gyro_offsets = [0 ,0 ,0 ]
363
363
avg_vals = [[0 ,0 ,0 ],[0 ,0 ,0 ]]
364
364
num_vals = 0
365
- while time .time () < start_time + calibration_time :
365
+ while time .ticks_ms () < start_time + calibration_time * 1000 :
366
366
cur_vals = self ._get_acc_gyro_rates ()
367
367
# Accelerometer averages
368
368
avg_vals [0 ][0 ] = (avg_vals [0 ][0 ]* num_vals + cur_vals [0 ][0 ])/ (num_vals + 1 )
@@ -393,35 +393,4 @@ def _update_imu_readings(self):
393
393
self .running_pitch += delta_pitch
394
394
self .running_roll += delta_roll
395
395
self .running_yaw += delta_yaw
396
- enable_irq (state )
397
-
398
-
399
- ## REMOVE BELOW BEFORE OFFICIAL RELEASE
400
-
401
- # We have two ways of obtaining the pitch of the robot:
402
- # - A noisy but accurate reading from the gyroscope
403
- # - A more consistent reading from the accelerometer that is affected by linear acceleration
404
- # We use a complementary filter to combine these two readings into a steady accurate signal.
405
-
406
- """
407
- scale = self.update_time
408
- measured_angle = math.atan2(self._get_acc_y_rate(), self._get_acc_z_rate()) *180/math.pi * 1000
409
-
410
- self.gyro_pitch_running_total += (self._get_gyro_x_rate()-self.gyro_pitch_bias) * scale
411
-
412
- if self.gyro_pitch_running_total > math.pi:
413
- self.gyro_pitch_running_total -= 2*math.pi
414
- elif self.gyro_pitch_running_total < -math.pi:
415
- self.gyro_pitch_running_total += 2*math.pi
416
-
417
- possible_error = measured_angle - self.gyro_pitch_running_total
418
-
419
- # The comp factor is the main tuning value of the complementary filter. A value 0 to 1
420
- # Skews the adjusted pitch to either the gyro total (closer to 0) or the accelerometer (closer to 1)
421
- comp_factor = 0.7
422
- self.adjusted_pitch = (self.gyro_pitch_running_total + comp_factor * possible_error) / 1000
423
-
424
- # Bias growth factor
425
- epsilon = 0.015
426
- self.gyro_pitch_bias -= epsilon / scale * possible_error
427
- """
396
+ enable_irq (state )
0 commit comments