L3S DRM Developer Guide
Formula Reference
Formulas are written in the portal's Formulas tab and delivered encrypted to your aircraft after activation (L3DRM 3.0 or newer). Your aircraft calls them with DRM_EVAL("VM_KEY", x, ..., fallback), usually through the generated wrappers in L3DRM_Formulas.h. This page lists everything a formula can use. The same reference is available in the formula editor under Functions.
Formulas vs. functions
A formula is what your C++ code calls. A function is a reusable piece of math you use inside formulas; C++ never calls it directly.
| Formula | Function | |
|---|---|---|
| Example | VM_THRUST_R1 | kts_to_ms(v) |
| Used by | Your C++: Formula_THRUST_R1(ias, n1, 0.0) | Other formulas and functions, in the portal |
| Inputs | 1 to 4, passed by C++ in argument order | 1 to 4 parameters, passed by the calling formula |
In L3DRM_Formulas.h | Yes, as a wrapper | No |
| Defined by | Your project (Formulas tab) | Your project or LAND3 (Functions tab) |
// Function (Functions tab)
kts_to_ms(v) = v * 0.514444
// Formula VM_THRUST_R1, inputs ias, n1 (Formulas tab)
clamp(kts_to_ms(ias) * 12.5 + n1 * 0.8, 0, 100)When you save a formula, every function call is replaced by the function's math, so the delivered formula contains no function calls. If you change a function later, the formulas using it are marked Library changed: open and save them to pick up the change.
Operators and inputs
| Syntax | Meaning |
|---|---|
+ - * / | Arithmetic, usual precedence (* and / before + and -). |
-e | Unary minus. |
( ) | Grouping. |
1.5 .5 1e-3 | Numeric literals. There is no ^ or pow: use x * x or poly(). |
x, y, ... | Input names: 1 to 4 inputs, passed in DRM_EVAL argument order (arg0..arg3), followed by the fallback. |
Built-in functions
| Function | Description | Rules | Example |
|---|---|---|---|
min(a, b) | Smaller of two expressions. |
| min(x, y) |
max(a, b) | Larger of two expressions. |
| max(x * 2, 10) |
abs(e) | Absolute value. |
| abs(x - y) |
clamp(e, lo, hi) | Limits e to the range lo..hi. |
| clamp(x * 0.4375, -10, 100) |
poly(e, [c0, c1, c2, ...]) | Polynomial c0 + c1*e + c2*e^2 + ... |
| poly(x, [1, 0.5, 0.25]) |
lerp1d(e, [xs], [ys]) | Piecewise linear lookup table. |
| lerp1d(x, [0, 50, 100], [0, 0.5, 1]) |
lerp2d(a, b, [xs], [ys], [grid]) | Bilinear 2D lookup table (a along xs, b along ys). |
| lerp2d(x, y, [0, 100], [0, 10], [0, 1, 2, 3]) |
Library functions
Besides the built-ins, a formula can call project functions (defined in the Functions tab of your project) and LAND3 functions (shared by LAND3 Simulations for all projects). Both are listed with their bodies in the formula editor and can be inserted from there.
- Any non-finite intermediate result (division by zero, overflow, NaN) makes the formula unavailable: the wrapper returns its fallback, or NaN.
- Functions are copied into each formula that uses them: f(a, b) becomes the body of f with a and b filled in.
- A project function with the same name as a LAND3 function replaces it in your formulas and functions, but not inside LAND3 functions.
- Builtin names (min, max, abs, clamp, poly, lerp1d, lerp2d) are reserved: no input, parameter or library function may use them.
- Literal-only positions (clamp bounds, poly coefficients, lerp tables) never accept inputs or parameters.
Limits
| Limit | Value |
|---|---|
| Inputs per formula | 1 to 4 |
| Source length | 8192 characters |
| Formula size | Checked on save; lookup tables and nested function calls count most |
| Library functions (project + LAND3) | 64 |
| Parameters per library function | 1 to 4, each used at least once |
Calling formulas from C++
The Formulas tab generates L3DRM_Formulas.h ("Download C++ header") with wrappers for every formula of the project. Inputs are positional, in the order shown in the editor.
#include "L3DRM_Formulas.h"
// Inputs, then the fallback (last): returns the fallback until the formula is available
double ff = Formula_FUEL_FLOW_R1(throttle, rpm, 0.0);
// One formula delivered and valid for this client?
bool one = Formula_FUEL_FLOW_R1_Ready();
// Every formula in the header delivered and valid?
bool all = L3DRM_FormulasReady();Use a degraded fallback (e.g. reduced output), never the correct value. The fallback is visible in your .wasm and is what runs without activation.
Changing the input order, units or meaning of a shipped formula needs a new key (e.g.
_R2): aircraft builds callDRM_EVALwith a fixed argument order.