Beta API. See the stability policy.
Flight outputs
A flight runs your throttle and airspeed schedule until it ends or the battery runs out. The website calls it a flight over time. This article shows what comes back and how to read it. The numbers inside each sample have the same names as in Test bench outputs.
A finished flight has a result and a display_labels map. display_labels gives a name you can show for each key, the same as in a test bench result. You start a flight with POST /v1/flights and read it at GET /v1/flights/{id}. Flight ids start with dyn_.
What is in the result
| Key | What it holds |
|---|---|
scorecard | A few headline numbers for the whole flight. |
samples | A full snapshot at each point in time. Each one looks like a test bench result. |
series | One list of numbers for each channel, such as thrust or current, in step with series["time_s"]. Good for plotting. |
series_raw | The same channels with more points. The CSV export is made from it. |
events | Things that happened during the flight, with their times. |
energy | Where the battery's energy went, in joules. |
start_dip | The lowest cell voltage while the rotors spun up from rest. See below. null on a fixed supply. |
esc_settings_used | The settings each rotor group's speed controller flew with, each with the rule that gave it. |
derived | Values worked out for the flight, such as the air density in derived.air_density_kg_m3. |
run_meta | How the flight went: how many rows, and why it ended. |
flight = client.flights.retrieve("dyn_2c5tQ...")
blob = flight["result"]
blob["scorecard"]["flight_time_s"] # how long the flight lasted, in seconds
blob["samples"][-1]["All"]["total_thrust_n"] # total thrust at the end, in newtons
blob["series"]["total_current_a"] # the current at every point in timeThe points in time are not evenly spaced. Always read the time from series["time_s"]. Don't work it out from the position in the list.
The scorecard
| Key | What it is |
|---|---|
flight_time_s | How long the flight lasted, in seconds. |
energy_wh | The energy used, in watt-hours. |
range_m | The distance covered, in meters. |
peak_current_a | The highest current drawn from the battery. |
min_cell_voltage_v | The lowest voltage of any battery cell. |
peak_winding_temp_c | The hottest the motor windings got, in degrees Celsius. |
avg_efficiency | The average efficiency of the powertrain, from 0 to 1. |
depletion_criterion | The limit that ended the flight, or null. |
terminated_early | true if a limit stopped the flight before the schedule ended. |
Some of these are null when the engine didn't give a number.
The start dip
A battery sags hardest while the rotors spin up from rest, because every motor draws a large current at once. A cell can fall under its limit then and recover a moment later. For that reason, the flight goes on through the spin-up. It lasts until every speed controller has caught its rotor, and never longer than 2.5 seconds. After it, every limit ends the flight.
start_dip reports how low the cells fell in that spin-up:
| Key | What it is |
|---|---|
lowest_cell_voltage_v | The lowest cell voltage in the spin-up, in volts. |
time_s | When that happened, in seconds from the start of the flight. |
minimum_cell_voltage_v | The limit it is compared with, in volts. It is the pack's minimum cell voltage, or the cut-off you set if that is higher. |
spin_up_end_s | When the spin-up ended, in seconds. null if the flight ended inside its spin-up. |
warning | A sentence when the lowest voltage was at or below the limit. null if not. |
In one example, a flight of two battery packs at 30 % throttle and 0 m/s has its cells fall to 2.39 V at 0.533 s, below its limit. It then flies its whole schedule. start_dip is null on a fixed supply.
The series
Every channel lines up with series["time_s"]. Channels for the whole vehicle include total_thrust_n, total_current_a, total_voltage_v, min_cell_soc_pct, max_winding_temp_c, max_core_temp_c, airspeed_ms and vertical_speed_ms.
Each rotor also has channels named rotor1_..., rotor2_... and so on. A group of four rotors has four sets. For rotor 1 they include rotor1_rpm, rotor1_current_a, rotor1_thrust_n, rotor1_motor_v, rotor1_torque_nm, rotor1_t_w_c (winding temperature) and rotor1_t_mag_c (magnet temperature).
Not every flight has every channel. List the keys you got and read from there:
series = blob["series"]
print(sorted(series.keys()))
t, thrust = series["time_s"], series["total_thrust_n"]The battery entry of each sample has three keys that a test bench result doesn't: min_cell_soc_pct, max_core_temp_c and pack_internal_resistance_mohm.
The events
events is a list. Each entry has a time t in seconds, a type, a severity and some detail:
| Type | Severity | What it means |
|---|---|---|
depletion | info | The flight reached a limit. detail.criterion says which one. |
segment_boundary | info | One part of your schedule ended and the next began. |
in_rush_peak | info | The moment of the highest current. |
thermal_threshold | warning | A part got too hot. detail names the part (winding, magnet or core) and the limit. |
motor_idle_current_implausible | warning | A motor's no-load current looks like a rated current. The flight ran, but the motor books losses it doesn't have. |
non_convergence | error | The total current of one sample wasn't a finite number. Only the first such sample is reported. |
run_meta
run_meta has the bookkeeping for the flight. depletion_t and depletion_criterion say when and why the battery ran out, or are null. terminated_early is true or false. max_sim_time_capped is true if the flight hit the server's time limit before the battery was empty. n_chunks says how many parts the flight was solved in. steps is the number of rows and save_dt is the time between the first two rows, in seconds. outcome holds the engine's kind, reason and time_s for what ended the flight. wall_s is how long the solve took.
When a flight fails
A flight that can't run ends with status: "failed". Fetching it still returns 200, and error holds a code and a message. There are two codes:
| Code | What it means |
|---|---|
engine_request_refused | The engine refused the request. The message names the input to change. |
solver_failure | The flight failed for another reason. The message is general. |
You get your compute units back.
Watching and stopping a flight
While a flight goes, run_progress tells you how far it has got, and you can stop it before it ends. See Async resources. A flight you stop keeps what it has solved, and the result has the same layout. run_meta.partial is true.
A complete example
This script runs a flight, then reads the scorecard, some channels and the events:
"""Read a flight result: the scorecard, the samples, the series and the events.
Run it:
export THRUSTLAB_API_KEY=key_... # never hard-code the key
python examples/outputs/read_flight.py
A completed flight runs the powertrain through a throttle and airspeed schedule until
the schedule ends or a limit stops it. Its `result` carries:
* scorecard - headline numbers for the whole flight (flight_time_s, peak_current_a,
min_cell_voltage_v, peak_winding_temp_c, avg_efficiency, ...).
* samples[] - one full snapshot per point in time, with the same per-rotor and "All"
keys as a test bench result, so display_labels applies to it too.
* series - {channel_name: list[float]} in step with series["time_s"], the source
for plots (total_thrust_n, total_current_a, rotor1_rpm, ...). Always
use time_s; do not work out the time from the row index.
* events - timestamped events of the flight.
* energy, esc_settings_used, derived, run_meta - where the energy went, the controller
settings flown, the air density, and how the flight ended.
Swap in your own component ids, or find them by name with
client.components.find(...).
"""
from thrustlab import Client
client = Client() # reads $THRUSTLAB_API_KEY from the environment
project = client.projects.create(name="sdk read-flight example")
# Resolve by name, or paste explicit IDs: motor_id = "comp_motor_xxx"
motor = client.components.find(name="BadAss 2826-820Kv")
prop = client.components.find(name="10.5x4.5")
battery = client.components.find(
name="Liperior 5000mAh 4S 35C 14.8V Lipo Battery With XT90 Plug"
)
flight = client.flights.create(
project_id=project["id"],
battery_component_id=battery["id"],
density_kg_m3=1.225,
state_of_charge_pct=100,
ambient_temp_c=25,
rotor_groups=[
{
"label": "main",
# Flights need the Pro plan, whatever the number of rotors.
"count": 4,
"motor_component_id": motor["id"],
"propeller_component_id": prop["id"],
}
],
# Ramp to 70% over 2 s (a soft start: a throttle step onto a stationary
# rotor sags the pack below the low-voltage cutoff), then hold for 20 s.
schedule={
"mode": "segments",
"segments": [
{
"duration_s": 2.0,
"airspeed_target": 0.0,
"per_group": {
"main": {"throttle_target": 70, "throttle_ramp": "linear"}
},
},
{
"duration_s": 20.0,
"airspeed_target": 0.0,
"per_group": {"main": {"throttle_target": 70}},
},
],
},
termination={"mode": "fixed"},
)
result = client.flights.wait(flight["id"], timeout=600)
print(f"flight status: {result['status']}")
if result["status"] == "completed":
blob = result["result"]
labels = result["display_labels"] # applies to each samples[] entry
# How the flight went: the number of rows and the time between the first two.
meta = blob["run_meta"]
print(f"rows: {meta['steps']} first save interval: {meta['save_dt']} s")
print(f"ended: {meta['outcome']}")
# scorecard: the headline numbers of the whole flight.
print("\n[scorecard]")
for key, value in blob["scorecard"].items():
print(f" {key:<24} {value}")
# samples[]: each entry is a full snapshot. Read the same per-rotor and "All"
# keys (and display_labels) as in a test bench result.
samples = blob["samples"]
first, last = samples[0], samples[-1]
print(f"\nreturned observations: {len(samples)}")
print(
f" t0 total_thrust_n: {first['All']['total_thrust_n']:.2f} "
f"({labels['total_thrust_n']})"
)
print(f" tN total_thrust_n: {last['All']['total_thrust_n']:.2f}")
# series: channels in step with series["time_s"], which is not evenly spaced.
series = blob["series"]
print("\n[series channels]")
print(f" available: {sorted(series.keys())}")
time_s = series["time_s"]
if len(time_s) > 1:
gaps = [b - a for a, b in zip(time_s, time_s[1:])]
print(f" time step range: {min(gaps):.6g} .. {max(gaps):.6g} s")
thrust = series.get("total_thrust_n", [])
current = series.get("total_current_a", [])
print("\n t (s) | total_thrust_n | total_current_a")
for i in range(0, len(time_s), max(1, len(time_s) // 5)):
t = time_s[i]
th = thrust[i] if i < len(thrust) else float("nan")
cu = current[i] if i < len(current) else float("nan")
print(f" {t:6.1f} | {th:>14.2f} | {cu:>15.2f}")
# events: depletion, segment_boundary, in_rush_peak, thermal_threshold, ...
print("\n[events]")
for ev in blob["events"]:
print(
f" t={ev['t']:.1f}s {ev['type']:<18} {ev['severity']:<8} {ev['detail']}"
)