跳转至

pid

PID controllers for flight and track control.

类:

名称 描述
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.

参数:

名称 类型 描述 默认

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

方法:

名称 描述
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.

参数:

名称 类型 描述 默认

error

ndarray | float

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

必需

返回:

类型 描述
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.

参数:

名称 类型 描述 默认

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

方法:

名称 描述
reset

Reset all inner PID loops of the flight controller.

update

Compute thrust and moments for the current target/state.

属性:

名称 类型 描述
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.

参数:

名称 类型 描述 默认

target

ndarray

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

必需

state

ndarray

Current state vector with the same ordering as target.

必需

返回:

类型 描述
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.

参数:

名称 类型 描述 默认

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

方法:

名称 描述
reset

Reset all inner PID loops of the track controller.

update

Compute track accelerations for the current target/state.

属性:

名称 类型 描述
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.

参数:

名称 类型 描述 默认

target

ndarray

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

必需

state

ndarray

Current state vector with the same ordering as target.

必需

返回:

类型 描述
ndarray

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