Analysis plug-ins
Write your own estimator or detector as a separate program, in any language. Downrange starts it, sends it samples, and treats what it sends back like the output of the built-in analysis module: estimated series, phase transitions, monitor events, predictions. No recompiling.
Two working examples that do the same thing:
examples/plugins/apogee_watch.py: Python, standard library only, about 60 lines.apps/downranged/src/bin/downrange-plugin-demo.rs: Rust, built with the workspace asdownrange-plugin-demo.
Using one #
The mission file names the plug-in:
[analysis]
module = "external"
plugin = "apogee-watch"
inputs = { altitude = "baro.alt" }
params = { drop_m = 5.0, ceiling_m = 450.0 }
The operator says which program that name means, when starting the daemon:
downranged run --mission my.toml --record flight.mcap \
--plugin apogee-watch="python3 examples/plugins/apogee_watch.py"
The same flag goes on verify, replay, export and report, which run the plug-in again on the recording.
Why the mission file can't name the program #
Mission files travel inside recordings. If a mission could carry a command, opening someone else's recording would run it. So the mission carries a name (letters, digits, - and _), and the command only ever comes from your own command line. A mission that names a plug-in you have not given still loads: analysis is off, and the log says which --plugin flag is missing.
The command is split on spaces and run directly. No shell is involved. A path with spaces can't be given this way.
The protocol #
One JSON object per line, UTF-8, over the program's standard input and output. Standard error is yours, and goes to the daemon's log.
1. The daemon introduces itself.
{"downrange_plugin":1,"mission":"demo-rocket","inputs":[{"role":"altitude","channel":"baro.alt","unit":"m"}],"params":{"drop_m":5.0}}
2. The plug-in answers once. name is required. series lists the time series it will write, at most 64. of names the measured channel a series estimates, if any.
{"name":"apogee-watch","version":"0.1","assumptions":["Altitude is noisy by less than drop_m."],"series":[{"name":"ext.peak_alt","unit":"m","of":"baro.alt"}]}
3. For every sample of an input channel, in order, one line each way.
{"r":"altitude","t":12345678,"v":101.5}
r is the role, t is vehicle time in microseconds, v is the value. Samples that are not numbers are not sent. The answer is {} or any of these keys:
| Key | Meaning |
|---|---|
"s": [[0, 104.2]] |
Values for series, by index in the list from step 2. Stamped with the sample's time. |
"transition": {"from", "to", "evidence"} |
A phase change. |
"event": {"id", "claim", "summary", "statistic", "threshold", "rule", "candidates": [{"hypothesis", "check"}]} |
A monitor event. Send the same id again to revise it. Up to 8 candidates. |
"prediction": {"quantity", "unit", "value", "sigma", "eta_s", "validity", "valid_for_s"} |
A forecast. validity is valid, suspect or not_applicable. value and sigma must be numbers. |
Rules:
- Answer every sample with exactly one line, and flush it. The daemon waits for the answer before sending the next sample.
- Write nothing else to standard output.
- Give the same answers for the same samples. Then a replay of the recording matches the live run, and
downranged verifycan check it. A plug-in that reads the clock, the network or a random number generator breaks that, and Downrange can't tell.
Text fields are cut at 300 characters. Values that are not finite numbers are dropped.
What happens when it goes wrong #
The plug-in runs on the analysis thread, behind the same bounded queue as the built-in module.
| The plug-in... | Downrange... |
|---|---|
| is slow | drops analysis input when the queue fills and counts it (ana_dropped). Telemetry and recording are not delayed. |
| does not answer a sample within 2 s | stops it, marks analysis failed. |
| exits, or writes something that isn't a JSON object, or a line over 64 kB | stops it, marks analysis failed. |
| cannot be started, or does not describe itself within 10 s | refuses to start the daemon, with the plug-in's name in the error. |
"Analysis failed" is shown on the workstation. Every frame is still received, decoded and recorded. These four cases are tested (apps/downranged/tests/plugin.rs).
There is no restart. A failed plug-in stays off until the daemon is restarted.
What a plug-in is not #
- It is not sandboxed. It runs as your user with your permissions. Only run programs you trust. Downrange limits what the mission file can do, not what the program can do.
- It cannot send anything to the vehicle. Downrange has no command path, and nothing a plug-in returns is acted on. Its output is shown and recorded as computed, with the plug-in's name and version, and with the line "Computed by a plug-in outside Downrange. Downrange has not checked its method."
- It is not for per-sample work at high rates. Each sample is a line out and a line back through two pipes. The Python example was run on the demo flight's 50 Hz barometer, sent at 20 times real time, with nothing dropped. No throughput limit has been measured.
- One plug-in per mission, and it replaces the built-in module rather than running beside it.
- A language model can be a plug-in. Its answers would not repeat, so replay would not match, and nothing downstream may treat them as measurements. Downrange shows them as computed. It still does nothing with them.