Skip to content

Conversation

Gui-FernandesBR
Copy link
Member

Pull request type

  • 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 vs New behavior

  1. The Flight.__simulate() method is more readable
  2. Controllers can now be used with time overshoot option = True (solves ENH: Allow overshooting controllers #663)
  3. the same is valid for sensors

Controllers and Sensors Simulations should run faster!!

Breaking change

  • No

Additional information

  • I need help to review this PR carefully, although tests are passing locally.

@Gui-FernandesBR Gui-FernandesBR requested a review from a team as a code owner August 15, 2025 02:44
@Gui-FernandesBR Gui-FernandesBR self-assigned this Aug 15, 2025
@Gui-FernandesBR Gui-FernandesBR added Refactor Flight Flight Class related features labels Aug 15, 2025
@Gui-FernandesBR Gui-FernandesBR added this to the Release v1.X.0 milestone Aug 15, 2025
@Gui-FernandesBR Gui-FernandesBR linked an issue Aug 15, 2025 that may be closed by this pull request
Copy link

@Copilot Copilot AI left a 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.

+ (self.y_sol[2] - self.env.elevation) ** 2
>= self.effective_1rl**2
if self.__check_simulation_events(phase, phase_index, node_index):
break # Stop if
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 707 'Stop if' is incomplete and unclear. It should explain what condition causes the simulation to stop.

Suggested change
break # Stop if
break # Stop simulation if a termination event (e.g., end of flight, crash, or other defined event) is detected

Copilot uses AI. Check for mistakes.

# Add last time node (always skipped)
overshootable_nodes.add_node(self.t, [], [], [])

if len(overshootable_nodes) < 1:
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The condition len(overshootable_nodes) < 1 should be simplified to not overshootable_nodes for better readability and consistency with Python idioms.

Suggested change
if len(overshootable_nodes) < 1:
if not overshootable_nodes:

Copilot uses AI. Check for mistakes.

overshootable_node.y_sol,
self.sensors,
):
return False # Early exit, parachute not triggred
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelling in comment: 'triggred' should be 'triggered'.

Suggested change
return False # Early exit, parachute not triggred
return False # Early exit, parachute not triggered

Copilot uses AI. Check for mistakes.

# reset controllable object to initial state (only airbrakes for now)
for air_brakes in self.rocket.air_brakes:
air_brakes._reset()
# Note: time_overshoot now supports both controllers and sensors
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This comment doesn't provide sufficient context about the change. It should explain what the previous limitation was and why this change is significant.

Suggested change
# Note: time_overshoot now supports both controllers and sensors
# Previously, time_overshoot only supported controllers.
# Now, it supports both controllers and sensors, allowing for more flexible
# simulation and monitoring of sensor-triggered events. This change enables
# users to track overshoot conditions based on sensor data as well as controller actions.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Flight Flight Class related features Refactor
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

ENH: Allow overshooting controllers
1 participant