Motion¶
Reference motions: the 50 Hz motion library the tasks read goals from, and the loaders of each source.
ndm_gym.motion.library
¶
Reference motion library: clips from any source at 50 Hz (resampled, unless recorded at 50 Hz), with FK of tracked bodies, and for human-object interaction the object's reference and the scene's other objects.
MotionLib
¶
MotionLib(
clips: list[Clip],
kin: ArticulationKinematics,
device: str,
)
cache_goals
¶
cache_goals(K: int, chunk: int = 65536)
train.py --goal_table: goal(f, K) of every frame computed once, eagerly and in chunks of frames; goal with
this K then reads the table's rows. They are the eager computation's values (a frame's goal does not depend on the
others of its batch); callers compiled with torch.compile (the imagination steps) computed them up to float rounding.
73 K floats per frame: 1.2 GB for LAFAN1's 441,140 frames at K = 10.
future_frames
¶
future_frames(f: Tensor, K: int) -> torch.Tensor
Frames f+1..f+K clamped to the clip's last frame, shape (B, K).
goal
¶
goal(f: Tensor, K: int) -> torch.Tensor
K future reference frames, holding the final pose with zero velocity beyond the clip (after cache_goals, the
table's rows).
ref_object
¶
ref_object(f: Tensor)
The object's reference state at frames f: position, rotation matrix, world linear and angular velocity.
ref_extras
¶
ref_extras(f: Tensor)
The other objects' reference poses at frames f: positions (B, n, 3) and rotation matrices (B, n, 3, 3), in the
order of extra_names.
object_goal
¶
object_goal(f: Tensor, K: int) -> torch.Tensor
The object's K future reference frames in the reference root's heading frame at f: position relative to the
root, rotation (6D), linear and angular velocity, and the object's joint if it has one; beyond the clip the last
pose is held with zero velocity, as in :meth:goal.
ndm_gym.motion.sources
¶
Motion sources. Each loader returns a list of :class:Clip (root pose and joint angles at the source rate, and for
human-object interaction the object's pose and the scene's other objects).
ndm_gym.motion.sources.lafan1
¶
LAFAN1 clips retargeted to the 29-DoF G1 (HF lvhaidong/LAFAN1_Retargeting_Dataset, folder g1/).
Each CSV row holds root position, root quaternion (xyzw) and 29 joint angles at 30 fps.
ndm_gym.motion.sources.spider
¶
SPIDER's hand-object clips (github.com/facebookresearch/spider; the retarget/retarget_full dataset), as
tools/download_hand_clips.py fetches them: per clip a MuJoCo scene of the hand, the object and the floor, and
<task>/<trial>/trajectory_kinematic.npz: qpos (n, 25), the human demonstration retargeted to the hand by inverse
kinematics, in the scene's qpos order (the hand's 18 joints, then the object's position and quaternion (w, x, y, z)),
one frame every ref_dt seconds of <task>/task_info.json.
The kinematic retarget is the tracking reference: no physics shaped it, so the fingers may float off or cut into the object, as a retargeted humanoid motion's feet do with the floor.
load_scene
¶
load_scene(trial_dir: str) -> mujoco.MjModel
The clip's scene with SPIDER's solver settings for hands.
load_reference
¶
load_reference(
trial_dir: str, model: MjModel, dt: float
) -> dict[str, torch.Tensor]
The clip's kinematic reference resampled every dt seconds: the hand's joint positions q (T, num_joints) and the
object's position p (T, 3) and quaternion quat (T, 4), linearly (the quaternion spherically) interpolated.
ndm_gym.motion.sources.hoi
¶
Human-object interaction clips for the G1 in one converted format, whatever their source (HDMI's
clips, OmniRetarget's retargeting of OMOMO): one <name>.npz per clip with
root_pos (T, 3), root_quat_wxyz (T, 4), joint_pos (T, 29) in the G1's (Unitree SDK) joint order,
object_pos (T, 3), object_quat_wxyz (T, 4), fps, and optionally object_joint_pos (T, k) for an
articulated object, contact (T, c) reference contact flags, and extra_pos (T, n, 3) and extra_quat_wxyz
(T, n, 4) for the scene's other objects;
and a <name>.json beside it that names the object (object_name), the other objects in their order
(extra_objects) and the source; it becomes the clip's meta.
A source may also store its own reference: keypoint_pos (T, b, 3), keypoint_quat_wxyz (T, b, 4),
keypoint_lin_vel and keypoint_ang_vel (T, b, 3) of the bodies named by the sidecar's keypoint_names,
joint_vel (T, 29) and object_joint_vel (T, k). The poses are checked but not loaded (forward kinematics
reproduces them); the velocities, which a source may not derive from its poses (HDMI's are not finite differences),
become the clip's src_vel.
load_dir
¶
load_dir(
path: str, object_name: str | None = None
) -> list[Clip]
Every clip in path, or only those with object_name; raises when none is found.
ndm_gym.motion.sources.interhuman
¶
Two-person clips retargeted to two G1s in their common world frame (InterHuman, tools/convert_interhuman.py):
one <pair>.npz per clip with root_p (T, 2, 3), root_quat (T, 2, 4) wxyz, dof (T, 2, 29) in the order of
dof_names, fps and the conversion's record (JSON). Each file gives two clips, <pair>_p1 and <pair>_p2,
in this order, whose meta names their pair and side; the two-robot scene (PairedTrackingSim) plays them together.
load
¶
load(path: str) -> list[Clip]
The pairs of one .npz or of every .npz in a directory (sorted by name), two clips each.
ndm_gym.motion.sources.musclevae
¶
MuscleVAE's reference motions (their LAFAN1 walk, run and jump, retargeted to their muscle-actuated character) as
tools/convert_musclevae.py writes them: one <name>.npz per clip with
root_pos (T, 3) and root_quat_wxyz (T, 4), the pose of the pelvis (its origin is its center of mass);
joint_qpos (T, 64), the character's joint positions in its MJCF's qpos order after the free joint: for each joint
in ndm_gym.robots.musclevae_char.JOINT_NAMES order, a ball joint's rotation relative to its parent as a quaternion
(w, x, y, z) or a hinge's angle; fps; and their dataset's own placement of the 23 bodies, body_pos (T, 23, 3) and
body_quat_wxyz (T, 23, 4), read by :func:load_placement;
and a <name>.json beside it that describes the clip (its meta). A clip's joints are these joint positions,
not one angle per joint as for the G1: ball joints need a motion library with ball-joint kinematics.
load_placement
¶
load_placement(
path: str,
) -> tuple[torch.Tensor, torch.Tensor]
Their dataset's placement of the bodies: positions (T, 23, 3) of the centers of mass, orientations (T, 23, 4) wxyz.
load_dir
¶
load_dir(path: str = CLIPS_DIR) -> list[Clip]
Every clip in path; raises when there is none.
ndm_gym.motion.sources.drone_racing
¶
Flights of Race Against the Machine (Bosello et al., RA-L 2024; github.com/tii-racing/drone-racing-dataset; the data CC BY
4.0), as tools/download_drone_racing.py converts them: per autonomous flight <flight>.npz with the drone's motion-capture
state at 275 Hz, t (n,) seconds, p (n, 3) metres and quat (n, 4) (w, x, y, z), the world's z up, and the racing
gates' poses gates (g, 12), each a centre and a rotation matrix (load_gates; the task does not read them).
A flight is a take-off, a hover, two laps of an ellipse or a lemniscate or three of a 3-D race track, a hover and a landing.
load_flight returns the part in the air, smoothed and resampled at the control rate.
load_gates
¶
load_gates(path: str) -> np.ndarray
The flight's gates (g, 12): per gate its centre (3) and its rotation matrix (9, row-major), the opening across the matrix's first column; none (0, 12) for a file converted without them.
load_flight
¶
load_flight(
path: str,
dt: float,
min_height: float = MIN_HEIGHT,
smooth: float = SMOOTH,
) -> dict[str, torch.Tensor]
The flight's part in the air every dt seconds: position p (T, 3) and quaternion quat (T, 4), the poses
smoothed at the capture's rate (the frames it dropped filled in first: the filter runs over samples a period apart),
then interpolated at the samples' own times (linearly, the quaternion spherically).
ndm_gym.motion.sources.lifelike
¶
Tencent's Labrador motion capture ("Lifelike agility and play in quadrupedal robots", Han et al., Nature Machine Intelligence 2024) retargeted to the Unitree Go2 by tools/convert_lifelike.py, which writes per clip
<clip>.npz: qpos (n, 19), the Go2's trunk position and quaternion (w, x, y, z) and its 12 joints in the model's
order (robots.go2.JOINT_NAMES); contacts (n, 4), the planted feet (FL, FR, RL, RR); fps; joint_names. Each clip
starts at the origin facing +x.
The retarget is kinematic: no physics shaped it, so the reference may ask for a gait the robot cannot follow exactly.
clip_paths
¶
clip_paths(
clips: str | list[str] | None = None,
root: str = DATA_DIR,
) -> list[str]
The clips' files: clips a directory (every clip in it), or names, globs or paths, comma-separated in a string or
a list; names and globs are looked up in root. None: every clip in root.
load_clip
¶
load_clip(path: str, dt: float) -> dict
A clip resampled every dt seconds: qpos (T, 19) with the joints and the position linearly interpolated, the
quaternion spherically and its sign made continuous; contacts (T, 4) of the nearest earlier frame; name.