Skip to content

Commit cdfc5f8

Browse files
committed
TST: make ideal sensor tests more strict regarding different axes
1 parent cdeb36f commit cdfc5f8

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

tests/integration/test_sensor.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ def test_accelerometer(self):
4545
"""Test an ideal accelerometer."""
4646
accelerometer = self.flight.rocket.sensors[0].component
4747
time, ax, ay, az = zip(*accelerometer.measured_data[0])
48-
a = np.sqrt(np.array(ax) ** 2 + np.array(ay) ** 2 + np.array(az) ** 2)
49-
sim_accel = self.flight.acceleration(time)
48+
sim_ax = self.flight.ax_body_frame(time)
49+
sim_ay = self.flight.ay_body_frame(time)
50+
sim_az = self.flight.az_body_frame(time)
51+
52+
assert np.allclose(ax, sim_ax, atol=1e-12)
53+
assert np.allclose(ay, sim_ay, atol=1e-12)
54+
assert np.allclose(az, sim_az, atol=1e-12)
5055

51-
# tolerance is bounded to numerical errors in the transformation matrixes
52-
assert np.allclose(a, sim_accel, atol=1e-12)
5356
# check if both added accelerometer instances saved the same data
5457
assert (
5558
self.flight.sensors[0].measured_data[0]
@@ -60,12 +63,13 @@ def test_gyroscope(self):
6063
"""Test an ideal gyroscope."""
6164
gyroscope = self.flight.rocket.sensors[2].component
6265
time, wx, wy, wz = zip(*gyroscope.measured_data)
63-
w = np.sqrt(np.array(wx) ** 2 + np.array(wy) ** 2 + np.array(wz) ** 2)
64-
flight_wx = np.array(self.flight.w1(time))
65-
flight_wy = np.array(self.flight.w2(time))
66-
flight_wz = np.array(self.flight.w3(time))
67-
sim_w = np.sqrt(flight_wx**2 + flight_wy**2 + flight_wz**2)
68-
assert np.allclose(w, sim_w, atol=1e-12)
66+
sim_wx = self.flight.w1(time)
67+
sim_wy = self.flight.w2(time)
68+
sim_wz = self.flight.w3(time)
69+
70+
assert np.allclose(wx, sim_wx, atol=1e-12)
71+
assert np.allclose(wy, sim_wy, atol=1e-12)
72+
assert np.allclose(wz, sim_wz, atol=1e-12)
6973

7074
def test_barometer(self):
7175
"""Test an ideal barometer."""

tests/unit/test_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_rotation_matrix(noisy_rotated_accelerometer):
7676
[0.7499999999999999, 0.43301270189221946, 0.5000000000000001],
7777
]
7878
)
79-
rotation_matrix = np.array(noisy_rotated_accelerometer.rotation_matrix.components)
79+
rotation_matrix = np.array(noisy_rotated_accelerometer.rotation_sensor_to_body.components)
8080
assert np.allclose(expected_matrix, rotation_matrix, atol=1e-8)
8181

8282

0 commit comments

Comments
 (0)