Implementation:Google deepmind Dm control Trajectory
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Motion Capture |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
The Trajectory class wraps a FittedTrajectory protobuf message into a Python object that provides convenient, time-indexed access to motion capture trajectory data for walkers and props.
Description
The Trajectory class serves as the primary data abstraction between raw protobuf trajectory data and the rest of the locomotion system. It accepts a protobuf, optional start/end times or step indices, and a flag controlling whether velocities are zeroed out in the final timestep (useful for creating stable end poses). Time values are quantized to the trajectory's discrete timestep grid, and out-of-range values are clipped.
The class provides dictionary-based access to the full trajectory via as_dict(), which converts the protobuf into numpy arrays, reshaping repeated position fields to (-1, 3) and quaternion fields to (-1, 4). The resulting arrays are made immutable by default. Individual timestep data is accessible via get_timestep_data(time). Walker and prop poses can be directly applied to a MuJoCo physics simulation using set_walker_poses and set_prop_poses.
Additional capabilities include configure_walkers for rescaling walkers to match the motion capture subject's proportions via WalkerInfo, create_props for instantiating prop entities from the trajectory's protobuf data, and get_modified_trajectory for applying proto modifiers to create transformed copies of the trajectory.
Usage
Use the Trajectory class to access and manipulate motion capture data within locomotion tasks. It is typically instantiated by a TrajectoryLoader rather than constructed directly. Use as_dict() for batch access to trajectory data for reward computation, get_timestep_data() for frame-by-frame access, and set_walker_poses()/set_prop_poses() for applying reference poses to the simulation.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/locomotion/mocap/trajectory.py
- Lines: 1-277
Signature
class Trajectory:
def __init__(self, proto, start_time=None, end_time=None,
start_step=None, end_step=None,
zero_out_velocities=True):
def as_dict(self):
def get_modified_trajectory(self, proto_modifier, random_state=None):
def identifier(self): # property
def start_time(self): # property (settable)
def start_step(self): # property (settable)
def end_time(self): # property (settable)
def end_step(self): # property (settable)
def clip_end_time(self): # property
def duration(self): # property
def num_steps(self): # property
def dt(self): # property
def configure_walkers(self, walkers):
def create_props(self, proto_modifier=None, priority_friction=False,
prop_factory=None):
def get_timestep_data(self, time):
def set_walker_poses(self, physics, walkers):
def set_prop_poses(self, physics, props):
Import
from dm_control.locomotion.mocap.trajectory import Trajectory
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| proto | FittedTrajectory | Yes | Protobuf message representing the motion capture trajectory |
| start_time | float | No | Start time in seconds for trajectory slicing (cannot be combined with start_step) |
| end_time | float | No | End time in seconds for trajectory slicing (cannot be combined with end_step) |
| start_step | int | No | Start step index for trajectory slicing (cannot be combined with start_time) |
| end_step | int | No | End step index for trajectory slicing (cannot be combined with end_time) |
| zero_out_velocities | bool | No | Whether to zero out velocities in the last timestep (default: True) |
Outputs
| Name | Type | Description |
|---|---|---|
| as_dict() | dict of numpy arrays | Dictionary mapping field names to numpy arrays for all timesteps |
| get_timestep_data(time) | timestep proto | Protobuf timestep data for the given time |
| create_props() | tuple of Prop | Tuple of Prop entities created from the trajectory's prop data |
| duration | float | Duration of the trajectory slice in seconds |
| num_steps | int | Number of timesteps in the trajectory slice |
| dt | float | Timestep duration in seconds |
Usage Examples
from dm_control.locomotion.mocap import loader
# Load a trajectory
traj_loader = loader.HDF5TrajectoryLoader('/path/to/data.h5')
traj = traj_loader.get_trajectory('clip_001', start_time=1.0, end_time=5.0)
# Access trajectory as dictionary of numpy arrays
data = traj.as_dict()
positions = data['walker/position'] # shape: (num_steps, 3)
quaternions = data['walker/quaternion'] # shape: (num_steps, 4)
# Configure walkers to match mocap subject proportions
traj.configure_walkers(walker)
# Create props from trajectory data
props = traj.create_props(priority_friction=True)
# Apply reference poses to physics
traj.set_walker_poses(physics, [walker])
traj.set_prop_poses(physics, props)
# Get specific timestep data
timestep = traj.get_timestep_data(2.5)