Skip to content

Commit 174efa9

Browse files
committed
MNT: changed default value of weather_coeff in flight.py and added fixtures to test_flight_3dof.py
1 parent a564397 commit 174efa9

2 files changed

Lines changed: 50 additions & 62 deletions

File tree

rocketpy/simulation/flight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-statements
492492
equations_of_motion="standard",
493493
ode_solver="LSODA",
494494
simulation_mode="6 DOF",
495-
weathercock_coeff=1.0,
495+
weathercock_coeff=None,
496496
):
497497
"""Run a trajectory simulation.
498498

tests/unit/simulation/test_flight_3dof.py

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,42 @@ def point_mass_rocket(point_mass_motor):
5050
return rocket
5151

5252

53-
def test_simulation_mode_sets_3dof_with_point_mass_rocket(
54-
example_plain_env, point_mass_rocket
55-
):
53+
@pytest.fixture
54+
def flight_weathercock_zero(example_plain_env, point_mass_rocket):
55+
"""Creates a Flight fixture with weathercock_coeff set to 0.0.
56+
57+
Returns
58+
-------
59+
rocketpy.simulation.flight.Flight
60+
A Flight object configured for 3-DOF with zero weathercock coefficient.
61+
"""
62+
return Flight(
63+
rocket=point_mass_rocket,
64+
environment=example_plain_env,
65+
rail_length=1,
66+
simulation_mode="3 DOF",
67+
weathercock_coeff=0.0,
68+
)
69+
70+
71+
@pytest.fixture
72+
def flight_3dof(example_plain_env, point_mass_rocket):
73+
"""Creates a standard 3-DOF Flight fixture with default weathercock_coeff=1.0.
74+
75+
Returns
76+
-------
77+
rocketpy.simulation.flight.Flight
78+
A Flight object configured for 3-DOF with default weathercock coefficient.
79+
"""
80+
return Flight(
81+
rocket=point_mass_rocket,
82+
environment=example_plain_env,
83+
rail_length=1,
84+
simulation_mode="3 DOF",
85+
)
86+
87+
88+
def test_simulation_mode_sets_3dof_with_point_mass_rocket(flight_3dof):
5689
"""Tests that simulation mode is correctly set to 3 DOF for PointMassRocket.
5790
5891
Parameters
@@ -62,13 +95,7 @@ def test_simulation_mode_sets_3dof_with_point_mass_rocket(
6295
point_mass_rocket : rocketpy.PointMassRocket
6396
A point mass rocket fixture for 3-DOF simulation.
6497
"""
65-
flight = Flight(
66-
rocket=point_mass_rocket,
67-
environment=example_plain_env,
68-
rail_length=1,
69-
simulation_mode="3 DOF",
70-
)
71-
assert flight.simulation_mode == "3 DOF"
98+
assert flight_3dof.simulation_mode == "3 DOF"
7299

73100

74101
def test_3dof_simulation_mode_warning(example_plain_env, point_mass_rocket):
@@ -94,9 +121,7 @@ class should emit a UserWarning and automatically switch to 3 DOF mode.
94121
assert flight.simulation_mode == "3 DOF"
95122

96123

97-
def test_u_dot_generalized_3dof_returns_valid_result(
98-
example_plain_env, point_mass_rocket
99-
):
124+
def test_u_dot_generalized_3dof_returns_valid_result(flight_3dof):
100125
"""Tests that 3-DOF equations of motion return valid derivative results.
101126
102127
Verifies that the u_dot_generalized_3dof method returns a list or numpy
@@ -109,12 +134,7 @@ def test_u_dot_generalized_3dof_returns_valid_result(
109134
point_mass_rocket : rocketpy.PointMassRocket
110135
A point mass rocket fixture for 3-DOF simulation.
111136
"""
112-
flight = Flight(
113-
rocket=point_mass_rocket,
114-
environment=example_plain_env,
115-
rail_length=1,
116-
simulation_mode="3 DOF",
117-
)
137+
flight = flight_3dof
118138
u = [0] * 13 # Generalized state vector size
119139
result = flight.u_dot_generalized_3dof(0, u)
120140
assert isinstance(result, (list, np.ndarray))
@@ -159,7 +179,7 @@ def test_weathercock_coeff_stored(example_plain_env, point_mass_rocket):
159179
assert flight.weathercock_coeff == 2.5
160180

161181

162-
def test_weathercock_coeff_default(example_plain_env, point_mass_rocket):
182+
def test_weathercock_coeff_default(flight_3dof):
163183
"""Tests that the default weathercock_coeff is 1.0.
164184
165185
Parameters
@@ -169,16 +189,10 @@ def test_weathercock_coeff_default(example_plain_env, point_mass_rocket):
169189
point_mass_rocket : rocketpy.PointMassRocket
170190
A point mass rocket fixture for 3-DOF simulation.
171191
"""
172-
flight = Flight(
173-
rocket=point_mass_rocket,
174-
environment=example_plain_env,
175-
rail_length=1,
176-
simulation_mode="3 DOF",
177-
)
178-
assert flight.weathercock_coeff == 1.0
192+
assert flight_3dof.weathercock_coeff == 1.0
179193

180194

181-
def test_weathercock_zero_gives_fixed_attitude(example_plain_env, point_mass_rocket):
195+
def test_weathercock_zero_gives_fixed_attitude(flight_weathercock_zero):
182196
"""Tests that weathercock_coeff=0 results in fixed attitude (no quaternion change).
183197
When weathercock_coeff is 0, the quaternion derivatives should be zero,
184198
meaning the attitude does not evolve.
@@ -190,13 +204,7 @@ def test_weathercock_zero_gives_fixed_attitude(example_plain_env, point_mass_roc
190204
point_mass_rocket : rocketpy.PointMassRocket
191205
A point mass rocket fixture for 3-DOF simulation.
192206
"""
193-
flight = Flight(
194-
rocket=point_mass_rocket,
195-
environment=example_plain_env,
196-
rail_length=1,
197-
simulation_mode="3 DOF",
198-
weathercock_coeff=0.0,
199-
)
207+
flight = flight_weathercock_zero
200208
# Create a state vector with non-zero velocity (to have freestream)
201209
# [x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
202210
u = [0, 0, 100, 10, 5, 50, 1, 0, 0, 0, 0, 0, 0]
@@ -207,7 +215,7 @@ def test_weathercock_zero_gives_fixed_attitude(example_plain_env, point_mass_roc
207215
assert all(abs(ed) < 1e-10 for ed in e_dot), "Quaternion derivatives should be zero"
208216

209217

210-
def test_weathercock_nonzero_evolves_attitude(example_plain_env, point_mass_rocket):
218+
def test_weathercock_nonzero_evolves_attitude(flight_3dof):
211219
"""Tests that non-zero weathercock_coeff causes attitude evolution.
212220
When the body axis is misaligned with the relative wind and weathercock_coeff
213221
is positive, the quaternion derivatives should be non-zero.
@@ -219,13 +227,7 @@ def test_weathercock_nonzero_evolves_attitude(example_plain_env, point_mass_rock
219227
point_mass_rocket : rocketpy.PointMassRocket
220228
A point mass rocket fixture for 3-DOF simulation.
221229
"""
222-
flight = Flight(
223-
rocket=point_mass_rocket,
224-
environment=example_plain_env,
225-
rail_length=1,
226-
simulation_mode="3 DOF",
227-
weathercock_coeff=1.0,
228-
)
230+
flight = flight_3dof
229231
# Create a state with misaligned body axis
230232
# Body pointing straight up (e0=1, e1=e2=e3=0) but velocity is horizontal
231233
# [x, y, z, vx, vy, vz, e0, e1, e2, e3, w1, w2, w3]
@@ -238,7 +240,7 @@ def test_weathercock_nonzero_evolves_attitude(example_plain_env, point_mass_rock
238240
assert e_dot_magnitude > 1e-6, "Quaternion derivatives should be non-zero"
239241

240242

241-
def test_weathercock_aligned_no_evolution(example_plain_env, point_mass_rocket):
243+
def test_weathercock_aligned_no_evolution(flight_3dof):
242244
"""Tests that when body axis is aligned with relative wind, no rotation occurs.
243245
When the rocket's body z-axis is already aligned with the negative of the
244246
freestream velocity, the quaternion derivatives should be approximately zero.
@@ -250,13 +252,7 @@ def test_weathercock_aligned_no_evolution(example_plain_env, point_mass_rocket):
250252
point_mass_rocket : rocketpy.PointMassRocket
251253
A point mass rocket fixture for 3-DOF simulation.
252254
"""
253-
flight = Flight(
254-
rocket=point_mass_rocket,
255-
environment=example_plain_env,
256-
rail_length=1,
257-
simulation_mode="3 DOF",
258-
weathercock_coeff=1.0,
259-
)
255+
flight = flight_3dof
260256
# Body pointing in +x direction (into the wind for vx=50)
261257
# Quaternion for 90 degree rotation about y-axis uses half-angle:
262258
# e0=cos(90°/2)=cos(45°), e2=sin(90°/2)=sin(45°)
@@ -273,22 +269,14 @@ def test_weathercock_aligned_no_evolution(example_plain_env, point_mass_rocket):
273269
)
274270

275271

276-
def test_weathercock_anti_aligned_uses_perp_axis_and_evolves(
277-
example_plain_env, point_mass_rocket
278-
):
272+
def test_weathercock_anti_aligned_uses_perp_axis_and_evolves(flight_3dof):
279273
"""Tests the anti-aligned case where body z-axis is opposite freestream.
280274
281275
This should exercise the branch that selects a perpendicular axis (y-axis)
282276
when the cross with x-axis is nearly zero, producing a non-zero quaternion
283277
derivative.
284278
"""
285-
flight = Flight(
286-
rocket=point_mass_rocket,
287-
environment=example_plain_env,
288-
rail_length=1,
289-
simulation_mode="3 DOF",
290-
weathercock_coeff=1.0,
291-
)
279+
flight = flight_3dof
292280

293281
sqrt2_2 = np.sqrt(2) / 2
294282
# Build quaternion that makes body z-axis = [-1, 0, 0]

0 commit comments

Comments
 (0)