Skip to content
Snippets Groups Projects
Commit bb041056 authored by schneider's avatar schneider
Browse files

imu: put imu state into an object

parent 1f19c23f
No related branches found
No related tags found
No related merge requests found
...@@ -25,8 +25,8 @@ class IMUDemo(Application): ...@@ -25,8 +25,8 @@ class IMUDemo(Application):
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) super().think(ins, delta_ms)
self.v_y += ins.acc[0] * delta_ms / 1000.0 * 10 self.v_y += ins.imu.acc[0] * delta_ms / 1000.0 * 10
self.v_x += ins.acc[1] * delta_ms / 1000.0 * 10 self.v_x += ins.imu.acc[1] * delta_ms / 1000.0 * 10
x = self.p_x + self.v_x * delta_ms / 1000.0 x = self.p_x + self.v_x * delta_ms / 1000.0
y = self.p_y + self.v_y * delta_ms / 1000.0 y = self.p_y + self.v_y * delta_ms / 1000.0
......
...@@ -8,6 +8,26 @@ from st3m.power import Power ...@@ -8,6 +8,26 @@ from st3m.power import Power
power = Power() power = Power()
class IMUState:
"""
State of the Inertial Measurement Unit
Acceleration in m/s**2, roation rate in deg/s, pressure in Pascal
"""
__slots__ = ("acc", "gyro", "pressure")
def __init__(
self,
acc: Tuple[float, float, float],
gyro: Tuple[float, float, float],
pressure: float,
) -> None:
self.acc = acc
self.gyro = gyro
self.pressure = pressure
class InputState: class InputState:
""" """
Current state of inputs from badge user. Passed via think() to every Current state of inputs from badge user. Passed via think() to every
...@@ -21,9 +41,7 @@ class InputState: ...@@ -21,9 +41,7 @@ class InputState:
captouch: captouch.CaptouchState, captouch: captouch.CaptouchState,
left_button: int, left_button: int,
right_button: int, right_button: int,
acc: Tuple[float, float, float], imu: IMUState,
gyro: Tuple[float, float, float],
pressure: float,
temperature: float, temperature: float,
battery_voltage: float, battery_voltage: float,
) -> None: ) -> None:
...@@ -31,9 +49,7 @@ class InputState: ...@@ -31,9 +49,7 @@ class InputState:
self.captouch = captouch self.captouch = captouch
self.left_button = left_button self.left_button = left_button
self.right_button = right_button self.right_button = right_button
self.acc = acc self.imu = imu
self.gyro = gyro
self.pressure = pressure
self.temperature = temperature self.temperature = temperature
self.battery_voltage = battery_voltage self.battery_voltage = battery_voltage
...@@ -52,14 +68,14 @@ class InputState: ...@@ -52,14 +68,14 @@ class InputState:
acc = imu.acc_read() acc = imu.acc_read()
gyro = imu.gyro_read() gyro = imu.gyro_read()
pressure, temperature = imu.pressure_read() pressure, temperature = imu.pressure_read()
imu_state = IMUState(acc, gyro, pressure)
battery_voltage = power.battery_voltage battery_voltage = power.battery_voltage
return InputState( return InputState(
cts, cts,
left_button, left_button,
right_button, right_button,
acc, imu_state,
gyro,
pressure,
temperature, temperature,
battery_voltage, battery_voltage,
) )
...@@ -484,21 +500,6 @@ class TriSwitchState: ...@@ -484,21 +500,6 @@ class TriSwitchState:
self.right._ignore_pressed() self.right._ignore_pressed()
class IMUState:
__slots__ = ("acc", "gyro", "pressure", "temperature")
def __init__(self) -> None:
self.acc = (0.0, 0.0, 0.0)
self.gyro = (0.0, 0.0, 0.0)
self.pressure = 0.0
self.temperature = 0.0
def _update(self, ts: int, hr: InputState) -> None:
self.acc = imu.acc_read()
self.gyro = imu.gyro_read()
self.pressure, self.temperature = imu.pressure_read()
class InputController: class InputController:
""" """
A stateful input controller. It accepts InputState updates from the Reactor A stateful input controller. It accepts InputState updates from the Reactor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment