Ship presets for your airframe
Flying a custom airframe takes a long open_sitl call: a model file, two or three parameter files, an overlay, often an RC position for the mode switch. Written out by every agent on every flight, that call drifts, and one missing parameter file gives you a different aircraft. A preset holds it once, in the project, under version control.
Write one
Section titled “Write one”A preset is a JSON object of open_sitl arguments, plus an optional description. Paths inside it are relative to the preset file:
{ "description": "Hover hop on the keel model with the harness parameters", "model": "quadplane-elevon:../models/keel.json", "params": ["../params/common.parm", "../params/airframe.parm"], "set": {"SERVO_AUTO_TRIM": 0, "BATT_MONITOR": 4}, "rc": {"5": 1425}, "speedup": 10, "wind": {"speed_mps": 6, "from_deg": 270, "gusts": "dryden", "seed": 7}}It can hold model, params, set, lua, run_files, speedup, rc, idle_speedup, wind, binary, tree, keep_logs, label, default_params, record_video, exact and airframe. Anything else is refused with the list of keys it may hold, so a typo fails loudly instead of being ignored.
run_files are files SITL reads from its working directory by name, such as the box.json a patched SITL reads for SIM_BOX_ENA. Each is copied in under its own name. A name SITL already uses there (overlay.parm, eeprom.bin, a parameter file) is refused. The files a session placed are removed when the next session starts on that instance, so a file nobody named is never read. Their sha256s go into the session’s provenance and its recipe, and repro refuses to fly a recipe whose run file has changed since, since the same recipe would then fly different inputs.
Point the server at it
Section titled “Point the server at it”MCARDUPILOT_PRESET_DIRS=~/my-project/sim/presetsSeveral directories can be given, separated by : or ,. <data_dir>/presets is always searched last, for presets of your own that belong to no project. If two directories hold the same name, the first one wins.
Use it
Section titled “Use it”list_presets() # names, files, descriptions, modelsopen_sitl(preset="hover")open_sitl(preset="hover", set={"Q_A_RAT_RLL_P": 0.3}, label="roll-p-0.3")open_sitl(preset="~/my-project/sim/presets/hover.json")An argument given with the preset overrides it. set, rc and wind merge key by key: the call above keeps the preset’s overlay and adds one parameter. Any other argument you change from its default replaces the preset’s value. One argument left at its default, such as model="quadplane" written out explicitly, cannot be told apart from one not given, so it takes the preset’s value.
With exact=True a preset’s rc is left out, and open_sitl’s warnings name the channels it dropped. An exact session sends no RC overrides, so channel 5 stays at SITL’s default 1800 and the vehicle boots in whatever mode the parameters map that to (FLTMODE6 when FLTMODE_CH is 5), while fly_exact sets the flight’s own mode. An rc you pass yourself in an exact session is still refused, since the session cannot honour it.