跳转至

pid

Torch-based PID controllers for batched simulation.

类:

名称 描述
PID

Vectorized PID controller for multiple environments.

FlightController

PID flight controller (batched).

TrackController

PID track controller (batched).

PID

PID(Kp: Tensor, Ki: Tensor | None = None, Kd: Tensor | None = None, dt: float = 0.01, N: float = 100.0, integral_limit: Tensor | None = None, num_envs: int = 1)

Vectorized PID controller for multiple environments.

Initialize PID gains and state tensors.

参数:

名称 类型 描述 默认

Kp

Tensor

Proportional gain tensor with a leading environment dimension.

必需

Ki

Tensor | None

Integral gain tensor with the same shape as Kp.

None

Kd

Tensor | None

Derivative gain tensor with the same shape as Kp.

None

dt

float

Controller time step.

0.01

N

float

First-order derivative filter coefficient.

100.0

integral_limit

Tensor | None

Optional clamp applied elementwise to the integral state.

None

num_envs

int

Number of environments.

1

方法:

名称 描述
reset

Reset PID state for selected environments.

update

Compute PID output for the given error tensor.

reset

reset(env_ids: slice | Sequence[int] | Tensor) -> None

Reset PID state for selected environments.

参数:

名称 类型 描述 默认

env_ids

slice | Sequence[int] | Tensor

Indices or slice selecting which environments to reset.

必需

update

update(error: Tensor) -> torch.Tensor

Compute PID output for the given error tensor.

参数:

名称 类型 描述 默认

error

Tensor

Batched control error tensor compatible with the internal state shape determined from Kp.

必需

返回:

类型 描述
Tensor

torch.Tensor: 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, num_envs: int = 1, device: str | device = 'cpu')

Bases: ControllerBase

PID flight controller (batched).

Initialize the batched flight PID controller.

方法:

名称 描述
randomize

Randomize configured PID gains and command limits for selected environments.

reset

Reset PID loops for selected environments.

update

Update controller.

属性:

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

randomize

randomize(env_ids=None, gains=None, limits=None)

Randomize configured PID gains and command limits for selected environments.

reset

reset(env_ids)

Reset PID loops for selected environments.

update

update(target: Tensor, state: Tensor) -> torch.Tensor

Update controller.

参数:

名称 类型 描述 默认

target

Tensor

(N, 12) desired [x, y, z, vx, vy, vz, roll, pitch, yaw, wx, wy, wz]

必需

state

Tensor

(N, 12) current state same ordering.

必需

返回:

类型 描述
Tensor

torch.Tensor: Tensor of shape (N, 4): [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, num_envs: int = 1, device: str | device = 'cpu')

Bases: ControllerBase

PID track controller (batched).

Initialize the batched track controller.

方法:

名称 描述
randomize

Randomize configured PID gains for all or selected environments.

reset

Reset PID loops for selected environments.

update

Update controller.

属性:

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

randomize

randomize(env_ids=None, gains=None)

Randomize configured PID gains for all or selected environments.

reset

reset(env_ids)

Reset PID loops for selected environments.

update

update(target: Tensor, state: Tensor) -> torch.Tensor

Update controller.

参数:

名称 类型 描述 默认

target

Tensor

(N, 6) desired [x, y, yaw, u, v, r]

必需

state

Tensor

(N, 6) current state same ordering.

必需

返回:

类型 描述
Tensor

torch.Tensor: (N, 2) left/right acceleration commands.