Files
NODEDC_MISSION_CORE/tests/test_rover_motion.py
T
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

52 lines
1.9 KiB
Python

import importlib.util
import json
import math
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
"rover_motion", ROOT / "simulation/ai-polygon/rover_motion.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
MOTION = json.loads(
(ROOT / "apps/control-station/public/rover-scene/dcd006-v020-motion.json").read_text()
)
def test_independent_tracks_stop_reverse_and_pivot():
phase = module.TrackPhase(MOTION)
phase.step(0.1, 0.3, -0.3)
left, right = dict(phase.distances), dict(phase.wheel_angles)
phase.step(0.1, 0, 0)
assert phase.distances == left
assert phase.wheel_angles == right
phase.step(0.1, -0.3, 0.3)
for side in ("L", "R"):
assert min(phase.distances[side], MOTION["length_m"] - phase.distances[side]) < 1e-9
for angle in phase.wheel_angles.values():
assert abs(math.sin(angle)) < 1e-9
def test_motion_matches_exported_gltf_rest_pose():
import struct
data = (ROOT / "apps/control-station/public/rover-scene/dcd006-v020-motion.glb").read_bytes()
size = struct.unpack_from("<I", data, 12)[0]
gltf = json.loads(data[20 : 20 + size])
nodes = {n["name"]: n for n in gltf["nodes"]}
for side in ("L", "R"):
for i in range(44):
position, angle = module.belt_pose(MOTION, 0, side, i)
node = nodes[f"{side}_BELT_{i:02d}"]
assert position == pytest.approx(node["translation"], abs=1e-6)
x, y, z, w = node.get("rotation", [0, 0, 0, 1])
assert x == pytest.approx(0, abs=1e-6)
assert y == pytest.approx(0, abs=1e-6)
assert math.sin(angle) == pytest.approx(2 * z * w, abs=1e-6)
assert math.cos(angle) == pytest.approx(1 - 2 * z * z, abs=1e-6)
for wheel in MOTION["wheels"]:
assert wheel["node"] in nodes