Skip to content

Commit 3cd1e79

Browse files
SensorManager: simplify IMU
1 parent e3c461f commit 3cd1e79

File tree

1 file changed

+0
-90
lines changed

1 file changed

+0
-90
lines changed

internal_filesystem/lib/mpos/hardware/drivers/wsen_isds.py

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ def __init__(self, i2c, address=0x6B, acc_range="2g", acc_data_rate="1.6Hz",
145145
self.gyro_range = 0
146146
self.gyro_sensitivity = 0
147147

148-
self.ACC_NUM_SAMPLES_CALIBRATION = 5
149-
self.ACC_CALIBRATION_DELAY_MS = 10
150-
151-
self.GYRO_NUM_SAMPLES_CALIBRATION = 5
152-
self.GYRO_CALIBRATION_DELAY_MS = 10
153-
154148
self.set_acc_range(acc_range)
155149
self.set_acc_data_rate(acc_data_rate)
156150

@@ -254,30 +248,6 @@ def set_interrupt(self, interrupts_enable=False, inact_en=False, slope_fds=False
254248
self._write_option('tap_double_to_int0', 1)
255249
self._write_option('int1_on_int0', 1)
256250

257-
def acc_calibrate(self, samples=None):
258-
"""Calibrate accelerometer by averaging samples while device is stationary.
259-
260-
Args:
261-
samples: Number of samples to average (default: ACC_NUM_SAMPLES_CALIBRATION)
262-
"""
263-
if samples is None:
264-
samples = self.ACC_NUM_SAMPLES_CALIBRATION
265-
266-
self.acc_offset_x = 0
267-
self.acc_offset_y = 0
268-
self.acc_offset_z = 0
269-
270-
for _ in range(samples):
271-
x, y, z = self._read_raw_accelerations()
272-
self.acc_offset_x += x
273-
self.acc_offset_y += y
274-
self.acc_offset_z += z
275-
time.sleep_ms(self.ACC_CALIBRATION_DELAY_MS)
276-
277-
self.acc_offset_x //= samples
278-
self.acc_offset_y //= samples
279-
self.acc_offset_z //= samples
280-
281251
def _acc_calc_sensitivity(self):
282252
"""Calculate accelerometer sensitivity based on range (in mg/digit)."""
283253
sensitivity_mapping = {
@@ -318,29 +288,6 @@ def _read_raw_accelerations(self):
318288

319289
return raw_a_x * self.acc_sensitivity, raw_a_y * self.acc_sensitivity, raw_a_z * self.acc_sensitivity
320290

321-
def gyro_calibrate(self, samples=None):
322-
"""Calibrate gyroscope by averaging samples while device is stationary.
323-
324-
Args:
325-
samples: Number of samples to average (default: GYRO_NUM_SAMPLES_CALIBRATION)
326-
"""
327-
if samples is None:
328-
samples = self.GYRO_NUM_SAMPLES_CALIBRATION
329-
330-
self.gyro_offset_x = 0
331-
self.gyro_offset_y = 0
332-
self.gyro_offset_z = 0
333-
334-
for _ in range(samples):
335-
x, y, z = self._read_raw_angular_velocities()
336-
self.gyro_offset_x += x
337-
self.gyro_offset_y += y
338-
self.gyro_offset_z += z
339-
time.sleep_ms(self.GYRO_CALIBRATION_DELAY_MS)
340-
341-
self.gyro_offset_x //= samples
342-
self.gyro_offset_y //= samples
343-
self.gyro_offset_z //= samples
344291

345292
def read_angular_velocities(self):
346293
"""Read calibrated gyroscope data.
@@ -383,43 +330,6 @@ def _read_raw_angular_velocities(self):
383330

384331
return raw_g_x * self.gyro_sensitivity, raw_g_y * self.gyro_sensitivity, raw_g_z * self.gyro_sensitivity
385332

386-
def read_angular_velocities_accelerations(self):
387-
"""Read both gyroscope and accelerometer in one call.
388-
389-
Returns:
390-
Tuple (gx, gy, gz, ax, ay, az) where gyro is in mdps, accel is in mg
391-
"""
392-
raw_g_x, raw_g_y, raw_g_z, raw_a_x, raw_a_y, raw_a_z = \
393-
self._read_raw_gyro_acc()
394-
395-
g_x = (raw_g_x - self.gyro_offset_x) * self.gyro_sensitivity
396-
g_y = (raw_g_y - self.gyro_offset_y) * self.gyro_sensitivity
397-
g_z = (raw_g_z - self.gyro_offset_z) * self.gyro_sensitivity
398-
399-
a_x = (raw_a_x - self.acc_offset_x) * self.acc_sensitivity
400-
a_y = (raw_a_y - self.acc_offset_y) * self.acc_sensitivity
401-
a_z = (raw_a_z - self.acc_offset_z) * self.acc_sensitivity
402-
403-
return g_x, g_y, g_z, a_x, a_y, a_z
404-
405-
def _read_raw_gyro_acc(self):
406-
"""Read raw gyroscope and accelerometer data in one call."""
407-
acc_data_ready, gyro_data_ready = self._acc_gyro_data_ready()
408-
if not acc_data_ready or not gyro_data_ready:
409-
raise Exception("sensor data not ready")
410-
411-
raw = self.i2c.readfrom_mem(self.address, Wsen_Isds._REG_G_X_OUT_L, 12)
412-
413-
raw_g_x = self._convert_from_raw(raw[0], raw[1])
414-
raw_g_y = self._convert_from_raw(raw[2], raw[3])
415-
raw_g_z = self._convert_from_raw(raw[4], raw[5])
416-
417-
raw_a_x = self._convert_from_raw(raw[6], raw[7])
418-
raw_a_y = self._convert_from_raw(raw[8], raw[9])
419-
raw_a_z = self._convert_from_raw(raw[10], raw[11])
420-
421-
return raw_g_x, raw_g_y, raw_g_z, raw_a_x, raw_a_y, raw_a_z
422-
423333
@staticmethod
424334
def _convert_from_raw(b_l, b_h):
425335
"""Convert two bytes (little-endian) to signed 16-bit integer."""

0 commit comments

Comments
 (0)