Skip to content

Commit

Permalink
Merge pull request #100 from CarletonURocketry/eh/velocity_magnitude
Browse files Browse the repository at this point in the history
Add magnitude component to linear acceleration and angular velocity
  • Loading branch information
linguini1 authored May 20, 2024
2 parents df1b3c4 + 2b7409f commit fcb1e35
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
9 changes: 6 additions & 3 deletions modules/telemetry/telemetry_packet.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
"linear_acceleration_rel": {
"x": { "1": { "5": "linear_acceleration.x" } },
"y": { "1": { "5": "linear_acceleration.y" } },
"z": { "1": { "5": "linear_acceleration.z" } }
"z": { "1": { "5": "linear_acceleration.z" } },
"magnitude": { "1": { "5": "linear_acceleration.magnitude" } }
},
"linear_acceleration_abs": {
"x": { "1": { "6": "linear_acceleration.x" } },
"y": { "1": { "6": "linear_acceleration.y" } },
"z": { "1": { "6": "linear_acceleration.z" } }
"z": { "1": { "6": "linear_acceleration.z" } },
"magnitude": { "1": { "6": "linear_acceleration.magnitude" } }
},
"angular_velocity": {
"x": { "1": { "7": "angular_velocity.x" } },
"y": { "1": { "7": "angular_velocity.y" } },
"z": { "1": { "7": "angular_velocity.z" } }
"z": { "1": { "7": "angular_velocity.z" } },
"magnitude": { "1": { "7": "angular_velocity.magnitude" } },
},
"humidity": {
"percentage": { "1": { "8": "percentage" } }
Expand Down
21 changes: 12 additions & 9 deletions modules/telemetry/v1/data_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,13 @@ def __init__(self, mission_time: int, x_axis: int, y_axis: int, z_axis: int) ->
x_axis: The acceleration about the x axis in meters per second squared.
y_axis: The acceleration about the y axis in meters per second squared.
z_axis: The acceleration about the z axis in meters per second squared.
magnitude: The magnitude of the linear acceleration in meters per second squared.
"""
super().__init__(mission_time)
self.x_axis: int = x_axis
self.y_axis: int = y_axis
self.z_axis: int = z_axis
self.x_axis: float = x_axis
self.y_axis: float = y_axis
self.z_axis: float = z_axis
self.magnitude: float = round((abs(x_axis) ** 2 + abs(y_axis) ** 2 + abs(z_axis) ** 2) ** 0.5, 2)

@classmethod
def from_bytes(cls, payload: bytes) -> Self:
Expand All @@ -368,11 +369,12 @@ def __len__(self) -> int:

def __str__(self):
return f"""{self.__class__.__name__} -> time: {self.mission_time} ms, x-axis: {self.x_axis} m/s^2, y-axis:
{self.y_axis} m/s^2, z-axis: {self.z_axis} m/s^2"""
{self.y_axis} m/s^2, z-axis: {self.z_axis} m/s^2, magnitude: {self.magnitude} m/s^2"""

def __iter__(self):
yield "mission_time", self.mission_time
yield "linear_acceleration", {"x": self.x_axis, "y": self.y_axis, "z": self.z_axis}
yield "magnitude", self.magnitude


class RelativeLinearAccelerationDB(LinearAccelerationDB):
Expand Down Expand Up @@ -401,12 +403,13 @@ def __init__(self, mission_time: int, x_axis: int, y_axis: int, z_axis: int) ->
x_axis: The velocity about the x axis in degrees per second.
y_axis: The velocity about the y axis in degrees per second.
z_axis: The velocity about the z axis in degrees per second.
magnitude: The magnitude of the angular velocity in degrees per second.
"""
super().__init__(mission_time)
self.x_axis: int = x_axis
self.y_axis: int = y_axis
self.z_axis: int = z_axis
self.x_axis: float = x_axis
self.y_axis: float = y_axis
self.z_axis: float = z_axis
self.magnitude: float = round((abs(x_axis) ** 2 + abs(y_axis) ** 2 + abs(z_axis) ** 2) ** 0.5, 2)

@classmethod
def from_bytes(cls, payload: bytes) -> Self:
Expand Down
2 changes: 2 additions & 0 deletions tests/parsing/test_block_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_linear_acceleration_data_block(linear_acceleration_data_content: bytes)
assert lin_acc.x_axis == 0.03
assert lin_acc.y_axis == -0.04
assert lin_acc.z_axis == 10.32
assert lin_acc.magnitude == 10.32


def test_angular_velocity_data_block(angular_velocity_data_content: bytes) -> None:
Expand All @@ -87,3 +88,4 @@ def test_angular_velocity_data_block(angular_velocity_data_content: bytes) -> No
assert ang_vel.x_axis == 0.6
assert ang_vel.y_axis == 1.1
assert ang_vel.z_axis == -0.3
assert ang_vel.magnitude == 1.29

0 comments on commit fcb1e35

Please sign in to comment.