Motion Optimization¶
Offline optimization of motion clips before training. The one optimizer that ships is TCRS, which turns
flat-ground biped clips into terrain-adapted ones: gait-phase and contact detection, MPPI foot-swing planning against
a terrain height field, support-aware pelvis-height filtering, and whole-body Jacobian IK on a MuJoCo model of the
robot. It needs no Eden env (numpy, scipy and mujoco only). Datasets reach it through the TCRSTerrainAdapt
dataset modifier. The TCRS terrain adaptation guide
explains the method and its settings.
from eden.extensions.motion_optimization.tcrs import HeightFieldTerrain, TCRSPlannerOptions, TCRSRobotOptions
Options¶
Configuration options for the offline motion-optimization extensions.
Holds the config surface of the TCRS terrain-adaptive motion optimizer
(:mod:eden.extensions.motion_optimization.tcrs).
Upstream TCRS hardcodes Unitree G1 geometry (body/joint names, foot contact
offsets, leg reach) across several modules. The port lifts all of it into
:class:TCRSRobotOptions so another biped can be targeted without touching
the algorithms; the no-argument default reproduces the upstream G1 values with
the name lists taken from Eden's canonical G1 definitions.
:class:TCRSPlannerOptions collects the pipeline knobs that upstream exposed
as CLI flags (defaults preserved). Both are :class:ConfigurableOptions
(extra="forbid"), matching Eden's library-wide config pattern; the TCRS
engine consumes them as read-only attribute bags and stays env-free.
Attributes¶
DEFAULT_IK_CONFIG
module-attribute
¶
DEFAULT_IK_CONFIG: dict = {'link_weights': {'pelvis': {'pos_weight': 1, 'rot_weight': 1.0}, 'left_hip_pitch_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'left_hip_roll_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'left_hip_yaw_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'left_knee_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'left_ankle_pitch_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'right_hip_pitch_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'right_hip_roll_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'right_hip_yaw_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'right_knee_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'right_ankle_pitch_link': {'pos_weight': 0.0, 'rot_weight': 0.0}, 'left_ankle_roll_link': {'pos_weight': 10.0, 'rot_weight': 6.0}, 'right_ankle_roll_link': {'pos_weight': 10.0, 'rot_weight': 6.0}, 'left_toe': {'pos_weight': 6.0, 'rot_weight': 0.0, 'offset': [0.12, 0.0, -0.03]}, 'left_heel': {'pos_weight': 6.0, 'rot_weight': 0.0, 'offset': [-0.05, 0.0, -0.03]}, 'right_toe': {'pos_weight': 6.0, 'rot_weight': 0.0, 'offset': [0.12, 0.0, -0.03]}, 'right_heel': {'pos_weight': 6.0, 'rot_weight': 0.0, 'offset': [-0.05, 0.0, -0.03]}}, 'solver': {'max_iters': 60, 'tol': 0.001, 'damping': 0.05, 'step_size': 0.5, 'orientation_weight': 0.2, 'posture_weight': 0.01, 'max_joint_step': 0.2, 'penetration_weight': 20.0, 'root_xy_weight': 3.0, 'root_z_weight': 20, 'knee_forward_weight': 15.0, 'multiseed_enabled': True, 'multiseed_num_seeds': 3, 'multiseed_trigger_pos_err': 0.2, 'multiseed_trigger_joint_step': 0.8, 'multiseed_seed_span': 0.35, 'multiseed_continuity_weight': 0.25, 'multiseed_posture_weight': 0.02}}
Classes¶
TCRSRobotOptions
¶
Bases: ConfigurableOptions
Robot geometry and naming the TCRS pipeline needs.
The no-argument default is the upstream Unitree G1 spec with Eden's
canonical name lists as clip orderings. There is no separate override
API: construction is always overrides-on-the-G1-defaults — any
unspecified field keeps its G1 value, and targeting another biped just
means overriding more of them. Eden clips store joints in
G1_DOFS29_NAME (chain) order; upstream PMT clips use an interleaved
"policy" order. Both are supported — pass the clip's actual ordering;
every consumer resolves columns by name.
Source code in eden/options/options.py
Attributes¶
dofs_name
class-attribute
instance-attribute
¶
dofs_name: list[str] = Field(default_factory=lambda: list(G1_DOFS29_NAME))
DOF order of the motion clip's dofs_pos columns. All MuJoCo qpos addressing
is resolved by these names — never by column index.
links_name
class-attribute
instance-attribute
¶
links_name: list[str] = Field(default_factory=lambda: list(G1_DOFS29_TRACKED_LINKS_NAME))
Link order of the motion clip's links_pos_w/links_quat_w rows (pelvis first).
left_leg_dofs_name
class-attribute
instance-attribute
¶
left_leg_dofs_name: tuple[str, ...] = ('left_hip_pitch_joint', 'left_hip_roll_joint', 'left_hip_yaw_joint', 'left_knee_joint', 'left_ankle_pitch_joint', 'left_ankle_roll_joint')
right_leg_dofs_name
class-attribute
instance-attribute
¶
right_leg_dofs_name: tuple[str, ...] = ('right_hip_pitch_joint', 'right_hip_roll_joint', 'right_hip_yaw_joint', 'right_knee_joint', 'right_ankle_pitch_joint', 'right_ankle_roll_joint')
waist_dofs_name
class-attribute
instance-attribute
¶
toe_offset
class-attribute
instance-attribute
¶
Representative toe contact point in the ankle-roll-link frame (from the G1 MJCF contact spheres).
heel_offset
class-attribute
instance-attribute
¶
Representative heel contact point in the ankle-roll-link frame.
toe_probe_offset_x
class-attribute
instance-attribute
¶
toe_probe_offset_x: float = 0.14
Forward probe distance used by footstep resolution (upstream TOE_OFFSET_X).
foot_nominal_z
class-attribute
instance-attribute
¶
foot_nominal_z: float = 0.06
Ankle height above the support surface when the foot is flat on the ground.
hip_offset_z
class-attribute
instance-attribute
¶
hip_offset_z: float = -0.251
Pelvis origin to hip joint, z component (m).
leg_max_length
class-attribute
instance-attribute
¶
leg_max_length: float = 0.494
Hip-to-ankle chain length at full extension (m).
pelvis_ankle_reach_slack
class-attribute
instance-attribute
¶
pelvis_ankle_reach_slack: float = 0.06
Extra reach beyond |hip_offset_z| + leg_max_length from the hip chain's
lateral/forward offsets; the pipeline works in pelvis-link ↔ ankle-link coordinates.
ik_config
class-attribute
instance-attribute
¶
Per-link IK weights and solver settings (schema of ik_config.json). Partial dicts —
including this empty default — deep-merge onto :data:DEFAULT_IK_CONFIG at construction
(see :func:merged_ik_config), so the stored value is always the full config.
mid_foot_offset
property
¶
Midpoint of toe and heel contact points (upstream MID_FOOT_OFFSET).
TCRSPlannerOptions
¶
Bases: ConfigurableOptions
TCRS pipeline knobs, mirroring the upstream CLI defaults.
Not ported (dropped features): planner="plum" (imports a module that
does not exist upstream), ik_backend curobo/drake, ik_mode="window"
trajectory IK, and rolling_interval viewer-time replanning.
Range constraints live on the fields (gt/ge/le/allow_inf_nan),
mirroring the upstream valid ranges.
Source code in eden/options/options.py
Attributes¶
contact_z_threshold
class-attribute
instance-attribute
¶
contact_z_threshold: float = Field(0.06, ge=0)
contact_speed_threshold
class-attribute
instance-attribute
¶
contact_speed_threshold: float = Field(0.5, gt=0)
smoothing_alpha
class-attribute
instance-attribute
¶
smoothing_alpha: float = Field(0.08, gt=0, le=1)
w_terrain
class-attribute
instance-attribute
¶
w_terrain: float = Field(1000.0, allow_inf_nan=False)
ik_stabilizer_stance_scale
class-attribute
instance-attribute
¶
ik_stabilizer_stance_scale: float = 2.2
ik_stabilizer_swing_scale
class-attribute
instance-attribute
¶
ik_stabilizer_swing_scale: float = 0.6
ik_stabilizer_root_xy_scale
class-attribute
instance-attribute
¶
ik_stabilizer_root_xy_scale: float = 0.6
ik_stabilizer_root_z_scale
class-attribute
instance-attribute
¶
ik_stabilizer_root_z_scale: float = 0.75
ik_stabilizer_root_continuity_weight
class-attribute
instance-attribute
¶
ik_stabilizer_root_continuity_weight: float = 80.0
ik_stabilizer_trigger_mm
class-attribute
instance-attribute
¶
ik_stabilizer_trigger_mm: float = 60.0
Functions:¶
merged_ik_solver_config
¶
Merge a (possibly partial) ik_config["solver"] section over the defaults.
DEFAULT_IK_CONFIG["solver"] is the complete set of solver knobs; every consumer
(:meth:~eden.extensions.motion_optimization.tcrs.ik.JacobianIK.from_config, the pipeline's
root-weight lookup) reads the merged dict, so a partial
override changes exactly the named keys and never falls back to a second,
disagreeing set of hardcoded defaults. Unknown keys raise.
Source code in eden/options/extensions/motion_optimization.py
merged_ik_config
¶
Deep-merge a partial ik_config dict onto :data:DEFAULT_IK_CONFIG.
Merge semantics:
solver: key-wise merge over the default solver section; unknown solver keys raise (see :func:merged_ik_solver_config).link_weights: per-link-name merge — each override entry is merged over the default entry of the same name (so{"pelvis": {"pos_weight": 2}}keeps the defaultrot_weight); names absent from the defaults are added as new constraints.
Sections other than solver/link_weights raise.
Source code in eden/options/extensions/motion_optimization.py
Pipeline¶
Offline TCRS pipeline: terrain-adaptive whole-body motion optimization.
Pipeline stages (per clip):
1. Build a :class:~eden.extensions.motion_optimization.tcrs.motion.MotionClip from raw arrays
(contact masks + gait-phase clock are derived on construction).
2. Apply an SE(2) placement transform (yaw about the frame-0 pelvis, then xy translation).
3. Build :class:~eden.extensions.motion_optimization.tcrs.motion.TerrainReference +
FootstepResolver (snap footholds onto safe terrain support surfaces).
4. MPPI-optimize every swing-foot trajectory on the mid-foot virtual point
(:func:precompute_mppi_foot), then post-process: lateral separation clamps,
side-wall pushes, capsule-based leg/foot collision resolution, stance latching.
5. Filter the pelvis z with :class:~eden.extensions.motion_optimization.tcrs.terrain_warp.SupportAwareRootZFilter
against a reach-bounded terrain-driven target.
6. Solve per-frame whole-body Jacobian IK (with the lower-body stance stabilizer post-pass)
and record raw / ghost-FK / optimized motion sets.
7. Zero-phase lowpass the optimized output's lower body for export.
Ported from Mondo-Robotics/PMT TCRS/stair_mppi/mppi_foot_planner_smooth.py @ 88838ca
(offline pipeline only; viewer, plum mode, window/trajectory IK, curobo/drake backends and
batch CLI not ported). The small joint/body reorder helpers come from the same repo's
TCRS/stair_mppi/minimal_mppi_demo.py; the mapping builders were rewritten to resolve
joints by name via jnt_qposadr instead of actuator ids.
Attributes¶
Classes¶
LowerBodyStabilizerState
dataclass
¶
LowerBodyStabilizerState(prev_leg_qpos: ndarray = None, prev_root_pos: ndarray = None, prev_left_contact: bool = False, prev_right_contact: bool = False, left_lock_pos: ndarray = None, left_lock_quat: ndarray = None, right_lock_pos: ndarray = None, right_lock_quat: ndarray = None)
ClipArrays
dataclass
¶
ClipArrays(fps: float, dofs_pos: ndarray, links_pos_w: ndarray, links_quat_w: ndarray, links_lin_vel_w: ndarray | None = None)
Input motion clip as plain arrays (orders defined by the adapter's TCRSRobotOptions).
Attributes¶
dofs_pos
instance-attribute
¶
(T, J) joint positions in robot_spec.dofs_name order.
links_pos_w
instance-attribute
¶
(T, K, 3) world link positions in robot_spec.links_name order.
links_lin_vel_w
class-attribute
instance-attribute
¶
(T, K, 3) world link linear velocities; finite-differenced when omitted.
Methods:¶
MotionSet
dataclass
¶
AdaptResult
dataclass
¶
AdaptResult(raw: MotionSet, ghost: MotionSet, optimized: MotionSet, left_contact: ndarray, right_contact: ndarray, ik_pos_errors: ndarray, ik_bad_frame_count: int)
Output of :meth:TCRSMotionAdapter.adapt for one clip placement.
Attributes¶
ghost
instance-attribute
¶
ghost: MotionSet
Raw joints + terrain-adjusted pelvis z, rebuilt by FK only (no IK).
optimized
instance-attribute
¶
optimized: MotionSet
IK-solved motion on terrain; root position, waist and legs zero-phase lowpassed (lowpass_cutoff_hz).
ik_pos_errors
instance-attribute
¶
(T,) per-frame max IK position error in millimeters.
ik_bad_frame_count
instance-attribute
¶
ik_bad_frame_count: int
Number of frames whose IK error exceeds params.reject_ik_mm.
Methods:¶
TCRSMotionAdapter
¶
TCRSMotionAdapter(model_path: str, robot_spec: TCRSRobotOptions | None = None, params: TCRSPlannerOptions | None = None)
Terrain-adaptive motion optimizer: adapts flat-ground clips to a terrain.
Loads the MuJoCo model once and reuses the IK solver across :meth:adapt
calls; each call allocates fresh MjData so no state leaks between clips.
| PARAMETER | DESCRIPTION |
|---|---|
model_path
|
Path to the robot's MuJoCo MJCF (floating base + 1-DOF joints).
TYPE:
|
robot_spec
|
Robot geometry/naming; defaults to
:class:
TYPE:
|
params
|
Pipeline knobs; defaults to
:class:
TYPE:
|
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
Attributes¶
robot_spec
instance-attribute
¶
robot_spec = robot_spec if robot_spec is not None else TCRSRobotOptions()
dofs_mapping
instance-attribute
¶
dofs_mapping = build_dofs_mapping(self.model, self.robot_spec.dofs_name)
links_mapping
instance-attribute
¶
links_mapping = build_links_mapping(self.model, self.robot_spec.links_name)
Methods:¶
adapt
¶
adapt(clip: ClipArrays, terrain: TerrainSource, dx: float = 0.0, dy: float = 0.0, dyaw: float = 0.0) -> AdaptResult
Run the full pipeline for one clip with a given SE(2) placement transform.
| PARAMETER | DESCRIPTION |
|---|---|
clip
|
Input motion arrays.
TYPE:
|
terrain
|
Terrain height source.
TYPE:
|
dx
|
X translation applied after the yaw rotation (m).
TYPE:
|
dy
|
Y translation applied after the yaw rotation (m).
TYPE:
|
dyaw
|
Yaw rotation about the frame-0 pelvis xy (rad).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AdaptResult
|
Raw / ghost / optimized motion sets and IK quality metrics. |
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 | |
Functions:¶
build_dofs_mapping
¶
Clip joint column i -> index into qpos[7:], resolved by joint name via jnt_qposadr.
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
build_links_mapping
¶
Build mapping from clip link index to MuJoCo body id: mapping[clip_idx] = mujoco_body_id.
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
reorder_to_mujoco
¶
Reorder a (n_dofs,) clip-order vector into MuJoCo qpos[7:] order.
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
reorder_from_mujoco
¶
Reorder a (n_dofs,) MuJoCo qpos[7:] vector into clip order.
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
update_robot_pose
¶
Write a root pose + joint vector into a MuJoCo data (velocities/controls zeroed).
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
precompute_mppi_foot
¶
precompute_mppi_foot(precomputed_ref, precomputed_quats, contact_mask, foot_nominal_z, terrain, mppi_params, fps, robot_spec)
Run MPPI trajectory optimization over all swing phases of one foot.
Core idea: plan on the mid-foot virtual center (midpoint of toe and heel) rather than the ankle origin. The planning point sits closer to the ground contact surface, reducing toe/heel penetration at step edges. After optimization the mid-foot result is transformed back to ankle coordinates for IK.
A swing between stances at the same height (< 1.5 cm apart) whose reference clears the terrain is kept as it is.
| PARAMETER | DESCRIPTION |
|---|---|
precomputed_ref
|
(N, 3) ankle reference positions from TerrainReference.
TYPE:
|
precomputed_quats
|
(N, 4) ankle reference quaternions (wxyz) from TerrainReference.
TYPE:
|
contact_mask
|
(N,) boolean contact mask (True = stance, False = swing).
TYPE:
|
foot_nominal_z
|
Nominal ankle z height on flat ground (m).
TYPE:
|
terrain
|
Terrain height source.
TYPE:
|
mppi_params
|
Optimizer parameters.
TYPE:
|
fps
|
Motion frame rate (Hz).
TYPE:
|
robot_spec
|
Robot geometry; provides the mid-foot offset for the ankle<->midfoot conversion.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
optimized_pos
|
(N, 3) ankle positions (stance frames unchanged, optimized swing frames overwritten).
TYPE:
|
optimized_quats
|
(N, 4) quaternions: yaw-only during stance (sole stays level), the reference ones during swing, slerp-blended over up to 10 frames at each stance boundary.
TYPE:
|
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 | |
apply_zero_phase_lowpass
¶
Zero-phase Butterworth lowpass on a (N,D) or (N,) array.
Uses scipy.signal.filtfilt for zero phase shift. Gracefully handles short sequences: if the signal is too short for the requested filter order, the order is reduced until filtfilt can run, or the original is returned unfiltered.
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
filter_motion_for_export
¶
Apply zero-phase lowpass to all exported channels consistently.
- dofs_pos, links_pos: Butterworth filtfilt.
- links_quat: log-map → filtfilt → exp-map (proper SO(3) smoothing).
(Upstream also recomputed velocities from the filtered channels; the port returns positions/quaternions only.)
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
filter_lower_body_motion_for_export
¶
filter_lower_body_motion_for_export(model, robot_spec, dofs_mapping, links_mapping, dofs_pos, links_pos, links_quat, fps, cutoff_hz=5.0, order=4)
Smooth root position + waist + leg joints, then rebuild full-body poses by FK.
This preserves shoulder/elbow/wrist motion while making the support chain smoother and keeping exported body poses consistent with the exported joint commands.
Root orientation is intentionally left unchanged. Smoothing pelvis quaternions over long clips can create catastrophic whole-body heading artefacts even when IK position error stays small, because the batch error metric does not constrain root orientation.
(Upstream loaded its own MjModel from the XML and recomputed velocities; the port reuses the caller's model/mappings and returns positions only.)
Source code in eden/extensions/motion_optimization/tcrs/pipeline.py
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 | |
Motion clips and terrain references¶
Motion clip container, footstep resolution, and terrain-adapted reference trajectories.
:class:MotionClip wraps a mocap segment (joint positions plus world-frame body
poses) and derives per-foot contact masks — an adaptive percentile z-threshold
combined with a speed gate, stabilized by :func:stabilize_contact_mask — and
an optional gait phase clock for gaits with flight phases. :class:FootstepResolver
snaps each touchdown to a safe landing pose on the terrain and locks it across
the stance phase. :class:TerrainReference builds the terrain-adapted pelvis
and foot reference trajectories consumed by the planner (stance-locked
footholds, smooth swing interpolation, floor clamping, lateral crossover and
step-order enforcement).
Ported from Mondo-Robotics/PMT TCRS/stair_mppi/minimal_mppi_demo.py @ 88838ca
(viewer demo, TinyMPPI and MuJoCo helpers not ported).
Classes¶
MotionClip
¶
MotionClip(robot_spec: TCRSRobotOptions, fps: float, dofs_pos: ndarray, links_pos_w: ndarray, links_quat_w: ndarray, links_lin_vel_w: ndarray | None = None, contact_z_threshold: float = 0.06, contact_speed_threshold: float = 0.5)
A mocap motion segment with derived foot-contact masks and gait phase.
| PARAMETER | DESCRIPTION |
|---|---|
robot_spec
|
Robot geometry/naming; resolves the pelvis and foot columns of the body arrays and provides the nominal ankle-to-sole height.
TYPE:
|
fps
|
Frame rate of the clip (Hz).
TYPE:
|
dofs_pos
|
(T, n_dofs) joint positions in
TYPE:
|
links_pos_w
|
(T, n_links, 3) world body positions in
TYPE:
|
links_quat_w
|
(T, n_links, 4) world body quaternions [w, x, y, z].
TYPE:
|
links_lin_vel_w
|
(T, n_links, 3) world body linear velocities. Finite-differenced from
TYPE:
|
contact_z_threshold
|
Minimum foot-z threshold for contact detection (m); the adaptive percentile threshold never goes below it.
TYPE:
|
contact_speed_threshold
|
Foot speed threshold for contact detection (m/s).
TYPE:
|
Source code in eden/extensions/motion_optimization/tcrs/motion.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Attributes¶
phase_params
instance-attribute
¶
phase_params = fit_phase_clock(lfoot_z, rfoot_z, lfoot_speed, rfoot_speed, self.fps, contact_z_threshold, contact_speed_threshold)
per_frame_phase
instance-attribute
¶
per_frame_phase = compute_per_frame_phase(self.phase_params, self.n_frames)
pelvis_height_above_foot
instance-attribute
¶
pelvis_height_above_foot = float(np.median(pelvis_z) - self.foot_nominal_z)
Methods:¶
get_future_indices
¶
get_future_segment
¶
Source code in eden/extensions/motion_optimization/tcrs/motion.py
get_future_contacts
¶
get_future_support_weights
¶
Return continuous support weights for pelvis z computation.
When phase clock is available, returns smooth cosine-decay weights. Otherwise, falls back to binary weights from contact masks (1.0/0.0).
Source code in eden/extensions/motion_optimization/tcrs/motion.py
get_future_foot_quats
¶
Source code in eden/extensions/motion_optimization/tcrs/motion.py
FootstepResolver
¶
FootstepResolver(robot_spec: TCRSRobotOptions, terrain: TerrainSource, raw_foot: ndarray, contact_mask: ndarray, foot_nominal_z: float, foot_quats: ndarray | None = None, foot_point_offsets: ndarray | None = None, toe_offset_x: float | None = None, max_landing_shift: float = 0.05)
Footstep resolver: snaps raw mocap ankle positions onto safe terrain support surfaces.
Core responsibilities:
- For each touchdown frame, call :meth:
_resolve_landing_poseto find the best support placement, constraining the ankle so all foot key points (heel/midfoot/toe) land on the same support surface. - Broadcast the resolved landing pose across the whole stance phase
(
contact_support) so the foot does not slide while in contact.
| PARAMETER | DESCRIPTION |
|---|---|
robot_spec
|
Robot geometry; provides the default toe probe offset.
TYPE:
|
terrain
|
Terrain object; must provide
TYPE:
|
raw_foot
|
(N, 3) raw mocap ankle positions (world frame).
TYPE:
|
contact_mask
|
(N,) boolean contact mask; True = stance.
TYPE:
|
foot_nominal_z
|
Nominal ankle z height when standing on flat ground (z=0).
TYPE:
|
foot_quats
|
(N, 4) ankle quaternions [w, x, y, z], used to rotate foot offsets into the world frame. Defaults to identity (facing forward).
TYPE:
|
foot_point_offsets
|
(M,) local x offsets of foot key points relative to the ankle. Each
offset is rotated by the quaternion into world coordinates and checked
against step edges. Defaults to
TYPE:
|
toe_offset_x
|
Toe x offset relative to the ankle (local frame). Defaults to
TYPE:
|
max_landing_shift
|
Maximum search displacement along the foot forward direction in
:meth:
TYPE:
|
Source code in eden/extensions/motion_optimization/tcrs/motion.py
Attributes¶
foot_point_offsets
instance-attribute
¶
touchdown
instance-attribute
¶
touchdown_support
instance-attribute
¶
next_touchdown_idx
instance-attribute
¶
contact_support
instance-attribute
¶
Methods:¶
prev_support_pose
¶
prev_support_pose(frame_idx: int) -> ndarray | None
Query the nearest support position before frame frame_idx.
Used during swing to determine the liftoff position: the contact_support of the last contact frame before the swing is the liftoff point.
| RETURNS | DESCRIPTION |
|---|---|
ndarray or None
|
(3,) position array [x, y, z], or None (no preceding support frame). |
Source code in eden/extensions/motion_optimization/tcrs/motion.py
next_touchdown_pose
¶
next_touchdown_pose(frame_idx: int) -> ndarray | None
Query the nearest touchdown (landing) position after frame frame_idx.
Used during swing to determine the landing target: the safe position the foot must reach at the end of the swing.
| RETURNS | DESCRIPTION |
|---|---|
ndarray or None
|
(3,) position array [x, y, z], or None (no subsequent touchdown). |
Source code in eden/extensions/motion_optimization/tcrs/motion.py
TerrainReference
¶
TerrainReference(terrain: TerrainSource, motion: MotionClip, lookahead: float = 0.0, smoothing_alpha: float = 0.08, toe_offset_x: float | None = None, heel_offset_x: float = -0.04, mid_offset_x: float = 0.1, swing_floor_margin: float = 0.003, soft_reach_limit: float = 0.7, max_landing_shift: float = 0.05)
Terrain reference trajectory builder: adapts raw mocap foot positions to the target terrain.
Core outputs: left_precomputed / right_precomputed: (N, 3) left/right ankle reference positions. left_precomputed_quats / right_precomputed_quats: (N, 4) left/right ankle reference quaternions.
Processing pipeline:
1. Create :class:FootstepResolver → resolve a safe landing position for
every touchdown frame.
2. :meth:_precompute_foot_reference → stance frames use the locked landing
position, swing frames use Hermite/quintic interpolation + floor clamping.
3. :meth:_flatten_stance_quats → the sole stays level during stance
(only yaw is kept).
| PARAMETER | DESCRIPTION |
|---|---|
terrain
|
Terrain object.
TYPE:
|
motion
|
Mocap motion data.
TYPE:
|
lookahead
|
Terrain lookahead distance (m), lets the pelvis lift ahead of upcoming steps.
TYPE:
|
smoothing_alpha
|
EMA smoothing coefficient for the pelvis z.
TYPE:
|
toe_offset_x
|
Toe x offset relative to the ankle (local frame). Defaults to
TYPE:
|
heel_offset_x
|
Heel x offset relative to the ankle (local frame, negative = behind).
TYPE:
|
mid_offset_x
|
Midfoot x offset relative to the ankle (local frame).
TYPE:
|
swing_floor_margin
|
Extra ground-clearance margin during swing (m).
TYPE:
|
soft_reach_limit
|
Soft pelvis-to-foot reach limit (m).
TYPE:
|
max_landing_shift
|
Maximum landing-position search displacement along fwd (m).
TYPE:
|
Source code in eden/extensions/motion_optimization/tcrs/motion.py
Attributes¶
left_resolver
instance-attribute
¶
left_resolver = FootstepResolver(robot_spec=robot_spec, terrain=terrain, raw_foot=motion.links_pos[:, lfoot_idx], contact_mask=motion.left_contact, foot_nominal_z=motion.foot_nominal_z, foot_quats=motion.links_quat[:, lfoot_idx], foot_point_offsets=foot_point_offsets, toe_offset_x=toe_offset_x, max_landing_shift=max_landing_shift)
right_resolver
instance-attribute
¶
right_resolver = FootstepResolver(robot_spec=robot_spec, terrain=terrain, raw_foot=motion.links_pos[:, rfoot_idx], contact_mask=motion.right_contact, foot_nominal_z=motion.foot_nominal_z, foot_quats=motion.links_quat[:, rfoot_idx], foot_point_offsets=foot_point_offsets, toe_offset_x=toe_offset_x, max_landing_shift=max_landing_shift)
left_precomputed
instance-attribute
¶
right_precomputed
instance-attribute
¶
left_precomputed_quats
instance-attribute
¶
left_precomputed_quats = motion.links_quat[:, lfoot_idx].copy()
right_precomputed_quats
instance-attribute
¶
right_precomputed_quats = motion.links_quat[:, rfoot_idx].copy()
Methods:¶
reset
¶
update
¶
Single-frame update of the pelvis-z exponential moving average (EMA).
Formula: ema_z += alpha * (target - ema_z). The smaller alpha, the smoother (but slower) the pelvis z response. For real-time per-frame use (not precomputation).
| RETURNS | DESCRIPTION |
|---|---|
float
|
The smoothed pelvis z reference for the current frame. |
Source code in eden/extensions/motion_optimization/tcrs/motion.py
segment_offsets
¶
Batch-compute EMA z offsets for a sequence of pelvis positions.
| PARAMETER | DESCRIPTION |
|---|---|
pelvis_positions
|
(N, 3) pelvis position sequence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
(N,) EMA-smoothed z reference per frame. |
Source code in eden/extensions/motion_optimization/tcrs/motion.py
build_segment
¶
build_segment(pelvis: ndarray, lfoot: ndarray, rfoot: ndarray, left_contact: ndarray, right_contact: ndarray, indices: ndarray) -> tuple[ndarray, ndarray, ndarray, ndarray, ndarray]
Source code in eden/extensions/motion_optimization/tcrs/motion.py
Functions:¶
stabilize_contact_mask
¶
stabilize_contact_mask(mask: ndarray, min_contact_frames: int = 4, min_swing_frames: int = 2) -> ndarray
Remove contact runs shorter than min_contact_frames and fill swing gaps shorter
than min_swing_frames that are surrounded by contact on both sides.
Source code in eden/extensions/motion_optimization/tcrs/motion.py
Gait phase¶
Phase-clock gait analysis for bipedal motion capture data.
Ported from Mondo-Robotics/PMT TCRS/stair_mppi/gait_phase.py @ 88838ca.
Fits a global phase clock φ ∈ [0,1) to periodic locomotion data, with per-foot phase offsets θ_L, θ_R and swing ratios.
Classifies: walking, running, hopping, galloping, standing.
Key design choices:
- Period estimation: hybrid of speed autocorrelation + speed minima touchdown
detection. Autocorrelation works well for walking; speed minima work for
running (where autocorrelation decays too fast).
- Phase timeline: local phase resets at detected touchdowns prevent drift
from stride frequency variation in long sequences.
- Contact z threshold: 0.06 m by default, terrain-invariant. For data where
foot z is not ground-referenced, the raw contact mask is empty and the clock
is fitted from foot speed alone.
- Clips with no significant flight phase are not fitted (fit_phase_clock
returns None): z-based contact is reliable for them.
Usage: from eden.extensions.motion_optimization.tcrs.gait_phase import fit_phase_clock, compute_per_frame_phase params = fit_phase_clock(lfoot_z, rfoot_z, lfoot_speed, rfoot_speed, fps) if params is not None: phase = compute_per_frame_phase(params, n_frames)
Classes¶
GaitPhaseParams
dataclass
¶
GaitPhaseParams(period_frames: float, period_sec: float, swing_ratio_left: float, swing_ratio_right: float, phase_offset_left: float, phase_offset_right: float, gait_type: str, fit_quality: float, fps: float, _left_touchdowns: ndarray = None, _right_touchdowns: ndarray = None)
PerFramePhase
dataclass
¶
PerFramePhase(global_phase: ndarray, left_local_phase: ndarray, right_local_phase: ndarray, left_contact: ndarray, right_contact: ndarray, flight_mask: ndarray, support_weight_left: ndarray, support_weight_right: ndarray)
Functions:¶
fit_phase_clock
¶
fit_phase_clock(lfoot_z: ndarray, rfoot_z: ndarray, lfoot_speed: ndarray, rfoot_speed: ndarray, fps: float, contact_z_threshold: float = 0.06, contact_speed_threshold: float = 0.5) -> GaitPhaseParams | None
Fit phase clock parameters from motion capture data.
Hybrid period estimation: 1. Try speed minima touchdown detection (robust for running) 2. Fallback to speed autocorrelation (better for slow walking)
| PARAMETER | DESCRIPTION |
|---|---|
lfoot_z
|
(N,) left foot z positions, m
TYPE:
|
rfoot_z
|
(N,) right foot z positions, m
TYPE:
|
lfoot_speed
|
(N,) left foot speed magnitude, m/s
TYPE:
|
rfoot_speed
|
(N,) right foot speed magnitude, m/s
TYPE:
|
fps
|
frames per second
TYPE:
|
contact_z_threshold
|
foot z (m) below which a foot can be in raw contact
TYPE:
|
contact_speed_threshold
|
foot speed (m/s) below which a foot can be in raw contact
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
GaitPhaseParams or None
|
None if the clip is shorter than 30 frames, has no significant flight phase (both feet off the ground in under 5% of frames by raw contact, where z-based contact is reliable), or is not periodic. |
Source code in eden/extensions/motion_optimization/tcrs/gait_phase.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
compute_per_frame_phase
¶
compute_per_frame_phase(params: GaitPhaseParams, n_frames: int) -> PerFramePhase
Compute per-frame phase, contact masks, and support weights.
Uses detected touchdowns for piecewise linear phase (drift-resistant).
Source code in eden/extensions/motion_optimization/tcrs/gait_phase.py
Foot-swing optimization (MPPI)¶
MPPI (Model Predictive Path Integral) foot swing trajectory optimizer.
Sampling-based foot swing planner. Uses cubic-spline-parameterized control points with a pre-computed basis matrix for fast batch expansion.
Usage: from eden.extensions.motion_optimization.tcrs.mppi_foot import MppiFootOptimizer, MppiFootParams opt = MppiFootOptimizer(MppiFootParams()) traj_x, traj_y, traj_z = opt.optimize_swing( liftoff_pos, landing_pos, swing_duration, ref_traj, ref_times, terrain )
Also exposes slerp_quaternion, used throughout the planner stack.
Ported from Mondo-Robotics/PMT TCRS/stair_mppi/mppi_foot.py @ 88838ca.
Classes¶
MppiFootParams
dataclass
¶
MppiFootParams(n_knots: int = 0, n_samples: int = 128, n_iterations: int = 10, n_dense: int = 100, temperature: float = 0.1, noise_std_xy: float = 0.02, noise_std_z: float = 0.04, w_track: float = 10.0, w_smooth: float = 10.0, w_terrain: float = 10000.0, w_ceiling: float = 500.0, h_clearance: float = 0.03, h_contact_z: float = 0.0, ceiling_margin: float = 0.3, seed: int = 42, w_stance_ground: float = 0.0, w_swing_clearance_reward: float = 0.0)
EvalWrapper
¶
Wraps dense trajectory arrays, providing an .eval(t) interface with linear interpolation at arbitrary times.
Internally stores (n_dense,) time and value arrays; eval() linearly interpolates the value at any time.
Source code in eden/extensions/motion_optimization/tcrs/mppi_foot.py
MppiFootOptimizer
¶
MppiFootOptimizer(params: MppiFootParams | None = None)
Optimize a single-foot swing trajectory via MPPI sampling.
Returns three EvalWrapper objects (x/y/z), as consumed by
:func:~eden.extensions.motion_optimization.tcrs.pipeline.precompute_mppi_foot.
Source code in eden/extensions/motion_optimization/tcrs/mppi_foot.py
Attributes¶
Methods:¶
optimize_swing
¶
optimize_swing(liftoff_pos: ndarray, landing_pos: ndarray, swing_duration: float, ref_traj: ndarray, ref_times: ndarray, terrain: TerrainSource, v_start: ndarray | None = None, v_end: ndarray | None = None, phase_stance_mask: ndarray | None = None, phase_swing_envelope: ndarray | None = None) -> tuple[EvalWrapper, EvalWrapper, EvalWrapper]
Optimize the xyz trajectory of one swing.
v_start/v_end are ignored (the clamped spline boundary conditions
fix zero endpoint velocity). The optional phase-aware inputs (None = disabled)
are phase_stance_mask, an (n_dense,) bool mask of stance samples along
the dense times, and phase_swing_envelope, an (n_dense,) swing
intensity in [0, 1].
| RETURNS | DESCRIPTION |
|---|---|
tuple[EvalWrapper, EvalWrapper, EvalWrapper]
|
|
Source code in eden/extensions/motion_optimization/tcrs/mppi_foot.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
Functions:¶
slerp_quaternion
¶
SLERP between two [w,x,y,z] quaternions. Returns (N, 4) in [w,x,y,z].
Aligns q1 to the same hemisphere as q0 (flips if dot < 0) to ensure shortest-arc interpolation — avoids unexpected 360 degree foot rotations.
Source code in eden/extensions/motion_optimization/tcrs/mppi_foot.py
Pelvis-height filtering¶
Support-aware pelvis-z filtering for terrain reference warping.
Smooths a per-frame absolute pelvis-z target with an asymmetric EMA and a per-frame rate limit, so the root tracks terrain height changes without step discontinuities. The caller (the pipeline's pelvis-z retargeting stage) constructs the target; this filter only smooths it.
Ported from Mondo-Robotics/PMT TCRS/stair_mppi/terrain_warp.py @ 88838ca
(the SupportAwareRootZFilter.step path only; upstream's legacy
TerrainReferenceWarper / raw-foot-data filter path is dead code and was
not ported).
Classes¶
SupportAwareRootZFilter
¶
SupportAwareRootZFilter(alpha_up: float = 0.35, alpha_down: float = 0.1, max_delta: float = 0.02, flight_alpha: float = 0.6)
Smooth a precomputed absolute pelvis-z target with EMA + rate limit.
The caller builds z_target externally; this filter applies an
asymmetric EMA (faster rise than fall, faster still in flight) followed by
a per-frame rate clamp.
Source code in eden/extensions/motion_optimization/tcrs/terrain_warp.py
Attributes¶
Methods:¶
reset
¶
step
¶
Smooth one externally-constructed z_target.
| PARAMETER | DESCRIPTION |
|---|---|
z_target
|
Absolute pelvis z target for this frame.
TYPE:
|
is_flight
|
If True, track with at least
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
Smoothed pelvis z. |
Source code in eden/extensions/motion_optimization/tcrs/terrain_warp.py
Whole-body IK¶
MuJoCo damped-least-squares whole-body IK on the leg joints.
The root pose is fixed (or softly tracked in :meth:JacobianIK.solve_with_root)
to the target root pose. Upper-body joints are held to the provided reference
joint angles. Only the leg joints are updated. Foot targets are tracked as
multi-point constraints (ankle body plus virtual toe and heel points offset in
the ankle frame), with asymmetric penetration weighting and a deterministic
multi-seed restart for hard frames.
Robot geometry (link/DOF names, toe/heel contact offsets) comes from
:class:~eden.options.extensions.motion_optimization.TCRSRobotOptions; nothing is
hardcoded to the G1 beyond the defaults that spec carries.
Ported from Mondo-Robotics/PMT TCRS/stair_mppi/ghost_ik.py @ 88838ca
(class G1GhostJacobianIK; config loading takes the dict from
TCRSRobotOptions.ik_config instead of a JSON path).
Classes¶
IKResult
dataclass
¶
IKResult(qpos: ndarray, leg_qpos: ndarray, left_pos_err: float, right_pos_err: float, left_rot_err: float, right_rot_err: float, converged: bool, iterations: int, root_pos_offset: ndarray = None, cost: float = 0.0, seed_index: int = 0, used_multiseed: bool = False)
FrameIKTargets
dataclass
¶
FrameIKTargets(root_pos: ndarray, root_quat: ndarray, left_pos: ndarray, left_quat: ndarray, right_pos: ndarray, right_quat: ndarray, fixed_upper_body_qpos: ndarray, ref_leg_qpos: ndarray = None, left_point_scale: ndarray = None, right_point_scale: ndarray = None, root_xy_weight: float = 2.0, root_z_weight: float = 10.0)
JacobianIK
¶
JacobianIK(model: MjModel, robot_spec: TCRSRobotOptions, max_iters: int = 30, tol: float = 0.001, damping: float = 0.05, step_size: float = 0.5, orientation_weight: float = 0.2, posture_weight: float = 0.02, max_joint_step: float = 0.2, penetration_weight: float = 10.0, ankle_weight: float = 1.0, toe_weight: float = 1.0, heel_weight: float = 1.0, ankle_rot_weight: float = 0.0, multiseed_enabled: bool = True, multiseed_num_seeds: int = 3, multiseed_trigger_pos_err: float = 0.2, multiseed_trigger_joint_step: float = 0.8, multiseed_seed_span: float = 0.35, multiseed_continuity_weight: float = 0.25, multiseed_posture_weight: float = 0.02)
Differential whole-body IK on the leg joints.
Supports per-link position and rotation constraints loaded from an
ik_config dict (see :data:~eden.options.extensions.motion_optimization.DEFAULT_IK_CONFIG).
Each link in the config can have:
- pos_weight: weight for 3D position tracking (0 = disabled)
- rot_weight: weight for 3D orientation tracking (0 = disabled)
Special entries (left_toe, left_heel, right_toe, right_heel) define virtual constraint points on the foot bodies with offsets.
Source code in eden/extensions/motion_optimization/tcrs/ik.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
Attributes¶
multiseed_trigger_pos_err
instance-attribute
¶
multiseed_trigger_joint_step
instance-attribute
¶
multiseed_continuity_weight
instance-attribute
¶
multiseed_posture_weight
instance-attribute
¶
point_weights
instance-attribute
¶
point_weights = np.array([ankle_weight, ankle_weight, ankle_weight, toe_weight, toe_weight, toe_weight, heel_weight, heel_weight, heel_weight], dtype=np.float64)
left_foot_body_id
instance-attribute
¶
right_foot_body_id
instance-attribute
¶
left_knee_body_id
instance-attribute
¶
right_knee_body_id
instance-attribute
¶
pelvis_body_id
instance-attribute
¶
leg_joint_ids
instance-attribute
¶
leg_qpos_adr
instance-attribute
¶
leg_dof_adr
instance-attribute
¶
non_leg_qpos_adr
instance-attribute
¶
Methods:¶
from_config
classmethod
¶
from_config(model: MjModel, robot_spec: TCRSRobotOptions) -> 'JacobianIK'
Create the IK solver from robot_spec.ik_config (GMR-style per-link weights).
The config dict has two sections: - link_weights: per-link pos_weight/rot_weight - solver: global solver parameters
Real MuJoCo bodies with non-zero pos/rot weights (excluding the foot multi-point entries) are added as extra body constraints.
The solver section is merged over DEFAULT_IK_CONFIG["solver"] and
read without per-key fallbacks — the defaults dict is the single source
of truth, and unknown solver keys raise.
Source code in eden/extensions/motion_optimization/tcrs/ik.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
extract_leg_qpos
¶
solve_with_root
¶
solve_with_root(data: MjData, target_root_pos: ndarray, target_root_quat: ndarray, target_lf_pos: ndarray, target_lf_quat: ndarray, target_rf_pos: ndarray, target_rf_quat: ndarray, fixed_upper_body_qpos: ndarray, initial_leg_qpos: ndarray = None, ref_leg_qpos: ndarray = None, root_xy_weight: float = 2.0, root_z_weight: float = 10.0, left_point_scale: ndarray = None, right_point_scale: ndarray = None, allow_multiseed: bool = True, force_multiseed: bool = False, initial_root_pos: ndarray = None, root_continuity_weight: float = 0.0) -> IKResult
Solve IK with cuRobo-style adaptive multi-seed fallback.
The fast path is differential IK from the previous frame seed. If that candidate has high pose error or a large joint jump, run a small deterministic seed bank and select the lowest-cost result.
Source code in eden/extensions/motion_optimization/tcrs/ik.py
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
pack_state
¶
Pack root_xyz (3) + leg_q (12 for the G1) into a flat (3 + n_leg_dofs,) vector.
Source code in eden/extensions/motion_optimization/tcrs/ik.py
Functions:¶
Terrain sources¶
Terrain height-query sources for the TCRS pipeline.
Upstream TCRS queries terrain through MuJoCo raycasts against a scene XML
(RaycastTerrain). Eden replaces that seam with a height-field-backed
implementation that can be built from any of Eden's terrain descriptions:
- :class:
~eden.options.entities.TerrainOptions(procedural generator grid), - a raw :class:
~eden.options.entities.EntityOptionspointing at a 3D mesh file (rasterized to a height field by downward raycasts at construction), - an exported height-field
.npz(see :mod:eden.utils.terrains.io).
The protocol the pipeline actually consumes is small: height_at /
height_batch, plus an optional
foot_side_penetration the planner probes with hasattr for side-wall
push-out. Upstream's steps list, local_heightmap and half_width_y
are dead code and are deliberately not ported.
Height queries interpolate the grid bilinearly. This matches the physical surface: Genesis triangulates the height field into a mesh, so the simulated terrain is piecewise-linear between grid points.
Classes¶
TerrainSource
¶
HeightFieldTerrain
¶
HeightFieldTerrain(height_field_m: ndarray, horizontal_scale: float, origin: tuple[float, float, float] = (0.0, 0.0, 0.0), oob_height: float = 0.0)
Bilinear height queries over a regular grid, in world coordinates.
Out-of-bounds queries return oob_height (upstream returns 0.0 outside
the scanned scene — keep that default) and log a one-time warning with the
observed out-of-bounds fraction so a mis-placed clip is visible.
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
Attributes¶
bounds
property
¶
Terrain extent as (x_min, x_max, y_min, y_max).
Methods:¶
from_terrain_options
classmethod
¶
from_terrain_options(options: 'TerrainOptions', oob_height: float = 0.0) -> 'HeightFieldTerrain'
Build from a procedural :class:TerrainOptions (runs the generators).
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
from_file
classmethod
¶
Build from an exported height-field .npz (:mod:eden.utils.terrains.io).
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
from_entity_options
classmethod
¶
from_entity_options(options: 'EntityOptions', resolution: float = 0.02, miss_height: float = 0.0, oob_height: float = 0.0) -> 'HeightFieldTerrain'
Rasterize a mesh-file entity to a height field by downward raycasts.
Applies the entity's scale, up/front alignment and
default_root_pos/default_root_quat so the grid matches where
the entity would sit in a scene. Cells the rays miss (holes, overhangs
seen from below) get miss_height — never -inf, which would
poison every mean/min in the planner; a miss fraction is logged.
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
state_bytes
¶
state_bytes() -> bytes
Stable byte encoding of everything that determines a height query.
Grid values, cell size, xy origin and the out-of-bounds fill — callers (e.g. the TCRS dataset modifier's result cache) hash these bytes instead of reaching into the private fields.
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
height_at
¶
height_batch
¶
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
print_info
¶
Log a terrain summary (upstream prints; Eden routes to the logger).
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
side_clearance
¶
Distance from (x, y, z) along horizontal direction to the first terrain wall.
A "wall" is where the terrain surface rises above z. Marches the
height field in :data:SIDE_MARCH_STEP increments (upstream shoots a
horizontal mj_ray); returns max_dist when nothing is hit.
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
foot_side_penetration
¶
foot_side_penetration(ankle_x: float, ankle_y: float, ankle_z: float, fwd_x: float, fwd_y: float, foot_half_width: float = 0.05, foot_half_length: float = 0.12) -> tuple[float, float]
Push-out correction if the foot rectangle penetrates terrain side walls.
Port of upstream RaycastTerrain.foot_side_penetration: probes 4
horizontal directions at sole height and accumulates a push away from
any wall closer than the foot half-extent. Returns (0, 0) if clear.
Source code in eden/extensions/motion_optimization/tcrs/terrain_source.py
Functions:¶
Synthetic demo clip¶
Synthetic demo clip for the TCRS examples and tests (numpy-only).
Lives in the package (not the example scripts) so the recipes and tests can
share one generator instead of importlib/sys.path hacks on examples/.
Functions:¶
make_demo_clip
¶
Synthetic straight-line G1 walk along +x (Eden dofs/links order).
Feet alternate 1.4 Hz strides with a 6 cm ankle clearance on flat ground;
hips/knees are roughly interpolated so leg-geometry helpers see sane
capsule lengths. Returns (fps, dofs_pos, links_pos_w, links_quat_w).