diff --git a/leads_arduino/accelerometer.py b/leads_arduino/accelerometer.py index 5433b5f..4ce47c9 100644 --- a/leads_arduino/accelerometer.py +++ b/leads_arduino/accelerometer.py @@ -25,10 +25,19 @@ class Acceleration(_Serializable): lateral_acceleration: float vertical_acceleration: float + def is_linear(self) -> bool: + return isinstance(self, _LinearAcceleration) + def linear(self) -> _Self: fg = rotation_matrix(self.yaw, self.pitch, self.roll).T @ _G - return Acceleration(self.yaw, self.pitch, self.roll, self.forward_acceleration + fg[0], - self.lateral_acceleration + fg[1], self.vertical_acceleration - fg[2]) + return _LinearAcceleration(self.yaw, self.pitch, self.roll, float(self.forward_acceleration + fg[0]), + float(self.lateral_acceleration + fg[1]), float(self.vertical_acceleration - fg[2])) + + +class _LinearAcceleration(Acceleration): + @_override + def linear(self) -> _Self: + return self class Accelerometer(_Device):