ENH: Refactor Flight class to improve time node handling and sensor/controllers#843
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Flight class's __simulate() method to improve readability and enable time overshoot functionality for controllers and sensors. The main changes include:
- Breaking down the monolithic
__simulate()method into smaller, focused methods for better maintainability - Enabling controllers and sensors to work with
time_overshoot=Trueoption, which was previously disabled - Optimizing simulation performance by allowing overshootable time nodes for sensors and controllers
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
rocketpy/simulation/flight.py |
Major refactoring of Flight simulation methods, breaking __simulate() into smaller helper methods and adding support for time overshoot with controllers/sensors |
tests/integration/test_plots.py |
Reduced number of test flight configurations from 16 to 4 for faster test execution |
tests/integration/test_flight.py |
Added new test for air brakes with time overshoot and renamed existing test for clarity |
tests/integration/test_environment.py |
Minor cleanup removing unused today variable |
tests/fixtures/flight/flight_fixtures.py |
Added new fixture for air brakes flight with time overshoot enabled |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Good work! I hope this is the beginning of having a much more readable and developer friendly Flight class.
My only concern is making sure the behavior is exactly the same as before, therefore I made a single important comment on the early return of parachute triggers just to make sure we are on the same page. Of course, all the tests being green is already a big step.
Aside from that, my other suggestions are more style/naming choices. I prefer having some more standardized names for some methods, but I would approve the PR in the current state even if these suggestions are not taken, since it already does loads for readability.
b9660cf to
dd80852
Compare
|
Remaining tasks:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #843 +/- ##
===========================================
+ Coverage 80.27% 81.08% +0.80%
===========================================
Files 104 107 +3
Lines 12769 13812 +1043
===========================================
+ Hits 10250 11199 +949
- Misses 2519 2613 +94 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d6a67bb to
c84e58f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (2)
rocketpy/simulation/flight.py:697
- Duplicate controller processing. Controllers are already processed inside
__process_sensors_and_controllers_at_current_node()at line 848-854. This loop at lines 691-697 should be removed to avoid executing controllers twice at each node.
self.__process_sensors_and_controllers_at_current_node(node, phase)
for controller in node._controllers:
controller(
self.t,
self.y_sol,
self.solution,
self.sensors,
)
rocketpy/simulation/flight.py:714
- Duplicate parachute handling logic. The parachute trigger check and deployment logic at lines 699-759 duplicates the functionality in
__check_and_handle_parachute_triggers()called at line 760. This entire block should be removed since the extracted method already handles this logic.
for parachute in node.parachutes:
# Calculate and save pressure signal
(
noisy_pressure,
height_above_ground_level,
) = self.__calculate_and_save_pressure_signals(
parachute, node.t, self.y_sol[2]
)
if parachute.triggerfunc(
noisy_pressure,
height_above_ground_level,
self.y_sol,
self.sensors,
):
# Remove parachute from flight parachutes
self.parachutes.remove(parachute)
5a9c9c6 to
69da915
Compare
…ontroller processing TST: add tests for overshootable controllers TST: fix slow tests fix merge conflicts
69da915 to
7358e68
Compare
|
I'm merging with this since no further comments were made since last copilot's review. I'm confident the test coverage will handle any problems. |
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior vs New behavior
Flight.__simulate()method is more readableControllers and Sensors Simulations should run faster!!
Breaking change
Additional information