pre-release v0.3.0-alpha.1 Tell us what breaks
downrange

The mission file

One TOML file describes a vehicle's telemetry. The daemon reads it at startup. Nothing about your vehicle is compiled in.

Two working examples: missions/demo-rocket.toml and missions/demo-orbit.toml. A third, for a vehicle that sends bare structs with no Downrange header, is examples/custom-udp/legacy-vehicle.toml.

This page covers schema 2. Schema 1 files still load. The daemon refuses a file with a higher downrange_schema than it knows, and says which version it supports.

Top level #

downrange_schema = 2

[mission]
name = "my-vehicle"

[link]
udp = "127.0.0.1:48620"     # where telemetry arrives
framing = "vtp"             # or "raw": see examples/custom-udp

[server]
tcp = "127.0.0.1:48621"     # where the workstation connects

[store]
capacity = 262144           # samples kept per channel
retention_s = 600           # optional: size each channel for this many seconds at its rate
memory_budget_mb = 128

Both addresses must be loopback. The daemon refuses to bind anything else.

Packets and fields #

[[packet]]
id = 3
name = "eps"
rate_hz = 1
  [[packet.field]]
  name = "vbat"
  type = "u16"
  scale = 0.001
  unit = "V"

Each field becomes a channel named <packet>.<field>, here eps.vbat. Types: u8 i8 u16 i16 u32 i32 u64 i64 f32 f64. Fields are laid out in order with no padding unless you say otherwise with at.

Field keys #

Key Meaning
scale, offset value = raw * scale + offset. Defaults 1 and 0.
poly Polynomial, lowest power first: [c0, c1, c2] gives c0 + c1*raw + c2*raw^2. Replaces scale and offset.
table Lookup table [[raw, value], ...], raw ascending. Linear between points, held flat past the ends. Replaces scale and offset.
endian "little" (default) or "big", per field.
bits [lowest bit, count]. Takes part of an unsigned integer.
at Byte offset in the payload. Lets several bits fields read the same status word.
states Names for values: { "0" = "SAFE", "1" = "ARMED" }. Shown in place of the number.
limit Warning and alarm bands. See below.
unit Free text. Display conversion in dashboards understands the units listed in 12-dashboards.md.
frame Free-text coordinate frame label. Not interpreted.
time Raw framing only: marks the field as the packet's vehicle timestamp ("us", "ms", "s", "ns").

A thermistor through a lookup table, and a status byte split into two channels:

  [[packet.field]]
  name = "tank_temp"
  type = "u16"
  unit = "degC"
  table = [[310, 125.0], [1240, 60.0], [2480, 25.0], [3500, -10.0]]

  [[packet.field]]
  name = "eclipse"
  type = "u8"
  bits = [0, 1]
  states = { "0" = "SUN", "1" = "ECLIPSE" }

  [[packet.field]]
  name = "mode"
  type = "u8"
  at = 7                    # same byte as "eclipse"
  bits = [1, 2]
  states = { "0" = "SAFE", "1" = "NOMINAL", "2" = "SCIENCE" }

Limits #

limit = { alarm_low = 6.6, warn_low = 7.0, warn_high = 8.4, alarm_high = 8.6, persist = 3, hysteresis = 0.05 }

Any of the four bands may be left out. A channel is at OK, WARN or ALARM.

  • persist: how many samples in a row must agree before the level changes. Default 1.
  • hysteresis: how far back inside a band the value must come before the level drops. Default 0.

Limits are checked in the daemon on every stored sample, from the sample alone. No clock is read. Replaying a recording gives the same alarm log in the same order, and downranged verify <file> --alarms prints it. The daemon keeps the last 1,024 changes.

A limit says a number crossed a line you drew. It does not say why, and it does nothing about it. Downrange sends no commands.

Derived channels #

[[derived]]
name = "prop.thrust"
expr = "max(pt.chamber - 101325, 0) * 0.00052"
unit = "N"
limit = { alarm_high = 2000.0 }

A derived channel is computed in the daemon from other channels. It is stored, streamed, plotted, limit-checked, exported and replayed like a measured one, and it is marked derived everywhere it is shown.

Rules:

  • It may read packet fields and derived channels defined above it.
  • It is computed each time one of its inputs gets a new sample, using the latest value of the others. Its timestamp is that sample's.
  • Nothing is computed until every input has been seen once.
  • Expressions have no loops and read no clock. Functions that remember earlier samples are listed below. Replay gives the same values as the live run, to the bit.

Expression language #

Operators, loosest first: or, and, not, comparisons (< <= > >= == !=), + -, * /, unary -, ^. Comparisons give 1 or 0. Anything non-zero is true.

Functions: abs sqrt exp ln log10 sin cos tan asin acos atan atan2 hypot min max pow clamp deg rad floor ceil round sign if. if(cond, a, b) picks a when cond is non-zero.

Constants: pi, e, g0 (9.80665).

Functions that remember earlier samples:

Function Value
rate(x) Change per second since the previous sample. NaN on the first.
delta(x) Change since the previous sample. NaN on the first.
prev(x) The previous sample. NaN on the first.
integral(x) Time integral by the trapezoid rule, from zero at the first sample.
ema(x, tau) Exponential moving average with time constant tau seconds.
mean(x, n) Mean of the last n samples. n is a written number from 1 to 1024.
peak(x), valley(x) Largest and smallest value so far.
rising(c) 1 on the sample where c becomes true, else 0.
count(c) How many times c has become true.

Time is the vehicle time of the sample, never the computer's clock. A sample that is not a number gives NaN and is not remembered. If vehicle time goes backwards (the vehicle restarted), the memory starts over.

One rule: a derived channel that uses any of these may read one channel. A derived channel is recomputed whenever any input arrives, so with two inputs rate() would also step on the other channel's samples. Split it:

[[derived]]
name = "nav.baro_rate"
expr = "ema(rate(baro.alt), 0.3)"        # one input: baro.alt
unit = "m/s"

[[derived]]
name = "nav.rate_disagree"
expr = "nav.baro_rate - gps.vel_up"      # no memory here, so two inputs are fine
unit = "m/s"

At most 16 such functions in one expression.

Limits on size: 2,000 characters, nesting depth 48. A bad expression is rejected with a message when the mission loads, not at run time.

Examples:

expr = "deg(atan2(hypot(imu.ax, imu.ay), imu.az))"          # tilt from vertical
expr = "if(fc.state >= 2 and batt.v > 6.5, 1, 0)"           # a go/no-go flag
expr = "baro.alt - gps.alt"                                 # two sensors that should agree

Analysis #

[analysis]
module = "rocket-vertical"                  # built in
inputs = { accel = "imu.az", baro = "baro.alt" }
params = { beta = 880.0 }

or your own program, without recompiling Downrange:

[analysis]
module = "external"
plugin = "apogee-watch"                     # a name, never a command
inputs = { altitude = "baro.alt" }
params = { drop_m = 5.0 }

See 13-plugins.md.

What the schema can't do yet #

  • No array fields, no variable-length packets, no strings.
  • No bit fields wider than the integer they sit in, and none on signed or float fields.
  • Derived channels have rates, integrals and averages, but no general filters, no lookbehind by time, and no way to read two channels inside a function with memory.
  • One vehicle per mission file and per daemon. Run two daemons on different ports for two vehicles.
  • Units are labels. The daemon does not check that an expression adds metres to metres.