Flights

A flight flies your powertrain through a plan over time, instead of holding one setting. You describe how the throttle and airspeed change, and ThrustLab follows the battery as it drains. You get back thrust, current, temperatures and a summary of the whole flight. Flights need the Pro plan, whatever the number of rotors.

A flight takes the air and the wires the way a simulation does. Give the air as altitude_m or as density_kg_m3 (only one of the two). Give a wire as a gauge and a length, for example {"awg": 14, "length_cm": 10}. A flight with no project_id goes to your default project, as a simulation does.

Fly a short plan

This plan ramps a quadcopter up to 70 percent throttle over 2 seconds, then holds it for 20 seconds:

python
from thrustlab import Client

client = Client()
project = client.projects.create(name="Flights")
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 = {
    "battery_component_id": battery["id"],
    "density_kg_m3": 1.225,
    "rotor_groups": [
        {
            "label": "main",
            "count": 4,
            "motor_component_id": motor["id"],
            "propeller_component_id": prop["id"],
        }
    ],
    "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"},
}

run = client.flights.create(project_id=project["id"], **flight)
done = client.flights.wait(run["id"], timeout=600)

A rotor group in a flight has no throttle_pct, because the schedule sets the throttle. Starting at 70 percent in one step would pull a large surge of current from a rotor at standstill, so the plan ramps up first.

Write the schedule

A schedule is a list of segments. Each segment lasts duration_s seconds, or runs until the battery is empty if you set until_depleted to true. A segment holds:

  • per_group, the throttle for each rotor group, with the group's label as the key. throttle_target is 0 to 100. throttle_ramp is "step" or "linear".
  • airspeed_target, the forward speed in meters per second, up to 300. It changes in one step unless you set airspeed_ramp to "linear".
  • vertical_speed_target, the climb speed in meters per second, from -30 to 30.

If your plan comes from a log, you can give it as a table instead: set mode to "csv" and pass the table as csv_text.

Say when the flight ends

termination has two modes:

  • "fixed" runs the schedule to its end.
  • "until_depleted" is the default. It ends when the battery reaches a limit. soc_cutoff_pct is the charge to stop at, and it defaults to 20. cell_voltage_cutoff_v sets a cell voltage to stop at. max_duration_s is a safety limit of up to 3600 seconds.

A flight can have as many rotors in total as your plan allows. client.simulations.limits() tells you the number for yours.

Read the result

python
if done["status"] == "completed":
    card = done["result"]["scorecard"]
    print(card["flight_time_s"], card["energy_wh"], card["peak_current_a"])

The result holds these:

  • scorecard, the headline numbers: flight_time_s, energy_wh, range_m, peak_current_a, min_cell_voltage_v, peak_winding_temp_c and avg_efficiency.
  • samples, a list of snapshots over time. Each one is laid out like the result of a simulation, so sample["All"]["total_thrust_n"] is the total thrust at that moment.
  • series, the main quantities as lists over time.
  • events, things that happened during the flight.
  • energy, esc_settings_used and derived, where the battery's energy went, the speed controller settings each rotor group flew with, and the air density.
  • start_dip, how low the cells fell while the rotors spun up from rest. It is None on a fixed supply.

See Flight outputs for every key.

Check the length first

estimate takes the same arguments as create and returns an estimate without running anything. It gives the length of the flight and the compute units it would cost. It uses only the battery, the schedule and the end condition:

python
est = client.flights.estimate(**flight)
print(est["estimated_duration_s"], est["estimated_compute_units"])

Cancel, rename and list

cancel(run_id) stops a flight. A running flight stops at its next step and keeps what it calculated. Its result then carries run_meta with partial set to true.

update(run_id, name="...") renames a flight. list(project_id=...) lists your flights, newest first.