Wire LinuxCNC tool table for cutter comp

This commit is contained in:
cnc
2026-05-22 15:38:22 +08:00
parent 3dae570f88
commit ca03981d3f
13 changed files with 119 additions and 49 deletions

View File

@@ -24,6 +24,7 @@ if(CNC_SIM_ENABLE_LINUXCNC_RS274_BACKEND)
list(APPEND cnc_sim_core_sources
src/linuxcnc_canon_bridge.cpp
src/linuxcnc_rs274_backend.cpp
src/linuxcnc_tooldata_fixture.cpp
)
endif()
@@ -143,7 +144,15 @@ if(CNC_SIM_ENABLE_LINUXCNC_BRIDGE)
${CNC_SIM_LINUXCNC_ROOT}/src
${CNC_SIM_LINUXCNC_ROOT}/include
)
target_link_libraries(cnc_sim_linuxcnc_canon_bridge PRIVATE cnc_sim_core)
target_link_directories(cnc_sim_linuxcnc_canon_bridge
PRIVATE
${CNC_SIM_LINUXCNC_ROOT}/lib
)
target_link_libraries(cnc_sim_linuxcnc_canon_bridge PRIVATE cnc_sim_core tooldata)
target_link_options(cnc_sim_linuxcnc_canon_bridge
PRIVATE
"-Wl,-rpath,${CNC_SIM_LINUXCNC_ROOT}/lib"
)
endif()
if(EMSCRIPTEN)

View File

@@ -3,6 +3,7 @@
#include "canon_event_sink.h"
#include "canon.hh"
#include "emc/tooldata/tooldata.hh"
#include <cstdarg>
#include <cstdio>
@@ -736,8 +737,11 @@ int GET_EXTERNAL_SELECTED_TOOL_SLOT() {
return active_sink ? active_sink->selected_tool() : -1;
}
CANON_TOOL_TABLE GET_EXTERNAL_TOOL_TABLE(int) {
CANON_TOOL_TABLE tool{};
CANON_TOOL_TABLE GET_EXTERNAL_TOOL_TABLE(int pocket) {
CANON_TOOL_TABLE tool = tooldata_entry_init();
if (tooldata_get(&tool, pocket) == IDX_OK) {
return tool;
}
std::memset(&tool, 0, sizeof(tool));
return tool;
}

View File

@@ -3,13 +3,13 @@
#include <Python.h>
#include "linuxcnc_canon_bridge.h"
#include "linuxcnc_tooldata_fixture.h"
#include "simulator_gcode_controls.h"
#include "linuxcnc.h"
#include "nml_intf/canon.hh"
#include "nml_intf/interp_return.hh"
#include "rs274ngc/interp_base.hh"
#include "emc/tooldata/tooldata.hh"
#include <sstream>
#include <string>
@@ -32,27 +32,6 @@ struct _inittab builtin_modules[] = {
namespace {
void init_minimal_tooldata_once() {
static bool created = false;
if (!created) {
tool_mmap_creator(nullptr, 0);
created = true;
}
tooldata_reset();
CANON_TOOL_TABLE spindle = tooldata_entry_init();
spindle.toolno = 0;
spindle.pocketno = 0;
tooldata_put(spindle, 0);
CANON_TOOL_TABLE tool = tooldata_entry_init();
tool.toolno = 1;
tool.pocketno = 1;
tool.diameter = 6.0;
tooldata_put(tool, 1);
}
bool normal_read_status(int status) {
return status == INTERP_OK ||
status == INTERP_EXECUTE_FINISH ||
@@ -192,7 +171,7 @@ int parse_linuxcnc_rs274_backend(CanonEventSink &sink,
if (const char *parameter_file = std::getenv("CNC_SIM_RS274_VAR")) {
SET_PARAMETER_FILE_NAME(parameter_file);
}
init_minimal_tooldata_once();
cnc_sim_init_minimal_linuxcnc_tooldata();
sink.clear_callback_status();
cnc_sim_linuxcnc_set_canon_sink(&sink);

View File

@@ -0,0 +1,25 @@
#include "linuxcnc_tooldata_fixture.h"
#include "emc/tooldata/tooldata.hh"
void cnc_sim_init_minimal_linuxcnc_tooldata() {
static bool created = false;
if (!created) {
tool_mmap_creator(nullptr, 0);
created = true;
}
tooldata_reset();
CANON_TOOL_TABLE spindle = tooldata_entry_init();
spindle.toolno = 0;
spindle.pocketno = 0;
tooldata_put(spindle, 0);
CANON_TOOL_TABLE tool = tooldata_entry_init();
tool.toolno = 1;
tool.pocketno = 1;
tool.diameter = 6.0;
tooldata_put(tool, 1);
tooldata_last_index_set(1);
}

View File

@@ -0,0 +1,3 @@
#pragma once
void cnc_sim_init_minimal_linuxcnc_tooldata();

View File

@@ -107,6 +107,10 @@ int main() {
bool saw_cutter_right_first = false;
bool saw_cutter_right_second = false;
bool saw_cutter_right_off_move = false;
bool saw_explicit_cutter_left_first = false;
bool saw_explicit_cutter_left_second = false;
bool saw_explicit_cutter_right_first = false;
bool saw_explicit_cutter_right_second = false;
for (const auto &event : events) {
saw_tool = saw_tool || event.type == CNC_SIM_EVENT_TOOL_CHANGE;
saw_rapid = saw_rapid || event.type == CNC_SIM_EVENT_RAPID;
@@ -356,6 +360,16 @@ int main() {
"G21 G90 G17\n"
"G0 X0 Y0 Z0\n"
"F100\n"
"G41 D1\n"
"G1 X20 Y0\n"
"G1 X20 Y20\n"
"G40\n"
"G1 X0 Y0\n"
"G42 D1\n"
"G1 X20 Y0\n"
"G1 X20 Y-20\n"
"G40\n"
"G1 X0 Y0\n"
"G41.1 D6\n"
"G1 X20 Y0\n"
"G1 X20 Y20\n"
@@ -399,13 +413,37 @@ int main() {
event.line == 13 &&
near(event.end.x, 0.0) &&
near(event.end.y, 0.0));
saw_explicit_cutter_left_first = saw_explicit_cutter_left_first ||
(event.type == CNC_SIM_EVENT_LINEAR_FEED &&
event.line == 16 &&
near(event.end.x, 17.0) &&
near(event.end.y, 3.0));
saw_explicit_cutter_left_second = saw_explicit_cutter_left_second ||
(event.type == CNC_SIM_EVENT_LINEAR_FEED &&
event.line == 17 &&
near(event.end.x, 17.0) &&
near(event.end.y, 20.0));
saw_explicit_cutter_right_first = saw_explicit_cutter_right_first ||
(event.type == CNC_SIM_EVENT_LINEAR_FEED &&
event.line == 21 &&
near(event.end.x, 17.0) &&
near(event.end.y, -3.0));
saw_explicit_cutter_right_second = saw_explicit_cutter_right_second ||
(event.type == CNC_SIM_EVENT_LINEAR_FEED &&
event.line == 22 &&
near(event.end.x, 17.0) &&
near(event.end.y, -20.0));
}
ok &= expect(saw_cutter_left_first, "expected LinuxCNC G41.1 compensated lead-in motion");
ok &= expect(saw_cutter_left_second, "expected LinuxCNC G41.1 compensated side motion");
ok &= expect(saw_cutter_left_first, "expected LinuxCNC G41 D1 compensated lead-in motion");
ok &= expect(saw_cutter_left_second, "expected LinuxCNC G41 D1 compensated side motion");
ok &= expect(saw_cutter_left_off_move, "expected LinuxCNC G40 move after left compensation");
ok &= expect(saw_cutter_right_first, "expected LinuxCNC G42.1 compensated lead-in motion");
ok &= expect(saw_cutter_right_second, "expected LinuxCNC G42.1 compensated side motion");
ok &= expect(saw_cutter_right_first, "expected LinuxCNC G42 D1 compensated lead-in motion");
ok &= expect(saw_cutter_right_second, "expected LinuxCNC G42 D1 compensated side motion");
ok &= expect(saw_cutter_right_off_move, "expected LinuxCNC G40 move after right compensation");
ok &= expect(saw_explicit_cutter_left_first, "expected LinuxCNC G41.1 D6 compensated lead-in motion");
ok &= expect(saw_explicit_cutter_left_second, "expected LinuxCNC G41.1 D6 compensated side motion");
ok &= expect(saw_explicit_cutter_right_first, "expected LinuxCNC G42.1 D6 compensated lead-in motion");
ok &= expect(saw_explicit_cutter_right_second, "expected LinuxCNC G42.1 D6 compensated side motion");
const char comment_program[] =
"G21 G90 G17\n"

View File

@@ -2,13 +2,13 @@
#include "canon_event_sink.h"
#include "linuxcnc_canon_bridge.h"
#include "linuxcnc_tooldata_fixture.h"
#include "simulator_gcode_controls.h"
#include "linuxcnc.h"
#include "nml_intf/interp_return.hh"
#include "nml_intf/canon.hh"
#include "rs274ngc/interp_base.hh"
#include "emc/tooldata/tooldata.hh"
#include <fstream>
#include <iostream>
@@ -238,22 +238,6 @@ bool execute_open_file(InterpBase *interp, const char *path) {
return ok;
}
void init_minimal_tooldata() {
tool_mmap_creator(nullptr, 0);
tooldata_reset();
CANON_TOOL_TABLE spindle = tooldata_entry_init();
spindle.toolno = 0;
spindle.pocketno = 0;
tooldata_put(spindle, 0);
CANON_TOOL_TABLE tool = tooldata_entry_init();
tool.toolno = 1;
tool.pocketno = 1;
tool.diameter = 6.0;
tooldata_put(tool, 1);
}
} // namespace
int main(int argc, char **argv) {
@@ -264,7 +248,7 @@ int main(int argc, char **argv) {
if (const char *parameter_file = std::getenv("CNC_SIM_RS274_VAR")) {
SET_PARAMETER_FILE_NAME(parameter_file);
}
init_minimal_tooldata();
cnc_sim_init_minimal_linuxcnc_tooldata();
CanonEventSink sink;
bool first = true;