Repository navigation
Conversation
…uash for RocketPy PR) (#7) * Merge RocketPy 1.12 and add updates for balloon popping challenge (#8) * Add actuator dynamics in TVC and ThrottleControl authored-by: RickyRicato <rickywang44@gmail.com> * Refactor actuator_tau parameters to use None as default in TVC and ThrottleControl authored-by: RickyRicato <rickywang44@gmail.com> * Add actuator dynamics to RollControl authored-by: RickyRicato <rickywang44@gmail.com> * Move actuators to a new actuator folder and rename actuator classes * Refactor roll, throttle, and thrust vector acutator with a new actuator class * Add pytest for all actuators * Update rocket.py and flight.py for actuator class update * Fix actuator class calls * Update active control example with new actuator class --------- Co-authored-by: RickyRicato <rickywang44@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## enh/control-refactor #1155 +/- ##
========================================================
+ Coverage 88.93% 89.26% +0.32%
========================================================
Files 156 164 +8
Lines 23562 24258 +696
========================================================
+ Hits 20955 21653 +698
+ Misses 2607 2605 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
studying if changes from #968 can be accommodated or not. ideally need the events PR to be closed for cleaner implementation and avoid double work |
|
1. ( 2. The docs build with Since this branch lives on the main repo I can push both fixes myself if you prefer — say the word. Otherwise please push them and I will review the substance (2500 lines deserves a real read, and I would rather do that against green CI). |
Hey Gui, most likely cant close this PR yet need the events and flight rework PR to close first as they will define major changes here as well. That's why havent closed lints and docs yet. Events work, potentially will trigger some fundamental changes here. |
There was a problem hiding this comment.
do we really need the "docs/notebooks/multistage_mission_test_report.ipynb" file here?
There was a problem hiding this comment.
nope its just for my use, it will reworked into a doc when the event and flight work changes come here
| from .plot_helpers import show_or_save_plot | ||
|
|
||
|
|
||
| def _default_vis_args(): |
There was a problem hiding this comment.
maybe we should allow users to select their preferred colors. A new issue could be opened about it, so contributors can solve it.
There was a problem hiding this comment.
long file... We should rather split it into smaller ones. Try 1 class por file.
There was a problem hiding this comment.
yeah can refactor into multiple classes easily
There was a problem hiding this comment.
again waiting for events and flight rework to come in before i make huge changes probably should have made this a draft PR
83ba268 to
672d9ad
Compare
|
I'm starting a claude session on this branch right now |
- ENH: added code architecture a new class called body - ENH: added code architecture a new class called mission aimed at deployable and stage implementation - ENH: added code architecture for flight branch class for multistage integration class to simulation
rocketpy/body/, rocketpy/mission/, and rocketpy/simulation/ flight_branch.py (added in 0caf343) never actually worked: rocketpy/mission/__initi__.py is misspelled so the package init never ran, four files were empty, and three others had function signatures with no body (IndentationError). None of it was imported by rocketpy/__init__.py or referenced anywhere else in the repo. Clearing the way for a simpler multistage/mission design (SeparableBody/Stage/Deployable/MultiStageRocket + Mission orchestrator) to be built incrementally.
First slice of the new multistage/mission architecture (see mission_multistage_design.md). SeparableBody is the shared base for anything that starts attached to a vehicle and becomes a free body at separation; Stage wraps a fully built Rocket representing one stage flying on its own. For now Stage is a thin wrapper: dry_mass and burn_out_time just forward to the wrapped Rocket's own already-computed attributes. Composition into a full multistage vehicle (MultiStageRocket) and orchestration (Mission) land in later commits.
Second slice of the multistage/mission architecture. Deployable is the mission-layer wrapper for an inert carried body (payload, nose cone, etc.) that gets ejected during flight: mass/inertia/position while attached, plus either a fully built free_rocket or surfaces added via add_surface() for its free-flight aerodynamics - mutually exclusive, matching mission_multistage_design.md. Also revises SeparableBody from the previous commit: it no longer holds a shared "separation" attribute. Stage's release event is named separation, Deployable's is named ejection - forcing both through one base attribute name was misleading, so each subclass now owns its own.
Third slice of the multistage/mission architecture. MultiStageRocket composes a Stage plus any Deployables aboard into one flight-ready Rocket via flight_rocket(): mass, inertia and center of mass are combined with the parallel axis theorem (reusing tools.parallel_axis_theorem_from_com, the same helper Rocket itself uses for structure+motor composition), then the stage's motor and aerodynamic surfaces are attached to the result. Only a single active stage is supported for now; flight_rocket() raises NotImplementedError otherwise. Multi-stage composition (booster + sustainer together, surfaces repositioned into stack coordinates) is a later commit, matching the roadmap in mission_multistage_design.md. Also adds docs/notebooks/multistage_mission.ipynb, a runnable demo of everything landed so far (Stage, Deployable, MultiStageRocket.flight_rocket single-stage case). Executed end-to-end to confirm it runs, outputs then cleared to match this repo's existing notebook convention (see docs/notebooks/ utilities_usage.ipynb).
Fourth slice of the multistage/mission architecture. flight_rocket() now composes any number of active stages, not just one: active_stages[0] is the currently firing stage (its motor becomes the composed Rocket's own motor); every stage above it is inert cargo, contributing its full current mass/inertia/CoM (structure + motor + unburned propellant, evaluated at that stage's own t=0) since its own motor clock hasn't started yet. Default stack drag (no stack_power_off_drag/on_drag override) is now an area-weighted sum of each active stage's own drag curve - the approach mission_multistage_design.md itself leans toward for _derive_stack_drag. This subsumes the single-stage case from the previous commit, so that code path is unchanged in behavior. Split flight_rocket() into _compose_mass_and_center_of_mass and _compose_inertia to keep it under pylint's statement-count limit, mirroring how Rocket itself splits mass/inertia composition into separate evaluate_* methods. Deviation from the design doc: _stack_position_of() (deriving each stage's axial position from interstage_lengths + physical extent) is not implemented. Every active stage's Rocket coordinate system is assumed to already share one common stack frame; positions are used as-is. Flagged in the notebook's "Not built yet" section as remaining work. Also updates docs/notebooks/multistage_mission.ipynb with a two-stage (booster + inert sustainer) demo, executed end-to-end and verified against the same hand-computed values used in test_multistage.py.
Brings the review fixes of #968 and #1064. Resolved here: - "apogee" is one condition for triggers, gates and parachutes, as on enh/events: _past_apogee, _reached_apogee and _GATE_PRESETS are removed. - The parachute noise reads the pressure and the sensors through the context of this branch. - The loaded flight rebuilds its surface switches instead of starting with none. - The sampled events skipped in a cut step call the rail exit trigger with the flight. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A rollback dropped the readings made after the time it goes back to, but the drift of the random walk kept the steps of those readings. Each reading now keeps the drift it left, and a rollback puts back the drift of the last reading kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sampled rocket only had the controller of air brakes given to StochasticRocket.add_air_brakes. It now flies a copy of every controller and of every sensor of the rocket, at its position, and the rocket's air brakes as they are when none were given to add_air_brakes. A surface added without its stochastic class is wrapped in it again, as it was before the wrapping was given a keyword its classes do not take. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Setting enabled after an event or a controller was built held only for the next flight: the flight put back the value given when it was built. enabled is now a property; setting it also sets how every later flight starts, and is what is saved. A flight turns events on and off without changing that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rollback put back the controls, the memory and the records of the events run after the time it goes back to, but not what their commands changed: a phase started, an event added, enabled or disabled, a surface switched, a parachute deployed or the end of the flight. The schedule is now saved before each event that changes it, and put back by the rollback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A NaN written to a control input, as after a division by zero, was kept and flown, and an infinite one on a control without limits too. Both now raise an error that names the control input and the event or controller that wrote it. An infinite value on a control with limits goes to the limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checking an event with a plain dictionary, or with a context that lacks the state, failed with an AttributeError or a KeyError deep in the event. Both now say what the context must hold, before the trigger runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each reading of a sensor evaluated the equations of motion once, for the derivative of the state, which only the accelerometer and a gyroscope with an acceleration sensitivity read. A 100 Hz barometer, GNSS receiver or plain gyroscope now costs about 1 s less per flight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A control write cuts the solver step, since the trajectory after it changes. The built-in parachute descent reads no control input, so the cut changed nothing there and only cost time: a controller fed by a noisy sensor made a flight with a 100 Hz loop take 12 s instead of 4 s. The write is still kept. A phase says whether it reads the control inputs with reads_controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings the aero refactor, the events stack and develop's v1.14 work into the control rework: - "previous" interpolation ported to develop's interpolation registry. - Core events bound to their flight, with the tip-off phase and the rail exits found by root finding. The parachute on-rail refusal is checked where the flight records the deployment. - udot_rail2 and solid propulsion on control's signature, with develop's corrected propellant terms. - _logging dropped for standard loggers. - add_air_brakes(sampling_rate=None), documented in v1.13, still runs the controller at every solver step, with a DeprecationWarning (removal in v1.16). Controller itself still requires a rate. - develop's tests ported to control's API (controls argument, nozzle exit, context pressure, sensors dict). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o multistage Brings in #968 (Events and Flight rework), #1064 (aero refactor) and #1065 (control refactor), the new base of this PR. Conflicts: - rocket_plots.py: upstream's draw() now draws per plane through _draw_on_plane(). Took upstream's version and kept only _default_vis_args() and draw_motor(); the return_axes hook is dropped. - docs/user/index.rst: kept upstream's Control Fins and Sensors guide entries plus the Multistage Mission notebook; dropped sensors.ipynb, which upstream replaced with sensors_usage.rst. MultiStageRocket.draw() now builds its own figure per plane and calls _draw_on_plane(), matching Rocket.plots.draw(): plane=None draws both planes for a non-axisymmetric stack, "pitch"/"yaw" are accepted and an unknown plane raises ValueError.
On the new Flight, a body handed off at or past apogee (each body after a deployable ejects at apogee) never sees vz cross from positive to non-positive, so its apogee_time stays at the default 0. Mission tested the sign of the final vz instead, and logged "apogee:<flight>" at t=0 for those flights. A flight now gets an apogee entry only when its apogee_time is after its own start, which the built-in apogee event guarantees for any apogee it records. The multistage notebook is re-executed on the new base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flight_rocket() added each stage's surfaces straight into aerodynamic_surfaces, skipping the checks Rocket.add_surfaces makes, so two stages' air brakes with the same name composed silently. The explicit evaluate_* calls are dropped: Rocket now rebuilds its center of pressure, margins and surfaces_cp_to_cdm whenever its surfaces change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds _wrap_event, the single place Mission builds on rocketpy Events: a deep copy of a user's staging Event whose callback runs the user's own, inside the Flight, then terminates it. The tests pin what Mission relies on, so an upstream change to Events fails here first: a Flight ends exactly where the event's exact_time_function is zero, the user's callback runs once and their Event is left untouched, and an "apogee" trigger fires at the exact apogee when the Flight also runs with terminate_on_apogee. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
after_burnout(delay), at_altitude(height), at_time(time) and at_apogee() each return a plain rocketpy Event for the common staging moments, with the trigger written once and an exact_time_function derived from it, so a Flight ended on one stops at the event itself rather than at the end of the solver step that crossed it. at_apogee() uses the "apogee" trigger, which Mission will pair with terminate_on_apogee to locate the apogee exactly. Every factory takes an optional callback and name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The two failing checks on this PR come from the base branch, not from the multistage changes.
Neither file is touched by this PR, so I'm leaving them to the base branch. They should clear here once they're fixed there. |
Stage.separation is now a rocketpy Event (or None) instead of a float delay after burnout; a float raises a TypeError pointing to after_burnout(). Mission gives the stack's Flight the wrapped copy of the bottom stage's separation Event and splits the vehicle wherever it fires, from the Flight's final state, instead of running the Flight to burn_out_time + separation as max_time. A separation Event with the "apogee" trigger runs its Flight with terminate_on_apogee so it fires at the exact apogee. If the Event never fires before the Flight ends, the Mission raises instead of carrying the stage to impact. Tests and the multistage notebook move from separation=<float> to after_burnout(<float>); separation times are unchanged, and later events in the three-stage examples move by at most 1 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deployable.ejection is now a rocketpy Event (or None) instead of the string "apogee"; the string raises a TypeError pointing to at_apogee(). Mission flies the carrier with the wrapped copy of the ejection Event and splits wherever it fires, raising if it never does. The handoff guard for a body already past apogee still applies to apogee ejections. Fixes apogee detection for both separation and ejection: Event resolves the "apogee" string to its own preset condition when built, so Mission now recognises that condition (on the user's Event) to run the Flight with terminate_on_apogee. On the root-found apogee row vz is zero only to the solver's tolerance and can come out slightly positive, which the preset (vz <= 0) misses, so the wrapped copy of an apogee Event fires when vz is within 1e-5 m/s of zero. Without these, an apogee separation or ejection fired late by up to a solver step, or never. The multistage notebook moves to at_apogee(); its timelines are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A configuration used to wait only on its bottom stage's separation, and handled at most one deployable ejection, after any separation. Now the separation and every carried deployable's ejection race in one Flight, and the first to fire splits the vehicle there. Events that fire in the same step are all applied at that instant, in a fixed order: the separation first, then deployables in carried order. The child configurations apply the rest at their first instant without flying again. The past-apogee handoff case now goes through the same path. When nothing fires, the error names every pending event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stage given an ignition Event no longer raises NotImplementedError. After the stage below separates, it coasts unlit: flight_rocket(..., unlit=True) carries it as inert cargo at its full mass, with an EmptyMotor. Its ignition Event races any pending ejection, and when it fires the motor is time-shifted to start there and the flight continues from the same state. The burnout is recorded only after ignition. The first stage ignites at liftoff and refuses an ignition Event. An ignition Event and an ignition_delay cannot both be given, and ignition must be an Event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mission.fired_events lists (time, event_name, event) for each split, with the user's own Event, since the user's Event is never modified and its triggered_times stay empty. Mission warns once about each staging Event that has neither an exact_time_function nor the "apogee" trigger, because such an event fires late, at the end of a solver step. Add a Staging Events user guide page and an event-triggered staging section to the multistage notebook. Rewrite the parts of the Mission docstring and the notebook that still described float delays and "apogee" strings, separation always winning, and ignition and simultaneous ejections as missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A deployable riding a stage that had been ignited (e.g. the middle of three) stayed aboard when that stage separated: the split compared Stage objects by identity, and ignition replaces the Stage with a time-shifted copy. It now compares names. add_deployable resolves a stage given by name, and refuses one not in the vehicle, instead of storing the string. - A callback could run twice, once with a context from after the flight had ended. When two staging Events come true in one solver step, the one listed first runs at its own, later, exact time, and is then undone by the earlier one, which ends the flight. Mission now keeps a snapshot of the context and runs each callback once, after the flight, only for the Events it really ended on. - An at_apogee Event of a body handed off already descending was applied without a flight, so its callback never ran. That flight now runs without terminate_on_apogee, and the event fires after its first step. - after_burnout during an unlit coast read the EmptyMotor's placeholder burnout. It now counts from the burnout of the stage that fired last, which also makes ignition=after_burnout(...) work. - A stage separating before burnout split separation_delta_v as if it were dry; it now uses its mass at the separation. - Every ignition time-shift logged "Overwriting previous motor". Also pin, as a strict xfail, an upstream Event bug: an exact-time event due earlier in a solver step that also holds the apogee fires at the end of that step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
state_dot names each value by what it is the derivative of, so state_dot.vz is dz/dt, the velocity. The snapshot test meant to compare an acceleration, which is state_dot.az. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
RocketPy has no first-class representation of multistage rockets or deployable
payloads. A
Rocketis always one rigid body with one motor; anything beyond thatrequires hand-rolling multiple
Flightruns and manually computing state handoff.This branch previously carried a scaffold attempting to solve this (
0caf343d) thatnever actually worked: a misspelled
__init__.pysilently turned the package into anempty namespace, four files were 0 bytes, three others didn't even parse
(
IndentationError), and none of it was imported anywhere. That scaffold is removedin
0099ac29.New behavior
Rebuilds the same goal from a simpler design:
SeparableBody/Stage/Deployable/MultiStageRocket(
rocketpy/rocket/multistage.py) — the vehicle-composition layer.Stagewraps afully built
Rocketas one stage;Deployableis a carried payload (mass/inertiawhile attached, plus either a
free_rocketoradd_surface()-built aerodynamicsafter ejection);
MultiStageRocket.flight_rocket()composes any number of activestages plus carried deployables into one real, working
Rocket(mass/inertia/CoMvia the parallel axis theorem, motor + aerodynamic surfaces attached) — verified
against hand-computed values, not just round-tripped through its own formulas.
Mission(rocketpy/simulation/mission.py) — orchestrates oneFlightpervehicle configuration:
Flight(confirms the design doc'sstated invariant)
Flights (full stack, spent booster falling away,sustainer continuing), with deterministic burnout+delay separation timing and a
physically-derived state handoff (
_handoff_state: rotates the body-frameoffset between parent/child center-of-dry-mass into the inertial frame, splits
separation_delta_vby momentum conservation)Flights, reusingFlight's existingterminate_on_apogeeflag rather than inventing newtrigger machinery
docs/notebooks/multistage_mission.ipynb— runnable, executed end-to-end demoof every feature above, growing alongside the commits. Caught two real bugs before
they shipped: a test rig with thrust below its own weight (crashed
Flight'simpact-detection code), and a
max_timetoo short to reach a genuine impact(mislabeled a mid-flight cutoff as
impact:).**Deliberate simplifications:
Event/trigger solver —Flightonly exposesmax_timeand
terminate_on_apogeetoday, soStage.separationis a plain float (delay inseconds after burnout) and deployable ejection is presently
"apogee"only.interstage_lengths+ physical stage extent;every active stage's
Rocketcoordinate system is assumed to already share oneframe.
free_rocket(not yet buildable from
add_surface()alone).Breaking change
Purely additive: 5 new files, 0 lines changed in any existing file
(
git diff --stat 7f85c072..HEAD→+1998/-0). Nothing is wired intorocketpy/__init__.py,rocketpy/rocket/__init__.py, orrocketpy/simulation/__init__.pyyet — new classes are reachable only via theirsubmodule paths (
from rocketpy.rocket.multistage import Stage), so this can'tcollide with anything existing.
Additional information