Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add magnitude component to linear acceleration and angular velocity #100

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 6 additions & 3 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.magnitude: int = round((abs(x_axis) ** 2 + abs(y_axis) ** 2 + abs(z_axis) ** 2) ** 0.5, 2)
EliasJRH marked this conversation as resolved.
Show resolved Hide resolved

@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.magnitude: int = round((abs(x_axis) ** 2 + abs(y_axis) ** 2 + abs(z_axis) ** 2) ** 0.5, 2)
EliasJRH marked this conversation as resolved.
Show resolved Hide resolved

@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
Loading