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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ Main `RateMapBattery` integration helpers:
`BatteryIntegrationResult` reports final state, sampled histories, delivered
energy, consumed charge, feasibility, and stop reason.

## System and Propeller Specs
## System Spec and Operating Point

| Class | Purpose |
|---|---|
| `SystemSpec` | Lumped resistance of the ESC, wires and connectors, and the ESC's optional motor-side current limit |
| `PropellerSpec` | Propeller geometry passed to the solver |
| `OperatingPoint` | Solved RPM, thrust, torque, motor/battery current, voltage, efficiency, and feasibility state |

## Propulsion Solver
Expand All @@ -90,7 +89,6 @@ point = solver.solve_operating_point(
battery_state=state, # required for RateMapBattery
system=system,
propeller=propeller,
prop_entry=prop_entry,
rho=1.225,
airspeed_mps=15.0,
throttle=0.7,
Expand Down Expand Up @@ -147,13 +145,37 @@ has no operating point (its reason is prefixed with `unit_<index>_`), or the
network cannot supply the units' current at any voltage they run at
(`bus_overload`). An infeasible point need not balance the network.

## Propeller Models

The solver takes any object that satisfies `pythrust.propeller.PropellerModel`:

| Member | Description |
|---|---|
| `diameter_m` | Propeller diameter in metres |
| `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:

```python
from pythrust.propeller import TablePropeller

propeller = TablePropeller(entry)
thrust_n, torque_nm = propeller.thrust_torque(rho=1.225, airspeed_mps=10.0, rpm=6000.0)
```

`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.propellers import PropellerDatabase
from pythrust.propeller import PropellerDatabase

db = PropellerDatabase()
db.load(dataset_dir() / "propellers" / "apc_202602", strict=False)
Expand Down
2 changes: 1 addition & 1 deletion docs/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ model, whose no-load current does not depend on speed.
### Loading Propeller Database
```python
from pythrust import dataset_dir
from pythrust.propellers import PropellerDatabase
from pythrust.propeller import PropellerDatabase

db = PropellerDatabase()
db.load(dataset_dir() / "propellers" / "apc_202602")
Expand Down
7 changes: 2 additions & 5 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ The core workflow is:
```python
from pythrust import dataset_dir
from pythrust.battery import FixedVoltageBattery
from pythrust.propellers import PropellerDatabase
from pythrust.propeller import PropellerDatabase, TablePropeller
from pythrust.propulsion import (
MotorSpec,
PropellerSpec,
PropulsionSolver,
SystemSpec,
)

prop_db = PropellerDatabase()
prop_db.load(dataset_dir() / "propellers" / "apc_202602", strict=False)
prop_entry = prop_db.get("APC_13x6.5E")
propeller = TablePropeller(prop_db.get("APC_13x6.5E"))

motor = MotorSpec(
kv_rpm_per_v=860.0,
Expand All @@ -68,15 +67,13 @@ motor = MotorSpec(
)
battery = FixedVoltageBattery(voltage_v=14.8)
system = SystemSpec(resistance_ohm=0.05)
propeller = PropellerSpec(diameter_m=0.3302, blade_count=2)

solver = PropulsionSolver()
point = solver.solve_operating_point(
motor=motor,
battery=battery,
system=system,
propeller=propeller,
prop_entry=prop_entry,
rho=1.225,
airspeed_mps=15.0,
throttle=0.7,
Expand Down
12 changes: 4 additions & 8 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The operating-point solver combines five inputs:
| Motor | `MotorSpec` | Kv, winding resistance, no-load current, current limit, optional higher-order loss terms |
| Battery | `FixedVoltageBattery` or `RateMapBattery` | Fixed pack voltage or state-dependent pack voltage from cell curves |
| System | `SystemSpec` | Lumped resistance for ESC, battery internal resistance, wiring, and connectors |
| Propeller | `PropellerSpec` + `PropellerEntry` | Geometry plus empirical aerodynamic coefficients |
| Propeller | A `PropellerModel`, such as `TablePropeller` | Thrust and torque at a given density, airspeed and RPM |
| Flight condition | `rho`, `airspeed_mps`, `throttle` | Air density, freestream speed, and commanded voltage fraction |

---
Expand Down Expand Up @@ -54,7 +54,7 @@ The operating-point solver combines five inputs:
```mermaid
flowchart LR
motor["MotorSpec"]:::motorStyle
prop["PropellerSpec + PropellerEntry"]:::propStyle
prop["PropellerModel"]:::propStyle
battery["FixedVoltageBattery or RateMapBattery"]:::batteryStyle
system["SystemSpec"]
flight["rho, airspeed, throttle"]
Expand Down Expand Up @@ -274,17 +274,16 @@ Here is a complete example showing how to load a propeller dataset, define speci
```python
from pythrust import dataset_dir
from pythrust.battery import FixedVoltageBattery
from pythrust.propellers import PropellerDatabase
from pythrust.propeller import PropellerDatabase, TablePropeller
from pythrust.propulsion import (
MotorSpec,
PropellerSpec,
PropulsionSolver,
SystemSpec,
)

db = PropellerDatabase()
db.load(dataset_dir() / "propellers" / "apc_202602", strict=False)
prop_entry = db.get("APC_13x6.5E")
propeller = TablePropeller(db.get("APC_13x6.5E"))

motor = MotorSpec(
kv_rpm_per_v=860.0,
Expand All @@ -299,15 +298,13 @@ battery = FixedVoltageBattery(
)

system = SystemSpec(resistance_ohm=0.05)
propeller = PropellerSpec(diameter_m=0.3302, blade_count=2)

solver = PropulsionSolver()
point = solver.solve_operating_point(
motor=motor,
battery=battery,
system=system,
propeller=propeller,
prop_entry=prop_entry,
rho=1.225,
airspeed_mps=15.0,
throttle=0.7,
Expand Down Expand Up @@ -343,7 +340,6 @@ point = solver.solve_operating_point(
battery_state=state,
system=system,
propeller=propeller,
prop_entry=prop_entry,
rho=1.225,
airspeed_mps=10.0,
throttle=0.6,
Expand Down
10 changes: 4 additions & 6 deletions examples/rate_map_battery_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from pythrust import dataset_dir
from pythrust.battery import BatteryState, RateMapBattery
from pythrust.motors import MotorDatabase
from pythrust.propellers import PropellerDatabase
from pythrust.propulsion import PropellerSpec, PropulsionSolver, SystemSpec
from pythrust.propeller import PropellerDatabase, TablePropeller
from pythrust.propulsion import PropulsionSolver, SystemSpec


MISSION_SEGMENTS = [
Expand All @@ -37,7 +37,7 @@ def load_propeller():
prop_entry = db.get("APC_13x6.5E")
if prop_entry is None:
raise SystemExit("Propeller 'APC_13x6.5E' not found in dataset.")
return prop_entry
return TablePropeller(prop_entry)


def load_motor():
Expand All @@ -56,8 +56,7 @@ def main():

motor = load_motor()
system = SystemSpec(resistance_ohm=0.015) # ESC and wiring; the battery model has its own resistance
prop_entry = load_propeller()
propeller = PropellerSpec(diameter_m=prop_entry.diameter_m)
propeller = load_propeller()
solver = PropulsionSolver()

total_energy_wh = 0.0
Expand All @@ -79,7 +78,6 @@ def main():
battery_state=state,
system=system,
propeller=propeller,
prop_entry=prop_entry,
rho=1.225,
airspeed_mps=segment["airspeed_mps"],
throttle=segment["throttle"],
Expand Down
23 changes: 11 additions & 12 deletions examples/select_motor_from_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from pythrust import dataset_dir
from pythrust.battery import FixedVoltageBattery
from pythrust.motors import MotorDatabase
from pythrust.propellers import PropellerDatabase
from pythrust.propulsion import PropellerSpec, PropulsionSolver, SystemSpec
from pythrust.propeller import PropellerDatabase, TablePropeller
from pythrust.propulsion import PropulsionSolver, SystemSpec

PROP_ID = "APC_13x6.5E"
BATTERY = FixedVoltageBattery(voltage_v=14.8) # 4S LiPo, nominal
Expand All @@ -49,50 +49,49 @@
SOLVER = PropulsionSolver()


def solve(motor, propeller, prop_entry, throttle):
def solve(motor, propeller, throttle):
return SOLVER.solve_operating_point(
motor=motor,
battery=BATTERY,
system=SYSTEM,
propeller=propeller,
prop_entry=prop_entry,
rho=RHO,
airspeed_mps=0.0,
throttle=throttle,
)


def hover_point(motor, propeller, prop_entry, thrust_n):
def hover_point(motor, propeller, thrust_n):
"""Return the feasible operating point that gives ``thrust_n``, or None."""

def thrust_error(throttle):
return solve(motor, propeller, prop_entry, throttle).thrust_n - thrust_n
return solve(motor, propeller, throttle).thrust_n - thrust_n

lowest_throttle = 0.05
if thrust_error(lowest_throttle) >= 0.0:
return None
throttle = brentq(thrust_error, lowest_throttle, 1.0, xtol=1e-5)
point = solve(motor, propeller, prop_entry, throttle)
point = solve(motor, propeller, throttle)
return (throttle, point) if point.is_feasible else None


def evaluate(entry, propeller, prop_entry):
def evaluate(entry, propeller):
"""Return ``(reason, result)``; ``reason`` is None when the motor passes."""
if not entry.has_current_limit:
return "no published max current", None

motor = entry.to_spec()
hover_thrust_n = (AIRFRAME_MASS_PER_MOTOR_G + entry.weight_g) * GRAVITY / 1000.0

full = solve(motor, propeller, prop_entry, 1.0)
full = solve(motor, propeller, 1.0)
if full.infeasible_reason == "current_limit":
return "over max current at full throttle", None
if not full.is_feasible:
return "no full-throttle operating point", None
if full.thrust_n < MIN_THRUST_TO_WEIGHT * hover_thrust_n:
return f"thrust-to-weight below {MIN_THRUST_TO_WEIGHT:g}", None

hover = hover_point(motor, propeller, prop_entry, hover_thrust_n)
hover = hover_point(motor, propeller, hover_thrust_n)
if hover is None:
return "no hover operating point", None
throttle, point = hover
Expand All @@ -113,7 +112,7 @@ def main():
prop_entry = prop_db.get(PROP_ID)
if prop_entry is None:
raise SystemExit(f"Propeller '{PROP_ID}' not found in dataset.")
propeller = PropellerSpec(diameter_m=prop_entry.diameter_m)
propeller = TablePropeller(prop_entry)

motor_db = MotorDatabase()
if not motor_db.load(dataset_dir() / "motors"):
Expand All @@ -128,7 +127,7 @@ def main():
rejected = Counter()
passed = []
for motor_id in motor_db.list_motors():
reason, result = evaluate(motor_db.get(motor_id), propeller, prop_entry)
reason, result = evaluate(motor_db.get(motor_id), propeller)
if reason is None:
passed.append(result)
else:
Expand Down
10 changes: 4 additions & 6 deletions pythrust/openmdao/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import openmdao.api as om

from pythrust.battery import FixedVoltageBattery
from pythrust.propellers.database import PropellerEntry
from pythrust.propeller import PropellerEntry, TablePropeller
from pythrust.propulsion import (
MotorSpec,
PropellerSpec,
PropulsionSolver,
SystemSpec,
)
Expand Down Expand Up @@ -69,7 +68,7 @@ def setup(self) -> None:
# Declare derivatives using finite-difference
self.declare_partials(of='*', wrt='*', method='fd')

def _get_specs(self, inputs: om.Vector) -> tuple[MotorSpec, FixedVoltageBattery, SystemSpec, PropellerSpec]:
def _get_specs(self, inputs: om.Vector) -> tuple[MotorSpec, FixedVoltageBattery, SystemSpec, TablePropeller]:
motor = MotorSpec(
kv_rpm_per_v=float(inputs['kv_rpm_per_v'][0]),
resistance_ohm=float(inputs['resistance_ohm'][0]),
Expand All @@ -83,14 +82,14 @@ def _get_specs(self, inputs: om.Vector) -> tuple[MotorSpec, FixedVoltageBattery,
system = SystemSpec(
resistance_ohm=float(inputs['resistance_system_ohm'][0]),
)
propeller = PropellerSpec(
propeller = TablePropeller(
self.options['prop_entry'],
diameter_m=float(inputs['diameter_m'][0]),
)
return motor, battery, system, propeller

def compute(self, inputs: om.Vector, outputs: om.Vector) -> None:
motor, battery, system, propeller = self._get_specs(inputs)
prop_entry = self.options['prop_entry']
throttle = float(inputs['throttle'][0])
rho = float(inputs['rho'][0])
airspeed_mps = float(inputs['airspeed_mps'][0])
Expand All @@ -101,7 +100,6 @@ def compute(self, inputs: om.Vector, outputs: om.Vector) -> None:
battery=battery,
system=system,
propeller=propeller,
prop_entry=prop_entry,
rho=rho,
airspeed_mps=airspeed_mps,
throttle=throttle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Propeller database and lookup utilities."""
"""Propeller models, database and lookup utilities."""

from .database import ( # noqa: F401
PropellerDataPoint,
PropellerEntry,
PropellerMetadata,
PropellerDatabase,
)
from .model import PropellerModel, TablePropeller # noqa: F401
File renamed without changes.
Loading
Loading