From 874610560a16f974db5ec1ff46525b7df7f57c4e Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 22 May 2026 16:19:55 +0800 Subject: [PATCH] Validate LinuxCNC tool length offsets --- core/src/linuxcnc_tooldata_fixture.cpp | 1 + .../cnc_sim_api_linuxcnc_rs274_smoke.cpp | 2 +- docs/linuxcnc-porting.md | 1 + test-linuxcnc-rs274-native.sh | 2 +- test-linuxcnc-source-link.sh | 22 +++++++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/core/src/linuxcnc_tooldata_fixture.cpp b/core/src/linuxcnc_tooldata_fixture.cpp index 5d0a1fd..ddab817 100644 --- a/core/src/linuxcnc_tooldata_fixture.cpp +++ b/core/src/linuxcnc_tooldata_fixture.cpp @@ -20,6 +20,7 @@ void cnc_sim_init_minimal_linuxcnc_tooldata() { tool.toolno = 1; tool.pocketno = 1; tool.diameter = 6.0; + tool.offset.tran.z = 12.5; tooldata_put(tool, 1); tooldata_last_index_set(1); } diff --git a/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp b/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp index 89c9984..4f3e480 100644 --- a/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp +++ b/core/tests/cnc_sim_api_linuxcnc_rs274_smoke.cpp @@ -346,7 +346,7 @@ int main() { (event.type == CNC_SIM_EVENT_COMMENT && event.line == 2 && event.reserved == 430 && - event.start.z == 0.0); + near(event.start.z, 12.5)); saw_tool_length_clear = saw_tool_length_clear || (event.type == CNC_SIM_EVENT_COMMENT && event.line == 3 && diff --git a/docs/linuxcnc-porting.md b/docs/linuxcnc-porting.md index 6b70676..c699926 100644 --- a/docs/linuxcnc-porting.md +++ b/docs/linuxcnc-porting.md @@ -188,6 +188,7 @@ This matrix tracks LinuxCNC feature coverage for the web/WASM simulator. A featu | --- | --- | --- | | Basic modal motion `G0/G1/G2/G3` | covered | `tests/gcode/linuxcnc_basic_motion.ngc`, `tests/gcode/basic_mill.ngc` | | Tool select/change `T... M6` | covered with minimal native tooldata | `tests/gcode/basic_mill.ngc` | +| Tool length offset `G43/G49` | covered with nonzero tool-table offset through LinuxCNC native/source backends | `tests/gcode/linuxcnc_tool_length.ngc` | | RTCP controls `G43.4/G43.5/G49` | covered as simulator-owned control lines | `tests/gcode/linuxcnc_rtcp_controls.ngc` | | Kinematics switch `M428/M429/M430` | covered as simulator-owned control lines | `tests/gcode/linuxcnc_rtcp_controls.ngc` | | Canned cycle `G81/G80` | covered for drilling expand-to-canon path | `tests/gcode/linuxcnc_canned_cycle.ngc` | diff --git a/test-linuxcnc-rs274-native.sh b/test-linuxcnc-rs274-native.sh index b69e695..b9493ae 100755 --- a/test-linuxcnc-rs274-native.sh +++ b/test-linuxcnc-rs274-native.sh @@ -157,7 +157,7 @@ if not any( event["type"] == "comment" and event["line"] == 2 and event["reserved"] == 430 and - event["start"]["z"] == 0 + event["start"]["z"] == 12.5 for event in tool_length ): raise SystemExit("missing G43 H1 tool length offset event") diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 761f178..80db647 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -101,6 +101,9 @@ CNC_SIM_RS274_VAR="$var_file" \ CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_rtcp_controls.ngc \ >/tmp/cnc_sim_linuxcnc_source_rtcp_controls.json +CNC_SIM_RS274_VAR="$var_file" \ + "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_tool_length.ngc \ + >/tmp/cnc_sim_linuxcnc_source_tool_length.json CNC_SIM_RS274_VAR="$var_file" \ "$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_canned_cycle.ngc \ >/tmp/cnc_sim_linuxcnc_source_canned_cycle.json @@ -147,6 +150,24 @@ 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 source-linked RTCP state sequence") +tool_length = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_tool_length.json").read_text()) +if not any( + event["type"] == "comment" and + event["line"] == 2 and + event["reserved"] == 430 and + event["start"]["z"] == 12.5 + for event in tool_length +): + raise SystemExit("missing source-linked G43 H1 tool length offset event") +if not any( + event["type"] == "comment" and + event["line"] == 3 and + event["reserved"] == 430 and + event["start"]["z"] == 0 + for event in tool_length +): + raise SystemExit("missing source-linked G49 tool length clear event") + cycle = json.loads(Path("/tmp/cnc_sim_linuxcnc_source_canned_cycle.json").read_text()) motions = [event for event in cycle if event["type"] in {"rapid", "linear-feed"}] expected_cycle = [ @@ -249,6 +270,7 @@ PY echo "linuxcnc rs274 source link smoke passed (${#objects[@]} local objects)" echo "dumped /tmp/cnc_sim_linuxcnc_source_basic_mill.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_rtcp_controls.json" +echo "dumped /tmp/cnc_sim_linuxcnc_source_tool_length.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_canned_cycle.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_canned_cycles_extended.json" echo "dumped /tmp/cnc_sim_linuxcnc_source_cutter_comp.json"