Skip to content

pid

Array API PID controllers for batched simulation.

Classes:

Name Description
PID

Vectorized PID controller with optional derivative filtering.

FlightController

PID-based flight controller for batched Array API arrays.

PID

PID(xp: ModuleType, device, Kp: ArrayLike, Ki: ArrayLike | None = None, Kd: ArrayLike | None = None, dt: float = 0.01, N: float = 100.0, integral_limit: ArrayLike | None = None)

Vectorized PID controller with optional derivative filtering.

Initialize PID gains and internal state arrays.

Methods:

Name Description
reset

Reset integrator and derivative state for selected environments.

update

Compute the PID output for the current batched error.

reset

reset(env_ids=None)

Reset integrator and derivative state for selected environments.

update

update(error: ArrayLike) -> ArrayLike

Compute the PID output for the current batched error.

FlightController

FlightController(params: VehicleParams = VehicleParams(), control_mask: dict | None = None, gains: dict | None = None, limits: dict | None = None, num_envs: int = 1, device=None, *, backend: BackendName | None = None, xp: ModuleType | None = None)

Bases: ControllerBase

PID-based flight controller for batched Array API arrays.

Initialize the batched 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. Channels not in the mask are filled by the cascade.

None

gains

dict | None

Optional PID gain dictionary.

None

limits

dict | None

Optional controller-side target limits.

None

num_envs

int

Number of parallel environments represented by the batch.

1

device

Optional backend device, mainly used by Torch.

None

backend

BackendName | None

Explicit Array API backend name.

None

xp

ModuleType | None

Pre-resolved Array API namespace. Overrides backend.

None

Methods:

Name Description
randomize

Randomize gains, limits, and selected physical parameters.

reset

Reset all inner PID loops for selected environments.

update

Compute batched thrust and moments for the current target/state.

gains_to_randomization_ranges

Gains to randomization ranges.

Attributes:

Name Type Description
params VehicleParams

Vehicle parameters for the controller.

params instance-attribute

params: VehicleParams = params

Vehicle parameters for the controller.

randomize

randomize(env_ids=None, gains: dict[str, Any] | None = None, limits: dict[str, Any] | None = None, params: dict[str, Any] | None = None)

Randomize gains, limits, and selected physical parameters.

reset

reset(env_ids=None)

Reset all inner PID loops for selected environments.

update

update(target: ControllerTarget, state: ControllerState) -> ArrayLike

Compute batched thrust and moments for the current target/state.

Parameters:

Name Type Description Default

target

ControllerTarget

Desired state dict with batched Array API arrays.

required

state

ControllerState

Current state dict with pos, vel, att_euler, and ang_vel arrays of shape (num_envs, 3). cmd_acc may provide a world-frame acc target to bypass the velocity PID.

required

Returns:

Type Description
ArrayLike

Control output [thrust, roll_moment, pitch_moment, yaw_moment]

ArrayLike

with shape (num_envs, 4).

gains_to_randomization_ranges classmethod

gains_to_randomization_ranges(gains: dict | None = None, scale: float = 0.2) -> dict

Gains to randomization ranges.