-
-
Notifications
You must be signed in to change notification settings - Fork 205
ENH: Refactor Flight class to improve time node handling and sensor/controllers #843
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
base: develop
Are you sure you want to change the base?
Conversation
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.
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=True
option, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
self.solution, | ||
self.sensors, | ||
) | ||
self.__process_sensors_and_controllers_at_current_node(node, phase) |
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.
I don't mind much, since this is a private method naming. However, do you think there might be a more scalable / descriptive name here, so as to avoid adding words to it in the future: e.g. __process_sensors_and_controllers_and...
? Having trouble naming a method may indicate it may do too much.
Actually, my suggestion would be going for a more standardized approach. I have never seen a fixed convention for this, but it is nice to have some internal consistency when naming checkers/process/handlers, my two cents would be:
handler
: returns a boolean and operate on solution variables;process
: can operate on solution variables, but does not return;checker
: returns a boolean, but only reads solution variables (e.g. does not setup phases/nodes, I did not see any pure checkers on this PR).
self.__process_sensors(...)
self.__process_controllers(...)
if self.__handle_parachute_triggers(...):
break
while running:
if self.__handle_simulation_events(...):
break
if self.time_overshoot:
# I nested the if clauses for readability
# Both ways are equivalent and should perform the same
if self.__handle_overshoot(...):
break
self.y_sol, | ||
self.sensors, | ||
): | ||
return False # Early exit: parachute not deployed |
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.
Really not sure, since the code is complex, but shouldn't this be a continue
(i.e. even if one trigger does not go off, there are other parachutes to check)?
|
||
return False | ||
|
||
def __check_simulation_events(self, phase, phase_index, node_index): |
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.
Since the three methods inside it are handlers, I would also call this one a handler.
Pull request type
Checklist
black rocketpy/ tests/
) has passed locallypytest tests -m slow --runslow
) have passed locallyCHANGELOG.md
has 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