Skip to content

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

Kp

Any

Proportional gain. Its shape defines the PID state shape.

0.0

Ki

Any

Integral gain broadcast against the PID state.

0.0

Kd

Any

Derivative gain broadcast against the PID state.

0.0

dt

float

Controller time step.

0.01

N

float

First-order derivative filter coefficient.

100.0

integral_limit

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

error

ndarray | float

Control error compatible with the PID state shape derived from Kp.

required

Returns:

Type Description
ndarray

np.ndarray: Combined P+I+D control output.

FlightController

FlightController(params: VehicleParams = VehicleParams(), control_mask: dict | None = None, gains: dict | None = None, limits: dict | None = None)

Bases: ControllerBase

PID-based flight controller.

Initialize the flight PID controller.

Parameters:

Name Type Description Default

params

VehicleParams

Vehicle parameters used by the controller.

VehicleParams()

control_mask

dict | None

Dict mask mapped to state keys, e.g. {"pos": [1, 1, 1], "att_euler": [0, 0, 1]} for position + yaw control. Channels not in the mask are filled by the cascade.

None

gains

dict | None

Optional PID gain dictionary. If omitted, the module-level flight defaults are used.

None

limits

dict | None

Optional controller-internal target limits. If omitted, limits are derived from params.

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.

params instance-attribute

params: VehicleParams = params

Vehicle parameters for the controller.

reset

reset() -> None

Reset all inner PID loops of the flight controller.

update

update(target: dict, state: dict) -> np.ndarray

Compute thrust and moments for the current target/state.

Parameters:

Name Type Description Default

target

dict

Desired state dict with keys matching the mask.

required

state

dict

Current state dict with keys: pos(3), vel(3), att_euler(3), ang_vel(3).

required

Returns:

Type Description
ndarray

np.ndarray: Control output [thrust, roll_moment, pitch_moment, yaw_moment].

TrackController

TrackController(params: VehicleParams = VehicleParams(), control_mask: dict | None = None, gains: dict | None = None)

Bases: ControllerBase

PID-based track controller.

Initialize the track PID controller.

Parameters:

Name Type Description Default

params

VehicleParams

Vehicle parameters used by the controller.

VehicleParams()

control_mask

dict | None

Dict mask mapped to target keys. Default {"vel_b": [1, 0, 0], "ang_vel": [0, 0, 1]} (u + yaw_rate externally set).

None

gains

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.

params instance-attribute

params: VehicleParams = params

Vehicle parameters for the controller.

reset

reset() -> None

Reset all inner PID loops of the track controller.

update

update(target: dict, state: dict) -> np.ndarray

Compute track accelerations for the current target/state.

Parameters:

Name Type Description Default

target

dict

Desired state dict with keys pos(3), vel_b(3), att_euler(3), ang_vel(3). Only pos[:2], vel_b[0], att_euler[2], ang_vel[2] are used.

required

state

dict

Current state dict with the same keys.

required

Returns:

Type Description
ndarray

np.ndarray: Left and right track acceleration commands [a_l, a_r].