Core¶
drone_controllers.core
¶
Core functionalities for controller parametrization and registration.
ControllerParams
¶
Protocol for controller parameters.
load(drone_model)
staticmethod
¶
Load the parameters from the config file.
parametrize(fn, drone_model)
¶
Parametrize a controller function with the default controller parameters for a drone model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
Callable[P, R]
|
The controller function to parametrize. |
required |
drone_model
|
str
|
The drone model to use. |
required |
Example
from drone_models.controller import parametrize from drone_models.controller.mellinger import state2attitude controller_fn = parametrize(state2attitude, drone_model="cf2x_L250") command_rpyt, int_pos_err = controller_fn( ... pos=pos, ... quat=quat, ... vel=vel, ... ang_vel=ang_vel, ... cmd=cmd, ... ctrl_errors=(int_pos_err,), ... ctrl_freq=100, ... )
Returns:
Type | Description |
---|---|
Callable[P, R]
|
The parametrized controller function with all keyword argument only parameters filled in. |
register_controller_parameters(params)
¶
Register the default controller parameters for this controller.
Warning
The controller parameters must be a named tuple with a function load
that takes in the
drone model name and returns an instance of itself, or a class that implements the
ControllerParams protocol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
ControllerParams | type[ControllerParams]
|
The controller parameter type. |
required |
Returns:
Type | Description |
---|---|
Callable[[Callable[P, R]], Callable[P, R]]
|
A decorator function that registers the parameters and returns the function unchanged. |
The core module provides the foundational functionality for controller parametrization and registration.
Key Concepts¶
Controller Parametrization¶
The parametrize
function allows you to automatically configure controllers with parameters for specific drone models:
from drone_controllers import parametrize
from drone_controllers.mellinger import state2attitude
# Get a controller configured for the Crazyflie 2.x
controller = parametrize(state2attitude, "cf2x_L250")
# Use the controller (all parameters are automatically filled in)
rpyt, pos_err = controller(pos, quat, vel, ang_vel, cmd)
Parameter Registry¶
Controllers register their parameter types using the @register_controller_parameters
decorator:
@register_controller_parameters(MyControllerParams)
def my_controller(pos, vel, *, param1, param2, param3):
# Controller implementation
pass
ControllerParams Protocol¶
All controller parameter classes must implement the ControllerParams
protocol:
load(drone_model: str)
- Load parameters for a specific drone model_asdict()
- Convert parameters to a dictionary
Example Usage¶
from functools import partial
from drone_controllers.mellinger.params import StateParams
# Manual parameter loading
params = StateParams.load("cf2x_L250")
controller = partial(state2attitude, **params._asdict())
# Equivalent to using parametrize
from drone_controllers import parametrize
controller = parametrize(state2attitude, "cf2x_L250")