Emit LinuxCNC probe moves as probe events

This commit is contained in:
CNC Local
2026-05-22 04:59:09 +08:00
parent 8afbadc6d0
commit a0d78b74b2
8 changed files with 65 additions and 1 deletions

View File

@@ -156,6 +156,14 @@ void CanonEventSink::arc_feed(int line, const CncSimPose &end, const CncSimPose
position_ = end;
}
void CanonEventSink::straight_probe(int line, const CncSimPose &end) {
CncSimEvent event = base_event(CNC_SIM_EVENT_PROBE, line);
event.start = position_;
event.end = end;
emit(event);
position_ = end;
}
void CanonEventSink::dwell(double seconds, int line) {
CncSimEvent event = base_event(CNC_SIM_EVENT_DWELL, line);
event.dwell_seconds = seconds;

View File

@@ -27,6 +27,7 @@ public:
void straight_traverse(int line, const CncSimPose &end);
void straight_feed(int line, const CncSimPose &end);
void arc_feed(int line, const CncSimPose &end, const CncSimPose &center, int turns);
void straight_probe(int line, const CncSimPose &end);
void dwell(double seconds, int line);
void program_end(int line);
void emit_raw(CncSimEvent event);

View File

@@ -341,7 +341,7 @@ void STRAIGHT_PROBE(int lineno,
double u, double v, double w,
unsigned char) {
if (active_sink) {
active_sink->straight_feed(lineno, make_pose(x, y, z, a, b, c, u, v, w));
active_sink->straight_probe(event_line(lineno), make_pose(x, y, z, a, b, c, u, v, w));
}
}

View File

@@ -71,6 +71,8 @@ int main() {
bool saw_coordinate_end_line = false;
bool saw_l20_g55_offset = false;
bool saw_l20_end_line = false;
bool saw_probe = false;
bool saw_probe_as_feed = 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;
@@ -119,6 +121,29 @@ int main() {
ok &= expect(saw_g49, "expected LinuxCNC G49 RTCP off state");
ok &= expect(saw_g434, "expected LinuxCNC G43.4 RTCP on state with H code");
const char probe_program[] =
"G21 G90 G17\n"
"G0 X0 Y0 Z5\n"
"F100\n"
"G38.3 Z0\n"
"M30\n";
events.clear();
ok &= expect(cnc_sim_parse_program(sim, probe_program, sizeof(probe_program) - 1) == 0,
cnc_sim_last_error(sim));
for (const auto &event : events) {
saw_probe = saw_probe ||
(event.type == CNC_SIM_EVENT_PROBE &&
event.line == 4 &&
event.feed == 100.0 &&
event.start.z == 5.0 &&
event.end.z == 0.0);
saw_probe_as_feed = saw_probe_as_feed ||
(event.type == CNC_SIM_EVENT_LINEAR_FEED &&
event.line == 4);
}
ok &= expect(saw_probe, "expected LinuxCNC G38.3 probe event");
ok &= expect(!saw_probe_as_feed, "expected LinuxCNC G38.3 to avoid linear-feed event");
const char l20_program[] =
"G21 G90 G17\n"
"G0 X5 Y6 Z7\n"

View File

@@ -39,6 +39,7 @@ int main() {
STRAIGHT_TRAVERSE(10, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
STRAIGHT_FEED(11, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
ARC_FEED(12, 10.0, 10.0, 10.0, 5.0, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
STRAIGHT_PROBE(13, 10.0, 10.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
SET_G5X_OFFSET(1, 10.0, 20.0, 30.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0);
SET_G92_OFFSET(1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
SET_XY_ROTATION(15.0);
@@ -53,6 +54,7 @@ int main() {
bool saw_rapid = false;
bool saw_feed = false;
bool saw_arc = false;
bool saw_probe = false;
bool saw_g5x = false;
bool saw_g92 = false;
bool saw_rotation = false;
@@ -65,6 +67,11 @@ int main() {
event.end.y == 10.0 &&
event.center.x == 10.0 &&
event.center.y == 5.0);
saw_probe = saw_probe || (event.type == CNC_SIM_EVENT_PROBE &&
event.line == 13 &&
event.start.x == 10.0 &&
event.start.y == 10.0 &&
event.end.z == -1.0);
saw_g5x = saw_g5x || (event.type == CNC_SIM_EVENT_SET_G5X_OFFSET &&
event.tool == 1 &&
event.start.x == 10.0 &&
@@ -86,6 +93,7 @@ int main() {
ok &= expect(saw_rapid, "expected rapid move");
ok &= expect(saw_feed, "expected linear feed");
ok &= expect(saw_arc, "expected arc feed");
ok &= expect(saw_probe, "expected probe event");
ok &= expect(saw_g5x, "expected G5X offset event");
ok &= expect(saw_g92, "expected G92 offset event");
ok &= expect(saw_rotation, "expected XY rotation event");