Initial wasm simulator checkpoint
This commit is contained in:
108
test-linuxcnc-rs274-native.sh
Executable file
108
test-linuxcnc-rs274-native.sh
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
|
||||
cxx=${CXX:-g++}
|
||||
build_dir=${TMPDIR:-/tmp}/cnc_sim_native
|
||||
mkdir -p "$build_dir"
|
||||
var_file="$build_dir/rs274ngc.var"
|
||||
cp "$linuxcnc_root/tests/halui/jogging/sim.var" "$var_file"
|
||||
|
||||
"$cxx" -std=c++17 \
|
||||
$(python3.13-config --includes 2>/dev/null || python3-config --includes) \
|
||||
-I core/include \
|
||||
-I core/src \
|
||||
-I "$linuxcnc_root/src" \
|
||||
-I "$linuxcnc_root/src/emc" \
|
||||
-I "$linuxcnc_root/src/emc/nml_intf" \
|
||||
-I "$linuxcnc_root/src/emc/rs274ngc" \
|
||||
-I "$linuxcnc_root/src/emc/motion" \
|
||||
-I "$linuxcnc_root/include" \
|
||||
core/src/canon_event_sink.cpp \
|
||||
core/src/linuxcnc_canon_bridge.cpp \
|
||||
core/src/rtcp_kinematics.cpp \
|
||||
core/src/simulator_gcode_controls.cpp \
|
||||
core/tools/linuxcnc_rs274_dump.cpp \
|
||||
-L "$linuxcnc_root/lib" \
|
||||
-Wl,-rpath,"$linuxcnc_root/lib" \
|
||||
-lrs274 \
|
||||
-ltooldata \
|
||||
-lpython3.13 \
|
||||
-o "$build_dir/linuxcnc_rs274_dump"
|
||||
|
||||
CNC_SIM_RS274_VAR="$var_file" "$build_dir/linuxcnc_rs274_dump" tests/gcode/linuxcnc_basic_motion.ngc >/tmp/cnc_sim_linuxcnc_basic_motion.json
|
||||
CNC_SIM_RS274_VAR="$var_file" "$build_dir/linuxcnc_rs274_dump" tests/gcode/basic_mill.ngc >/tmp/cnc_sim_linuxcnc_basic_mill.json
|
||||
CNC_SIM_RS274_VAR="$var_file" "$build_dir/linuxcnc_rs274_dump" tests/gcode/linuxcnc_rtcp_controls.ngc >/tmp/cnc_sim_linuxcnc_rtcp_controls.json
|
||||
CNC_SIM_RS274_VAR="$var_file" "$build_dir/linuxcnc_rs274_dump" tests/gcode/linuxcnc_canned_cycle.ngc >/tmp/cnc_sim_linuxcnc_canned_cycle.json
|
||||
CNC_SIM_RS274_VAR="$var_file" "$build_dir/linuxcnc_rs274_dump" tests/gcode/linuxcnc_coordinate_offsets.ngc >/tmp/cnc_sim_linuxcnc_coordinate_offsets.json
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
def check(path, required):
|
||||
events = json.loads(Path(path).read_text())
|
||||
types = [event["type"] for event in events]
|
||||
missing = sorted(required - set(types))
|
||||
if missing:
|
||||
raise SystemExit(f"{path}: missing events: {', '.join(missing)}")
|
||||
final_motion = [event for event in events if event["type"] in {"rapid", "linear-feed", "arc-feed"}][-1]
|
||||
if final_motion["end"]["x"] != 0 or final_motion["end"]["y"] != 0:
|
||||
raise SystemExit(f"{path}: unexpected final XY position")
|
||||
return events
|
||||
|
||||
required_motion = {"set-units", "set-plane", "set-spindle", "rapid", "set-feed", "linear-feed", "arc-feed", "dwell", "program-end"}
|
||||
check("/tmp/cnc_sim_linuxcnc_basic_motion.json", required_motion)
|
||||
check("/tmp/cnc_sim_linuxcnc_basic_mill.json", required_motion | {"tool-change"})
|
||||
|
||||
controls = json.loads(Path("/tmp/cnc_sim_linuxcnc_rtcp_controls.json").read_text())
|
||||
kin = [event for event in controls if event["type"] == "kinematics-switch"]
|
||||
if [(event["reserved"], event["feed"]) for event in kin] != [(1, 1), (0, 0), (2, 1)]:
|
||||
raise SystemExit("unexpected kinematics switch sequence")
|
||||
rtcp = [event for event in controls if event["type"] == "rtcp-state"]
|
||||
if [(event["line"], event["tool"], event["feed"]) for event in rtcp] != [(3, 0, 0), (4, 7, 1)]:
|
||||
raise SystemExit("unexpected RTCP state sequence")
|
||||
|
||||
cycle = json.loads(Path("/tmp/cnc_sim_linuxcnc_canned_cycle.json").read_text())
|
||||
motions = [event for event in cycle if event["type"] in {"rapid", "linear-feed"}]
|
||||
expected_cycle = [
|
||||
("rapid", 0, 0, 5),
|
||||
("rapid", 20, 0, 5),
|
||||
("rapid", 20, 0, 3),
|
||||
("linear-feed", 20, 0, -2),
|
||||
("rapid", 20, 0, 3),
|
||||
]
|
||||
actual_cycle = [(event["type"], event["end"]["x"], event["end"]["y"], event["end"]["z"]) for event in motions]
|
||||
if actual_cycle != expected_cycle:
|
||||
raise SystemExit(f"unexpected G81/G80 expansion: {actual_cycle!r}")
|
||||
|
||||
coords = json.loads(Path("/tmp/cnc_sim_linuxcnc_coordinate_offsets.json").read_text())
|
||||
g5x = [event for event in coords if event["type"] == "set-g5x-offset"]
|
||||
g92 = [event for event in coords if event["type"] == "set-g92-offset"]
|
||||
rot = [event for event in coords if event["type"] == "set-xy-rotation"]
|
||||
if not any(
|
||||
event["tool"] == 1 and
|
||||
event["start"]["x"] == 12.5 and
|
||||
event["start"]["y"] == -3 and
|
||||
event["start"]["z"] == 4
|
||||
for event in g5x
|
||||
):
|
||||
raise SystemExit("missing G10 L2 G5X offset event")
|
||||
if not any(event["feed"] == 30 for event in rot):
|
||||
raise SystemExit("missing G10 L2 XY rotation event")
|
||||
if not any(
|
||||
event["start"]["x"] == 0 and
|
||||
event["start"]["y"] == 0 and
|
||||
event["start"]["z"] == 0
|
||||
for event in g92
|
||||
):
|
||||
raise SystemExit("missing G92.1 clear offset event")
|
||||
PY
|
||||
|
||||
echo "linuxcnc rs274 native smoke passed"
|
||||
echo "dumped /tmp/cnc_sim_linuxcnc_basic_motion.json"
|
||||
echo "dumped /tmp/cnc_sim_linuxcnc_basic_mill.json"
|
||||
echo "dumped /tmp/cnc_sim_linuxcnc_rtcp_controls.json"
|
||||
echo "dumped /tmp/cnc_sim_linuxcnc_canned_cycle.json"
|
||||
echo "dumped /tmp/cnc_sim_linuxcnc_coordinate_offsets.json"
|
||||
Reference in New Issue
Block a user