Skip to content

ENH: Refactor Aero Surface, Make GenericSurface the Mother Class - #1064

Open
MateusStano wants to merge 45 commits into
enh/eventsfrom
enh/aero-refactor
Open

MateusStano wants to merge 45 commits into
enh/eventsfrom
enh/aero-refactor

Conversation

@MateusStano

@MateusStano MateusStano commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

Summary

All aerodynamic surfaces now come from one mother class, GenericSurface. Before, the nose cone, fins and tail each had their own way of computing forces. Now they all describe themselves with the same set of coefficients, and the flight treats every surface the same way.

I took the opportunity to rework how coefficients are stored, to add full-vehicle aerodynamics, and to redo the stability analysis on top of it.

Here is a summary of all the changes:

Aerodynamic surfaces (rocketpy/rocket/aero_surface/)

  • GenericSurface is now the mother class of every surface: NoseCone, all fins, Tail, RailButtons and AirBrakes.
  • _BarrowmanSurface: new private base for the surfaces that use Barrowman equations (nose, fins, tail).
  • AeroCoefficient: new class that holds one coefficient. It accepts a number, a function, a Function, a list of points or a CSV file, and only keeps the variables the coefficient really depends on.
  • ControllableGenericSurface: new surface whose coefficients also depend on control variables, such as a canard deflection. AirBrakes is now one of these.
  • AeroSurface is deprecated. It still works and isinstance(surface, AeroSurface) is still true.

New options on GenericSurface and LinearGenericSurface:

  • Coefficients in the body frame (cN, cY, cA) or the wind frame (cL, cQ, cD), chosen with force_convention.
  • Coefficients from a CSV file, including several coefficients from one file (from_csv).
  • Coefficients given against the total angle of attack (alpha_total).
  • Rate derivatives such as cm_q next to a tabulated coefficient, to add damping.
  • interpolation and extrapolation options for tabulated coefficients.
  • reynolds_length, to use a different length for the Reynolds number.
  • axisymmetric=True on LinearGenericSurface, to give only the pitch-plane derivatives.
  • active_during ("always", "power_on", "power_off") and active, to make a surface work only in part of the flight.
  • Every argument after name is keyword-only.

Rocket

  • add_full_body_aerodynamics: describe the whole rocket with one surface (from CFD, wind tunnel, OpenRocket...). overwrite=True removes the other surfaces and clears the drag curves.
  • to_coefficients and to_surface: turn an assembled rocket into one set of coefficients, or one surface.
  • power_on_drag and power_off_drag can now depend on more than Mach (angle of attack, Reynolds, rotation rates).
  • Stability now has pitch and yaw versions: aerodynamic_center, center_of_pressure, neutral_point, static_margin, stability_margin and their _yaw twins.
  • stability_phase: choose if the stability numbers describe the powered or the coasting rocket.
  • disturbance_response: how the rocket oscillates after a disturbance.
  • is_axisymmetric, is_incidence_linear and length.

Flight

  • Yaw-plane stability margins (stability_margin_yaw, static_margin_yaw, min, max, out of rail).
  • Dynamic stability: pitch_natural_frequency, pitch_damping_ratio, their yaw versions, corrective_moment_coefficient, damping_moment_coefficient and disturbance_response.
  • New event commands activate_surface and deactivate_surface, to switch a surface on or off at any moment of the flight.

Function

  • Data on a regular grid is now found automatically and looked up much faster. Function.from_regular_grid_csv and interpolation="regular_grid" are deprecated.

Fixes

  • The equations of motion now take the moments about the rocket's center of mass. This was wrong in master for a rocket with propellant.
  • Drag now always acts against the air velocity, also when the rocket falls tail first.
  • Saving and loading a flight with air brakes or sensors works again: the controller is reconnected to the rocket's own objects.

Changes after the review (November 2026):

  • The flight's stability (stability_margin, stability_margin_yaw, natural frequencies, damping ratios, disturbance_response) follows the surfaces an event switches on or off and active_during across burnout.
  • A LinearGenericSurface given in the wind frame is linear in that frame again, and keeps cL_alpha, cLf, cLd and the rest.
  • rocket.power_off_drag = rocket.power_off_drag * 1.1 works (it raised a RecursionError).
  • A drag CSV with a header such as Mach Number,Cd loads again (it raised since v1.12.0).
  • A grid lookup given sequences of one value returns an array.
  • disturbance_response refuses an unknown plane and a time after the flight.
  • stability_and_control_data(filename=...) saves its three plots to three files; Rocket.draw draws the plane asked for, and accepts "pitch" and "yaw".
  • The dynamic stability printout shows N/A where the rocket does not oscillate.
  • The surface switches made by events are saved with the flight and come back when it is loaded.
  • Docstrings: the sign of com_to_cdm_function, and the cant angle defined as a right-hand rotation about the fin's outward span axis (a positive cant gives a negative roll moment).

Plots and prints

  • Aero surface, rocket and flight plots and prints updated for the new coefficients.
  • New stability plots in Flight.plots (stability_margin_data, stability_and_control_data, stability_summary) and Rocket.plots.stability_margin_yaw.

Docs

  • docs/user/rocket/generic_surface.rst rewritten: frames, coefficients, CSV files, damping, interpolation, activation, whole-vehicle aerodynamics.
  • New guide: docs/user/center_of_pressure_and_stability.rst.
  • New reference pages: ControllableGenericSurface, PointMassRocket, PointMassMotor, EmptyMotor, StochasticAirBrakes.

Notes for reviewers

The diff is large. The best way in is to read the two guides above, then aero_coefficient.py and generic_surface.py. The other surfaces are small once those two are clear.

Breaking change

  • No, but:
    • AeroSurface is deprecated in favor of GenericSurface.
    • Function.from_regular_grid_csv and interpolation="regular_grid" are deprecated.
    • Flight results change slightly because of the fixes above.
    • A table of two or more inputs whose points form a complete grid is now interpolated linearly on the grid instead of with shepard (for example 1.344 becomes 1.0 between the points of a 3x3 grid of x**2 + y**2). Pass interpolation="shepard" for the old values.
    • .cl of a surface is now the roll moment coefficient. The old cl(alpha, mach) was the normal force coefficient: use cN(alpha, 0, mach, 0, 0, 0, 0), or cL for the wind-frame lift.
    • Fin sets now roll the rocket in the direction individual fins already did in v1.13 for the same cant_angle.

Both of the first two are in CHANGELOG.md.

MateusStano and others added 8 commits June 22, 2026 21:55
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Every aerodynamic surface is now rooted in GenericSurface and stores its
force coefficients in the body frame (cN/cY/cA) plus the cm/cn/cl moments,
exposing all nine coefficients (cL/cD/cQ/cN/cY/cA/cm/cn/cl) with the wind
trio lazily derived. A force_convention argument lets users supply wind- or
body-frame coefficients. Barrowman surfaces (nose, tail, fin sets) keep the
classic geometric normal-force/moment method, report the force at the
geometric center of pressure via the classic 180-degree surface rotation,
and expose cN_alpha/cY_beta stability slopes (the old clalpha relabelled).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the poorly defined calisto_linear_generic fixture, which kept the
Barrowman nose cone and tail and swapped only the fins for a
LinearGenericSurface with arbitrary made-up coefficients. The new fixture is a
standalone Calisto whose nose cone, tail and fins are all LinearGenericSurfaces
built from coefficient curves extracted off the standard Barrowman surfaces
(normal-force-curve slope, center of pressure, fin roll damping).

Each linear surface applies its force at its own origin and is placed at the
source surface's center-of-pressure station, so both the static-margin path and
the flight-moment path land at the same point as calisto_robust. The resulting
flight matches the standard Calisto (identical apogee, out-of-rail time and
ascent angle of attack), so the fixture now exercises the linear
generic-surface path against a known-good reference.

Also fix test_linear_generic_surface_flight_is_stable to check the angle of
attack only during the ascent off the rail: on the rail the freestream speed is
~0 and the angle of attack is reported as a degenerate 90 degrees for any
launcher, which previously failed the < 45 assertion.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MateusStano
MateusStano changed the base branch from master to enh/events July 11, 2026 13:12
@MateusStano MateusStano self-assigned this Jul 11, 2026
@codecov

codecov Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23634% with 129 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (enh/events@f66cf90). Learn more about missing BASE report.

Files with missing lines Patch % Lines
rocketpy/plots/aero_surface_plots.py 83.61% 29 Missing ⚠️
rocketpy/rocket/aero_surface/_helpers.py 82.66% 13 Missing ⚠️
rocketpy/rocket/aero_surface/aero_coefficient.py 96.02% 13 Missing ⚠️
rocketpy/plots/flight_plots.py 95.00% 11 Missing ⚠️
rocketpy/prints/aero_surface_prints.py 92.07% 8 Missing ⚠️
rocketpy/rocket/_helpers.py 98.52% 8 Missing ⚠️
rocketpy/prints/flight_prints.py 92.22% 7 Missing ⚠️
rocketpy/mathutils/_calc/polation_1d.py 68.42% 6 Missing ⚠️
rocketpy/plots/rocket_plots.py 91.04% 6 Missing ⚠️
rocketpy/plots/sensors_plots.py 42.85% 4 Missing ⚠️
... and 13 more
Additional details and impacted files
@@              Coverage Diff              @@
##             enh/events    #1064   +/-   ##
=============================================
  Coverage              ?   88.94%           
=============================================
  Files                 ?      156           
  Lines                 ?    23439           
  Branches              ?        0           
=============================================
  Hits                  ?    20848           
  Misses                ?     2591           
  Partials              ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread docs/user/rocket/generic_surface.rst Resolved
Comment thread docs/user/rocket/generic_surface.rst Resolved
Comment thread docs/user/rocket/generic_surface.rst Resolved
Comment thread docs/user/rocket/generic_surface.rst Resolved
Comment thread docs/user/rocket/generic_surface.rst Resolved
Comment thread docs/user/rocket/generic_surface.rst Resolved
@ting-hong-shieh

Copy link
Copy Markdown
Contributor

I checked two behaviors from the upstream worklist on head 84d3b6a9f0b4a8074d764130dc3d189bdc402036.

Scalar coefficients

GenericSurface(1, 1, {"cN": 0.75, "cA": 0.2, "cm": -0.1}) constructs successfully. The three values evaluate unchanged and cN.depends_on == (). The focused initialization/constant selection reports 13 passed, 23 deselected.

Wind-to-body force mapping (#932)

At alpha = 0.2 rad, beta = 0.1 rad, the head produces these body vectors for unit wind-frame coefficients:

side: [ 0.995004165, -0.019833838, -0.097843395]
lift: [ 0.000000000, -0.980066578,  0.198669331]
drag: [-0.099833417, -0.197676812, -0.975170327]

Those match Rx(-alpha) @ Ry(+beta) applied to [Q, -L, -D]; current develop has the opposite signs in the affected components. I posted the complete before/after table on #932.

Both pieces appear covered by this draft, but the branch also includes a substantially larger aerodynamic redesign. If a smaller review unit would help, the scalar AeroCoefficient support and the #932 force-frame correction are independently testable candidates for extraction. I have not opened overlapping pull requests.

Environment: Python 3.12.6; NumPy 2.5.2; pytest 9.1.1; macOS 26.5.2 arm64. Current develop: cb6106a717207dd8fc2dfe1446d80ff75022f21b.

@Gui-FernandesBR

Copy link
Copy Markdown
Member

This is a huge PR, yet not finished tho

MateusStano and others added 11 commits September 19, 2026 12:19
Conflicts were resolved toward the event context design of enh/events:

- controller.py, rocket.py: the controller save/load fix from 3260573 is
  ported to the context convention. The controlled-object hashes are still
  saved so a loaded rocket reconnects its controllers, controller_needs is
  dropped since the context works values out when first read, and the
  legacy air brakes wrapper keeps the 7-argument form but passes the live
  context["controlled_objects"] instead of the captured air brakes.
- event.py, event_builders.py, event_calling.py, event_commands.py,
  flight_phase.py: docstrings follow the new signatures (no needs or
  kwargs), keeping the reworded text where the parameter still exists.
- tests/unit/simulation/test_flight.py: both import additions kept.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Rocket.stability_margin takes (mach, time) again, at zero angle of attack
- aerodynamic center counts each surface's whole moment (pure couples, axial
  force at a sideways offset, canted individual fins)
- Rocket.disturbance_response and Flight.disturbance_response, built on
  attitude oscillator helpers shared with the flight's dynamic stability
- GenericSurface: data against alpha_total is split between the pitch and yaw
  planes from the variable name alone, also for lift and drag; force_convention
  is only "body" or "wind"
- LinearGenericSurface(axisymmetric=True) fills in the yaw-plane derivatives;
  add_full_body_aerodynamics no longer takes symmetric
- remove angular_position from GenericSurface
- stability guide: simpler center of pressure section, displayed C1 and C2
  equations, disturbance response section, parts 6 and 7 removed
- generic surface guide: full list of variable names, total angle of attack
  by variable name, axisymmetric linear surfaces
- rocket usage: drag curve at an angle of attack, stability_margin(mach, time)
A GenericSurface takes a rate derivative such as cm_q next to a coefficient,
to add damping to tabulated data: it is multiplied by its reduced rate and
added to the coefficient. Documented in the generic surface guide.
Brings in the attribute-style event context (`context.state.vz`,
`context.state_dot.az`, `context.controlled`) and the move of the event
code from `simulation/helpers` to `simulation/events`.

Conflict in `rocketpy/control/controller.py`: kept the `enh/events`
side, where `__build_controlled` replaces
`__verify_controlled_objects_name`.

Ported two places that merged cleanly but still used what that commit
removed:

- `_Controller.rebind_controlled_objects` now rebuilds
  `context.controlled` from the reconnected objects.
- The wrapper for legacy positional air brake controllers reads the
  air brakes from `context["controlled"][0]` instead of
  `context["controlled_objects"]`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A surface's `active_during` now accepts only "always", "power_on" and
"power_off". The function form `active_during(t, flight)` is removed:
to switch a surface at any other moment, an event calls one of two new
commands from its callback,

    context.event.commands.activate_surface(surface)
    context.event.commands.deactivate_surface(surface)

and the solver restarts at the switch. A surface that only appears
later in the flight is built with the new `active=False` argument, so
that it starts each flight switched off.

The flight stores each switch with its time, so `surface.is_active(t,
flight)` is still a plain question about time and the outputs computed
after the flight see the surfaces that were on at each moment. The
surfaces themselves are not modified, so another flight of the same
rocket starts from their own `active` setting.

The stability analysis leaves out a surface built with `active=False`.
… name

GenericSurface, LinearGenericSurface and ControllableGenericSurface now
take their shared arguments in the same order, with each class's own
argument last (`axisymmetric`, `controls`). ControllableGenericSurface
had `interpolation`/`extrapolation` and `force_convention`/
`active_during` swapped relative to the other two.

Every argument after `name` is keyword-only. The first five arguments
are the ones released on master and can still be passed by position.
Add a "Which drag is used" section to the generic surfaces guide: the
rocket's own drag curves always apply, every surface's axial force is
added on top, and `overwrite=True` in `add_full_body_aerodynamics`
removes the existing surfaces and zeroes both drag curves. Warn that
full-vehicle data that already includes drag is counted twice otherwise.

Also fix a typo ("collapses" to "collapse").
- Remove unused imports and the unused `plane` argument of
  `_draw_center_of_mass_and_pressure`.
- Give every `to_dict` override the `include_outputs` argument of its
  base class.
- Explain and disable the warnings that misread a deliberate pattern:
  `_BaseFin` initializes `GenericSurface` later, `Fin` and `Fins` are
  still abstract, and `u_dot_parachute` keeps the shared `t` argument.
- Disable too-many-lines in `rocket.py` and `flight.py`, too-many-locals
  in `full_body_coefficients` and too-many-statements in
  `AeroCoefficient.__init__`.
- Allow names like `M1_cm` in `.pylintrc`.
- Tests: move imports to the top, use dict literals, drop unused
  variables and arguments.
052babd, a commit about the stability and generic surface guides, also
cut soundings.rst down to its introduction. The Wyoming and NOAA RUC
sections are back as they were before it.

@Gui-FernandesBR Gui-FernandesBR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review compared against enh/events at 17d32fe. gh pr diff can't load this PR because the diff is too large, so I diffed locally. The four items that change results for existing users are the drag recursion (rocket.py:511), drag CSVs with a text header, the controllable surface that isn't reset or driven in Monte Carlo, and the stability outputs ignoring event switches. The rest are smaller fixes or CHANGELOG items. Each claim with numbers was reproduced on this branch.

Comment thread rocketpy/rocket/_helpers.py Resolved
Comment thread rocketpy/plots/flight_plots.py Resolved
Comment thread rocketpy/plots/rocket_plots.py Resolved
Comment thread rocketpy/prints/flight_prints.py Resolved
Brings the review fixes of #968. One conflict, in
tests/integration/simulation/test_event.py, where both branches added
tests at the end of the file: both are kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MateusStano and others added 13 commits November 21, 2026 14:08
rocket.power_off_drag = rocket.power_off_drag * 1.1 gave a curve that read
itself. The curve against Mach number now keeps the coefficient it was
built from, and is built again whenever the coefficient is replaced.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A CSV file with the header "Mach Number,Cd" was refused. The header of
a file with one variable column is now matched as the input label of a
Function is. Two columns the wrong way round are refused.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A number is returned only when the variables are given as numbers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ce_response

A plane that was neither "pitch" nor "yaw" was read as pitch, and a time
after the end of the flight gave the response at the last instant.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The three plots of the deprecated method were saved to the same file,
each over the one before. They are saved with _margin, _dynamics and
_frequency added to the file name.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Rocket.draw kept drawing both planes of a rocket that is not
axisymmetric, whatever plane was given. A plane that is given is now
the one drawn; both are drawn only by default. "pitch" and "yaw" are
accepted for "yz" and "xz".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The dynamic stability printout showed 0 for a natural frequency or a
damping ratio that does not exist at that instant.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
It is the position of the center of dry mass relative to the center of
mass, positive towards the nose. The docstrings said the opposite.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The switches are saved with the flight, each surface by its place in
the rocket's list, and rebuilt for the loaded rocket. A file saved
before this loads with none.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The stability margin, the natural frequencies, the damping ratios and
disturbance_response of a flight described the rocket with the surfaces
it starts with, in one motor phase. They now follow the surfaces an
event switches on or off, and active_during across burnout. A flight
whose surfaces never change is computed as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Wind-frame derivatives were converted once to body-frame ones about zero
angle, so the lift and drag moved away from what was given as the angle
grew. The lift, side force and drag are linear again and are turned into
the body frame at the angles of each instant. The derivatives as given
(cL_alpha, ...) and the parts cLf, cLd, cDf, cDd, cQf and cQd can be
read. The body-frame slopes at zero angle are kept for the stability
analysis.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MateusStano added a commit that referenced this pull request Nov 21, 2026
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>
# Call it once, so a function that cannot be called or does not
# return a number fails here rather than during the flight
try:
float(self._evaluate(*[0.0] * len(self.depends_on)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Important: a callable coefficient that is undefined when every variable is 0 now fails at construction, where it worked before.

The probe calls the function at alpha=beta=mach=reynolds=...=0, but mach=0 and reynolds=0 are not points a user function has to handle. GenericSurface(..., coefficients={"cD": lambda alpha, beta, mach, reynolds, pitch_rate, yaw_rate, roll_rate: 0.3 / mach}) and the same with 0.074 * reynolds ** -0.2 both raise ValueError: ... could not be evaluated with every variable at zero: ZeroDivisionError on this head. Both construct on enh/events and evaluate fine at mach 0.5 (0.6) and Reynolds 1e6 (0.0047).

Fix: drop the probe, or turn the failure into a warning, or probe at a representative non-zero point (for example mach 0.5, Reynolds 1e6).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are right, this was a regression. Fixed in e632e40.

A function that fails at zero, such as 0.3 / mach, is now evaluated at Mach 0.001 and Reynolds 1000 instead of zero. The check at construction stays, since the flight and the margins also call every coefficient at zero.

## the position itself.
r_CM_z = flight.rocket.com_to_cdm_function
r_CM_t = r_CM_z.get_value_opt(t)
r_CM_t = -r_CM_z.get_value_opt(t)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Important: this change moves the results of the default standard equations by about 3x in a crosswind flight, and the CHANGELOG has no entry for it.

Calisto-like rocket, M1670 motor, crosswind 4 to 12 m/s, inclination 85, terminate_on_apogee. Downrange at apogee: standard 65.7 m on v1.13.0 (and on enh/events) vs 206.6 m here; solid_propulsion 653.6 m on v1.13.0 vs 208.6 m here. Reverting only this r_CM_t sign takes standard back to 76.5 m, so it is most of the move.

The change looks right: the two formulations disagreed by 10x on v1.13.0 and now agree within 1%. But every flight with propellant and lateral loads changes, so users upgrading from v1.13.0 need to see it, together with the drag now carrying the cosine of the total angle (R3 in _compute_drag_area).

Fix: add a ### Fixed entry for the moments about the center of mass and the drag direction, saying that v1.13.0 results change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a ### Fixed entry in 91810e2 for the moments about the center of mass and the drag direction.

It does not name v1.13.0: v1.14.0 already fixed the sign in solid_propulsion (#1217), so what this PR changes now is the moment transfer in standard and the drag cosine.

Comment thread CHANGELOG.md Outdated
### Changed

- ENH: `cl` of an aerodynamic surface (nose cones, fins, tails and generic surfaces) is now its roll moment coefficient. What `surface.cl(alpha, mach)` used to return is the normal force coefficient, now `surface.cN(alpha, 0, mach, 0, 0, 0, 0)`; `surface.cL` is the lift coefficient in the wind frame. The name was reused, so no warning can be given: update code that calls `cl` for the lift. [#1064](https://github.com/RocketPy-Team/RocketPy/pull/1064)
- ENH: a table of two or more inputs whose points form a complete grid is now interpolated linearly on that grid by default, where it used `shepard`. This holds for `Function` and for every coefficient given as such a table, and changes the values between the points. Pass `interpolation="shepard"` to get the previous values. [#1064](https://github.com/RocketPy-Team/RocketPy/pull/1064)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): the new default also changes what a Function table returns outside its grid, which this entry does not say.

With the default extrapolation="natural", shepard stayed near the data, and the linear grid now extends the edge cells without bound. On a 3x3 grid of x**2 + y (values 0 to 6): f(10, 3) is 3.15 on enh/events and 31.0 here, and f(-2, 0.5) is 1.48 vs -1.5, below the smallest data value. Coefficients given to a GenericSurface are not affected, since they default to constant extrapolation.

Fix: say "and outside the grid" in the entry, and name extrapolation="constant" as the way to keep results bounded.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 91810e2. The entry now says the values also change outside the grid, and names extrapolation="constant" to keep them within the data.

Brings develop (v1.14) and the events stack into the aero refactor.

- Function: grid detection kept, grid evaluation moved into develop's _calc
  registry (RegularGridInterpolation/Evaluator with the fast single-point
  linear path); from_grid kept, from_regular_grid_csv deprecated.
- Fin: develop's roll damping fix (no explicit term on a single fin).
- TubeFins ported onto _BarrowmanSurface.
- Rocket: deprecated static_margin setter, warn_if_unstable checks pitch and
  yaw just before a Flight simulates, fin-count check warns.
- Non-grid coefficient CSV warning moved into AeroCoefficient._load_csv.
- Pinned apogee values re-measured; they now match develop except the axial
  force, which follows aero's drag along the rocket axis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aZira371 added a commit that referenced this pull request Dec 3, 2026
…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.
MateusStano and others added 2 commits December 6, 2026 08:55
A function such as 0.3 / mach or 0.074 * reynolds ** -0.2 was rejected
when the surface was built, and would fail in the flight and in the
margins, which evaluate coefficients at a Mach and Reynolds number of
zero. Such a function now reads a Mach number of 0.001 and a Reynolds
number of 1000 in place of any lower value.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ngelog

Restores the two entries the last merge of enh/events dropped, says that
a grid table also changes outside its grid, and adds an entry for the
moments about the center of mass and the drag direction.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@MateusStano
MateusStano added this pull request to stack #1257 December 6, 2026 12:35
@MateusStano
MateusStano removed this pull request from stack #1257 December 6, 2026 12:59
* ENH: Add actuator class for roll, throttle, thrust vector control (squash 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>

* Fix actuator unit tests

* Enhance ThrustVectorActuator2D with serialization methods and improve documentation

* Fix comment msg

* Fix pylint unused parameters

* Fix: use warning instead of printf

* Fix comment

* Fix: use warning instead of printf

* Run ruff format

* Revert changes on weight_in_body_frame

* Fix thrust3 and effective_thrust name

* ENH: pass the control inputs to the equations of motion

Controller rework, step 1 (docs/development/controller_rework/design.md).

- The flight's control inputs are a plain dict, channel name to value,
  built from rocket.actuators at the start of every flight
  (flight.control_signal, context.controls in every event). The rocket is
  never changed by flying, so Flight no longer resets the air brakes.
- Derivatives take (flight, t, x, u) and read surface and air-brakes
  controls from u by channel name.
- Writes from an event callback are checked against the limits once the
  callback returns; a change marks the event's commands as changing the
  trajectory.
- A copy of u is stored with every solution row and given to a row worked
  out again after the flight. Post-processing and surface switching are
  unchanged.
- Controls move into GenericSurface (controls, control_defaults,
  control_limits, clamp); ControllableGenericSurface is removed, and saved
  files load as a GenericSurface. AirBrakes subclasses GenericSurface.
- New Actuator protocol and Rocket.actuators / Rocket.control_channels;
  actuators are checked when added.

Flights are bit-identical to before on the comparison flights (plain,
solid propulsion, 3-DOF, air brakes with and without time overshoot,
legacy controller, surface switch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: store, restore and read back the control inputs

Each solution row keeps the control inputs it was flown with, so the
flight can be replayed and read after it ends:

- Function gets a "previous" interpolation that holds each value.
- flight.control_history and solution["<channel>"] give the inputs over
  time; the solution saves and loads them.
- A rollback puts the inputs back to their value at the start of the
  solver step and applies the triggering event's writes again.
- context.record(...) keeps timed values per event; flight.records
  gathers them and is saved with the flight.
- flight.plots.controls(), flight.plots.records() and
  flight.prints.controls().

Flight results are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: add a public Controller that writes the flight's control inputs

Controller(controller_function, sampling_rate, writes=...) replaces
_Controller and Controlled. It writes context.controls, a returned dict is
recorded, writes outside 'writes' are refused, and it saves and loads.
Positional air-brakes functions still work, deprecated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: let actuators turn the thrust, push the rocket and add mass

rocket.add_actuator files a part by what it does: thrust_vector,
force_and_moment or mass_properties. GenericEffector wraps a force and
moment function. Flights without such parts are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: let each flight phase name the actuators it reads

_PhaseDynamics(reads=...) lists what a phase reads; parts with no physics of
their own go to rocket.phase_actuators. A flight warns about actuators no
flown phase read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: fly air brakes as an aerodynamic surface

Air brakes are summed with the other surfaces, at the center of dry mass or
at add_air_brakes(position=...). Controllers no longer declare
changes_dynamics. rocket.air_brakes and the memory and return_controller
arguments of add_air_brakes are deprecated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: keep flying after a rollback, and run every event at a shared time

A rolled-back step that had reached the end of its node left the solver
marked finished, so the phase ended at the rollback: with a short max_time,
a flight with an event that changes the dynamics stopped at its first
sample. The solver now restarts whenever the flight is short of the node's
end. An event that changes the dynamics also no longer loses its sampling
time to another such event sampled at the same time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: add controllables, control fins and continuous controllers

The parts a controller can move share one base, Controllable, and the
flight reads and writes them by name:

- ControlFins: fins that deflect, with a mixer, effectiveness and hinge
  moments. ThrustEffector and ForceEffector replace Actuator and
  GenericEffector, added with rocket.add_effector at a position.
- ContinuousController: a control law evaluated inside the equations of
  motion, with states of its own. Controller takes outputs= and
  sampling_rate=None. rocket.controllers and
  rocket.continuous_controllers list them.
- context.controls, context.sensors and context.outputs are read by name;
  context.conditions gives the air at the rocket (FlightConditions).
- flight.controls, flight.state_history, flight.sensor_history,
  flight.records and flight.event_outputs give the results as Functions
  of time; flight.solution holds the same as arrays, sensor readings
  included, and saves them.
- AirBrakes built with override_rocket_drag add the difference between
  their curve and its retracted values to the rocket's drag. A curve that
  disagrees with the rocket's drag warns through add_surfaces and
  add_air_brakes alike.
- The positional air brakes controller function still works, deprecated,
  from control/_legacy.py.

The record of what each event did in a solver step is looked up by time
and event instead of searched: a Calisto flight with two parachutes
simulates about 20% faster.

* DOC: document controllers, control fins and the flight solution

- New guides: controllers and control fins. The air brakes, sensors and
  events guides follow the new way of reading and writing by name.
- flight.rst explains reading results as Functions of time or as the
  stored numbers in flight.solution, in place of the deprecated
  solution_array and get_solution_at_time, and what a flight continued
  from another one carries over.
- The air brakes guide says how a whole-rocket drag curve works with the
  rocket's power-on and power-off drag.
- Reference pages for the control classes, ControlFins, AeroCoefficient,
  Commands, the event views and FlightDataExporter.
- The sensors and Camoes notebooks use the new controller function.

* MNT: require a sampling rate on Controller

Controller(sampling_rate=None) ran the controller once per solver step, so
how often it ran depended on the solver's tolerances. A controller now
needs a positive rate, and the error points to ContinuousController for a
law that acts at every instant. Event keeps sampling_rate=None.

* DOC: stop suggesting to subclass the controllables

Subclassing an effector or a continuous controller is machinery for the
controllables RocketPy will ship, not something for users. The
ThrustEffector, ForceEffector and ContinuousController docstrings and two
error messages now only describe building them from functions, and
Controllable is no longer in the API reference.

* DOC: add the air brakes as a surface and a controller in the sensors guide

The example builds AirBrakes and Controller and adds each to the rocket,
as the air brakes guide does, and points to flight.sensor_history for
the readings after the flight.

* ENH: command control fins by roll, pitch and yaw

ControlFins.deflections takes roll, pitch and yaw commands in place of
roll, x and y. A positive command raises the angular velocity of that
name (w3, w1, w2), on canards and on tail fins alike, so a controller
that opposes the rates uses roll=-K*w3, pitch=-K*w1, yaw=-K*w2. The
roll command changes sign with this: it used to lower w3.

The rocket tells a set where it sits when it is added, and the set turns
its fins one way ahead of the center of dry mass and the other way behind
it. A pitch or yaw command on a set that is not on a rocket raises an
error.

ControlFins.effectiveness gives the moment coefficient per radian of each
command, the pitch and yaw ones about the center of dry mass. The prints
and the plot follow.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* DOC: clarify the control fins guide and the sign of the moment coefficients

Control fins guide: the two ways to model control fins, the limits of the
Barrowman method the fins are computed with, how w1, w2 and w3 relate to
the body axes, the roll, pitch and yaw commands with a worked example of
the moment each gives, a controller that writes each fin itself, and a
yaw command shown by how far it moves the flight. The section on fins
that lag is removed until actuators are added.

Generic surface guide: a table of which way a positive cm, cn and cl turn
the rocket.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* BUG: take a sensor's random walk back when the flight goes back in time

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>

* BUG: carry the controllers and sensors into each Monte Carlo sample

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>

* ENH: make Event.enabled set how every flight starts

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>

* BUG: undo an event's changes to the schedule when the step is cut

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>

* BUG: refuse a control input that is not a finite number

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>

* ENH: explain what an event checked by hand needs

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>

* DOC: give the version the deprecated export aliases are removed in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: work out the state derivative only for sensors that read it

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>

* ENH: do not stop the solver for a control write under a parachute

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>

* MNT: move the helper that copies recorded values to tools

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* STY: clear the pylint findings of the control work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: accept any return annotation on an event trigger

A trigger annotated `-> np.bool_`, or with an annotation written as text,
was rejected with a ValueError. What a trigger returns is read as true or
false, so its annotation is no longer checked, as for the callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* MNT: show the positional parachute trigger deprecation to users

Python hides a DeprecationWarning that does not point at the user's own
script, and this one points inside Parachute, so most users never saw
it. It is now a FutureWarning, which Python always shows, as the noise
deprecation next to it already was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* MNT: remove Flight.calculate_stall_wind_velocity, deprecated for 1.15

Use rocketpy.utilities.calculate_stall_wind_velocity instead. Also date
the positional parachute trigger deprecation to 1.15 and name the
FutureWarning it emits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: reject a zero or negative event sampling rate

A sampling rate of 0 crashed with ZeroDivisionError and a negative one
was accepted. Event now raises a ValueError for both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: let enable_on turn back on an event turned off during a flight

A continuous or non-overshootable event turned off during a flight was
taken off the schedule, so its enable_on was never checked again. Events
with an enable_on now stay on the schedule while off, and turning them
back on no longer warns that they were already enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* MNT: point the positional parachute trigger warning at the user's line

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* DOC: say what context.time and context.dt each are in the controllers guide

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: give a loaded flight's solution the histories saved with it

A flight read back from a file cannot work out its post-process
variables again, so loaded.solution.az raised while loaded.az worked.
The solution now falls back to the histories already saved with the
flight (ax to M3, net_thrust).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: count control fins in the rocket length

Rocket.length skipped ControlFins, so a rocket ending in control fins
measured short, or had no length at all without other fins or a motor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: load a v1.13 controller with its initial_observed_variables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: fly the controller given to StochasticRocket.add_air_brakes

Air brakes added only to the stochastic rocket were dispersed but flew
without their controller. The controller given with them is now copied
into each sampled rocket when it is not already one of the rocket's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: draw only reachable levels in the air brakes drag plot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: print controllers under the names flight.records gives them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* MNT: print sensor readings with seven significant digits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* BUG: search an event's exact time over the whole solver step

The search started from the row before the last, which another event of
the same step may have inserted. It now starts from the row the step
started at. Rows inserted in a step keep time order, and an event that
ends the step drops the rows inserted after its time. _replace_last is
no longer used and is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ENH: run the events of a solver step in time order

The events of a solver step now run in the order of the moments they
happen at, so a callback never runs at a moment the flight does not
reach and nothing is undone. A step is only cut: the rows after the cut
are dropped.

- The flight keeps no list of time nodes. Each event answers for its own
  sampling times and the next node is worked out from the events as they
  are, so turning an event on or off only sets its flag. _TimeNodes and
  the undo code are removed.
- Event.__call__ is a wrapper over _call_trigger and _call_callback, and
  its reset argument is removed.
- Sampling times within a rounding error are one moment, run in order of
  priority, and each moment falls in exactly one solver step.
- A node's events run once, also when one of them starts a phase there,
  and the flight's last node is run.
- An event turned on or added inside a step is checked from that moment
  on: the step is cut there.
- enable_on does not turn an event on while its disable_on holds.
- The states at the sampling times of a step are interpolated in one
  call to the solver's dense output.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* MNT: clear the pylint messages

Remove two unused imports and a duplicated test helper, and mark the
arguments pylint flags where the signature is intended.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* TST: check the rail exits to the root finder's tolerance

The exit times are found to about 4e-9 s, which is about 1e-7 m of
travel, so the 1e-9 relative check failed on Windows by 1.5e-8 m.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: ZuoRen Chen <180084773+zuorenchen@users.noreply.github.com>
Co-authored-by: RickyRicato <rickywang44@gmail.com>
Co-authored-by: zuorenchen <zuorenchen@m110.nthu.edu.tw>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants