v2d / simulation /source /v2d_sim /sonic /constants.py
hk239's picture
Upload v2d project (excluding data and .venv) (part 18)
3f4bb1d verified
Raw History Blame Contribute Delete
7.11 kB
"""SONIC v1.1 G1 29-DoF layout.
Matches GR00T ``gear_sonic_deploy/.../policy_parameters.hpp`` and
``checkpoints/sonic/sonic_v1_1/{observation_config,model_config}.yaml``.
Two joint orders coexist and mixing them silently produces a robot that
thrashes instead of standing:
* **MuJoCo order** – hardware/URDF order. ``default_angles``, ``kps``/``kds``
and ``g1_action_scale`` in ``policy_parameters.hpp`` are indexed this way.
* **Isaac Lab order** – what the network actually reads and writes. All policy
observations (``body_joint_positions``, ``last_actions``, reference motion)
and the 29-D action vector are in this order.
Deploy bridges them in ``CreatePolicyCommand``::
q_target_mujoco[i] = default_angles[i]
+ action_isaaclab[isaaclab_to_mujoco[i]] * g1_action_scale[i]
Everything exported below (``DEFAULT_ANGLES``, ``G1_ACTION_SCALE``,
``G1_SONIC_JOINT_NAMES``) is in **Isaac Lab order** so the whole pipeline can
stay in one frame of reference.
"""
from __future__ import annotations
G1_MUJOCO_JOINT_NAMES: list[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_hip_pitch_joint",
"right_hip_roll_joint",
"right_hip_yaw_joint",
"right_knee_joint",
"right_ankle_pitch_joint",
"right_ankle_roll_joint",
"waist_yaw_joint",
"waist_roll_joint",
"waist_pitch_joint",
"left_shoulder_pitch_joint",
"left_shoulder_roll_joint",
"left_shoulder_yaw_joint",
"left_elbow_joint",
"left_wrist_roll_joint",
"left_wrist_pitch_joint",
"left_wrist_yaw_joint",
"right_shoulder_pitch_joint",
"right_shoulder_roll_joint",
"right_shoulder_yaw_joint",
"right_elbow_joint",
"right_wrist_roll_joint",
"right_wrist_pitch_joint",
"right_wrist_yaw_joint",
]
G1_ISAACLAB_JOINT_NAMES: list[str] = [
"left_hip_pitch_joint",
"right_hip_pitch_joint",
"waist_yaw_joint",
"left_hip_roll_joint",
"right_hip_roll_joint",
"waist_roll_joint",
"left_hip_yaw_joint",
"right_hip_yaw_joint",
"waist_pitch_joint",
"left_knee_joint",
"right_knee_joint",
"left_shoulder_pitch_joint",
"right_shoulder_pitch_joint",
"left_ankle_pitch_joint",
"right_ankle_pitch_joint",
"left_shoulder_roll_joint",
"right_shoulder_roll_joint",
"left_ankle_roll_joint",
"right_ankle_roll_joint",
"left_shoulder_yaw_joint",
"right_shoulder_yaw_joint",
"left_elbow_joint",
"right_elbow_joint",
"left_wrist_roll_joint",
"right_wrist_roll_joint",
"left_wrist_pitch_joint",
"right_wrist_pitch_joint",
"left_wrist_yaw_joint",
"right_wrist_yaw_joint",
]
# Policy I/O order.
G1_SONIC_JOINT_NAMES: list[str] = list(G1_ISAACLAB_JOINT_NAMES)
# lower_body_joint_mujoco_order_in_isaaclab_index / wrist_joint_isaaclab_order_in_isaaclab_index
LOWER_BODY_ISAAC_IDX = [0, 3, 6, 9, 13, 17, 1, 4, 7, 10, 14, 18]
WRIST_ISAAC_IDX = [23, 24, 25, 26, 27, 28]
# ManagerEnvWrapper clips the raw network action before scaling.
ACTION_CLIP = 20.0
# TrackingCommandCfg.vr_3point_body / vr_3point_body_offset (offsets are body-local).
VR3_BODIES = ("left_wrist_yaw_link", "right_wrist_yaw_link", "torso_link")
DEFAULT_ANGLES_MUJOCO = [
-0.312,
0.0,
0.0,
0.669,
-0.363,
0.0,
-0.312,
0.0,
0.0,
0.669,
-0.363,
0.0,
0.0,
0.0,
0.0,
0.2,
0.2,
0.0,
0.6,
0.0,
0.0,
0.0,
0.2,
-0.2,
0.0,
0.6,
0.0,
0.0,
0.0,
]
_ARMATURE_5020 = 0.003609725
_ARMATURE_7520_14 = 0.010177520
_ARMATURE_7520_22 = 0.025101925
_ARMATURE_4010 = 0.00425
_W = 10 * 2.0 * 3.1415926535
_STIFF_5020 = _ARMATURE_5020 * _W**2
_STIFF_7520_14 = _ARMATURE_7520_14 * _W**2
_STIFF_7520_22 = _ARMATURE_7520_22 * _W**2
_STIFF_4010 = _ARMATURE_4010 * _W**2
_DAMP_5020 = 2.0 * 2.0 * _ARMATURE_5020 * _W
_DAMP_7520_14 = 2.0 * 2.0 * _ARMATURE_7520_14 * _W
_DAMP_7520_22 = 2.0 * 2.0 * _ARMATURE_7520_22 * _W
_DAMP_4010 = 2.0 * 2.0 * _ARMATURE_4010 * _W
STIFFNESS_5020 = _STIFF_5020
STIFFNESS_7520_14 = _STIFF_7520_14
STIFFNESS_7520_22 = _STIFF_7520_22
STIFFNESS_4010 = _STIFF_4010
DAMPING_5020 = _DAMP_5020
DAMPING_7520_14 = _DAMP_7520_14
DAMPING_7520_22 = _DAMP_7520_22
DAMPING_4010 = _DAMP_4010
ARMATURE_5020 = _ARMATURE_5020
ARMATURE_7520_14 = _ARMATURE_7520_14
ARMATURE_7520_22 = _ARMATURE_7520_22
ARMATURE_4010 = _ARMATURE_4010
ACTION_SCALE_MUJOCO = [
0.25 * 139.0 / _STIFF_7520_22,
0.25 * 139.0 / _STIFF_7520_22,
0.25 * 88.0 / _STIFF_7520_14,
0.25 * 139.0 / _STIFF_7520_22,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 139.0 / _STIFF_7520_22,
0.25 * 139.0 / _STIFF_7520_22,
0.25 * 88.0 / _STIFF_7520_14,
0.25 * 139.0 / _STIFF_7520_22,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 88.0 / _STIFF_7520_14,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 5.0 / _STIFF_4010,
0.25 * 5.0 / _STIFF_4010,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 25.0 / _STIFF_5020,
0.25 * 5.0 / _STIFF_4010,
0.25 * 5.0 / _STIFF_4010,
]
def _to_isaaclab(values_mujoco: list[float]) -> list[float]:
"""Reindex a MuJoCo-ordered per-joint array into Isaac Lab order, by name."""
by_name = dict(zip(G1_MUJOCO_JOINT_NAMES, values_mujoco, strict=True))
return [by_name[n] for n in G1_ISAACLAB_JOINT_NAMES]
DEFAULT_ANGLES = _to_isaaclab(DEFAULT_ANGLES_MUJOCO)
G1_ACTION_SCALE = _to_isaaclab(ACTION_SCALE_MUJOCO)
ENCODER_DIM = 1751
DECODER_DIM = 994
TOKEN_DIM = 64
NUM_JOINTS = 29
HIST_FRAMES = 10
FUTURE_FRAMES = 10
G1_STEP = 5
ENCODER_SLICES: list[tuple[str, int]] = [
("encoder_mode_4", 4),
("motion_joint_positions_10frame_step5", 290),
("motion_joint_velocities_10frame_step5", 290),
("motion_anchor_orientation_heading_10frame_step5", 60),
("motion_anchor_orientation_heading", 6),
("motion_joint_positions_lowerbody_10frame_step5", 120),
("motion_joint_velocities_lowerbody_10frame_step5", 120),
("vr_3point_local_target", 9),
("vr_3point_local_orn_target", 12),
("smpl_joints_10frame_step1", 720),
("smpl_anchor_orientation_heading_10frame_step1", 60),
("motion_joint_positions_wrists_10frame_step1", 60),
]
MODE_IDS = {"g1": 0, "teleop": 1, "smpl": 2}
VR3_OFFSETS = (
(0.18, -0.025, 0.0), # left wrist
(0.18, 0.025, 0.0), # right wrist
(0.0, 0.0, 0.35), # torso / head proxy
)
def encoder_offsets() -> dict[str, tuple[int, int]]:
out: dict[str, tuple[int, int]] = {}
i = 0
for name, dim in ENCODER_SLICES:
out[name] = (i, i + dim)
i += dim
if i != ENCODER_DIM:
raise RuntimeError(f"encoder layout {i} != {ENCODER_DIM}")
return out
ENCODER_OFF = encoder_offsets()