pid
PID controllers for flight and track control.
Classes:
| Name | Description |
|---|---|
PID |
Classic PID controller with optional derivative filtering. |
FlightController |
PID-based flight controller. |
TrackController |
PID-based track controller. |
PID
PID(Kp: Any = 0.0, Ki: Any = 0.0, Kd: Any = 0.0, dt: float = 0.01, N: float = 100.0, integral_limit: Any | None = None)
Classic PID controller with optional derivative filtering.
The internal state shape follows Kp through NumPy broadcasting. This
makes scalar and multi-axis gains behave consistently without additional
shape bookkeeping.
Initialize PID gains and internal state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Proportional gain. Its shape defines the PID state shape. |
0.0
|
|
Any
|
Integral gain broadcast against the PID state. |
0.0
|
|
Any
|
Derivative gain broadcast against the PID state. |
0.0
|
|
float
|
Controller time step. |
0.01
|
|
float
|
First-order derivative filter coefficient. |
100.0
|
|
Any | None
|
Optional elementwise clamp for the integral state. |
None
|
Methods:
| Name | Description |
|---|---|
reset |
Reset integrator and derivative state. |
update |
Compute the PID output for the current error. |
reset
reset() -> None
Reset integrator and derivative state.
update
update(error: ndarray | float) -> np.ndarray
Compute the PID output for the current error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray | float
|
Control error compatible with the PID state shape derived
from |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Combined P+I+D control output. |
FlightController
FlightController(params: VehicleParams = VehicleParams(), control_mask: list[int] = [1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0], gains: dict | None = None, limits: dict | None = None)
Bases: ControllerBase
PID-based flight controller.
Initialize the flight PID controller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VehicleParams
|
Vehicle parameters used by the controller. |
VehicleParams()
|
|
list[int]
|
Boolean-like mask indicating which target channels are provided externally and which are filled by the controller. |
[1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0]
|
|
dict | None
|
Optional PID gain dictionary. If omitted, the module-level flight defaults are used. |
None
|
|
dict | None
|
Optional command-limit configuration. Supported keys
include |
None
|
Methods:
| Name | Description |
|---|---|
reset |
Reset all inner PID loops of the flight controller. |
update |
Compute thrust and moments for the current target/state. |
Attributes:
| Name | Type | Description |
|---|---|---|
params |
VehicleParams
|
Vehicle parameters for the controller. |
control_mask |
ndarray | Tensor
|
unified control mask for target/state channels, used in update(). e.g. using 9~11 for attitude yaw control. |
params
instance-attribute
params: VehicleParams = params
Vehicle parameters for the controller.
control_mask
instance-attribute
control_mask: ndarray | Tensor = control_mask
unified control mask for target/state channels, used in update(). e.g. using 9~11 for attitude yaw control.
reset
reset() -> None
Reset all inner PID loops of the flight controller.
update
update(target: ndarray, state: ndarray) -> np.ndarray
Compute thrust and moments for the current target/state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
Desired state vector with shape |
required |
|
ndarray
|
Current state vector with the same ordering as |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Control output |
TrackController
TrackController(params: VehicleParams = VehicleParams(), control_mask: list[int] = [0, 0, 0, 1, 0, 1], gains: dict | None = None)
Bases: ControllerBase
PID-based track controller.
Initialize the track PID controller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
VehicleParams
|
Vehicle parameters used by the controller. |
VehicleParams()
|
|
list[int]
|
Boolean-like mask indicating which target channels are provided externally and which are filled by the controller. |
[0, 0, 0, 1, 0, 1]
|
|
dict | None
|
Optional PID gain dictionary. If omitted, the module-level track defaults are used. |
None
|
Methods:
| Name | Description |
|---|---|
reset |
Reset all inner PID loops of the track controller. |
update |
Compute track accelerations for the current target/state. |
Attributes:
| Name | Type | Description |
|---|---|---|
params |
VehicleParams
|
Vehicle parameters for the controller. |
control_mask |
ndarray | Tensor
|
unified control mask for target/state channels, used in update(). e.g. using 9~11 for attitude yaw control. |
params
instance-attribute
params: VehicleParams = params
Vehicle parameters for the controller.
control_mask
instance-attribute
control_mask: ndarray | Tensor = control_mask
unified control mask for target/state channels, used in update(). e.g. using 9~11 for attitude yaw control.
reset
reset() -> None
Reset all inner PID loops of the track controller.
update
update(target: ndarray, state: ndarray) -> np.ndarray
Compute track accelerations for the current target/state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
Desired state vector with shape |
required |
|
ndarray
|
Current state vector with the same ordering as |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Left and right track acceleration commands |