mujoco-react 8.9.0 → 8.9.2
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 +14 -27
- package/bin/mujoco-react.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,6 @@ export default defineConfig({
|
|
|
32
32
|
mujocoReact({
|
|
33
33
|
models: {
|
|
34
34
|
franka: "models/panda/scene.xml",
|
|
35
|
-
spot: "models/spot/scene.xml",
|
|
36
35
|
},
|
|
37
36
|
}),
|
|
38
37
|
],
|
|
@@ -57,15 +56,6 @@ const generatedRobotResources = {
|
|
|
57
56
|
geoms: { floor: "floor" },
|
|
58
57
|
keyframes: { home: "home" },
|
|
59
58
|
},
|
|
60
|
-
spot: {
|
|
61
|
-
actuators: { fl_hx: "fl_hx", fl_hy: "fl_hy", fl_kn: "fl_kn" },
|
|
62
|
-
sensors: {},
|
|
63
|
-
bodies: { body: "body", fl_hip: "fl_hip", fl_uleg: "fl_uleg" },
|
|
64
|
-
joints: { fl_hx: "fl_hx", fl_hy: "fl_hy", fl_kn: "fl_kn" },
|
|
65
|
-
sites: {},
|
|
66
|
-
geoms: { floor: "floor" },
|
|
67
|
-
keyframes: { home: "home" },
|
|
68
|
-
},
|
|
69
59
|
};
|
|
70
60
|
|
|
71
61
|
registerRobotResources(generatedRobotResources);
|
|
@@ -82,19 +72,10 @@ declare module "mujoco-react" {
|
|
|
82
72
|
geoms: "floor";
|
|
83
73
|
keyframes: "home";
|
|
84
74
|
};
|
|
85
|
-
spot: {
|
|
86
|
-
actuators: "fl_hx" | "fl_hy" | "fl_kn";
|
|
87
|
-
sensors: never;
|
|
88
|
-
bodies: "body" | "fl_hip" | "fl_uleg";
|
|
89
|
-
joints: "fl_hx" | "fl_hy" | "fl_kn";
|
|
90
|
-
sites: never;
|
|
91
|
-
geoms: "floor";
|
|
92
|
-
keyframes: "home";
|
|
93
|
-
};
|
|
94
75
|
};
|
|
95
|
-
actuators: "joint1" | "joint2" | "joint3" | "gripper"
|
|
76
|
+
actuators: "joint1" | "joint2" | "joint3" | "gripper";
|
|
96
77
|
sensors: "force_sensor" | "torque_sensor";
|
|
97
|
-
bodies: "link0" | "link1" | "hand"
|
|
78
|
+
bodies: "link0" | "link1" | "hand";
|
|
98
79
|
}
|
|
99
80
|
}
|
|
100
81
|
```
|
|
@@ -104,7 +85,7 @@ Once generated, hooks like `useCtrl`, `useSensor`, `useBodyState`, and API metho
|
|
|
104
85
|
Non-Vite projects can generate the same file with:
|
|
105
86
|
|
|
106
87
|
```bash
|
|
107
|
-
npx mujoco-react codegen franka=models/panda/scene.xml
|
|
88
|
+
npx mujoco-react codegen franka=models/panda/scene.xml
|
|
108
89
|
```
|
|
109
90
|
|
|
110
91
|
## Load a Model
|
|
@@ -228,14 +209,14 @@ Use control groups when a robot's actuator order does not match a simple `qpos[0
|
|
|
228
209
|
|
|
229
210
|
```tsx
|
|
230
211
|
import { useRef } from "react";
|
|
231
|
-
import { resolveControlGroup, useBeforePhysicsStep } from "mujoco-react";
|
|
212
|
+
import { resolveControlGroup, RobotSites, useBeforePhysicsStep } from "mujoco-react";
|
|
232
213
|
import type { ControlGroupInfo } from "mujoco-react";
|
|
233
214
|
|
|
234
215
|
function HoldTcpPose() {
|
|
235
216
|
const armRef = useRef<ControlGroupInfo | null>(null);
|
|
236
217
|
|
|
237
218
|
useBeforePhysicsStep((model, data) => {
|
|
238
|
-
armRef.current ??= resolveControlGroup(model, { siteName:
|
|
219
|
+
armRef.current ??= resolveControlGroup(model, { siteName: RobotSites.franka.tcp });
|
|
239
220
|
if (!armRef.current) return;
|
|
240
221
|
|
|
241
222
|
armRef.current.writeCtrl(data, armRef.current.readQpos(data));
|
|
@@ -798,7 +779,9 @@ await moveCameraTo(
|
|
|
798
779
|
Read sensor values by name. Returns a `SensorHandle` with `read()`, `dim`, and `name`:
|
|
799
780
|
|
|
800
781
|
```tsx
|
|
801
|
-
|
|
782
|
+
import { RobotSensors, useSensor } from "mujoco-react";
|
|
783
|
+
|
|
784
|
+
const force = useSensor(RobotSensors.franka.force_sensor);
|
|
802
785
|
// force.read() -> Float64Array, force.dim -> number
|
|
803
786
|
```
|
|
804
787
|
|
|
@@ -823,7 +806,9 @@ const { position, velocity } = useJointState("joint1");
|
|
|
823
806
|
Read/write actuator control by name. Returns a `CtrlHandle` with `read()`, `write()`, `name`, and `range`:
|
|
824
807
|
|
|
825
808
|
```tsx
|
|
826
|
-
|
|
809
|
+
import { RobotActuators, useCtrl } from "mujoco-react";
|
|
810
|
+
|
|
811
|
+
const gripper = useCtrl(RobotActuators.franka.gripper);
|
|
827
812
|
// gripper.read() -> number, gripper.write(0.04), gripper.range -> [min, max]
|
|
828
813
|
```
|
|
829
814
|
|
|
@@ -843,11 +828,13 @@ useContactEvents("block_1", {
|
|
|
843
828
|
Map keyboard keys to actuators:
|
|
844
829
|
|
|
845
830
|
```tsx
|
|
831
|
+
import { RobotActuators, useKeyboardTeleop } from "mujoco-react";
|
|
832
|
+
|
|
846
833
|
useKeyboardTeleop({
|
|
847
834
|
bindings: {
|
|
848
835
|
"w": { actuator: "forward", delta: 0.1 },
|
|
849
836
|
"s": { actuator: "forward", delta: -0.1 },
|
|
850
|
-
"v": { actuator:
|
|
837
|
+
"v": { actuator: RobotActuators.franka.gripper, toggle: [0, 0.04] },
|
|
851
838
|
},
|
|
852
839
|
});
|
|
853
840
|
```
|
package/bin/mujoco-react.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { generateMujocoRegister } from '../dist/vite.js';
|
|
|
6
6
|
const usage = `
|
|
7
7
|
Usage:
|
|
8
8
|
mujoco-react codegen <scene.xml> [...more.xml] [--out src/mujoco-register.gen.ts] [--watch]
|
|
9
|
-
mujoco-react codegen franka=models/panda/scene.xml
|
|
9
|
+
mujoco-react codegen franka=models/panda/scene.xml
|
|
10
10
|
|
|
11
11
|
Vite users usually do not need this command. Prefer:
|
|
12
12
|
|