mjlab.actuator#
Actuator implementations for mjlab.
Classes
Base#
- class mjlab.actuator.Actuator[source]#
Bases:
ABC,Generic[ActuatorCfgT]Base actuator interface.
- __init__(cfg: ActuatorCfgT, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- property target_ids: Tensor#
Local indices of targets controlled by this actuator.
- property transmission_type: TransmissionType#
Transmission type of this actuator.
- property ctrl_ids: Tensor#
Local indices of control inputs within the entity.
- property global_ctrl_ids: Tensor#
Global indices of control inputs in the MuJoCo model.
- abstractmethod edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- initialize(mj_model: MjModel, model: mujoco_warp.Model, data: mujoco_warp.Data, device: str) None[source]#
Initialize the actuator after model compilation.
This is called after the MjSpec is compiled into an MjModel.
- Parameters:
mj_model – The compiled MuJoCo model.
model – The compiled mjwarp model.
data – The mjwarp data arrays.
device – Device for tensor operations (e.g., “cuda”, “cpu”).
- get_command(data: EntityData) ActuatorCmd[source]#
Extract command data for this actuator from entity data.
- Parameters:
data – The entity data containing all state and target information.
- Returns:
ActuatorCmd with appropriate data based on transmission type.
- abstractmethod compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.ActuatorCfg[source]#
- target_names_expr: tuple[str, ...]#
Targets that are part of this actuator group.
Can be a tuple of names or tuple of regex expressions. Interpreted based on transmission_type (joint/tendon/site).
- transmission_type: TransmissionType = 'joint'#
Transmission type. Defaults to JOINT.
- frictionloss: float = 0.0#
Friction loss force limit.
Applies a constant friction force opposing motion, independent of load or velocity. Also known as dry friction or load-independent friction.
- abstractmethod build(entity: Entity, target_ids: list[int], target_names: list[str]) Actuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.ActuatorCmd[source]#
High-level actuator command with targets and current state.
Passed to actuator’s compute() method to generate low-level control signals. All tensors have shape (num_envs, num_targets).
- position_target: Tensor#
Desired positions (joint positions, tendon lengths, or site positions).
- velocity_target: Tensor#
Desired velocities (joint velocities, tendon velocities, or site velocities).
- effort_target: Tensor#
Feedforward effort (torques or forces).
- pos: Tensor#
Current positions (joint positions, tendon lengths, or site positions).
- vel: Tensor#
Current velocities (joint velocities, tendon velocities, or site velocities).
Builtin Actuators#
- class mjlab.actuator.BuiltinActuatorGroup[source]#
Bases:
objectGroups builtin actuators for batch processing.
Builtin actuators (position, velocity, motor) just pass through target values from entity data to control signals. This class pre-computes the mappings and enables direct writes without per-actuator overhead.
- static process(actuators: list[Actuator]) tuple[BuiltinActuatorGroup, tuple[Actuator, ...]][source]#
Register builtin actuators and pre-compute their mappings.
- Parameters:
actuators – List of initialized actuators to process.
- Returns:
BuiltinActuatorGroup with pre-computed mappings.
List of custom (non-builtin) actuators.
- Return type:
A tuple containing
- apply_controls(data: EntityData) None[source]#
Write builtin actuator controls directly to simulation data.
- Parameters:
data – Entity data containing targets and control arrays.
- __init__(_index_groups: dict[tuple[type[BuiltinMotorActuator | BuiltinMuscleActuator | BuiltinPositionActuator | BuiltinVelocityActuator], TransmissionType], tuple[Tensor, Tensor]]) None#
- class mjlab.actuator.BuiltinMotorActuator[source]#
Bases:
Actuator[BuiltinMotorActuatorCfg]MuJoCo built-in motor actuator.
- __init__(cfg: BuiltinMotorActuatorCfg, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.BuiltinMotorActuatorCfg[source]#
Configuration for MuJoCo built-in motor actuator.
Under the hood, this creates a <motor> actuator for each target and sets its effort limit and gear ratio accordingly. It also modifies the target’s properties, namely armature and frictionloss.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) BuiltinMotorActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.BuiltinPositionActuator[source]#
Bases:
Actuator[BuiltinPositionActuatorCfg]MuJoCo built-in position actuator.
- __init__(cfg: BuiltinPositionActuatorCfg, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.BuiltinPositionActuatorCfg[source]#
Configuration for MuJoCo built-in position actuator.
Under the hood, this creates a <position> actuator for each target and sets the stiffness, damping and effort limits accordingly. It also modifies the target’s properties, namely armature and frictionloss.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) BuiltinPositionActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.BuiltinVelocityActuator[source]#
Bases:
Actuator[BuiltinVelocityActuatorCfg]MuJoCo built-in velocity actuator.
- __init__(cfg: BuiltinVelocityActuatorCfg, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.BuiltinVelocityActuatorCfg[source]#
Configuration for MuJoCo built-in velocity actuator.
Under the hood, this creates a <velocity> actuator for each target and sets the damping gain. It also modifies the target’s properties, namely armature and frictionloss.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) BuiltinVelocityActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.BuiltinMuscleActuator[source]#
Bases:
Actuator[BuiltinMuscleActuatorCfg]MuJoCo built-in muscle actuator.
- __init__(cfg: BuiltinMuscleActuatorCfg, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.BuiltinMuscleActuatorCfg[source]#
Configuration for MuJoCo built-in muscle actuator.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) BuiltinMuscleActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
XML Actuators#
- class mjlab.actuator.XmlMotorActuator[source]#
Bases:
XmlActuator[XmlMotorActuatorCfg]Wrapper for XML-defined <motor> actuators.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.XmlMotorActuatorCfg[source]#
Wrap existing XML-defined <motor> actuators.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) XmlMotorActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.XmlPositionActuator[source]#
Bases:
XmlActuator[XmlPositionActuatorCfg]Wrapper for XML-defined <position> actuators.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.XmlPositionActuatorCfg[source]#
Wrap existing XML-defined <position> actuators.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) XmlPositionActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.XmlVelocityActuator[source]#
Bases:
XmlActuator[XmlVelocityActuatorCfg]Wrapper for XML-defined <velocity> actuators.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.XmlVelocityActuatorCfg[source]#
Wrap existing XML-defined <velocity> actuators.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) XmlVelocityActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
- class mjlab.actuator.XmlMuscleActuator[source]#
Bases:
XmlActuator[XmlMuscleActuatorCfg]Wrapper for XML-defined <muscle> actuators.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.XmlMuscleActuatorCfg[source]#
Wrap existing XML-defined <muscle> actuators.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) XmlMuscleActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
Ideal PD Actuator#
- class mjlab.actuator.IdealPdActuator[source]#
Bases:
Actuator,Generic[IdealPdCfgT]Ideal PD control actuator.
- __init__(cfg: IdealPdCfgT, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- initialize(mj_model: MjModel, model: mujoco_warp.Model, data: mujoco_warp.Data, device: str) None[source]#
Initialize the actuator after model compilation.
This is called after the MjSpec is compiled into an MjModel.
- Parameters:
mj_model – The compiled MuJoCo model.
model – The compiled mjwarp model.
data – The mjwarp data arrays.
device – Device for tensor operations (e.g., “cuda”, “cpu”).
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- set_gains(env_ids: Tensor | slice, kp: Tensor | None = None, kd: Tensor | None = None) None[source]#
Set PD gains for specified environments.
- Parameters:
env_ids – Environment indices to update.
kp – New proportional gains. Shape: (num_envs, num_actuators) or (num_envs,).
kd – New derivative gains. Shape: (num_envs, num_actuators) or (num_envs,).
- class mjlab.actuator.IdealPdActuatorCfg[source]#
Configuration for ideal PD actuator.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) IdealPdActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
DC Motor Actuator#
- class mjlab.actuator.DcMotorActuator[source]#
Bases:
IdealPdActuator[DcMotorCfgT],Generic[DcMotorCfgT]DC motor actuator with velocity-based saturation model.
This actuator extends IdealPdActuator with a realistic DC motor model that limits torque based on current joint velocity. The model implements a linear torque-speed curve where: - At zero velocity: can produce full saturation_effort (stall torque) - At max velocity: can produce zero torque - Between: torque limit varies linearly
The continuous torque limit (effort_limit) further constrains the output.
- __init__(cfg: DcMotorCfgT, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- initialize(mj_model: MjModel, model: mujoco_warp.Model, data: mujoco_warp.Data, device: str) None[source]#
Initialize the actuator after model compilation.
This is called after the MjSpec is compiled into an MjModel.
- Parameters:
mj_model – The compiled MuJoCo model.
model – The compiled mjwarp model.
data – The mjwarp data arrays.
device – Device for tensor operations (e.g., “cuda”, “cpu”).
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- class mjlab.actuator.DcMotorActuatorCfg[source]#
Configuration for DC motor actuator with velocity-based saturation.
This actuator implements a DC motor torque-speed curve for more realistic actuator behavior. The motor produces maximum torque (saturation_effort) at zero velocity and reduces linearly to zero torque at maximum velocity.
Note: effort_limit should be explicitly set to a realistic value for proper motor modeling. Using the default (inf) will trigger a warning. Use IdealPdActuator if unlimited torque is desired.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) DcMotorActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
Delayed Actuator#
- class mjlab.actuator.DelayedActuator[source]#
Bases:
Actuator[DelayedActuatorCfg]Generic wrapper that adds delay to any actuator.
Delays the specified command target(s) (position, velocity, and/or effort) before passing it to the underlying actuator’s compute method.
- __init__(cfg: DelayedActuatorCfg, base_actuator: Actuator) None[source]#
- edit_spec(spec: MjSpec, target_names: list[str]) None[source]#
Edit the MjSpec to add actuators.
This is called during entity construction, before the model is compiled.
- Parameters:
spec – The entity’s MjSpec to edit.
target_names – Names of targets (joints, tendons, or sites) controlled by this actuator.
- initialize(mj_model: MjModel, model: mujoco_warp.Model, data: mujoco_warp.Data, device: str) None[source]#
Initialize the actuator after model compilation.
This is called after the MjSpec is compiled into an MjModel.
- Parameters:
mj_model – The compiled MuJoCo model.
model – The compiled mjwarp model.
data – The mjwarp data arrays.
device – Device for tensor operations (e.g., “cuda”, “cpu”).
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute low-level actuator control signal from high-level commands.
- Parameters:
cmd – High-level actuator command.
- Returns:
Control signal tensor of shape (num_envs, num_actuators).
- reset(env_ids: Tensor | slice | None = None) None[source]#
Reset actuator state for specified environments.
Base implementation does nothing. Override in subclasses that maintain internal state.
- Parameters:
env_ids – Environment indices to reset. If None, reset all environments.
- class mjlab.actuator.DelayedActuatorCfg[source]#
Configuration for delayed actuator wrapper.
Wraps any actuator config to add delay functionality. Delays are quantized to physics timesteps (not control timesteps). For example, with 500Hz physics and 50Hz control (decimation=10), a lag of 2 represents a 4ms delay (2 physics steps).
- target_names_expr: tuple[str, ...] = ()#
Targets that are part of this actuator group.
Can be a tuple of names or tuple of regex expressions. Interpreted based on transmission_type (joint/tendon/site).
- base_cfg: ActuatorCfg#
Configuration for the underlying actuator.
- delay_target: Literal['position', 'velocity', 'effort'] | tuple[Literal['position', 'velocity', 'effort'], ...] = 'position'#
Which command target(s) to delay.
Can be a single string like ‘position’, or a tuple of strings like (‘position’, ‘velocity’, ‘effort’) to delay multiple targets together.
- build(entity: Entity, target_ids: list[int], target_names: list[str]) DelayedActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.
Learned MLP Actuator#
- class mjlab.actuator.LearnedMlpActuator[source]#
Bases:
DcMotorActuator[LearnedMlpActuatorCfg]MLP-based learned actuator with joint history.
This actuator uses a trained neural network to map from joint commands and state history to torque outputs. The network captures complex actuator dynamics that are difficult to model analytically.
The actuator maintains circular buffers of joint position errors and velocities, which are used as inputs to the MLP. The network outputs are then scaled and clipped using the DC motor limits from the parent class.
- __init__(cfg: LearnedMlpActuatorCfg, entity: Entity, target_ids: list[int], target_names: list[str]) None[source]#
- initialize(mj_model: MjModel, model: mujoco_warp.Model, data: mujoco_warp.Data, device: str) None[source]#
Initialize the actuator after model compilation.
This is called after the MjSpec is compiled into an MjModel.
- Parameters:
mj_model – The compiled MuJoCo model.
model – The compiled mjwarp model.
data – The mjwarp data arrays.
device – Device for tensor operations (e.g., “cuda”, “cpu”).
- reset(env_ids: Tensor | slice | None = None) None[source]#
Reset history buffers for specified environments.
- Parameters:
env_ids – Environment indices to reset. If None, reset all environments.
- compute(cmd: ActuatorCmd) Tensor[source]#
Compute actuator torques using the learned MLP model.
- Parameters:
cmd – High-level actuator command containing targets and current state.
- Returns:
Computed torque tensor of shape (num_envs, num_joints).
- class mjlab.actuator.LearnedMlpActuatorCfg[source]#
Configuration for MLP-based learned actuator model.
This actuator learns the mapping from joint commands and state history to actual torque output. It’s useful for capturing actuator dynamics that are difficult to model analytically, such as delays, non-linearities, and friction effects.
The network is trained offline using data from the real system and loaded as a TorchScript file. The model uses a sliding window of historical joint position errors and velocities as inputs.
- input_order: Literal['pos_vel', 'vel_pos'] = 'pos_vel'#
Order of inputs to the network.
“pos_vel”: position errors followed by velocities
“vel_pos”: velocities followed by position errors
- history_length: int = 3#
Number of timesteps of history to use as network inputs.
For example, history_length=3 uses the current timestep plus the previous 2 timesteps (total of 3 frames).
- build(entity: Entity, target_ids: list[int], target_names: list[str]) LearnedMlpActuator[source]#
Build actuator instance.
- Parameters:
entity – Entity this actuator belongs to.
target_ids – Local target indices (for indexing entity arrays).
target_names – Target names corresponding to target_ids.
- Returns:
Actuator instance.