Skip to content

mdp

Modules:

Name Description
actions
commands
events
observations
rewards
terminations

Classes:

Name Description
FlightActionMapper

Map batched normalized actions into controller targets, wrench, or RPM.

FlightMappingLimits

Per-channel limits used when mapping normalized actions to targets.

Mixer

Map thrust and moment demands to rotor commands.

FlightController

PID flight controller (batched).

VehicleParams

LAV2 vehicle parameters.

RotorDynamics

Batched rotor dynamics model.

TrackDynamics

Batched track dynamics model.

ControlAction

Body torque control action term.

ControlActionCfg

See :class:ControlAction for more details.

TrackControlAction

Track force control action term.

TrackControlActionCfg

See :class:ControlAction for more details.

UniformPoseCommandGlobal

Command generator that generates pose commands containing a 3-D position and heading.

UniformPoseCommandGlobalCfg

Configuration for the uniform 3D-pose command generator.

UniformVelocityGlobalCommand

Command generator that generates a velocity command with uniform distribution.

UniformVelocityGlobalCommandCfg

Configuration for the uniform velocity command generator.

UniformBimodalVelocityCommand

Bimodal velocity command generator with a discrete mode indicator (4+1).

UniformBimodalVelocityCommandCfg

Configuration for the bimodal velocity command generator (flight vs ground).

Functions:

Name Description
randomize_action_term_attr

Randomize a selected action-term attribute.

randomize_controller_params

Randomize controller gains and command limits attached to an action term.

randomize_mixer_params

Randomize mixer parameters attached to an action term.

randomize_rotor_params

Randomize rotor parameters attached to an action term.

target_pos_b

Position of target in body frame.

root_euler_w

Euler angles of the root in world frame.

lin_vel_l2

Penalize base linear velocity using L2 squared kernel.

ang_vel_l2

Penalize base angular velocity using L2 squared kernel.

pos_error_l2

Penalize asset pos from its target pos using L2 squared kernel.

pos_error_tanh

Penalize asset pos from its target pos using tanh kernel.

yaw_error_l2

Penalize heading error from target heading using L2 squared kernel.

yaw_error_tanh

Penalize heading error from target heading using tanh kernel.

track_lin_vel_z_exp

Reward tracking of linear velocity commands (z axis) using exponential kernel.

track_lin_vel_exp

Reward tracking of linear velocity commands using exponential kernel.

track_yaw_vel_exp

Reward tracking of angular velocity commands (yaw) using exponential kernel.

bimodal_action_tanh

Penalize bimodal actions using tanh kernel.

bimodal_height_tanh

Penalize bimodal height using tanh kernel.

contact_impulse

Penalize excessive contact impulse (rate of change of contact forces).

bimodal_contacts

Penalize contacts when switching from flight to ground mode.

died

Termination condition based on the robot's height.

FlightActionMapper

FlightActionMapper(control_mode: str, params: VehicleParams = VehicleParams(), limits: FlightMappingLimits = FlightMappingLimits(), *, num_envs: int = 1, device: str | device = 'cpu')

Map batched normalized actions into controller targets, wrench, or RPM.

Initialize a batched Torch flight action mapper for the selected mode.

Methods:

Name Description
map_action

Map a normalized batched action into RPM commands and intermediates.

Attributes:

Name Type Description
requires_controller bool

Whether this mode needs a controller target expansion step.

requires_controller property

requires_controller: bool

Whether this mode needs a controller target expansion step.

map_action

map_action(action: Tensor, mixer: Mixer, *, state: Tensor | None = None, flight_controller: ControllerBase | None = None) -> FlightMappingResult

Map a normalized batched action into RPM commands and intermediates.

FlightMappingLimits dataclass

FlightMappingLimits(vel_limits: tuple[float, float, float] = (5.0, 5.0, 5.0), att_limits: tuple[float, float, float] = (1.0, 1.0, math.pi), br_limits: tuple[float, float, float] = (2.0, 2.0, 2.0))

Per-channel limits used when mapping normalized actions to targets.

Mixer

Mixer(params: VehicleParams = VehicleParams(), num_envs: int = 1, device: str | device = 'cpu')

Map thrust and moment demands to rotor commands.

Note

电机推力分配: 电机1 = 推力 - 横滚(roll) + 俯仰(pitch) + 偏航(yaw) 电机2 = 推力 + 横滚(roll) - 俯仰(pitch) + 偏航(yaw) 电机3 = 推力 + 横滚(roll) + 俯仰(pitch) - 偏航(yaw) 电机4 = 推力 - 横滚(roll) - 俯仰(pitch) - 偏航(yaw)

Initialize the torch mixer with vehicle parameters and device.

Methods:

Name Description
randomize

Randomize mixer runtime parameters from nominal values.

apply_thrust_curve

Apply thrust curve to normalized thrust command.

calculate_rotor_commands

Allocate thrust and moments into rotor speeds.

randomize

randomize(env_ids=None, randomization=None)

Randomize mixer runtime parameters from nominal values.

apply_thrust_curve

apply_thrust_curve(normalized_thrust: Tensor, mode: int = 1) -> torch.Tensor

Apply thrust curve to normalized thrust command.

References

cmd_ctatt: https://github.com/PX4/PX4-Autopilot/blob/e5a483e4b71ab4b994cb0121fe28992d8ce0c8cd/src/modules/mc_att_control/mc_att_control_main.cpp#L111-L137 cmd_ctbr: https://github.com/PX4/PX4-Autopilot/blob/e5a483e4b71ab4b994cb0121fe28992d8ce0c8cd/src/modules/mc_rate_control/MulticopterRateControl.cpp#L156-L179

Parameters:

Name Type Description Default

normalized_thrust

Tensor

Normalized thrust command [-1, 1]. Shape: arbitrary, e.g. (num_envs, n_motors). Applied elementwise.

required

mode

int

Thrust curve mode.

1

Returns:

Type Description
Tensor

torch.Tensor: Thrust in Newtons with the same shape as normalized_thrust.

Raises:

Type Description
NotImplementedError

If the specified mode is not implemented.

calculate_rotor_commands

calculate_rotor_commands(control: Tensor) -> torch.Tensor

Allocate thrust and moments into rotor speeds.

Parameters:

Name Type Description Default

control

Tensor

Desired total thrust and roll/pitch/yaw moments. Shape: (num_envs, 4)

required

Returns:

Type Description
Tensor

torch.Tensor: The amplitude of each motor's rotational speed (calculated using sqrt(clip(rpm_sq))). Shape: (num_envs, 4)

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.

Methods:

Name Description
randomize

Randomize configured PID gains and command limits for selected environments.

reset

Reset PID loops for selected environments.

update

Update controller.

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.

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.

Parameters:

Name Type Description Default

target

Tensor

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

required

state

Tensor

(N, 12) current state same ordering.

required

Returns:

Type Description
Tensor

torch.Tensor: Tensor of shape (N, 4): [thrust, roll_moment, pitch_moment, yaw_moment].

VehicleParams dataclass

VehicleParams(rho: float = 1.184, g: float = 9.81, sim_dt: float = 0.01, step_dt: float = 0.01, randomization: dict[str, dict[str, tuple[float, float]]] = dict(), mass: float = 2.1, inertia: list = (lambda: np.diag([0.11, 0.108, 0.215]).tolist())(), diameter: float = 0.476, Cdx: float = 0.5, x: float = 0.0952, y: float = 0.114423, h: float = -0.0125, alpha: float = 8 * (np.pi / 180), r_p: float = 0.0775, J_m: float = 1e-05, Ct: float = 0.666, Cq: float = 0.0716, theta0: float = 14.6 * (np.pi / 180), thetaTip: float = 6.8 * (np.pi / 180), lock: float = 0.6051, max_rpm: float = 10000.0, init_rpm: float = -1.0, rotor_rpm_rate_limit: float = 50000.0, tau_f: float = 0.01, tau_m: float = 0.05, tau_up: float = -1.0, tau_down: float = -1.0, r_w: float = 0.0285, n_w: int = 4, B: float = 0.136, L: float = 0.23, h_cg: float = 0.078, f: float = 0.01, mu0: float = 0.8, K: float = 20, track_cmd_rate_limit: float = 100, min_throttle_manual: float = 0.08, min_throttle: float = 0.12, max_throttle: float = 1.0, hover_throttle: float = -1)

LAV2 vehicle parameters.

Methods:

Name Description
__post_init__

Calculate derived parameters.

Attributes:

Name Type Description
rho float

空气密度 (kg/m^3)

g float

重力加速度 (m/s^2)

sim_dt float

仿真步长 (s)

step_dt float

控制步长 (s)

randomization dict[str, dict[str, tuple[float, float]]]

运行时参数随机化配置,按组件 (e.g. rotor/mixer) 划分为多个 scale 相对范围子表

mass float

质量 (kg)

inertia list

惯性矩阵 (kg*m^2)

diameter float

直径 (m)

Cdx float

空气阻力系数

x float

x方向臂长 (m)

y float

y方向臂长 (m)

h float

重心高度 (m)

alpha float

y方向涵道外倾角度 (rad)

r_p float

螺旋桨半径 (m)

J_m float

电机转动惯量 (kg*m^2)

Ct float

推力系数

Cq float

扭矩系数

theta0 float

桨根角 (rad)

thetaTip float

桨尖角 (rad)

theta1 float

桨叶扭转角 (rad)

lock float

Lock number

max_rpm float

最大转速

init_rpm float

初始转速

rotor_rpm_rate_limit float

旋翼转速变化率限制 (rpm/s)

cT float

转速平方到推力增益 (N/(rpm^2))

cM float

转速平方到扭矩增益 (N*m/(rpm^2))

tau_f float

电机滤波时间常数 (s)

tau_m float

兼容保留的电机时间常数 (s)

tau_up float

电机升速时间常数 (s)

tau_down float

电机降速时间常数 (s)

r_w float

主动轮半径 (m)

n_w int

负重轮个数

B float

两侧履带中心距 (m)

L float

履带节点接地部分长度 (m)

h_cg float

车体质心高度 (m)

f float

滚动阻力系数(以干燥混凝土路面或沥青路面为例)

mu0 float

滑转率为1时的摩擦系数

K float

依赖于土壤黏聚系数和摩擦特性的常数

track_cmd_rate_limit float

履带主动轮指令变化率限制 (rad/s^2)

min_throttle_manual float

MPC_MANTHR_MIN: Minimum manual thrust (0.0 - 1.0). Default: 0.08

min_throttle float

MPC_THR_MIN: Minimum thrust in auto thrust control (0.05 - 1.0). Default: 0.12

max_throttle float

MPC_THR_MAX: Maximum thrust in auto thrust control (0.0 - 1.0). Default: 1.0

hover_throttle float

MPC_THR_HOVER: Hover throttle manual (0.1 - 0.8). Default: 0.5 in PX4, calculated hover throttle in LAV2

rho class-attribute instance-attribute

rho: float = 1.184

空气密度 (kg/m^3)

g class-attribute instance-attribute

g: float = 9.81

重力加速度 (m/s^2)

sim_dt class-attribute instance-attribute

sim_dt: float = 0.01

仿真步长 (s)

step_dt class-attribute instance-attribute

step_dt: float = 0.01

控制步长 (s)

randomization class-attribute instance-attribute

randomization: dict[str, dict[str, tuple[float, float]]] = field(default_factory=dict)

运行时参数随机化配置,按组件 (e.g. rotor/mixer) 划分为多个 scale 相对范围子表

mass class-attribute instance-attribute

mass: float = 2.1

质量 (kg)

inertia class-attribute instance-attribute

inertia: list = field(default_factory=lambda: tolist())

惯性矩阵 (kg*m^2)

diameter class-attribute instance-attribute

diameter: float = 0.476

直径 (m)

Cdx class-attribute instance-attribute

Cdx: float = 0.5

空气阻力系数

x class-attribute instance-attribute

x: float = 0.0952

x方向臂长 (m)

y class-attribute instance-attribute

y: float = 0.114423

y方向臂长 (m)

h class-attribute instance-attribute

h: float = -0.0125

重心高度 (m)

alpha class-attribute instance-attribute

alpha: float = 8 * (pi / 180)

y方向涵道外倾角度 (rad)

r_p class-attribute instance-attribute

r_p: float = 0.0775

螺旋桨半径 (m)

J_m class-attribute instance-attribute

J_m: float = 1e-05

电机转动惯量 (kg*m^2)

Ct class-attribute instance-attribute

Ct: float = 0.666

推力系数

Cq class-attribute instance-attribute

Cq: float = 0.0716

扭矩系数

theta0 class-attribute instance-attribute

theta0: float = 14.6 * (pi / 180)

桨根角 (rad)

thetaTip class-attribute instance-attribute

thetaTip: float = 6.8 * (pi / 180)

桨尖角 (rad)

theta1 class-attribute instance-attribute

theta1: float = field(init=False)

桨叶扭转角 (rad)

lock class-attribute instance-attribute

lock: float = 0.6051

Lock number

max_rpm class-attribute instance-attribute

max_rpm: float = 10000.0

最大转速

init_rpm class-attribute instance-attribute

init_rpm: float = -1.0

初始转速

rotor_rpm_rate_limit class-attribute instance-attribute

rotor_rpm_rate_limit: float = 50000.0

旋翼转速变化率限制 (rpm/s)

cT class-attribute instance-attribute

cT: float = field(init=False)

转速平方到推力增益 (N/(rpm^2))

cM class-attribute instance-attribute

cM: float = field(init=False)

转速平方到扭矩增益 (N*m/(rpm^2))

tau_f class-attribute instance-attribute

tau_f: float = 0.01

电机滤波时间常数 (s)

tau_m class-attribute instance-attribute

tau_m: float = 0.05

兼容保留的电机时间常数 (s)

tau_up class-attribute instance-attribute

tau_up: float = -1.0

电机升速时间常数 (s)

tau_down class-attribute instance-attribute

tau_down: float = -1.0

电机降速时间常数 (s)

r_w class-attribute instance-attribute

r_w: float = 0.0285

主动轮半径 (m)

n_w class-attribute instance-attribute

n_w: int = 4

负重轮个数

B class-attribute instance-attribute

B: float = 0.136

两侧履带中心距 (m)

L class-attribute instance-attribute

L: float = 0.23

履带节点接地部分长度 (m)

h_cg class-attribute instance-attribute

h_cg: float = 0.078

车体质心高度 (m)

f class-attribute instance-attribute

f: float = 0.01

滚动阻力系数(以干燥混凝土路面或沥青路面为例)

mu0 class-attribute instance-attribute

mu0: float = 0.8

滑转率为1时的摩擦系数

K class-attribute instance-attribute

K: float = 20

依赖于土壤黏聚系数和摩擦特性的常数

track_cmd_rate_limit class-attribute instance-attribute

track_cmd_rate_limit: float = 100

履带主动轮指令变化率限制 (rad/s^2)

min_throttle_manual class-attribute instance-attribute

min_throttle_manual: float = 0.08

MPC_MANTHR_MIN: Minimum manual thrust (0.0 - 1.0). Default: 0.08

min_throttle class-attribute instance-attribute

min_throttle: float = 0.12

MPC_THR_MIN: Minimum thrust in auto thrust control (0.05 - 1.0). Default: 0.12

max_throttle class-attribute instance-attribute

max_throttle: float = 1.0

MPC_THR_MAX: Maximum thrust in auto thrust control (0.0 - 1.0). Default: 1.0

hover_throttle class-attribute instance-attribute

hover_throttle: float = -1

MPC_THR_HOVER: Hover throttle manual (0.1 - 0.8). Default: 0.5 in PX4, calculated hover throttle in LAV2

__post_init__

__post_init__()

Calculate derived parameters.

RotorDynamics

RotorDynamics(params: VehicleParams = VehicleParams(), num_envs: int = 1, device: str | device = 'cpu')

Bases: DynamicsBase

Batched rotor dynamics model.

Initialize batched rotor dynamics on the specified device.

Methods:

Name Description
randomize

Randomize rotor runtime parameters from nominal values.

update

Calculate the output thrust and torque for each motor based on the motor commands.

reset

Resets the rotor model to initial conditions.

Attributes:

Name Type Description
params VehicleParams

Vehicle parameters for the dynamics model.

params instance-attribute

params: VehicleParams = params

Vehicle parameters for the dynamics model.

randomize

randomize(env_ids: slice | Sequence[int] | Tensor | None = None, randomization: dict[str, tuple[float, float]] | None = None) -> None

Randomize rotor runtime parameters from nominal values.

update

update(commands: Tensor) -> torch.Tensor

Calculate the output thrust and torque for each motor based on the motor commands.

Parameters:

Name Type Description Default

commands

Tensor

Command tensor for each motor. Shape: (num_envs, 4)

required

Returns:

Type Description
Tensor

torch.Tensor: Thrust and torque tensor for each motor. Shape: (num_envs, 8)

reset

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

Resets the rotor model to initial conditions.

Parameters:

Name Type Description Default

env_ids

slice | Sequence[int] | Tensor

The environment ids to reset.

required

TrackDynamics

TrackDynamics(params: VehicleParams = VehicleParams(), num_envs: int = 1, device: str | device = 'cpu')

Bases: DynamicsBase

Batched track dynamics model.

Initialize batched track dynamics on the specified device.

Methods:

Name Description
update

Compute track forces for batched environments.

reset

Resets the track model to initial conditions.

Attributes:

Name Type Description
params VehicleParams

Vehicle parameters for the dynamics model.

params instance-attribute

params: VehicleParams = params

Vehicle parameters for the dynamics model.

update

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

Compute track forces for batched environments.

Parameters:

Name Type Description Default

commands

Tensor

Shape (num_envs, 2) track commands [left, right].

required

state

Tensor

Shape (num_envs, 3) body-frame velocities [u, v, r].

required

Returns:

Type Description
Tensor

torch.Tensor: Tensor of shape (num_envs, 2, n_w, 2) [side, wheel, (Fx, Fy)].

reset

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

Resets the track model to initial conditions.

Parameters:

Name Type Description Default

env_ids

slice | Sequence[int] | Tensor

The environment ids to reset.

required

ControlAction

ControlAction(cfg: ControlActionCfg, env: ManagerBasedRLEnv)

Bases: ActionTerm

Body torque control action term.

This action term applies a wrench to the drone body frame based on action commands

Attributes:

Name Type Description
cfg ControlActionCfg

The configuration of the action term.

cfg instance-attribute

cfg: ControlActionCfg = cfg

The configuration of the action term.

ControlActionCfg

Bases: ActionTermCfg

See :class:ControlAction for more details.

Attributes:

Name Type Description
class_type type[ActionTerm]

Class of the action term.

asset_name str

Name of the asset in the environment for which the commands are generated.

params VehicleParams

Vehicle parameters.

gains dict | None

Optional gains configuration for the flight controller. See FlightController for details.

limits dict | None

Optional command-limit configuration passed directly to the flight controller.

control_mode str

Control mode, options: cmd_motor_thrusts, cmd_motor_speeds, cmd_ctbm, cmd_ctbr, cmd_ctatt, cmd_vel, cmd_pos.

class_type class-attribute instance-attribute

class_type: type[ActionTerm] = ControlAction

Class of the action term.

asset_name class-attribute instance-attribute

asset_name: str = 'robot'

Name of the asset in the environment for which the commands are generated.

params class-attribute instance-attribute

params: VehicleParams = VehicleParams()

Vehicle parameters.

gains class-attribute instance-attribute

gains: dict | None = None

Optional gains configuration for the flight controller. See FlightController for details.

limits class-attribute instance-attribute

limits: dict | None = None

Optional command-limit configuration passed directly to the flight controller.

control_mode class-attribute instance-attribute

control_mode: str = 'cmd_motor_speeds'

Control mode, options: cmd_motor_thrusts, cmd_motor_speeds, cmd_ctbm, cmd_ctbr, cmd_ctatt, cmd_vel, cmd_pos.

rotorpy ref: - https://github.com/spencerfolk/rotorpy/blob/main/rotorpy/learning/quadrotor_environments.py#L319C1-L350C12 - https://github.com/spencerfolk/rotorpy/blob/main/rotorpy/vehicles/multirotor.py#L997

TODO: also align control modes with px4, see: https://docs.px4.io/v1.14/en/flight_modes/offboard (version is unclear ATM)

TrackControlAction

TrackControlAction(cfg: TrackControlActionCfg, env: ManagerBasedRLEnv)

Bases: ActionTerm

Track force control action term.

This action term converts normalized track commands into ground reaction forces applied on each track body.

Attributes:

Name Type Description
cfg TrackControlActionCfg

The configuration of the action term.

cfg instance-attribute

cfg: TrackControlActionCfg = cfg

The configuration of the action term.

TrackControlActionCfg

Bases: ActionTermCfg

See :class:ControlAction for more details.

Attributes:

Name Type Description
class_type type[ActionTerm]

Class of the action term.

asset_name str

Name of the asset in the environment for which the commands are generated.

params VehicleParams

Vehicle parameters.

class_type class-attribute instance-attribute

class_type: type[ActionTerm] = TrackControlAction

Class of the action term.

asset_name class-attribute instance-attribute

asset_name: str = 'robot'

Name of the asset in the environment for which the commands are generated.

params class-attribute instance-attribute

params: VehicleParams = VehicleParams()

Vehicle parameters.

UniformPoseCommandGlobal

UniformPoseCommandGlobal(cfg: UniformPoseCommandGlobalCfg, env: ManagerBasedEnv)

Bases: CommandTerm

Command generator that generates pose commands containing a 3-D position and heading.

The command generator samples uniform 3D positions around the environment origin. The heading command is either set to point towards the target or is sampled uniformly. This can be configured through the :attr:UniformPoseCommandGlobalCfg.simple_heading parameter in the configuration.

Initialize the command generator class.

Parameters:

Name Type Description Default

cfg

UniformPoseCommandGlobalCfg

The configuration parameters for the command generator.

required

env

ManagerBasedEnv

The environment object.

required

Attributes:

Name Type Description
cfg UniformPoseCommandGlobalCfg

Configuration for the command generator.

command Tensor

The desired 3D-pose in base frame. Shape is (num_envs, 4).

cfg instance-attribute

cfg: UniformPoseCommandGlobalCfg

Configuration for the command generator.

command property

command: Tensor

The desired 3D-pose in base frame. Shape is (num_envs, 4).

UniformPoseCommandGlobalCfg

Bases: CommandTermCfg

Configuration for the uniform 3D-pose command generator.

Classes:

Name Description
Ranges

Uniform distribution ranges for the position commands.

Attributes:

Name Type Description
asset_name str

Name of the asset in the environment for which the commands are generated.

simple_heading bool

Whether to use simple heading or not.

ranges Ranges

Distribution ranges for the position commands.

goal_pose_visualizer_cfg VisualizationMarkersCfg

The configuration for the goal pose visualization marker. Defaults to GREEN_ARROW_X_MARKER_CFG.

asset_name class-attribute instance-attribute

asset_name: str = MISSING

Name of the asset in the environment for which the commands are generated.

simple_heading class-attribute instance-attribute

simple_heading: bool = MISSING

Whether to use simple heading or not.

If True, the heading is in the direction of the target position.

ranges class-attribute instance-attribute

ranges: Ranges = MISSING

Distribution ranges for the position commands.

goal_pose_visualizer_cfg class-attribute instance-attribute

goal_pose_visualizer_cfg: VisualizationMarkersCfg = replace(prim_path='/Visuals/Command/pose_goal')

The configuration for the goal pose visualization marker. Defaults to GREEN_ARROW_X_MARKER_CFG.

Ranges

Uniform distribution ranges for the position commands.

Attributes:

Name Type Description
pos_x tuple[float, float]

Range for the x position (in m).

pos_y tuple[float, float]

Range for the y position (in m).

pos_z tuple[float, float]

Range for the z position (in m).

heading tuple[float, float]

Heading range for the position commands (in rad).

pos_x class-attribute instance-attribute

pos_x: tuple[float, float] = MISSING

Range for the x position (in m).

pos_y class-attribute instance-attribute

pos_y: tuple[float, float] = MISSING

Range for the y position (in m).

pos_z class-attribute instance-attribute

pos_z: tuple[float, float] = MISSING

Range for the z position (in m).

heading class-attribute instance-attribute

heading: tuple[float, float] = MISSING

Heading range for the position commands (in rad).

Used only if :attr:simple_heading is False.

UniformVelocityGlobalCommand

UniformVelocityGlobalCommand(cfg: UniformVelocityGlobalCommandCfg, env: ManagerBasedEnv)

Bases: CommandTerm

Command generator that generates a velocity command with uniform distribution.

The command comprises linear velocity in x, y, z directions and an angular velocity around the z-axis. It is given in the robot's base frame.

If the :attr:cfg.heading_command flag is set to True, the angular velocity is computed from the heading error similar to doing a proportional control on the heading error. The target heading is sampled uniformly from the provided range. Otherwise, the angular velocity is sampled uniformly from the provided range.

Mathematically, the angular velocity is computed as follows from the heading command:

.. math::

\omega_z = \frac{1}{2} \text{wrap_to_pi}(\theta_{\text{target}} - \theta_{\text{current}})

Initialize the command generator.

Parameters:

Name Type Description Default

cfg

UniformVelocityGlobalCommandCfg

The configuration of the command generator.

required

env

ManagerBasedEnv

The environment.

required

Raises:

Type Description
ValueError

If the heading command is active but the heading range is not provided.

Methods:

Name Description
__str__

Return a string representation of the command generator.

Attributes:

Name Type Description
cfg UniformVelocityGlobalCommandCfg

The configuration of the command generator.

command Tensor

The desired base velocity command in the base frame. Shape is (num_envs, 4).

cfg instance-attribute

cfg: UniformVelocityGlobalCommandCfg

The configuration of the command generator.

command property

command: Tensor

The desired base velocity command in the base frame. Shape is (num_envs, 4).

__str__

__str__() -> str

Return a string representation of the command generator.

UniformVelocityGlobalCommandCfg

Bases: CommandTermCfg

Configuration for the uniform velocity command generator.

Classes:

Name Description
Ranges

Uniform distribution ranges for the velocity commands.

Attributes:

Name Type Description
asset_name str

Name of the asset in the environment for which the commands are generated.

heading_command bool

Whether to use heading command or angular velocity command. Defaults to False.

heading_control_stiffness float

Scale factor to convert the heading error to angular velocity command. Defaults to 1.0.

rel_standing_envs float

The sampled probability of environments that should be standing still. Defaults to 0.0.

rel_heading_envs float

The sampled probability of environments where the robots follow the heading-based angular velocity command

ranges Ranges

Distribution ranges for the velocity commands.

goal_vel_visualizer_cfg VisualizationMarkersCfg

The configuration for the goal velocity visualization marker. Defaults to GREEN_ARROW_X_MARKER_CFG.

current_vel_visualizer_cfg VisualizationMarkersCfg

The configuration for the current velocity visualization marker. Defaults to BLUE_ARROW_X_MARKER_CFG.

asset_name class-attribute instance-attribute

asset_name: str = MISSING

Name of the asset in the environment for which the commands are generated.

heading_command class-attribute instance-attribute

heading_command: bool = False

Whether to use heading command or angular velocity command. Defaults to False.

If True, the angular velocity command is computed from the heading error, where the target heading is sampled uniformly from provided range. Otherwise, the angular velocity command is sampled uniformly from provided range.

heading_control_stiffness class-attribute instance-attribute

heading_control_stiffness: float = 1.0

Scale factor to convert the heading error to angular velocity command. Defaults to 1.0.

rel_standing_envs class-attribute instance-attribute

rel_standing_envs: float = 0.0

The sampled probability of environments that should be standing still. Defaults to 0.0.

rel_heading_envs class-attribute instance-attribute

rel_heading_envs: float = 1.0

The sampled probability of environments where the robots follow the heading-based angular velocity command (the others follow the sampled angular velocity command). Defaults to 1.0.

This parameter is only used if :attr:heading_command is True.

ranges class-attribute instance-attribute

ranges: Ranges = MISSING

Distribution ranges for the velocity commands.

goal_vel_visualizer_cfg class-attribute instance-attribute

goal_vel_visualizer_cfg: VisualizationMarkersCfg = replace(prim_path='/Visuals/Command/velocity_goal')

The configuration for the goal velocity visualization marker. Defaults to GREEN_ARROW_X_MARKER_CFG.

current_vel_visualizer_cfg class-attribute instance-attribute

current_vel_visualizer_cfg: VisualizationMarkersCfg = replace(prim_path='/Visuals/Command/velocity_current')

The configuration for the current velocity visualization marker. Defaults to BLUE_ARROW_X_MARKER_CFG.

Ranges

Uniform distribution ranges for the velocity commands.

Attributes:

Name Type Description
lin_vel_x tuple[float, float]

Range for the linear-x velocity command (in m/s).

lin_vel_y tuple[float, float]

Range for the linear-y velocity command (in m/s).

lin_vel_z tuple[float, float]

Range for the linear-z velocity command (in m/s).

ang_vel_z tuple[float, float]

Range for the angular-z velocity command (in rad/s).

heading tuple[float, float] | None

Range for the heading command (in rad). Defaults to None.

lin_vel_x class-attribute instance-attribute

lin_vel_x: tuple[float, float] = MISSING

Range for the linear-x velocity command (in m/s).

lin_vel_y class-attribute instance-attribute

lin_vel_y: tuple[float, float] = MISSING

Range for the linear-y velocity command (in m/s).

lin_vel_z class-attribute instance-attribute

lin_vel_z: tuple[float, float] = MISSING

Range for the linear-z velocity command (in m/s).

ang_vel_z class-attribute instance-attribute

ang_vel_z: tuple[float, float] = MISSING

Range for the angular-z velocity command (in rad/s).

heading class-attribute instance-attribute

heading: tuple[float, float] | None = None

Range for the heading command (in rad). Defaults to None.

This parameter is only used if :attr:~UniformVelocityGlobalCommandCfg.heading_command is True.

UniformBimodalVelocityCommand

UniformBimodalVelocityCommand(cfg: UniformBimodalVelocityCommandCfg, env: ManagerBasedEnv)

Bases: CommandTerm

Bimodal velocity command generator with a discrete mode indicator (4+1).

This command samples base-frame velocities with two modes: - Flight mode: uses ranges_flight - Ground mode: uses ranges_ground

The output command augments the 4-D velocity with a 1-D discrete indicator: - 0.0 for flight mode - 1.0 for ground/terrestrial mode

Heading behavior matches UniformVelocityGlobalCommand with optional heading-target proportional control. Ranges are applied per selected mode.

Attributes:

Name Type Description
command Tensor

Return 4-D velocity plus 1-D mode indicator. Shape: (num_envs, 5).

command property

command: Tensor

Return 4-D velocity plus 1-D mode indicator. Shape: (num_envs, 5).

UniformBimodalVelocityCommandCfg

Bases: CommandTermCfg

Configuration for the bimodal velocity command generator (flight vs ground).

Classes:

Name Description
Ranges

Uniform distribution ranges for velocity commands per mode.

Attributes:

Name Type Description
asset_name str

Name of the asset receiving commands.

heading_command bool

Whether to convert heading error to angular velocity (per-mode ranges apply).

heading_control_stiffness float

Scale factor for heading error to yaw rate conversion.

rel_standing_envs float

Probability that an environment should be standing still (zero command).

rel_heading_envs float

Probability that an environment uses heading-based angular velocity when enabled.

rel_flight_envs float

Probability of sampling flight mode (vs ground).

ranges_flight Ranges

Ranges for flight mode sampling.

ranges_ground Ranges

Ranges for ground/terrestrial mode sampling.

goal_vel_visualizer_cfg VisualizationMarkersCfg

The configuration for the goal velocity visualization marker. Defaults to GREEN_ARROW_X_MARKER_CFG.

current_vel_visualizer_cfg VisualizationMarkersCfg

The configuration for the current velocity visualization marker. Defaults to BLUE_ARROW_X_MARKER_CFG.

asset_name class-attribute instance-attribute

asset_name: str = MISSING

Name of the asset receiving commands.

heading_command class-attribute instance-attribute

heading_command: bool = False

Whether to convert heading error to angular velocity (per-mode ranges apply).

heading_control_stiffness class-attribute instance-attribute

heading_control_stiffness: float = 1.0

Scale factor for heading error to yaw rate conversion.

rel_standing_envs class-attribute instance-attribute

rel_standing_envs: float = 0.0

Probability that an environment should be standing still (zero command).

rel_heading_envs class-attribute instance-attribute

rel_heading_envs: float = 1.0

Probability that an environment uses heading-based angular velocity when enabled.

rel_flight_envs class-attribute instance-attribute

rel_flight_envs: float = 0.5

Probability of sampling flight mode (vs ground).

ranges_flight class-attribute instance-attribute

ranges_flight: Ranges = MISSING

Ranges for flight mode sampling.

ranges_ground class-attribute instance-attribute

ranges_ground: Ranges = MISSING

Ranges for ground/terrestrial mode sampling.

goal_vel_visualizer_cfg class-attribute instance-attribute

goal_vel_visualizer_cfg: VisualizationMarkersCfg = VisualizationMarkersCfg(prim_path='/Visuals/Command/velocity_goal', markers={'flight': UsdFileCfg(usd_path=f'{ISAAC_NUCLEUS_DIR}/Props/UIElements/arrow_x.usd', scale=(1.0, 0.1, 0.1), visual_material=PreviewSurfaceCfg(diffuse_color=(0.0, 1.0, 0.0))), 'ground': UsdFileCfg(usd_path=f'{ISAAC_NUCLEUS_DIR}/Props/UIElements/arrow_x.usd', scale=(1.0, 0.1, 0.1), visual_material=PreviewSurfaceCfg(diffuse_color=(1.0, 0.0, 0.0)))})

The configuration for the goal velocity visualization marker. Defaults to GREEN_ARROW_X_MARKER_CFG.

current_vel_visualizer_cfg class-attribute instance-attribute

current_vel_visualizer_cfg: VisualizationMarkersCfg = replace(prim_path='/Visuals/Command/velocity_current')

The configuration for the current velocity visualization marker. Defaults to BLUE_ARROW_X_MARKER_CFG.

Ranges

Uniform distribution ranges for velocity commands per mode.

Attributes:

Name Type Description
lin_vel_x tuple[float, float]

Range for the linear-x velocity command (in m/s).

lin_vel_y tuple[float, float]

Range for the linear-y velocity command (in m/s).

lin_vel_z tuple[float, float]

Range for the linear-z velocity command (in m/s).

ang_vel_z tuple[float, float]

Range for the angular-z velocity command (in rad/s).

heading tuple[float, float] | None

Range for the heading command (in rad). Defaults to None.

lin_vel_x class-attribute instance-attribute

lin_vel_x: tuple[float, float] = MISSING

Range for the linear-x velocity command (in m/s).

lin_vel_y class-attribute instance-attribute

lin_vel_y: tuple[float, float] = MISSING

Range for the linear-y velocity command (in m/s).

lin_vel_z class-attribute instance-attribute

lin_vel_z: tuple[float, float] = MISSING

Range for the linear-z velocity command (in m/s).

ang_vel_z class-attribute instance-attribute

ang_vel_z: tuple[float, float] = MISSING

Range for the angular-z velocity command (in rad/s).

heading class-attribute instance-attribute

heading: tuple[float, float] | None = None

Range for the heading command (in rad). Defaults to None.

This parameter is only used if :attr:~UniformBimodalVelocityCommandCfg.heading_command is True.

randomize_action_term_attr

randomize_action_term_attr(env, env_ids: Tensor | None, action_term_name: str = 'control_action', attr_name: str = '_flight_controller', **kwargs)

Randomize a selected action-term attribute.

randomize_controller_params

randomize_controller_params(env, env_ids: Tensor | None, action_term_name: str = 'control_action', controller_attr: str = '_flight_controller', gains: dict | None = None, limits: dict | None = None)

Randomize controller gains and command limits attached to an action term.

randomize_mixer_params

randomize_mixer_params(env, env_ids: Tensor | None, action_term_name: str = 'control_action', mixer_attr: str = '_mixer', param_range: dict[str, tuple[float, float]] | None = None)

Randomize mixer parameters attached to an action term.

randomize_rotor_params

randomize_rotor_params(env, env_ids: Tensor | None, action_term_name: str = 'control_action', rotor_attr: str = '_rotor_dynamics', param_range: dict[str, tuple[float, float]] | None = None)

Randomize rotor parameters attached to an action term.

target_pos_b

target_pos_b(env: ManagerBasedRLEnv, command_name: str | None = None, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Position of target in body frame.

root_euler_w

root_euler_w(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Euler angles of the root in world frame.

lin_vel_l2

lin_vel_l2(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Penalize base linear velocity using L2 squared kernel.

ang_vel_l2

ang_vel_l2(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Penalize base angular velocity using L2 squared kernel.

pos_error_l2

pos_error_l2(env: ManagerBasedRLEnv, command_name: str) -> torch.Tensor

Penalize asset pos from its target pos using L2 squared kernel.

pos_error_tanh

pos_error_tanh(env: ManagerBasedRLEnv, std: float, command_name: str) -> torch.Tensor

Penalize asset pos from its target pos using tanh kernel.

yaw_error_l2

yaw_error_l2(env: ManagerBasedRLEnv, command_name: str) -> torch.Tensor

Penalize heading error from target heading using L2 squared kernel.

yaw_error_tanh

yaw_error_tanh(env: ManagerBasedRLEnv, std: float, command_name: str) -> torch.Tensor

Penalize heading error from target heading using tanh kernel.

track_lin_vel_z_exp

track_lin_vel_z_exp(env: ManagerBasedRLEnv, std: float, command_name: str, is_bimodal: bool = False, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Reward tracking of linear velocity commands (z axis) using exponential kernel.

track_lin_vel_exp

track_lin_vel_exp(env: ManagerBasedRLEnv, std: float, command_name: str, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Reward tracking of linear velocity commands using exponential kernel.

track_yaw_vel_exp

track_yaw_vel_exp(env: ManagerBasedRLEnv, std: float, command_name: str, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot')) -> torch.Tensor

Reward tracking of angular velocity commands (yaw) using exponential kernel.

bimodal_action_tanh

bimodal_action_tanh(env: ManagerBasedRLEnv, std: float, command_name: str, flight_action_name: str = 'control_action', ground_action_name: str = 'track_control_action', ground_weight: float = 1.0, flight_weight: float = 1.0) -> torch.Tensor

Penalize bimodal actions using tanh kernel.

bimodal_height_tanh

bimodal_height_tanh(env: ManagerBasedRLEnv, std: float, command_name: str, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot'), ground_weight: float = 1.0, flight_weight: float = 1.0) -> torch.Tensor

Penalize bimodal height using tanh kernel.

contact_impulse

contact_impulse(env: ManagerBasedRLEnv, threshold: float, sensor_cfg: SceneEntityCfg, mode: str = 'threshold') -> torch.Tensor

Penalize excessive contact impulse (rate of change of contact forces).

This function calculates the impulse as the change in contact forces between consecutive time steps and penalizes values that exceed a threshold.

Parameters:

Name Type Description Default

env

ManagerBasedRLEnv

The learning environment.

required

threshold

float

Maximum acceptable impulse magnitude. Forces below this are not penalized.

required

sensor_cfg

SceneEntityCfg

Configuration for the contact sensor, specifying which bodies to monitor.

required

mode

str

Penalty calculation mode: - "threshold": Penalize only the amount exceeding threshold (continuous) - "binary": Return 1.0 if any impulse exceeds threshold, else 0.0 (discrete) - "total": Return total impulse magnitude regardless of threshold (for monitoring)

'threshold'

Returns:

Type Description
Tensor

torch.Tensor: Penalty value for each environment: - "threshold" mode: Sum of (impulse - threshold) for all violations - "binary" mode: 1.0 if violation exists, 0.0 otherwise - "total" mode: Total impulse magnitude

Raises:

Type Description
ValueError

If the sensor history length is less than 2 or the mode is invalid.

Examples:

>>> # Penalize hard landings (impulse > 50 N·s)
>>> impulse_penalty = contact_impulse(
...     env, threshold=50.0,
...     sensor_cfg=SceneEntityCfg("contact_sensor", body_ids=[arml_id, armr_id]),
...     mode="threshold"
... )
>>> rewards["impulse_penalty"] = impulse_penalty * -1.0

bimodal_contacts

bimodal_contacts(env: ManagerBasedRLEnv, command_name: str, threshold: float, sensor_cfg: SceneEntityCfg, mode: str = 'threshold', ground_weight: float = 1.0, flight_weight: float = 1.0) -> torch.Tensor

Penalize contacts when switching from flight to ground mode.

died

died(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg('robot'), min: float = 0.2, max: float = 2.0) -> torch.Tensor

Termination condition based on the robot's height.