Skip to content

Commit

Permalink
Linear Acceleration should not be Linear Again (#442)
Browse files Browse the repository at this point in the history
* Bug fixed: duplicated `linear()` call. (#440)

* Bug fixed: duplicated `linear()` call. (#440)
  • Loading branch information
ATATC authored Oct 5, 2024
1 parent 88f245b commit 0f58045
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions leads_arduino/accelerometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0f58045

Please sign in to comment.