Spaces:
Running
Running
Download tools/eval_kitchen.mjs from VectorW/xlerobot-sim: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/VectorW/xlerobot-sim/resolve/main/tools/eval_kitchen.mjs
- Command line
-
hf download hf://spaces/VectorW/xlerobot-sim/tools/eval_kitchen.mjs
-
curl -L -o eval_kitchen.mjs https://huggingface.co/spaces/VectorW/xlerobot-sim/resolve/main/tools/eval_kitchen.mjs
1.73 kB
| // The pick policy in the kitchen, where it was not trained: go to each object with the approach skill, | |
| // then let the policy pick it. Uses the page's code and ONNX Runtime Web, as tools/eval_policy.mjs. | |
| // | |
| // usage: node tools/eval_kitchen.mjs [assets/policies/xlerobot_pick] | |
| import { readFileSync } from "node:fs"; | |
| import { join } from "node:path"; | |
| import * as ort from "onnxruntime-web"; | |
| import { loadScene, ROOT } from "./node_env.mjs"; | |
| import { approach, restArm, runSkill, runSkillAsync } from "../src/robots/skills.js"; | |
| import { PolicyRunner, policyPick } from "../src/policy/runner.js"; | |
| const dir = process.argv[2] ?? join(ROOT, "assets", "policies", "xlerobot_pick"); | |
| ort.env.wasm.numThreads = 1; | |
| const meta = JSON.parse(readFileSync(join(dir, "policy.json"), "utf8")); | |
| const runner = await PolicyRunner.load(ort, readFileSync(join(dir, meta.onnx)), meta); | |
| const { sim, robot } = await loadScene("kitchen"); | |
| sim.reset(() => { | |
| robot.home(); | |
| robot.snapJoints(); | |
| }); | |
| sim.run(1.0, () => robot.update()); | |
| const settled = sim.snapshot(); | |
| let ok = 0; | |
| const names = ["orange", "apple", "cube"]; | |
| for (const name of names) { | |
| sim.restore(settled); | |
| robot.home(); | |
| const id = sim.id("body", name); | |
| const a = runSkill(sim, robot, approach(robot, id), { maxSeconds: 60 }); | |
| // The go-to skill drives with the arms folded; the policy learned to start with the arm at rest. | |
| if (a.ok) runSkill(sim, robot, restArm(robot, a.side)); | |
| const r = a.ok ? await runSkillAsync(sim, robot, policyPick(robot, runner, id, a.side), { maxSeconds: 14 }) : { ok: false, message: a.message }; | |
| if (r.ok) ok++; | |
| console.log(`${name}: ${a.message} -> ${r.message}`); | |
| } | |
| console.log(`kitchen: the policy picked ${ok}/${names.length}`); | |