You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Reduce debug output
This commit is contained in:
@@ -295,15 +295,15 @@ class CalibrateIMUActivity(Activity):
|
||||
print(f"[CalibrateIMU] Accel sensor: {accel}, Gyro sensor: {gyro}")
|
||||
|
||||
if accel:
|
||||
print("[CalibrateIMU] Calibrating accelerometer (100 samples)...")
|
||||
accel_offsets = SensorManager.calibrate_sensor(accel, samples=100)
|
||||
print("[CalibrateIMU] Calibrating accelerometer (30 samples)...")
|
||||
accel_offsets = SensorManager.calibrate_sensor(accel, samples=30)
|
||||
print(f"[CalibrateIMU] Accel offsets: {accel_offsets}")
|
||||
else:
|
||||
accel_offsets = None
|
||||
|
||||
if gyro:
|
||||
print("[CalibrateIMU] Calibrating gyroscope (100 samples)...")
|
||||
gyro_offsets = SensorManager.calibrate_sensor(gyro, samples=100)
|
||||
print("[CalibrateIMU] Calibrating gyroscope (30 samples)...")
|
||||
gyro_offsets = SensorManager.calibrate_sensor(gyro, samples=30)
|
||||
print(f"[CalibrateIMU] Gyro offsets: {gyro_offsets}")
|
||||
else:
|
||||
gyro_offsets = None
|
||||
|
||||
@@ -165,15 +165,6 @@ class Wsen_Isds:
|
||||
print("[WSEN_ISDS] Waiting 100ms for sensors to stabilize...")
|
||||
time.sleep_ms(100)
|
||||
|
||||
# Debug: Read all control registers to see full sensor state
|
||||
print("[WSEN_ISDS] === Sensor State After Initialization ===")
|
||||
for reg_addr in [0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19]:
|
||||
try:
|
||||
reg_val = self.i2c.readfrom_mem(self.address, reg_addr, 1)[0]
|
||||
print(f"[WSEN_ISDS] Reg 0x{reg_addr:02x} (CTRL{reg_addr-0x0f}): 0x{reg_val:02x} = 0b{reg_val:08b}")
|
||||
except:
|
||||
pass
|
||||
|
||||
print("[WSEN_ISDS] Initialization complete")
|
||||
|
||||
def get_chip_id(self):
|
||||
@@ -193,7 +184,6 @@ class Wsen_Isds:
|
||||
config_value &= opt["mask"]
|
||||
config_value |= (bits << opt["shift_left"])
|
||||
self.i2c.writeto_mem(self.address, opt["reg"], bytes([config_value]))
|
||||
print(f"[WSEN_ISDS] _write_option: {option}={value} → reg {hex(opt['reg'])}: {hex(old_value)} → {hex(config_value)}")
|
||||
except KeyError as err:
|
||||
print(f"Invalid option: {option}, or invalid option value: {value}.", err)
|
||||
|
||||
@@ -280,11 +270,14 @@ class Wsen_Isds:
|
||||
if samples is None:
|
||||
samples = self.ACC_NUM_SAMPLES_CALIBRATION
|
||||
|
||||
print(f"[WSEN_ISDS] Calibrating accelerometer with {samples} samples...")
|
||||
self.acc_offset_x = 0
|
||||
self.acc_offset_y = 0
|
||||
self.acc_offset_z = 0
|
||||
|
||||
for _ in range(samples):
|
||||
for i in range(samples):
|
||||
if i % 10 == 0:
|
||||
print(f"[WSEN_ISDS] Accel sample {i}/{samples}")
|
||||
x, y, z = self._read_raw_accelerations()
|
||||
self.acc_offset_x += x
|
||||
self.acc_offset_y += y
|
||||
@@ -294,6 +287,7 @@ class Wsen_Isds:
|
||||
self.acc_offset_x //= samples
|
||||
self.acc_offset_y //= samples
|
||||
self.acc_offset_z //= samples
|
||||
print(f"[WSEN_ISDS] Accelerometer calibration complete: offsets=({self.acc_offset_x}, {self.acc_offset_y}, {self.acc_offset_z})")
|
||||
|
||||
def _acc_calc_sensitivity(self):
|
||||
"""Calculate accelerometer sensitivity based on range (in mg/digit)."""
|
||||
@@ -324,19 +318,15 @@ class Wsen_Isds:
|
||||
|
||||
def _read_raw_accelerations(self):
|
||||
"""Read raw accelerometer data."""
|
||||
print("[WSEN_ISDS] _read_raw_accelerations: checking data ready...")
|
||||
if not self._acc_data_ready():
|
||||
print("[WSEN_ISDS] _read_raw_accelerations: DATA NOT READY!")
|
||||
raise Exception("sensor data not ready")
|
||||
|
||||
print("[WSEN_ISDS] _read_raw_accelerations: data ready, reading registers...")
|
||||
raw = self.i2c.readfrom_mem(self.address, Wsen_Isds._REG_A_X_OUT_L, 6)
|
||||
|
||||
raw_a_x = self._convert_from_raw(raw[0], raw[1])
|
||||
raw_a_y = self._convert_from_raw(raw[2], raw[3])
|
||||
raw_a_z = self._convert_from_raw(raw[4], raw[5])
|
||||
|
||||
print(f"[WSEN_ISDS] _read_raw_accelerations: raw values = ({raw_a_x}, {raw_a_y}, {raw_a_z})")
|
||||
return raw_a_x, raw_a_y, raw_a_z
|
||||
|
||||
def gyro_calibrate(self, samples=None):
|
||||
@@ -348,11 +338,14 @@ class Wsen_Isds:
|
||||
if samples is None:
|
||||
samples = self.GYRO_NUM_SAMPLES_CALIBRATION
|
||||
|
||||
print(f"[WSEN_ISDS] Calibrating gyroscope with {samples} samples...")
|
||||
self.gyro_offset_x = 0
|
||||
self.gyro_offset_y = 0
|
||||
self.gyro_offset_z = 0
|
||||
|
||||
for _ in range(samples):
|
||||
for i in range(samples):
|
||||
if i % 10 == 0:
|
||||
print(f"[WSEN_ISDS] Gyro sample {i}/{samples}")
|
||||
x, y, z = self._read_raw_angular_velocities()
|
||||
self.gyro_offset_x += x
|
||||
self.gyro_offset_y += y
|
||||
@@ -362,6 +355,7 @@ class Wsen_Isds:
|
||||
self.gyro_offset_x //= samples
|
||||
self.gyro_offset_y //= samples
|
||||
self.gyro_offset_z //= samples
|
||||
print(f"[WSEN_ISDS] Gyroscope calibration complete: offsets=({self.gyro_offset_x}, {self.gyro_offset_y}, {self.gyro_offset_z})")
|
||||
|
||||
def read_angular_velocities(self):
|
||||
"""Read calibrated gyroscope data.
|
||||
@@ -379,19 +373,15 @@ class Wsen_Isds:
|
||||
|
||||
def _read_raw_angular_velocities(self):
|
||||
"""Read raw gyroscope data."""
|
||||
print("[WSEN_ISDS] _read_raw_angular_velocities: checking data ready...")
|
||||
if not self._gyro_data_ready():
|
||||
print("[WSEN_ISDS] _read_raw_angular_velocities: DATA NOT READY!")
|
||||
raise Exception("sensor data not ready")
|
||||
|
||||
print("[WSEN_ISDS] _read_raw_angular_velocities: data ready, reading registers...")
|
||||
raw = self.i2c.readfrom_mem(self.address, Wsen_Isds._REG_G_X_OUT_L, 6)
|
||||
|
||||
raw_g_x = self._convert_from_raw(raw[0], raw[1])
|
||||
raw_g_y = self._convert_from_raw(raw[2], raw[3])
|
||||
raw_g_z = self._convert_from_raw(raw[4], raw[5])
|
||||
|
||||
print(f"[WSEN_ISDS] _read_raw_angular_velocities: raw values = ({raw_g_x}, {raw_g_y}, {raw_g_z})")
|
||||
return raw_g_x, raw_g_y, raw_g_z
|
||||
|
||||
def read_angular_velocities_accelerations(self):
|
||||
@@ -468,5 +458,4 @@ class Wsen_Isds:
|
||||
gyro_data_ready = bool(status & 0x02) # Bit 1
|
||||
temp_data_ready = bool(status & 0x04) # Bit 2
|
||||
|
||||
print(f"[WSEN_ISDS] Status register: 0x{status:02x} = 0b{status:08b}, acc_ready={acc_data_ready}, gyro_ready={gyro_data_ready}, temp_ready={temp_data_ready}")
|
||||
return acc_data_ready, gyro_data_ready, temp_data_ready
|
||||
|
||||
@@ -652,53 +652,47 @@ class _QMI8658Driver(_IMUDriver):
|
||||
|
||||
def calibrate_accelerometer(self, samples):
|
||||
"""Calibrate accelerometer (device must be stationary)."""
|
||||
print(f"[QMI8658Driver] calibrate_accelerometer: starting with {samples} samples")
|
||||
print(f"[QMI8658Driver] Calibrating accelerometer with {samples} samples...")
|
||||
sum_x, sum_y, sum_z = 0.0, 0.0, 0.0
|
||||
|
||||
for i in range(samples):
|
||||
if i % 10 == 0:
|
||||
print(f"[QMI8658Driver] Sample {i}/{samples}: about to read acceleration...")
|
||||
print(f"[QMI8658Driver] Accel sample {i}/{samples}")
|
||||
ax, ay, az = self.sensor.acceleration
|
||||
if i % 10 == 0:
|
||||
print(f"[QMI8658Driver] Sample {i}/{samples}: read complete, values=({ax:.3f}, {ay:.3f}, {az:.3f}), sleeping...")
|
||||
# Convert to m/s²
|
||||
sum_x += ax * _GRAVITY
|
||||
sum_y += ay * _GRAVITY
|
||||
sum_z += az * _GRAVITY
|
||||
time.sleep_ms(10)
|
||||
if i % 10 == 0:
|
||||
print(f"[QMI8658Driver] Sample {i}/{samples}: sleep complete")
|
||||
|
||||
print(f"[QMI8658Driver] All {samples} samples collected, calculating offsets...")
|
||||
# Average offsets (assuming Z-axis should read +9.8 m/s²)
|
||||
self.accel_offset[0] = sum_x / samples
|
||||
self.accel_offset[1] = sum_y / samples
|
||||
self.accel_offset[2] = (sum_z / samples) - _GRAVITY # Expect +1G on Z
|
||||
|
||||
print(f"[QMI8658Driver] Calibration complete: offsets = {tuple(self.accel_offset)}")
|
||||
print(f"[QMI8658Driver] Accelerometer calibration complete: offsets = {tuple(self.accel_offset)}")
|
||||
return tuple(self.accel_offset)
|
||||
|
||||
def calibrate_gyroscope(self, samples):
|
||||
"""Calibrate gyroscope (device must be stationary)."""
|
||||
print(f"[QMI8658Driver] calibrate_gyroscope: starting with {samples} samples")
|
||||
print(f"[QMI8658Driver] Calibrating gyroscope with {samples} samples...")
|
||||
sum_x, sum_y, sum_z = 0.0, 0.0, 0.0
|
||||
|
||||
for i in range(samples):
|
||||
if i % 20 == 0:
|
||||
print(f"[QMI8658Driver] Reading sample {i}/{samples}...")
|
||||
if i % 10 == 0:
|
||||
print(f"[QMI8658Driver] Gyro sample {i}/{samples}")
|
||||
gx, gy, gz = self.sensor.gyro
|
||||
sum_x += gx
|
||||
sum_y += gy
|
||||
sum_z += gz
|
||||
time.sleep_ms(10)
|
||||
|
||||
print(f"[QMI8658Driver] All {samples} samples collected, calculating offsets...")
|
||||
# Average offsets (should be 0 when stationary)
|
||||
self.gyro_offset[0] = sum_x / samples
|
||||
self.gyro_offset[1] = sum_y / samples
|
||||
self.gyro_offset[2] = sum_z / samples
|
||||
|
||||
print(f"[QMI8658Driver] Calibration complete: offsets = {tuple(self.gyro_offset)}")
|
||||
print(f"[QMI8658Driver] Gyroscope calibration complete: offsets = {tuple(self.gyro_offset)}")
|
||||
return tuple(self.gyro_offset)
|
||||
|
||||
def get_calibration(self):
|
||||
|
||||
Reference in New Issue
Block a user