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: 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

params

VehicleParams

Vehicle parameters used by the controller.

VehicleParams()

control_mask

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]

gains

dict | None

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

None

limits

dict | None

Optional command-limit configuration. Supported keys include vel_cmd, vel_error and att_cmd. Any key can be set to None to disable that clamp.

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

target

ndarray

Desired state vector with shape (12,) ordered as [x, y, z, vx, vy, vz, roll, pitch, yaw, wx, wy, wz].

required

state

ndarray

Current state vector with the same ordering as target.

required

Returns:

Type Description
ndarray

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

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

params

VehicleParams

Vehicle parameters used by the controller.

VehicleParams()

control_mask

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]

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.

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

target

ndarray

Desired state vector with shape (6,) ordered as [x, y, yaw, u, v, r].

required

state

ndarray

Current state vector with the same ordering as target.

required

Returns:

Type Description
ndarray

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