-
-
Notifications
You must be signed in to change notification settings - Fork 268
ENH: Events Class and Flight Rework #968
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
Draft
MateusStano
wants to merge
25
commits into
develop
Choose a base branch
from
enh/events
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
080e316
ENH: first structure
MateusStano a927248
ENH: improve structure
MateusStano fae72c1
Merge remote-tracking branch 'origin/develop' into enh/events
MateusStano 31952a1
ENH: Add flight phase management classes for simulation
MateusStano 6e9876a
DOC: add .rst files
MateusStano 2e86a37
ENH: adapt event affect code
MateusStano 2ea45f3
ENH: class Event
MateusStano 4241ff5
ENH: first final flight refactor
MateusStano 2aabe20
DOC: improve docstrings
MateusStano 73a9985
Merge remote-tracking branch 'origin/develop' into enh/events
MateusStano 46b84ad
ENH: Refactor parachute trigger function and improve controller obser…
MateusStano 4786f28
DOC: remove noise usage in docs and tests
MateusStano dfbba5d
ENH: optimize simulation speed
MateusStano 33b98b0
ENH: imrpove plots and prints
MateusStano 968dad4
DOC: improve/fix docs
MateusStano 737bc98
MNT: pylint
MateusStano d954278
DOC: sensor docs
MateusStano 97b5e90
TST: add tests
MateusStano 7cb5b60
ENH: sensor data access via the Flight class, with prints, plots and …
MateusStano 4cdf2b1
DOC: revert forecast.rst changes
MateusStano a1b4be9
MNT: ruff lint
MateusStano 91e2130
TST: fix get_controller_observed_variables test
MateusStano dc12d23
MNT: pylint
MateusStano 8f95df6
MNT: pylint
MateusStano 5fff32c
DOC: add event class to references
MateusStano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Event Class | ||
| ----------- | ||
|
|
||
| .. autoclass:: rocketpy.Event | ||
| :members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| Accelerometer Class | ||
| ------------------- | ||
|
|
||
| .. autoclass:: rocketpy.sensors.Accelerometer | ||
| .. autoclass:: rocketpy.Accelerometer | ||
| :members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| Barometer Class | ||
| --------------- | ||
|
|
||
| .. autoclass:: rocketpy.sensors.Barometer | ||
| .. autoclass:: rocketpy.Barometer | ||
| :members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| GNSS Receiver Class | ||
| ------------------- | ||
|
|
||
| .. autoclass:: rocketpy.sensors.GnssReceiver | ||
| .. autoclass:: rocketpy.GnssReceiver | ||
| :members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| Gyroscope Class | ||
| --------------- | ||
|
|
||
| .. autoclass:: rocketpy.sensors.Gyroscope | ||
| .. autoclass:: rocketpy.Gyroscope | ||
| :members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| Simulation Loop | ||
| =============== | ||
|
|
||
| Overview | ||
| -------- | ||
| This page gives a short overview of how the simulation loop is organized. A | ||
| ``Flight`` is split into phases, each phase is advanced by its own solver, and | ||
| events are evaluated at selected time nodes along the way. The main purpose of | ||
| this structure is to keep the numerical integration, event handling, and phase | ||
| changes coordinated without making the loop hard to extend. | ||
|
|
||
| Key concepts | ||
| ------------ | ||
| - **Flight**: the top-level simulation object. It builds the phases, runs the | ||
| solver loop, and stores the final results. | ||
| - **Phase**: one segment of flight with its own solver and derivative | ||
| function. | ||
| - **Time node**: a scheduled time where the solver state is checked and events | ||
| can be evaluated. | ||
| - **Event**: a trigger/callback pair that can request simulation changes. | ||
| - **Commands**: a small result container used by events to request actions such | ||
| as enabling, disabling, adding, or redirecting simulation behavior. | ||
|
|
||
| Classes | ||
| ------- | ||
|
|
||
| - ``Flight``: orchestrates the whole run. | ||
| - ``_FlightPhase``: stores the solver, derivative, and timing for one phase. | ||
| - ``_FlightPhases``: keeps the ordered list of phases. | ||
| - ``_TimeNode`` and ``_TimeNodes``: store the node schedule for a phase. | ||
| - ``Event``: evaluates trigger logic, runs callbacks, and optionally refines an | ||
| event time. | ||
| - ``Commands``: stores any actions requested by an event callback. | ||
|
|
||
| Simulation structure and loop | ||
| ----------------------------- | ||
| At a high level the loop works like this: | ||
|
|
||
| 1. ``Flight`` builds the phase list and the initial event set. | ||
| 2. Each phase creates its solver and its ordered time nodes. | ||
| 3. The solver advances to each node, then events are checked at that time. | ||
| 4. Event callbacks can request changes through ``Commands``. | ||
| 5. If a callback changes the phase layout, the loop updates the node schedule. | ||
| 6. If an overshootable event forces a rollback, the solver is rebuilt from the | ||
| rolled-back state. | ||
|
|
||
| In practice, ``Flight`` owns the orchestration, ``Event`` owns the trigger and | ||
| callback logic, ``Commands`` stores requested actions, and ``_TimeNodes`` keeps | ||
| the schedule that ties everything together. | ||
|
|
||
| .. _time_overshoot_processing: | ||
|
|
||
| Time-overshoot processing (implementation detail) | ||
| ----------------------------------------------- | ||
| ``time_overshootable`` is only used for sampled events. RocketPy checks those | ||
| events on interpolated states between solver steps, so it can detect a trigger | ||
| without forcing a tiny step size everywhere. If a sampled event triggers in the | ||
| overshoot path, the simulation rolls back to that interpolated point and then | ||
| restarts the solver from there. | ||
|
|
||
| .. important:: | ||
|
|
||
| Events that change dynamics should not rely on overshoot handling. In | ||
| those cases, the callback should request an explicit phase or solver change | ||
| instead of trying to move the trigger later. | ||
|
|
||
|
|
||
| Post-processing and derivative updates | ||
| -------------------------------------- | ||
| Some callbacks mutate simulation state, such as enabling a controller or | ||
| changing a parachute condition. ``Flight`` applies those requests after the | ||
| event fires, then refreshes the derivative or phase schedule if needed so the | ||
| next solver step uses the updated setup. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A diagram like below would probably help this page a lot.
flowchart TD A["Initialize Flight"] --> B["Build event set<br/>and flight phases"] B --> C["Start phase<br/>create solver and time-node schedule"] C --> D["Advance solver<br/>and store state"] D --> E["Evaluate events<br/>scheduled, continuous, or interpolated"] E --> F["Run triggered callbacks"] F --> G["Apply Commands<br/>update events, dynamics, phases, or termination"] G --> H{"Next action"} H -- Continue phase --> D H -- Roll back --> I["Restore event state<br/>and restart solver"] I --> D H -- Start new phase --> C H -- Flight complete --> J["Finalize and cache results"] classDef main fill:#17324d,color:#fff,stroke:#17324d; classDef process fill:#e8f1f8,color:#17324d,stroke:#5b84a6; classDef event fill:#fff3d6,color:#5b4100,stroke:#d39b24; classDef decision fill:#fff,color:#333,stroke:#666; class A,B,J main; class C,D,I process; class E,F,G event; class H decision;Or a more complex/comprehensive:
flowchart TD A["Flight.__init__"] --> B["Initialize events, equations of motion,<br/>solution history, and solver settings"] B --> C["Classify events by priority"] C --> C1["Non-overshootable<br/>scheduled nodes or continuous checks"] C --> C2["Sampled + overshootable<br/>checked through interpolation"] C1 --> D["Flight.__simulate"] C2 --> D D --> E["_FlightPhases<br/>initial phase + max-time sentinel"] E --> F{"Next flight phase?"} F -- Yes --> G["Create phase solver<br/>derivative, initial state, time bound"] G --> H["_TimeNodes builds phase schedule<br/>phase bounds + sampled events"] H --> I{"Next time node?"} I -- Yes --> J["Set solver bound to next node"] J --> K["Evaluate events scheduled<br/>at current node"] K --> L["Event pipeline<br/>trigger → optional exact-time refinement<br/>→ callback → Commands"] L --> M["Apply commands"] M --> M1["Enable, disable, or add events<br/>update _TimeNodes"] M --> M2["Set derivative or start phase<br/>insert _FlightPhase and finish current solver"] M --> M3["Terminate flight<br/>truncate phases and finish solver"] M1 --> N["Re-sync solver bound if<br/>node schedule changed"] N --> O M2 --> O M3 --> O O{"Solver still running?"} O -- Yes --> P["solver.step"] P --> Q["Store time, state, and<br/>function-evaluation count"] Q --> R["Build sampled event nodes between<br/>previous and current solver times"] R --> S["Use dense output to evaluate<br/>interpolated states"] S --> T{"Overshoot event<br/>requires rollback?"} T -- Yes --> U["Restore interpolated<br/>time and state"] T -- No --> V U --> V["Combine triggered overshoot events<br/>with continuous events"] V --> W["Evaluate by priority through<br/>the Event pipeline"] W --> X{"Rolled back, but phase<br/>and derivative unchanged?"} X -- Yes --> Y["Rebuild solver from<br/>rolled-back state"] X -- No --> Z["Continue with current solver state"] Y --> AA Z --> AA AA["Derivative post-processing<br/>when dynamics-changing events exist"] AA --> O O -- No --> I I -- No --> F F -- No --> AB["Finalize simulation<br/>cache outputs and sensor data"] classDef flight fill:#17324d,color:#fff,stroke:#17324d; classDef structure fill:#e8f1f8,color:#17324d,stroke:#5b84a6; classDef event fill:#fff3d6,color:#5b4100,stroke:#d39b24; classDef command fill:#f5e8f7,color:#53245c,stroke:#9b59a5; classDef decision fill:#fff,color:#333,stroke:#666; class A,B,D,AB flight; class E,G,H,J,P,Q,R,S,Y,AA structure; class C,C1,C2,K,L,V,W event; class M,M1,M2,M3,N,U command; class F,I,O,T,X decision;