rfx.decorators module provides the @policy decorator for marking functions as deployable and MotorCommands for building actions from named joints.
Decorator
@policy
Mark a function as an rfx policy for deployment withrfx deploy.
A policy is any callable: Dict[str, Tensor] -> Tensor. This decorator stamps _rfx_policy = True so that rfx deploy my_file.py can discover it automatically.
The function to decorate (when used without parentheses).
Callable - The decorated function, unchanged except for the _rfx_policy marker.
Classes
MotorCommands
Build action tensors from named joint positions. Instead of writingaction[0, 5] = 0.8 and hoping index 5 is the gripper, use joint names from the robot config:
Dict mapping joint name to target position.
RobotConfig with joints list. Required for
to_tensor().Position gain (for backends that use it).
Damping gain (for backends that use it).
Methods
to_tensor(batch_size=1)
Convert named positions to a padded action tensor.
Returns a tensor of shape (batch_size, max_action_dim) with joint positions placed at the correct indices from the robot config.
Leading batch dimension.
torch.Tensor - Action tensor ready to pass to robot.act().
Raises: ValueError - If config is not set or a joint name is not found.
to_list()
Convert to a flat position list using config joint ordering.
Returns a list of length action_dim with positions at the correct indices. Joints not specified default to 0.0.
list[float] - Flat position list.
Raises: ValueError - If config is not set.
MotorCommands.from_positions(positions, config=None, kp=20.0, kd=0.5) (classmethod)
Create commands from named positions.
Dict mapping joint name to target position.
RobotConfig with joints list.
Position gain.
Damping gain.
MotorCommands - New MotorCommands instance.
