File size: 7,108 Bytes
3f4bb1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
241
242
243
244
245
246
247
248
"""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()