feat: release v0.2 multi-robot simulator
Add declarative robot packages, shared simulation lifecycle and Microban ONNX/PD walking with independent head control. Unify comic UI and chase camera; default robot packages to a 4.5m arena with real collision walls. Include regression tests, asset provenance/licenses and verification evidence.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Explicit, offline asset import; never needed to run the browser app.
|
||||
Usage: python3 app/scripts/import-microban.py /path/to/microban
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
source = Path(sys.argv[1]).resolve()
|
||||
target = Path(__file__).resolve().parents[1] / 'public/robots/microban'
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
xml = source / 'src/model/mjcf/robot.xml'
|
||||
files = [('src/model/mjcf/robot.xml', 'model.xml'), ('src/agents/walk.onnx', 'policies/walk.onnx'), ('LICENSE', 'LICENSES/SOURCE-LICENSE.txt')]
|
||||
for mesh in ET.parse(xml).getroot().findall('./asset/mesh'):
|
||||
name = mesh.attrib['file']
|
||||
files.append((f'src/model/mjcf/assets/{name}', f'assets/{name}'))
|
||||
records = []
|
||||
for src, dst in files:
|
||||
data = (source / src).read_bytes()
|
||||
dest = target / dst
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(source / src, dest)
|
||||
records.append({'source': src, 'file': dst, 'sha256': hashlib.sha256(data).hexdigest(), 'bytes': len(data)})
|
||||
# Control sources are not copied into the product, but their working-tree
|
||||
# hashes pin the behavior used to build the adapter/reference fixtures.
|
||||
refs = ['src/constants.py', 'src/moves/walk.py', 'src/moves/rotate_head.py', 'src/observer.py', 'src/imu_reader.py', 'src/sim/mujoco_controller.py', 'src/sim/sim_main.py']
|
||||
manifest = {'head': subprocess.check_output(['git', '-C', str(source), 'rev-parse', 'HEAD'], text=True).strip(), 'dirty': bool(subprocess.check_output(['git', '-C', str(source), 'status', '--porcelain'], text=True)), 'files': records, 'behaviorReferences': [{'file': name, 'sha256': hashlib.sha256((source / name).read_bytes()).hexdigest()} for name in refs]}
|
||||
# Do not guess a remote URL: preserve the actual configured source instead.
|
||||
manifest['source'] = subprocess.check_output(['git', '-C', str(source), 'remote', 'get-url', 'origin'], text=True).strip()
|
||||
apache = Path(__file__).resolve().parents[2] / 'LICENSE'
|
||||
notice = target / 'LICENSES/Apache-2.0.txt'
|
||||
shutil.copyfile(apache, notice)
|
||||
manifest['additionalNotices'] = [{'file': 'LICENSES/Apache-2.0.txt', 'origin': 'Apache-2.0 license text (model.xml notice)', 'sha256': hashlib.sha256(apache.read_bytes()).hexdigest()}]
|
||||
(target / 'source-manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
||||
print(f'Copied {len(records)} files ({sum(r["bytes"] for r in records)} bytes) to {target}')
|
||||
@@ -0,0 +1,57 @@
|
||||
import { readFile, access } from "node:fs/promises";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
validatePackage,
|
||||
validateWorld,
|
||||
} from "../src/platform/loader/SchemaValidator.js";
|
||||
import { resolveWorldId } from "../src/platform/worlds/arena.js";
|
||||
const root = fileURLToPath(new URL("../public/robots/", import.meta.url));
|
||||
const entries = JSON.parse(await readFile(resolve(root, "index.json"), "utf8"));
|
||||
for (const entry of entries) {
|
||||
const file = resolve(root, entry.manifest),
|
||||
config = validatePackage(JSON.parse(await readFile(file, "utf8")));
|
||||
if (config.id !== entry.id || config.family !== entry.family)
|
||||
throw new Error(`Index identity mismatch ${entry.id}`);
|
||||
const paths = [
|
||||
config.model,
|
||||
...config.assets.map((a) => a.path),
|
||||
...config.skills
|
||||
.filter((s) => s.controller.type === "onnx")
|
||||
.map((s) => s.controller.policy),
|
||||
];
|
||||
for (const path of paths) await access(resolve(dirname(file), path));
|
||||
validateWorld(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
resolve(root, `../worlds/${resolveWorldId(config)}/world.json`),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
let provenance;
|
||||
try {
|
||||
provenance = JSON.parse(
|
||||
await readFile(resolve(dirname(file), "source-manifest.json"), "utf8"),
|
||||
);
|
||||
} catch (error) {
|
||||
if (error.code !== "ENOENT") throw error;
|
||||
}
|
||||
if (provenance)
|
||||
for (const record of [
|
||||
...provenance.files,
|
||||
...(provenance.additionalNotices ?? []),
|
||||
]) {
|
||||
const hash = createHash("sha256")
|
||||
.update(await readFile(resolve(dirname(file), record.file)))
|
||||
.digest("hex");
|
||||
if (hash !== record.sha256)
|
||||
throw new Error(
|
||||
`${entry.id}/${record.file}: source SHA-256 mismatch (check git lfs pull or document asset changes)`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`${config.id}: schema, World, ${paths.length} resource paths${provenance ? " and source hashes" : ""} OK`,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user