Overview
Custom expressions are stored in your.ork rocket document. To manage them, go to Analyze → Custom expressions. The Custom Expressions window lists all expressions defined for the current document.
Initially the list is empty. Use the New expression button in the lower right to open the Expression Builder. You can also import expressions from another .ork file.
Building an expression
The Expression Builder requires four fields before you can save an expression:| Field | Rules |
|---|---|
| Name | Any string not previously used as an expression name |
| Symbol | A short locale-independent identifier: no numbers, whitespace, or special characters (brackets, operators, etc.) |
| Units | Any string; leave blank for dimensionless quantities. If you enter a standard SI unit exactly, OpenRocket will offer unit conversion when plotting or exporting. |
| Expression | A valid mathematical expression using variable symbols, operators, and numbers |
Supported SI units for automatic conversion
If your expression’s Units field contains one of these exactly, OpenRocket will automatically offer unit conversion:m m^2 m/s kg kg m^2 kg m^3 N Ns s Pa V A J W kg m/s Hz K
Inserting variables and operators
Click Insert Variable to open a searchable list of all available simulation variables and their symbols. Selecting a variable inserts its symbol at the current cursor position in the expression box. Click Insert Operator to open a similar list of all available mathematical operators and functions. This is especially useful for operators whose symbols cannot be typed on a standard keyboard.Nesting custom expressions
You can use the symbol of one custom expression inside another. This allows you to build up complex calculations incrementally.Available variables
The full list of available variables is accessible from the Insert Variable dialog. The variables correspond to the built-inFlightDataType values used throughout OpenRocket’s simulation engine. Key variables and their symbols include:
Time and position
Time and position
| Symbol | Variable |
|---|---|
t | Time |
h | Altitude |
ha | Altitude above sea level |
Vz | Vertical velocity |
Vt | Total velocity |
Az | Vertical acceleration |
At | Total acceleration |
Px | Position East of launch |
Py | Position North of launch |
Pl | Lateral distance |
Mass and inertia
Mass and inertia
| Symbol | Variable |
|---|---|
m | Total mass |
mp | Motor mass |
Il | Longitudinal moment of inertia |
Ir | Rotational moment of inertia |
g | Gravity |
Stability
Stability
| Symbol | Variable |
|---|---|
Cp | CP location |
Cg | CG location |
S | Stability margin (calibers) |
Thrust and drag
Thrust and drag
| Symbol | Variable |
|---|---|
Ft | Thrust force |
Twr | Thrust-to-weight ratio |
Fd | Drag force |
Cd | Drag coefficient |
Cdf | Friction drag coefficient |
Cdp | Pressure drag coefficient |
Cdb | Base drag coefficient |
Characteristic numbers
Characteristic numbers
| Symbol | Variable |
|---|---|
M | Mach number |
R | Reynolds number |
Index expressions
Custom expressions are evaluated at each time step, but sometimes you need a value from an earlier point in the flight. Index expressions use square bracket syntax to specify a time in seconds:t, it is clamped to 0 or t respectively. You cannot reference data that has not yet been calculated.
You cannot nest another index or range expression inside square brackets.
Range expressions
Some operators work on a range of values rather than a single point. These range operators are identified in the Insert Operator dialog by the[:] placeholder already filled in for one or more parameters.
Range expressions use a start:end syntax inside square brackets:
At) over the last 0.5 seconds — a simple model of a low-pass filtered accelerometer output.
The bounds can be any valid expression. If you omit the upper bound, it defaults to t; if you omit the lower bound, it defaults to 0:
Practical example: filtered accelerometer voltage
Many accelerometers clip above a maximum acceleration and return an analog voltage. This expression models a sensor that clips at 10 g and returns 0.2 V per g:uclip(x, max)clipsxto a maximum value ofmaxmean(At[t-.5:])computes the mean of total acceleration over the last 0.5 s- The outer
0.2 *converts from acceleration (m/s²) to a voltage-like output
trapz([:]) (trapezoidal integration) or tnear([:], x) (find the time when a variable is nearest a target value).
Example expressions
Launch mass fraction
Launch mass fraction
The ratio of current rocket mass to launch mass:Symbol:
Units: (dimensionless, leave blank)
mfUnits: (dimensionless, leave blank)
Net force
Net force
Thrust minus drag gives the net axial force:Symbol:
Units:
FnUnits:
NDrag-to-thrust ratio
Drag-to-thrust ratio
How much drag relative to available thrust:Symbol:
Units: (dimensionless)
DtTUnits: (dimensionless)
Stability margin in body diameters
Stability margin in body diameters
Convert the standard caliber stability margin to a fraction of body length (assuming reference length is the body diameter):Note: Replace
h with the appropriate reference length symbol for your design.Troubleshooting
If an expression produces no data after running a simulation:- Verify all indicator lights in the Expression Builder are green before saving
- Check the error log at Help → Debug log; look for entries under the
USERcategory - Verify that nested expressions are in the correct calculation order
Custom expressions are interpreted during the simulation and are slower than built-in variables. A few simple expressions have negligible overhead, but range expressions in particular can noticeably increase simulation time. If performance is a concern, consider implementing your calculation as a simulation extension instead.