跳转至

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: dict | None = None, 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

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

方法:

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

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.

参数:

名称 类型 描述 默认

target

dict

Desired state dict with keys matching the mask.

必需

state

dict

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

必需

返回:

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

参数:

名称 类型 描述 默认

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

方法:

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

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.

参数:

名称 类型 描述 默认

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.

必需

state

dict

Current state dict with the same keys.

必需

返回:

类型 描述
ndarray

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