95 lines
5.3 KiB
Python
95 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic evidence for SCARA, PUMA and Scorbot kinematics."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
INPUTS = {
|
|
"scara_source": "linuxcnc/src/emc/kinematics/scarakins.c",
|
|
"puma_source": "linuxcnc/src/emc/kinematics/pumakins.c",
|
|
"scorbot_source": "linuxcnc/src/emc/kinematics/scorbot-kins.c",
|
|
"scara_config": "linuxcnc/configs/sim/axis/vismach/scara/scara.ini",
|
|
"puma_config": "linuxcnc/configs/sim/axis/vismach/puma/puma.ini",
|
|
"puma_params": "linuxcnc/configs/sim/axis/vismach/puma/puma_dh.hal",
|
|
"scorbot_config": "linuxcnc/configs/sim/axis/vismach/scorbot/scorbot.ini",
|
|
"implementation": "wasm-core/src/sim_kinematics.c",
|
|
"header": "wasm-core/include/sim_kinematics.h",
|
|
"test": "wasm-core/tests/sim_kinematics_test.c",
|
|
}
|
|
|
|
|
|
def sha256(path: Path) -> str:
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def run_sample(command: list[str], root: Path) -> dict[str, object]:
|
|
completed = subprocess.run(command, cwd=root, check=False, text=True, capture_output=True)
|
|
if completed.returncode != 0:
|
|
raise RuntimeError(f"{command[0]} exited {completed.returncode}: {completed.stderr.strip()}")
|
|
for line in reversed(completed.stdout.splitlines()):
|
|
if line.startswith("{"):
|
|
return json.loads(line)
|
|
raise RuntimeError(f"{command[0]} did not emit a robot sample")
|
|
|
|
|
|
def generate(root: Path, output: Path) -> dict[str, object]:
|
|
root = root.resolve()
|
|
native_all = run_sample([str(root / "build-native/sim_kinematics_test")], root)
|
|
wasm_all = run_sample(["node", str(root / "build-wasm/sim_kinematics_wasm_test.js")], root)
|
|
names = ("scara", "puma", "scorbot")
|
|
native = {name: native_all[name] for name in names}
|
|
wasm = {name: wasm_all[name] for name in names}
|
|
source_records = {name: {"path": path, "sha256": sha256(root / path)} for name, path in INPUTS.items()}
|
|
config_text = {name: (root / INPUTS[f"{name}_config"]).read_text(encoding="utf-8") for name in names}
|
|
native_json = json.dumps(native, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
wasm_json = json.dumps(wasm, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
report = {
|
|
"schema": "robot-kinematics-report.v1",
|
|
"status": "partial",
|
|
"implementation_status": "verified",
|
|
"source_records": source_records,
|
|
"configuration_candidates": {
|
|
"scara": {"path": INPUTS["scara_config"], "kinematics": "scarakins", "coordinates": "xyzcab", "joints": 6, "origin": "shipped", "scan": "KINEMATICS = scarakins coordinates=xyzcab" in config_text["scara"]},
|
|
"puma": {"path": INPUTS["puma_config"], "kinematics": "pumakins", "coordinates": "XYZABC", "joints": 6, "origin": "shipped", "scan": "KINEMATICS = pumakins" in config_text["puma"]},
|
|
"scorbot": {"path": INPUTS["scorbot_config"], "kinematics": "scorbot-kins", "coordinates": "XYZAB", "joints": 5, "origin": "workspace_derived_fixture; source has no shipped sim INI", "scan": "KINEMATICS = scorbot-kins" in config_text["scorbot"]},
|
|
},
|
|
"geometry": {
|
|
"scara": {"defaults": {"D1": 490.0, "D2": 340.0, "D3": 50.0, "D4": 250.0, "D5": 50.0, "D6": 50.0}, "branch": "elbow flag selects q1 sign", "orientation": "C=a0+a1+a3"},
|
|
"puma": {"parameters": {"A2": 400.0, "A3": 50.0, "D3": 100.0, "D4": 400.0, "D6": 95.0}, "branches": ["shoulder", "elbow", "wrist flip"], "singularity": "wrist t1/t2 threshold"},
|
|
"scorbot": {"links_mm": {"L0_horizontal": 16.0, "L0_vertical": 140.0, "L1": 221.0, "L2": 221.0}, "controlled_point": "wrist J3/J4", "branch": "fixed elbow solution from source"},
|
|
},
|
|
"samples": {"native": native, "wasm": wasm, "byte_identical_json": native_json == wasm_json},
|
|
"boundaries": {
|
|
"scara_unreachable": "SIM_KIN_ERR_RANGE verified",
|
|
"puma_unreachable_or_singular": "SIM_KIN_ERR_RANGE/SINGULAR verified",
|
|
"scorbot_unreachable": "SIM_KIN_ERR_RANGE verified",
|
|
"state_hash": "native/WASM identical after 1e-9 hash quantization",
|
|
},
|
|
"oracle": {"status": "blocked", "reason": "linuxcnc/unit_tests/kinematics is absent from the locked source"},
|
|
"native_wasm": {"status": "passed", "native_command": "build-native/sim_kinematics_test", "wasm_command": "node build-wasm/sim_kinematics_wasm_test.js"},
|
|
}
|
|
report["report_sha256"] = hashlib.sha256(json.dumps(report, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")).hexdigest()
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
output.write_text(json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8")
|
|
return report
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
|
|
parser.add_argument("--output", type=Path, default=Path("coverage/robot-kinematics.report.json"))
|
|
args = parser.parse_args()
|
|
report = generate(args.repo_root, args.repo_root / args.output)
|
|
print(f"robot_kinematics={report['status']} native_wasm={report['native_wasm']['status']} oracle={report['oracle']['status']}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|