core
Core tools for registering and capability checking for the drone models.
load_params(physics, drone_model, xp=None)
¶
Load and merge physical and model-specific parameters for a drone configuration.
Reads parameters from two TOML files:
drone_models/data/params.toml— physical parameters shared across all models (mass, inertia, thrust curves, …).drone_models/<physics>/params.toml— model-specific coefficients (e.g. fitted RPY coefficients forso_rpy).
The two dicts are merged (model-specific values take precedence), and
J_inv is computed from J and added to the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
physics
|
str
|
Name of the model sub-package, e.g. |
required |
drone_model
|
str
|
Name of the drone configuration, e.g. |
required |
xp
|
ModuleType | None
|
Array API module used to convert parameter values. If |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A flat dict mapping parameter names to arrays (or scalars) in the |
dict
|
requested array namespace. Always contains at least |
dict
|
|
dict
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in drone_models/core.py
parametrize(fn, drone_model, xp=None, device=None)
¶
Parametrize a dynamics function with the default dynamics parameters for a drone model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[P, R]
|
The dynamics function to parametrize. |
required |
drone_model
|
str
|
The drone model to use. |
required |
xp
|
ModuleType | None
|
The array API module to use. If not provided, numpy is used. |
None
|
device
|
str | None
|
The device to use. If none, the device is inferred from the xp module. |
None
|
Example
from drone_models.core import parametrize
from drone_models.first_principles import dynamics
dynamics_fn = parametrize(dynamics, drone_model="cf2x_L250")
pos_dot, quat_dot, vel_dot, ang_vel_dot, rotor_vel_dot = dynamics_fn(
pos=pos, quat=quat, vel=vel, ang_vel=ang_vel, cmd=cmd, rotor_vel=rotor_vel
)
Returns:
| Type | Description |
|---|---|
Callable[P, R]
|
The parametrized dynamics function with all keyword argument only parameters filled in. |
Source code in drone_models/core.py
supports(rotor_dynamics=True)
¶
Decorator that declares which optional inputs a dynamics function supports.
Wraps the decorated function so that:
- If
rotor_dynamics=Falseand the caller passesrotor_vel, aValueErroris raised immediately. - If
rotor_dynamics=Trueand the caller omitsrotor_vel, aUserWarningis issued and the commanded value is used directly.
The decorator also attaches a __drone_model_features__ attribute to the
wrapper, which model_features reads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotor_dynamics
|
bool
|
Whether the decorated function models rotor velocity
dynamics. Set to |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
A decorator that wraps the dynamics function with the capability checks |
Callable[[F], F]
|
described above. |