Simulations

A simulation tests a powertrain at one setting, the way you would on a test stand: a motor, a propeller and a battery, with the throttle held steady. You start it, wait for it to finish, and read back thrust, current, power and more.

Run one simulation

You need a motor, a propeller and a battery. A project to keep the run in is optional. The find method looks a part up by name. See Components.

python
from thrustlab import Client

client = Client()
project = client.projects.create(name="Hover tests")
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"
)

sim = client.simulations.create(
    project_id=project["id"],
    battery_component_id=battery["id"],
    airspeed_m_s=0.0,
    density_kg_m3=1.225,
    rotor_groups=[
        {
            "label": "main",
            # Four rotors need the Pro plan. On the Free plan, use "count": 1.
            "count": 4,
            "motor_component_id": motor["id"],
            "propeller_component_id": prop["id"],
            "throttle_pct": 70,
        }
    ],
)
done = client.simulations.wait(sim["id"], timeout=300)
print(done["status"])

create returns right away with the run waiting in line. wait checks every so often and gives you the finished run. Async resources explains the statuses.

What a simulation needs

  • project_id, the project that keeps the run. Leave it out and the run goes to your default project, the one Users names as default_project_id.
  • battery_component_id, the battery.
  • airspeed_m_s, the forward speed. Use 0.0 for a hover. The limit is 300.
  • The air, as altitude_m or as density_kg_m3. Use only one of the two. altitude_m is the height above sea level in meters, from -500 to 11,000, and ThrustLab works out the air density for you. density_kg_m3 is the density itself. Sea level is 1.225, and the limit is 2.0.
  • rotor_groups, a list of groups of identical rotors. Each group needs a label, a motor, a propeller and a throttle_pct from 0 to 100. count says how many rotors share those parts, and it defaults to 1.

Wires are optional. Give the wire between the battery and the speed controllers as battery_esc_wire and the wire to a motor as esc_motor_wire on its group. Each takes a gauge and a length, for example {"awg": 14, "length_cm": 10}, and ThrustLab works out its resistance. You can give the resistance yourself instead, in milliohms, as battery_esc_wire_resistance_mohm and esc_motor_wire_resistance_mohm. Use only one form for each wire. A gauge that ThrustLab does not list is refused, and the message names the gauges it knows.

How many rotors a simulation can have depends on your plan. client.simulations.limits() tells you the number for yours. A simulation can have up to 10 groups.

A quadcopter with four identical rotors is one group with count 4. That needs the Pro plan; on the Free plan, use count 1. Rotors with different propellers need separate groups.

Choose the speed controller

Every rotor runs through a model of a speed controller. Set esc_type on a group to "six_step" (the default) or "foc". To change settings of that controller, add esc_settings. Every setting is optional, and the ones you leave out are chosen for you.

python
"esc_type": "six_step",
"esc_settings": {"am32": {"timing_advance_deg": 15}, "ratings": {"current_cont_a": 40}},

A foc controller takes vesc and vesc_hardware instead of am32. A setting for the other type, or a value out of range, is refused with a message that names the field.

Set up the test bench

A run starts the rotor in a chosen state, holds the throttle, and reads the result over the last part of the hold. These arguments are all optional:

Set up the test bench
ArgumentDefaultMeaning
start"rest""rest" starts the rotor from standstill. "spinning" starts it at the expected speed.
hold_s5Seconds to hold the throttle, from 2 to 60. A run that hasn't settled is held up to 10 seconds longer.
window_s1Seconds at the end of the hold that the result is read over. At least 0.2, and at most half the hold.
state_of_charge_pct100How full the battery is at the start.
resting_voltage_v_per_cellnoneStart the battery at a voltage instead. Give this or the charge, never both.

flight_duration is an old argument. A run ignores it, and the library warns you if you pass it. Use hold_s.

Read the result

python
if done["status"] == "completed":
    result = done["result"]
    print(result["1"]["thrust_n"])
    print(result["All"]["total_thrust_n"])
    print(result["Bench"]["outcome"])

The result has one entry for each rotor, named "1", "2" and so on, so a group with count 4 gives four entries. Each holds thrust_n, rpm, current_a, efficiency_pct and many more. The "All" entry holds totals, such as total_thrust_n. The "Bench" entry says how the run went. Its outcome tells you whether the rotor settled. done["display_labels"] maps each key to a name you can show to people.

If the run failed, done["error"] says why.

Check the cost before you run

python
est = client.simulations.estimate(
    [{"count": 4, "esc_type": "six_step"}], hold_s=5, points=1
)
print(est["compute_estimate"])

estimate returns how much computing time a run should take. Set points to the number of points for a sweep.

Queue runs and cancel them

Add launch_intent="queue" to park a run without starting it. Start every parked run with client.simulations.run_queued(), or only some with run_selected([ids]).

A run that is still waiting can be canceled with cancel(sim_id). A run already running can't be, and the call raises a ConflictError. cancel_selected takes a list of run ids of any kind, and cancel_queued cancels everything waiting, or everything in one project if you pass project_id.

List your runs

python
for sim in client.simulations.list(project_id=project["id"], status="completed"):
    print(sim["id"], sim["created_at"])

The status filter takes queued, running, completed, failed or canceled.