Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ Operating instructions for coding agents. Keep this file short and concrete.
- Lint / Typecheck: none configured
- Docs: `mkdocs build --strict`
- Examples: `PYTHONPATH=. python examples/<script>.py`
- **Layout:** Source: `pythrust/` | Tests: `tests/` | Docs: `docs/` | Examples: `examples/` | Tools: `scripts/`
- **Layout:** Source: `pythrust/` | Tests: `tests/` | Docs: `docs/` | Examples: `examples/` | Test data: `tests/data/`
- **Conventions:**
- Conventional Commits: `feat(scope):`, `fix(scope):`, `refactor!:` with a `BREAKING CHANGE:` footer for API breaks.
- Work on `feat/...` or `fix/...` branches and merge to `main` through a pull request; never commit to `main` directly.
- Pull request titles use the same Conventional Commits format. Squash-merge, so the commit on `main` carries the PR title, not `Merge pull request #...`.
- Release: bump `__version__` in `pythrust/__init__.py` in a separate `chore(release): bump version to X.Y.Z` commit. Publishing a GitHub release uploads to PyPI.
- SI units, with the unit as a field-name suffix (`resistance_ohm`, `diameter_m`, `kv_rpm_per_v`).
- Solvers return an infeasible `OperatingPoint` with `infeasible_reason`; they do not raise for infeasible operating points.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

## About

PyThrust is an open-source framework for electric propulsion system analysis, co-design, and parameter optimization in UAV applications. It can be used for multidisciplinary design optimization (MDO) within OpenMDAO. It includes steady-state performance solvers and database search tools to map theoretical designs onto real-world brushless motor and propeller catalogs.
PyThrust is an open-source framework for electric propulsion system analysis, co-design, and parameter optimization in UAV applications. It can be used for multidisciplinary design optimization (MDO) within OpenMDAO. It includes steady-state performance solvers that couple motor, propeller and battery models, with readers for manufacturer propeller data.

## Feature Visuals

| Empirical Propeller Database | Rate-Map Battery Mission |
| APC Propeller Coefficients | Rate-Map Battery Mission |
| :---: | :---: |
| ![Empirical Propeller Database](docs/images/propeller_coefficients.png) | ![Rate-Map Battery Mission](docs/images/rate_map_battery_mission.png) |
| ![APC propeller coefficients](docs/images/propeller_coefficients.png) | ![Rate-Map Battery Mission](docs/images/rate_map_battery_mission.png) |

## Documentation

Expand All @@ -29,7 +29,7 @@ Key sections:
- [Propulsion Solver](https://setuav.github.io/PyThrust/usage/)
- [Examples](https://setuav.github.io/PyThrust/examples/)
- [Propulsion and Battery Theory](https://setuav.github.io/PyThrust/theory/)
- [Component Databases](https://setuav.github.io/PyThrust/databases/)
- [Data Files](https://setuav.github.io/PyThrust/data_files/)

## License

Expand Down
82 changes: 19 additions & 63 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This page summarizes the main public classes and helpers. For implementation details, see the source modules under `pythrust/`.

## Propulsion Models
## Motor Model

`MotorSpec` defines brushless motor electrical parameters:
`pythrust.motor.MotorSpec` defines brushless motor electrical parameters:

| Field | Unit | Description |
|---|---:|---|
Expand Down Expand Up @@ -155,85 +155,41 @@ The solver takes any object that satisfies `pythrust.propeller.PropellerModel`:
| `max_advance_ratio` | Advance ratio up to which the model is expected to give thrust; the RPM search starts there |
| `thrust_torque(rho, airspeed_mps, rpm)` | Thrust in N and shaft torque in N m; zero torque where the model has no data |

`TablePropeller` is the model for tabulated coefficients. It interpolates a
`PropellerEntry` from the database:
`TablePropeller` is the model for tabulated coefficients. It holds a diameter
and, for each RPM band, a list of `PropellerDataPoint(j, ct, cp)` sorted by
advance ratio. `pythrust.io.read_apc` builds one from an APC performance file:

```python
from pythrust.propeller import TablePropeller
from pythrust.io import read_apc

propeller = TablePropeller(entry)
propeller = read_apc("PER3_13x65E.dat")
thrust_n, torque_nm = propeller.thrust_torque(rho=1.225, airspeed_mps=10.0, rpm=6000.0)
ct, cp = propeller.get_coefficients(rpm=6000.0, advance_ratio=0.3)
```

`TablePropeller(entry, diameter_m=0.30)` scales the tabulated propeller to
another diameter with its coefficients unchanged: a geometrically similar
propeller, without the Reynolds number effects of the size change.

## Propeller Database

`PropellerDatabase` loads JSON metadata and CSV performance tables:

```python
from pythrust import dataset_dir
from pythrust.propeller import PropellerDatabase

db = PropellerDatabase()
db.load(dataset_dir() / "propellers" / "apc_202602", strict=False)
entry = db.get("APC_13x6.5E")
ct, cp = entry.get_coefficients(rpm=5000.0, advance_ratio=0.4)
```

Main helpers:

| Method | Description |
|---|---|
| `load(data_dir, strict=False)` | Load every propeller JSON file in a directory |
| `load_entry(json_path, data_dir=None, strict=False)` | Load one propeller entry |
| `list_propellers()` | Return sorted propeller IDs |
| `get(prop_id)` | Return a `PropellerEntry` by ID |
| `find_by_size(diameter_in, pitch_in, blade_count=2, tolerance=0.5)` | Find the closest size match |
| `get_interpolated_coefficients(...)` | Fetch `Ct` and `Cp` through a size lookup |

## Motor Database

`MotorDatabase` loads brushless motor JSON files and converts catalog entries into solver specs:

```python
from pythrust import dataset_dir
from pythrust.motors import MotorDatabase

db = MotorDatabase()
db.load(dataset_dir() / "motors")
motor_entry = db.get("SunnySky_X2826_KV550_3-4S")
motor = motor_entry.to_spec()
```

Main helpers:

| Method | Description |
| Member | Description |
|---|---|
| `load(data_dir)` | Recursively load motor JSON files |
| `load_entry(json_path)` | Load one motor JSON file |
| `list_motors()` | Return sorted motor IDs |
| `get(motor_id)` | Return a `MotorEntry` by ID |
| `search(...)` | Filter by Kv, current, and weight constraints |
| `TablePropeller(diameter_m, data_by_rpm)` | Build a table from your own data |
| `scaled(diameter_m)` | The propeller at another diameter with its coefficients unchanged: a geometrically similar propeller, without the Reynolds number effects of the size change |
| `get_coefficients(rpm, advance_ratio)` | Interpolated `Ct` and `Cp`; zero past a band's largest advance ratio |
| `rpm_levels` | Sorted RPM bands |

`MotorEntry.has_current_limit` is `False` for catalog entries without a maximum
current (`max_current` of `0`); `to_spec()` gives those motors an infinite
`current_max_a`.
See [Data Files](data_files.md) for what `read_apc` takes from the file.

## OpenMDAO

`pythrust.openmdao.PropulsionComponent` wraps `PropulsionSolver` as an `ExplicitComponent` for optimization models.

Its `propeller` option is a `TablePropeller`, for example `PropulsionComponent(propeller=read_apc("PER3_13x65E.dat"))`.

Inputs include motor parameters, fixed battery voltage, system resistance, propeller diameter, throttle, density, and airspeed. Outputs include RPM, thrust, torque, battery current, battery power, motor current, motor voltage, and feasibility.

!!! warning "Inputs are not catalog parts"
!!! warning "Inputs are not real parts"
The motor inputs are independent: changing `kv_rpm_per_v` leaves
`resistance_ohm` and `no_load_current_a` unchanged, although a real motor
with a lower Kv has a higher resistance. `diameter_m` scales the
`prop_entry` propeller with unchanged coefficients, which describes a
`propeller` option's table with unchanged coefficients, which describes a
geometrically similar propeller that may not exist. An optimizer that
varies Kv or diameter therefore drifts toward low Kv and large diameter.
Use catalog values as fixed inputs, or check any optimum against real
Use datasheet values as fixed inputs, or check any optimum against real
motors and propellers.
63 changes: 63 additions & 0 deletions docs/data_files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Data Files

PyThrust ships no motor or propeller catalogs. You supply the data for the
components you analyze: propeller tables from the manufacturer's files, motor
constants from a datasheet or a test.

## Propellers: APC Performance Files

APC publishes a performance file for each of its propellers at
<https://www.apcprop.com/technical-information/performance-data/>. The files
are named `PER3_<size>.dat`, for example `PER3_13x65E.dat` for the 13x6.5E.

`pythrust.io.read_apc` reads one file into a `TablePropeller`:

```python
from pythrust.io import read_apc

propeller = read_apc("PER3_13x65E.dat")
print(propeller.diameter_m) # 0.3302
print(propeller.rpm_levels) # [1000.0, 2000.0, ..., 18000.0]
```

The reader takes from the file:

| Item | Use |
|---|---|
| Size in the first line, such as `13x6.5E` | Diameter in inches, converted to metres |
| `PROP RPM = ...` headers | One table band per RPM |
| `J`, `Ct` and `Cp` columns | Advance ratio and the thrust and power coefficients |

Rows with a negative `Ct` or `Cp`, where the propeller windmills, are left
out: each RPM band ends at the last advance ratio with positive thrust and
power. A file without a size in its first line, or without data rows, raises
`ValueError`.

APC computes these tables with its own blade-element software; they are not
wind-tunnel measurements.

## Motors: Datasheet Values

Write the motor constants into a `MotorSpec`:

```python
from pythrust.motor import MotorSpec

motor = MotorSpec(
kv_rpm_per_v=860.0, # Kv
resistance_ohm=0.0258, # winding resistance Rm
no_load_current_a=1.3, # no-load current Io
current_max_a=65.0, # maximum continuous current
)
```

Datasheets give the no-load current at a stated voltage, usually 10 V. The
first-order model treats it as constant. For a motor without a published
current limit, pass `current_max_a=math.inf`; the solver then never reports
`current_limit`.

## Batteries: Cell Datasets

`RateMapBattery.from_json(...)` reads a cell dataset. The format is described
in [Battery Model](battery_model.md); `pythrust.dataset_dir()` holds the example
cell `batteries/example_liion_cell.json`.
94 changes: 0 additions & 94 deletions docs/databases.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ The CI workflow runs the test suite on Python 3.10, 3.11, and 3.12.
```bash
PYTHONPATH=. python examples/rate_map_battery_point_states.py
PYTHONPATH=. python examples/rate_map_battery_mission.py
PYTHONPATH=. python examples/select_motor_from_database.py
```

See [Examples](examples.md) for a user-facing walkthrough of each script.
Expand Down
47 changes: 6 additions & 41 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Examples

PyThrust includes runnable examples that show the main workflows: solving
propulsion models, inspecting rate-map battery behavior, and selecting catalog
motors. They load the bundled datasets through
`pythrust.dataset_dir()`.
propulsion models and inspecting rate-map battery behavior. They load the
example battery cell through `pythrust.dataset_dir()`.

```bash
PYTHONPATH=. python examples/<example_name>.py
Expand All @@ -15,7 +14,6 @@ PYTHONPATH=. python examples/<example_name>.py
|---|---|
| `rate_map_battery_point_states.py` | Core PyThrust dependencies |
| `rate_map_battery_mission.py` | Core PyThrust dependencies |
| `select_motor_from_database.py` | Core PyThrust dependencies |

Install PyThrust from the repository root:

Expand Down Expand Up @@ -54,12 +52,13 @@ validates the battery model surface before mission or solver integration.
Script:

```bash
PYTHONPATH=. python examples/rate_map_battery_mission.py
PYTHONPATH=. python examples/rate_map_battery_mission.py [PER3_13x65E.dat]
```

This example couples `RateMapBattery` to `PropulsionSolver` over a short
segment schedule with the `SunnySky_X2820_KV860_V3_3-4S` catalog motor and the
`APC_13x6.5E` propeller. Each segment solves the propulsion operating point
segment schedule with a SunnySky X2820 KV860 motor, entered from its datasheet,
and the APC 13x6.5E propeller. The argument is an APC performance file; without
it the example uses the copy kept in `tests/data/`. Each segment solves the propulsion operating point
using the current battery state, reports thrust, pack current and voltage, then
integrates state of charge from the solved battery current.

Expand All @@ -73,37 +72,3 @@ It demonstrates:
| Advance state | Use `integrate_current(...)` to update SoC and delivered energy for the next segment |

![Rate-map battery mission simulation](images/rate_map_battery_mission.png)

## Motor Selection

Script:

```bash
PYTHONPATH=. python examples/select_motor_from_database.py
```

This example picks catalog motors for a hover requirement with one catalog
propeller, `APC_13x6.5E`, on a `14.8 V` battery.

For every motor in the catalog it solves the full-throttle and hover operating
points. A motor passes when:

| Rule | Meaning |
|---|---|
| Published current limit | Motors whose catalog entry has no maximum current are skipped |
| Current at full throttle | The full-throttle motor current stays within the motor's maximum current |
| Thrust-to-weight | Full-throttle thrust is at least `2` times the hover thrust |

The hover thrust is `400 g` of airframe per rotor plus the motor's own weight,
so a heavier motor also has to lift itself. Passing motors are ranked by the
battery power they draw in hover. Catalogs list one frame in several windings,
so the table shows the best winding of each frame, taking motors of one
manufacturer with the same weight as one frame.

The output reports how many motors each rule rejected and, for the best frames,
hover power, hover efficiency in g/W, hover throttle and current, the
full-throttle current against the motor's limit, and the thrust-to-weight
ratio.

See [Component Databases](databases.md) for motor catalog format and query
helpers.
Loading
Loading