@hackbuild/humanoid 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -8
- package/dist/files.d.ts +6 -1
- package/dist/files.js +7 -2
- package/dist/humanoid.iife.js +482 -2
- package/dist/sim.d.ts +7 -0
- package/dist/sim.js +15 -0
- package/dist/single.d.ts +1 -0
- package/dist/single.js +2 -1
- package/dist/sonic.d.ts +173 -0
- package/dist/sonic.js +329 -0
- package/how.ts +1 -0
- package/llms.md +147 -5
- package/package.json +11 -3
package/llms.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hackbuild/humanoid
|
|
2
2
|
|
|
3
|
-
> Run a physics humanoid in the page: MuJoCo simulates a robot from its MJCF files,
|
|
3
|
+
> Run a physics humanoid in the page: MuJoCo simulates a robot from its MJCF files, NVIDIA's GEAR-SONIC policy balances the Unitree G1, and you pose it, shove it and draw it.
|
|
4
4
|
|
|
5
5
|
Generated by tools/llms.mjs from the TypeDoc JSON, the README and the examples of hackbuild-motion. Human docs: https://hackbuild.github.io/hackbuild-motion/docs/humanoid/
|
|
6
6
|
|
|
@@ -11,6 +11,7 @@ Generated by tools/llms.mjs from the TypeDoc JSON, the README and the examples o
|
|
|
11
11
|
- Steps the robot at the model's own timestep however the page's frames fall, resets it to a keyframe, writes joint targets to its position actuators, holds its current pose, shoves it, and reads any body's world pose.
|
|
12
12
|
- Draws it in three.js from the `./three` subpath: one mesh per visible geom, MuJoCo's meshes shared, turned from MuJoCo's z up into y up with the robot facing +Z.
|
|
13
13
|
- Names the Unitree G1 (29 joints) from MuJoCo Menagerie, pinned to one commit, as a ready robot; its files load from GitHub at run time.
|
|
14
|
+
- Runs GEAR-SONIC, NVIDIA's whole body controller for the G1, from the `./sonic` subpath: an encoder and a decoder 50 times a second through onnxruntime-web and a PD loop at every MuJoCo step, so the G1 stands, holds a crouch or a raised arm, and steps to catch a shove. The weights load from Hugging Face at run time.
|
|
14
15
|
|
|
15
16
|
## Install
|
|
16
17
|
|
|
@@ -18,22 +19,25 @@ Generated by tools/llms.mjs from the TypeDoc JSON, the README and the examples o
|
|
|
18
19
|
npm install @hackbuild/humanoid
|
|
19
20
|
```
|
|
20
21
|
|
|
21
|
-
It has no dependencies. MuJoCo and three.js are optional peers: install `@mujoco/mujoco` to import its factory, or let `loadMujoco` load it from `https://cdn.jsdelivr.net/npm/@mujoco/mujoco@4.0.1/mujoco.js`, with `mujoco.wasm` read beside it. `onLicence` receives the line to show. The G1's files come from GitHub when you load it.
|
|
22
|
+
It has no dependencies. MuJoCo, onnxruntime-web and three.js are optional peers: install `@mujoco/mujoco` to import its factory, or let `loadMujoco` load it from `https://cdn.jsdelivr.net/npm/@mujoco/mujoco@4.0.1/mujoco.js`, with `mujoco.wasm` read beside it. `onLicence` receives the line to show. The G1's files come from GitHub when you load it.
|
|
22
23
|
|
|
23
24
|
| download | size |
|
|
24
25
|
|---|---|
|
|
25
26
|
| mujoco.wasm | 11.2 MB, 2.8 MB gzip (measured) |
|
|
26
27
|
| the G1's meshes | 19.7 MB (vendor) |
|
|
28
|
+
| GEAR-SONIC encoder and decoder | 91.0 MB (vendor), from Hugging Face, pinned to one revision |
|
|
29
|
+
|
|
30
|
+
`Sonic.load` loads onnxruntime-web from jsDelivr when you pass no `ort` module, and the policy files from their pinned URLs when you pass no bytes.
|
|
27
31
|
|
|
28
32
|
## Exports
|
|
29
33
|
|
|
30
34
|
### @hackbuild/humanoid
|
|
31
35
|
|
|
32
36
|
```ts
|
|
33
|
-
function fetchModel(url: string, o?: { fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>; onFile?: (path: string, done: number, of: number) => void }): Promise<ModelFiles>
|
|
37
|
+
function fetchModel(url: string, o?: { assetBase?: string; fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>; onFile?: (path: string, done: number, of: number) => void }): Promise<ModelFiles>
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
A robot from the URL of its main MJCF; every file it names is fetched beside it.
|
|
40
|
+
A robot from the URL of its main MJCF; every file it names is fetched beside it, or for files that are not MJCF beside `assetBase` when given (a repository whose meshes live on another host, such as Git LFS).
|
|
37
41
|
|
|
38
42
|
```ts
|
|
39
43
|
function filesFrom(list: Iterable<File>): Promise<ModelFiles>
|
|
@@ -61,13 +65,15 @@ class Humanoid {
|
|
|
61
65
|
readonly rootBody: string | null;
|
|
62
66
|
readonly targets: Float64Array;
|
|
63
67
|
readonly time: number;
|
|
68
|
+
address(joint: string): { qpos: number; qvel: number } | null;
|
|
64
69
|
dispose(): void;
|
|
65
70
|
hold(): void;
|
|
66
71
|
joint(name: string): { dq: number; q: number } | null;
|
|
67
|
-
moveTo(targets:
|
|
72
|
+
moveTo(targets: ArrayLike<number> | Record<string, number>, seconds?: number): void;
|
|
68
73
|
pose(body: string | number): Pose | null;
|
|
69
74
|
push(vx: number, vy: number, vz?: number): boolean;
|
|
70
75
|
reset(key?: string | number): void;
|
|
76
|
+
run(n: number, control?: (sim: Humanoid) => void): void;
|
|
71
77
|
step(seconds: number, max?: number): number;
|
|
72
78
|
static open(mj: Mujoco, files: Pick<ModelFiles, "xml" | "assets"> & { missing?: string[] }): Humanoid;
|
|
73
79
|
}
|
|
@@ -217,6 +223,138 @@ function referencedFiles(xml: string, dirs?: { assetdir?: string; meshdir?: stri
|
|
|
217
223
|
|
|
218
224
|
The files one MJCF names, split into includes and the rest, joined onto its compiler's directories.
|
|
219
225
|
|
|
226
|
+
### @hackbuild/humanoid/sonic
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
function anchorSix(base: Q): number[]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The anchor observation for an upright reference: the base's tilt with its heading removed (heading is the normalized (w, 0, 0, z) of the quaternion), as the first two columns of the rotation from base to reference, read row by row.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
function encoderInput(ref: { dq?: ArrayLike<number>; q: ArrayLike<number> }[], anchor: number[]): Float32Array
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The encoder's 1762 inputs in its g1 mode: mode 0, then ten reference frames 0.1 s apart of joint angles (absolute, policy order) and velocities, then ten anchor observations; the other modes' parts stay zero.
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
const G1_SONIC: { readonly assetBase: "https://media.githubusercontent.com/media/NVlabs/GR00T-WholeBodyControl/2a5e6a1b55d9d0205a96e757b86007ec020cf589/gear_sonic_deploy/g1/"; readonly licence: "g1 deploy model from nvidia's gr00t-wholebodycontrol (apache-2.0), meshes copyright unitree robotics (bsd-3-clause). they load at run time and are not part of this library."; readonly name: "unitree g1, 29 joints, the gear-sonic deploy model"; readonly url: "https://raw.githubusercontent.com/NVlabs/GR00T-WholeBodyControl/2a5e6a1b55d9d0205a96e757b86007ec020cf589/gear_sonic_deploy/g1/scene_29dof.xml" }
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
The G1 model the policy was deployed on: motor actuators, its own joint damping, armature and friction.
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
function intoBody(q: Q, v: [number, number, number]): [number, number, number]
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Rotates world vector v into the frame of quaternion q (w x y z): R(q) transposed times v.
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
interface Ort {
|
|
254
|
+
env: { wasm: { numThreads?: number; wasmPaths?: string } };
|
|
255
|
+
InferenceSession: { create(model: Uint8Array, options?: Record<string, unknown>): Promise<OrtSession> };
|
|
256
|
+
Tensor: new (type: "float32", data: Float32Array, dims: number[]) => unknown;
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The parts of onnxruntime-web this library calls.
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
const ORT_URL: "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.23.2/dist/ort.wasm.min.mjs"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Where onnxruntime-web loads from when no module is given.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
interface OrtSession {
|
|
270
|
+
release?(): Promise<void>;
|
|
271
|
+
run(feeds: Record<string, unknown>): Promise<Record<string, { data: unknown }>>;
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
An onnxruntime session.
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
class Sonic {
|
|
279
|
+
readonly ort: Ort;
|
|
280
|
+
act(encoderIn: Float32Array, history: SonicHistory): Promise<Float32Array<ArrayBufferLike>>;
|
|
281
|
+
dispose(): Promise<void>;
|
|
282
|
+
drive(sim: Humanoid): SonicDriver;
|
|
283
|
+
static load(o?: SonicOptions): Promise<Sonic>;
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
The loaded policy: an encoder and a decoder session.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
const SONIC: { readonly bytes: number; readonly decoder: "https://huggingface.co/nvidia/GEAR-SONIC/resolve/6733128a3d8a523b1418b06bca3cdf61c8b0987f/model_decoder.onnx"; readonly encoder: "https://huggingface.co/nvidia/GEAR-SONIC/resolve/6733128a3d8a523b1418b06bca3cdf61c8b0987f/model_encoder.onnx"; readonly hz: 50; readonly licence: "gear-sonic weights by nvidia. licensed by nvidia corporation under the nvidia open model license (https://huggingface.co/nvidia/GEAR-SONIC/blob/main/LICENSE). they load at run time and are not part of this library."; readonly name: "gear-sonic, the default g1 controller"; readonly revision: "6733128a3d8a523b1418b06bca3cdf61c8b0987f" }
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
The policy files and their terms.
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
const SONIC_JOINTS: { defaults: number[]; effort: (5 | 25 | 88 | 139)[]; kd: number[]; kp: number[]; policyIndex: number[]; scale: number[] }
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
The deployment's joint tables, each in the model's joint order (`G1.joints`).
|
|
300
|
+
|
|
301
|
+
```ts
|
|
302
|
+
class SonicDriver {
|
|
303
|
+
constructor(sonic: Sonic, sim: Humanoid);
|
|
304
|
+
inferenceMs: number;
|
|
305
|
+
reference: number[];
|
|
306
|
+
readonly sim: Humanoid;
|
|
307
|
+
advance(seconds: number): Promise<number>;
|
|
308
|
+
reset(): void;
|
|
309
|
+
state(): SonicState;
|
|
310
|
+
tick(): Promise<void>;
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Runs the policy on one robot: 50 ticks a second, the PD loop at every timestep between.
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
class SonicHistory {
|
|
318
|
+
constructor();
|
|
319
|
+
add(s: SonicState, lastAction: ArrayLike<number>): void;
|
|
320
|
+
decoderInput(token: ArrayLike<number>): Float32Array;
|
|
321
|
+
prime(s: SonicState): void;
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Ten ticks of state and actions, oldest first, laid out as the decoder reads them.
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
interface SonicOptions {
|
|
329
|
+
decoder?: string | ArrayBuffer | Uint8Array<ArrayBufferLike>;
|
|
330
|
+
encoder?: string | ArrayBuffer | Uint8Array<ArrayBufferLike>;
|
|
331
|
+
fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
332
|
+
onLicence?: (line: string) => void;
|
|
333
|
+
onProgress?: (loaded: number, total: number) => void;
|
|
334
|
+
ort?: Ort;
|
|
335
|
+
ortUrl?: string;
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Options for Sonic.load.
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
interface SonicState {
|
|
343
|
+
angularVelocity: number[];
|
|
344
|
+
dq: number[];
|
|
345
|
+
gravity: number[];
|
|
346
|
+
q: number[];
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
One control tick of robot state, in the policy's order.
|
|
351
|
+
|
|
352
|
+
```ts
|
|
353
|
+
function toPolicyOrder(v: ArrayLike<number>): number[]
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
A model order array (29) in the policy's order.
|
|
357
|
+
|
|
220
358
|
### @hackbuild/humanoid/three
|
|
221
359
|
|
|
222
360
|
```ts
|
|
@@ -274,11 +412,15 @@ renderer.setAnimationLoop(() => (robot.step(1 / 60), view.update(), renderer.ren
|
|
|
274
412
|
- Do not commit the G1's meshes or any robot's files to an app; load them from `G1.url` or from a drop, and show the robot's licence.
|
|
275
413
|
- Call `dispose()` on a Humanoid you are done with; MuJoCo's model and data live on the wasm heap and are not garbage collected.
|
|
276
414
|
- Read poses after `step()`; they are MuJoCo's frame (z up), and the three.js view turns them to y up for you.
|
|
415
|
+
- Do not give the GEAR-SONIC driver the menagerie G1; it needs the deploy model (`G1_SONIC.url` with `assetBase: G1_SONIC.assetBase`), whose joints are on motors.
|
|
416
|
+
- Do not bundle or commit the GEAR-SONIC weights; load them from their pinned Hugging Face URLs and show `SONIC.licence`.
|
|
277
417
|
- Write targets in the actuators' order (`actuated`), not the model's joint order; for the G1 they are the same 29 joints in `G1.joints`.
|
|
278
418
|
|
|
279
419
|
## Errors this package throws
|
|
280
420
|
|
|
281
421
|
- `mujoco did not load from ...` (offline, or the URL is blocked): install `@mujoco/mujoco` and pass its factory, or serve it and pass `url`
|
|
422
|
+
- `no actuator drives ... load the g1 deploy model` (the policy was given the menagerie G1): load `G1_SONIC.url` with `assetBase: G1_SONIC.assetBase`
|
|
423
|
+
- `onnxruntime-web did not load from ...` (offline, or jsDelivr is blocked): install `onnxruntime-web` and pass the module as `ort`
|
|
282
424
|
- `mujoco could not compile the model: ...` (a named file is missing or the MJCF is invalid): keep the robot's folder structure; the message names files that did not arrive
|
|
283
425
|
- `the model has no keyframe ...` (a keyframe name the model lacks): use one from `keyframes`
|
|
284
426
|
- `no mjcf here` (the drop holds no MJCF with a worldbody): drop the robot's whole folder
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/humanoid",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A physics humanoid in the page: MuJoCo (Google DeepMind's WebAssembly build, loaded at run time and never bundled) runs a robot from its MJCF files, holds joint targets with its position actuators, and gives the body's pose to a three.js view. Starts with the Unitree G1
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A physics humanoid in the page: MuJoCo (Google DeepMind's WebAssembly build, loaded at run time and never bundled) runs a robot from its MJCF files, holds joint targets with its position actuators, and gives the body's pose to a three.js view. Starts with the Unitree G1, and runs NVIDIA's GEAR-SONIC policy on it so it balances (weights and onnxruntime-web loaded at run time).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Moheeb Zara <hackbuildvideo@gmail.com>",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"types": "./dist/three.d.ts",
|
|
24
24
|
"import": "./dist/three.js"
|
|
25
25
|
},
|
|
26
|
+
"./sonic": {
|
|
27
|
+
"types": "./dist/sonic.d.ts",
|
|
28
|
+
"import": "./dist/sonic.js"
|
|
29
|
+
},
|
|
26
30
|
"./iife": "./dist/humanoid.iife.js"
|
|
27
31
|
},
|
|
28
32
|
"unpkg": "dist/humanoid.iife.js",
|
|
@@ -39,7 +43,8 @@
|
|
|
39
43
|
},
|
|
40
44
|
"peerDependencies": {
|
|
41
45
|
"@mujoco/mujoco": ">=4.0.1",
|
|
42
|
-
"three": ">=0.186.1"
|
|
46
|
+
"three": ">=0.186.1",
|
|
47
|
+
"onnxruntime-web": ">=1.23.2"
|
|
43
48
|
},
|
|
44
49
|
"peerDependenciesMeta": {
|
|
45
50
|
"@mujoco/mujoco": {
|
|
@@ -47,6 +52,9 @@
|
|
|
47
52
|
},
|
|
48
53
|
"three": {
|
|
49
54
|
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"onnxruntime-web": {
|
|
57
|
+
"optional": true
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
}
|