Skip to content

Commit 297d38a

Browse files
committed
BUG: Fix no time initialization when passing initial_solution as array to Flight object
## Pull request type - [x] Code changes (bugfix, features) - [x] Code maintenance (refactoring, formatting, tests) ## Checklist - [ ] Tests for the changes have been added (if needed) - [ ] Docs have been reviewed and added / updated - [ ] Lint (`black rocketpy/ tests/`) has passed locally - [ ] All tests (`pytest tests -m slow --runslow`) have passed locally - [ ] `CHANGELOG.md` has been updated (if relevant) ## Current behavior Passing initial_solution to a Flight object raises `AttributeError: 'Flight' object has no attribute 't_initial'` when running a simulation involving a controller. Attempt to run [this script](https://github.com/werocketry/airbrakes-lookuptable-generator/blob/main/main.py) to reproduce. ## New behavior Initializes t_initial in __init_flight_state when an array is provided as the initial solution. As a result, a simulation can successfully run from an initial condition when controllers are used. Additionally, minor fixes to docstrings in Flight.py ## Breaking change - [ ] Yes - [x] No
1 parent b0aacdc commit 297d38a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

rocketpy/simulation/flight.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class Flight:
143143
Flight.heading : int, float
144144
Launch heading angle relative to north given in degrees.
145145
Flight.initial_solution : list
146-
List defines initial condition - [tInit, x_init,
146+
List defines initial condition - [t_initial, x_init,
147147
y_init, z_init, vx_init, vy_init, vz_init, e0_init, e1_init,
148148
e2_init, e3_init, w1_init, w2_init, w3_init]
149149
Flight.t_initial : int, float
@@ -155,10 +155,6 @@ class Flight:
155155
Current integration time.
156156
Flight.y : list
157157
Current integration state vector u.
158-
Flight.initial_solution : list
159-
List defines initial condition - [tInit, x_init,
160-
y_init, z_init, vx_init, vy_init, vz_init, e0_init, e1_init,
161-
e2_init, e3_init, w1_init, w2_init, w3_init]
162158
Flight.out_of_rail_time : int, float
163159
Time, in seconds, in which the rocket completely leaves the
164160
rail.
@@ -544,7 +540,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-statements
544540
rtol : float, array, optional
545541
Maximum relative error tolerance to be tolerated in the
546542
integration scheme. Can be given as array for each
547-
state space variable. Default is 1e-3.
543+
state space variable. Default is 1e-6.
548544
atol : float, optional
549545
Maximum absolute error tolerance to be tolerated in the
550546
integration scheme. Can be given as array for each
@@ -1168,6 +1164,7 @@ def __init_flight_state(self):
11681164
self.out_of_rail_state = self.initial_solution[1:]
11691165
self.out_of_rail_time = self.initial_solution[0]
11701166
self.out_of_rail_time_index = 0
1167+
self.t_initial = self.initial_solution[0]
11711168
self.initial_derivative = self.u_dot_generalized
11721169
if self._controllers or self.sensors:
11731170
# Handle post process during simulation, get initial accel/forces
@@ -2080,7 +2077,7 @@ def x(self):
20802077

20812078
@funcify_method("Time (s)", "Y (m)", "spline", "constant")
20822079
def y(self):
2083-
"""Rocket y position relative to the lauch pad as a Function of
2080+
"""Rocket y position relative to the launch pad as a Function of
20842081
time."""
20852082
return self.solution_array[:, [0, 2]]
20862083

@@ -2976,7 +2973,7 @@ def max_rail_button2_shear_force(self):
29762973
"Time (s)", "Horizontal Distance to Launch Point (m)", "spline", "constant"
29772974
)
29782975
def drift(self):
2979-
"""Rocket horizontal distance to tha launch point, in meters, as a
2976+
"""Rocket horizontal distance to the launch point, in meters, as a
29802977
Function of time."""
29812978
return np.column_stack(
29822979
(self.time, (self.x[:, 1] ** 2 + self.y[:, 1] ** 2) ** 0.5)

0 commit comments

Comments
 (0)