Adding an existing extension to a simulation
Open Edit simulation
Select a simulation and click the Edit simulation button to open the simulation configuration dialog.
Click Add extension
Click Add extension. A menu appears listing all available extensions organized by category (for example, Launch conditions, Data recording).
Simulation internals
Before writing an extension, it helps to understand three core concepts.SimulationStatus
As a simulation runs, all state is held in aSimulationStatus object. It contains:
- Current position, orientation, and velocity of the rocket
- The current simulation time
- The simulation’s event queue
- A reference to the rocket design and its configuration
SimulationStatus through get*() and set*() methods. For example, getRocketPosition() returns the current position, and setRocketPosition(Coordinate position) changes it. The full API is in core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java.
FlightData and FlightDataBranch
Simulation variables (altitude, velocity, drag, etc.) are stored asFlightDataType objects — each is a List<Double> with one element per time step. To retrieve a variable, call:
FlightDataType definitions are in core/src/main/java/info/openrocket/core/simulation/FlightDataType.java.
Each stage of the flight is stored in a FlightDataBranch — the sustainer has one branch, and each booster adds another at separation. All branches plus summary data are collected in a FlightData object.
FlightConditions
Current aerodynamic state — velocity, angle of attack, roll and pitch rates, and a reference toAtmosphericConditions — is stored in a FlightConditions object. Computation listeners receive this as a parameter.
Simulation listener interfaces
Listeners are called by the simulation engine at specific points during the computation. There are three listener interfaces:SimulationListener
Lifecycle events: simulation start, simulation end, branch start, branch end, pre-step, and post-step.
SimulationComputationListener
Pre/post hooks for each physical model computation: acceleration, aerodynamics, atmospheric model, wind model, gravity model, mass calculation, flight conditions, and thrust.
SimulationEventListener
Flight event hooks: adding a flight event, handling a flight event, motor ignition, and recovery device deployment.
AbstractSimulationListener, which provides no-op default implementations for every method. You only override the methods you need.
Listener method return values
| Method type | Return behavior |
|---|---|
startSimulation(), endSimulation(), postStep() | void — called for side effects only |
preStep() and event hooks (e.g., addFlightEvent(), motorIgnition()) | boolean — return true to proceed normally, false to suppress the action |
Pre-computation methods (e.g., preAerodynamicCalculation()) | Return an object to override the computation entirely, or null/Double.NaN to use the default |
Post-computation methods (e.g., postAerodynamicCalculation()) | Return an object to replace the computed value, or null/Double.NaN to keep the original |
SimulationStatus as its first argument. Additional arguments vary by method.
Throwing exceptions from a listener
-
Throw a
SimulationExceptionto report an expected error condition. OpenRocket shows an error dialog with your message; the simulation data up to that point is discarded. -
Throwing a
RuntimeExceptionis treated as a software bug and triggers a bug report dialog. -
To stop the simulation cleanly without an error, add a
SIMULATION_ENDevent to the event queue:
Creating a new extension
Every extension requires three classes:- A listener — extends
AbstractSimulationListener; does the real work - An extension — extends
AbstractSimulationExtension; inserts the listener into the simulation - A provider — extends
AbstractSimulationExtensionProvider; registers the extension in the UI menu
- A configurator — extends
AbstractSwingSimulationExtensionConfigurator<E>
File placement
The most convenient approach is to add your files directly to the OpenRocket source tree:- Extension and listener:
core/src/main/java/info/openrocket/core/simulation/extension/ - Configurator:
swing/src/main/java/info/openrocket/swing/simulation/extension/
Step-by-step example: air-start extension
The following builds a simplified version of theAirStart extension included in the OpenRocket source tree.
Step 1 — Write the extension and listener
initialize()is the only method required byAbstractSimulationExtension. It adds the listener toSimulationConditions.getName()provides the display name shown in the extensions menu.getDescription()provides the text shown when the user clicks the Info button.- The inner
AirStartListeneroverridesstartSimulation()to move the rocket to 1000 m altitude at simulation start.
Step 2 — Write the provider
super() call registers the extension. The first string ("Launch conditions") is the top-level menu category; the second ("Air-start example") is the menu item label. Both strings are arbitrary — using a category name that doesn’t exist yet creates a new top-level menu entry.
Step 3 — Add a configuration GUI (optional)
To allow the user to set the launch altitude at runtime, first add getter and setter methods to the extension, backed by theconfig object provided by AbstractSimulationExtension:
startSimulation() to use the configured value:
swing module:
The
DoubleModel constructor parameter "LaunchAltitude" must exactly match the get/set method names (getLaunchAltitude and setLaunchAltitude). The system synthesizes calls to these methods by reflection. A mismatch causes a runtime exception when the user changes the value.UnitGroup.UNITS_DISTANCE specifies the unit group for the field, enabling OpenRocket’s standard unit conversion. Available UnitGroup values are defined in core/src/main/java/info/openrocket/core/unit/UnitGroup.java.
Example extensions included with OpenRocket
The following examples are incore/src/main/java/info/openrocket/core/simulation/extension/example/. Configurators are in swing/src/main/java/info/openrocket/swing/simulation/extension/example/.
| Purpose | Extension | Configurator |
|---|---|---|
| Set air-start altitude and velocity | AirStart.java | AirStartConfigurator.java |
| Save simulation values as a CSV file | CSVSave.java | (none) |
| Calculate damping moment coefficient after every step | DampingMoment.java | (none) |
| Print simulation progress summary after each step | PrintSimulation.java | (none) |
| Active roll control | RollControl.java | RollControlConfigurator.java |
| Stop simulation at a specified time or step count | StopSimulation.java | StopSimulationConfigurator.java |