Examples
PyThrust includes runnable examples that show the main workflows: solving against catalog data, calibrating losses from measurements, and using OpenMDAO for propulsion co-design.
Run examples from the repository root so relative data/ and docs/images/ paths resolve correctly.
Requirements
| Example | Extra dependencies |
|---|---|
calibrate_from_datasheet.py |
Core PyThrust dependencies |
select_motor.py |
openmdao |
optimize_and_plot_propulsion.py |
openmdao, matplotlib |
Install the full example environment:
Datasheet Calibration
Script:
This example identifies the lumped system resistance for a motor, propeller, battery, ESC, and wiring setup.
It uses:
| Input | Value or source |
|---|---|
| Motor | Datasheet Kv, resistance, no-load current, and current limit |
| Propeller | APC_13x6.5E from data/propellers/apc_202602 |
| Battery | 4S nominal voltage, 14.8 V |
| Test table | RPM, thrust in grams, and battery current in amps |
The output reports:
| Metric | Meaning |
|---|---|
| System resistance | Fitted SystemSpec.resistance_ohm |
| Thrust RMSE | Propeller-model thrust error against measured thrust |
| Current RMSE | Battery-current prediction error |
| Thrust R2 | Fit quality for the aerodynamic thrust prediction |
| Per-point table | Predicted vs measured thrust/current for each RPM row |
See Motor Calibration for the calibration model and equations.

Motor Selection
Script:
This example combines theoretical co-design with real motor database lookup.
Workflow:
- Load
APC_13x6.5Epropeller data. - Use OpenMDAO to find an efficient theoretical motor/propeller/throttle combination for hover.
- Load the brushless motor database from
data/motors. - Search real motors near the optimized Kv and current requirement.
- Print the top candidates sorted by winding resistance and weight.
The optimization target is a hover thrust of 4.903 N, approximately 500 gf.
Typical output includes:
| Output | Meaning |
|---|---|
| Target Kv | Ideal speed constant from the theoretical optimization |
| Target diameter | Optimized propeller diameter |
| Target hover current | Current at the optimized hover point |
| Minimum hover power | Battery power objective value |
| Top motor matches | Closest catalog motors with Kv, resistance, weight, and current limit |
See Component Databases for motor catalog format and query helpers.
Propulsion Optimization and Plotting
Script:
This example demonstrates OpenMDAO-based propulsion co-design and a parametric Kv sweep.
It performs three stages:
- Run the baseline propulsion model.
- Optimize motor Kv, propeller diameter, and throttle for a fixed hover thrust.
- Sweep Kv and re-optimize diameter/throttle at each point.
The generated plot is saved to:
The plot shows:
| Panel | Shows |
|---|---|
| Power and propeller size vs motor Kv | Hover battery power and optimized propeller diameter |
| Throttle and RPM vs motor Kv | Optimized throttle setting and shaft speed |

See Propulsion Solver for the operating-point solver used inside the OpenMDAO component.