From 6c2e496d55ef2d0c44c169620adeacb0d269d0e9 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Tue, 1 Dec 2026 16:46:15 +1100 Subject: [PATCH] task: send G33 $1 moves when no F word was set STRAIGHT_FEED drops a move with zero feed rate unless spindle sync is on, so G33 runs with F still 0. That check read the sync flag of canon.spindle_num, which only G94/G95 set (0 in G94), while G33 $1 set the flag of spindle 1. So G33 ... $1 with no F word programmed was dropped silently and the axis never moved. STOP_SPEED_FEED_SYNCH likewise cleared the wrong spindle's flag. Motion syncs one spindle at a time, so canon keeps one flag instead of one per spindle. tests/motion/g33-spindle-select runs G33 $1 on two simulated spindles with no F word; it fails on master with Z left at the start. --- include/nml_intf/canon.hh | 3 +- src/emc/task/emccanon.cc | 8 +- tests/motion/g33-spindle-select/README | 7 ++ tests/motion/g33-spindle-select/expected | 1 + tests/motion/g33-spindle-select/spindles.hal | 27 ++++++ tests/motion/g33-spindle-select/test-ui.py | 65 +++++++++++++ tests/motion/g33-spindle-select/test.ini | 96 ++++++++++++++++++++ tests/motion/g33-spindle-select/test.sh | 4 + 8 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 tests/motion/g33-spindle-select/README create mode 100644 tests/motion/g33-spindle-select/expected create mode 100644 tests/motion/g33-spindle-select/spindles.hal create mode 100755 tests/motion/g33-spindle-select/test-ui.py create mode 100644 tests/motion/g33-spindle-select/test.ini create mode 100755 tests/motion/g33-spindle-select/test.sh diff --git a/include/nml_intf/canon.hh b/include/nml_intf/canon.hh index a89772c224f..8d262819811 100644 --- a/include/nml_intf/canon.hh +++ b/include/nml_intf/canon.hh @@ -145,7 +145,6 @@ struct CANON_VECTOR { typedef struct { int feed_mode; - int synched; double speed; int dir; double css_maximum; @@ -170,6 +169,7 @@ typedef struct CanonConfig_t { naivecamTolerance(0.0), feed_mode(0), spindle_num(0), + synched(0), spindle{}, linearFeedRate(0.0), angularFeedRate(0.0), @@ -214,6 +214,7 @@ typedef struct CanonConfig_t { double naivecamTolerance; int feed_mode; int spindle_num; //current spindle for spindle-synch motion + int synched; // a spindle-synched move is active; motion syncs one spindle at a time CanonSpindle_t spindle[EMCMOT_MAX_SPINDLES]; /* Prepped tool is saved here */ diff --git a/src/emc/task/emccanon.cc b/src/emc/task/emccanon.cc index 589935dbc84..51e5056a19f 100644 --- a/src/emc/task/emccanon.cc +++ b/src/emc/task/emccanon.cc @@ -1425,7 +1425,7 @@ static void flush_segments(void) { linearMoveMsg->type = EMC_MOTION_TYPE_FEED; linearMoveMsg->indexer_jnum = -1; - if ((vel && acc) || canon.spindle[canon.spindle_num].synched) { + if ((vel && acc) || canon.synched) { interp_list.set_line_number(line_no); tag_and_send(std::move(linearMoveMsg), pos.tag); } @@ -1882,13 +1882,13 @@ void START_SPEED_FEED_SYNCH(int spindle, double feed_per_revolution, bool veloci spindleSyncMsg->velocity_mode = velocity_mode; spindleSyncMsg->angular_offset_degrees = angle_degrees; interp_list.append(std::move(spindleSyncMsg)); - canon.spindle[spindle].synched = 1; + canon.synched = 1; } void STOP_SPEED_FEED_SYNCH() { START_SPEED_FEED_SYNCH(0, 0, false); - canon.spindle[canon.spindle_num].synched = 0; + canon.synched = 0; } /* Machining Functions */ @@ -3984,8 +3984,8 @@ void INIT_CANON() SET_NAIVECAM_TOLERANCE(0); for (int s = 0; s < EMCMOT_MAX_SPINDLES; s++) { canon.spindle[s].speed = 0.0; - canon.spindle[s].synched = 0; } + canon.synched = 0; canon.optional_program_stop = ON; //set enabled by default (previous EMC behaviour) canon.block_delete = ON; //set enabled by default (previous EMC behaviour) canon.cartesian_move = 0; diff --git a/tests/motion/g33-spindle-select/README b/tests/motion/g33-spindle-select/README new file mode 100644 index 00000000000..fbb474d2c5a --- /dev/null +++ b/tests/motion/g33-spindle-select/README @@ -0,0 +1,7 @@ +G33 with a $ word must run when no F word has been programmed. + +A synchronized move takes its speed from the spindle, so task sends it even +with a zero feed rate. That exception looked at the sync state of spindle 0 +in G94, so "G33 ... $1" with F still 0 was dropped without an error and the +axis never moved. Two simulated spindles; checks that a G33 synchronized to +spindle 1, with no F ever set, ends at its programmed Z. diff --git a/tests/motion/g33-spindle-select/expected b/tests/motion/g33-spindle-select/expected new file mode 100644 index 00000000000..8c0382aa4aa --- /dev/null +++ b/tests/motion/g33-spindle-select/expected @@ -0,0 +1 @@ +Completed successfully diff --git a/tests/motion/g33-spindle-select/spindles.hal b/tests/motion/g33-spindle-select/spindles.hal new file mode 100644 index 00000000000..d10ac777915 --- /dev/null +++ b/tests/motion/g33-spindle-select/spindles.hal @@ -0,0 +1,27 @@ +# two spindles, each with a simulated encoder giving revs and an index pulse +loadrt [KINS]KINEMATICS +loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS num_spindles=[TRAJ]SPINDLES +loadrt sim_spindle names=sim_spindle.0,sim_spindle.1 + +addf motion-command-handler servo-thread +addf motion-controller servo-thread +addf sim_spindle.0 servo-thread +addf sim_spindle.1 servo-thread + +net Xpos joint.0.motor-pos-cmd => joint.0.motor-pos-fb +net Ypos joint.1.motor-pos-cmd => joint.1.motor-pos-fb +net Zpos joint.2.motor-pos-cmd => joint.2.motor-pos-fb + +net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in +net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared +net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed + +# speed-out is rpm, sim_spindle position is revs +setp sim_spindle.0.scale 0.01666667 +setp sim_spindle.1.scale 0.01666667 +net spindle0-cmd spindle.0.speed-out => sim_spindle.0.velocity-cmd +net spindle0-index spindle.0.index-enable <=> sim_spindle.0.index-enable +net spindle0-pos sim_spindle.0.position-fb => spindle.0.revs +net spindle1-cmd spindle.1.speed-out => sim_spindle.1.velocity-cmd +net spindle1-index spindle.1.index-enable <=> sim_spindle.1.index-enable +net spindle1-pos sim_spindle.1.position-fb => spindle.1.revs diff --git a/tests/motion/g33-spindle-select/test-ui.py b/tests/motion/g33-spindle-select/test-ui.py new file mode 100755 index 00000000000..98d24b3f9d7 --- /dev/null +++ b/tests/motion/g33-spindle-select/test-ui.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# +# G33 synchronized to spindle 1 with no F word ever programmed, see README. + +import linuxcnc +import linuxcnc_util +import hal + +import sys +import time + +TIMEOUT = 30 # seconds for one MDI line to finish + +c = linuxcnc.command() +s = linuxcnc.stat() +e = linuxcnc.error_channel() +l = linuxcnc_util.LinuxCNC(command=c, status=s, error=e) + +c.state(linuxcnc.STATE_ESTOP_RESET) +c.state(linuxcnc.STATE_ON) +c.home(-1) +c.wait_complete() +l.wait_for_home([1, 1, 1, 0, 0, 0, 0, 0, 0]) + +c.mode(linuxcnc.MODE_MDI) +c.wait_complete() + + +def mdi(cmd): + c.mdi(cmd) + c.wait_complete() + end = time.time() + TIMEOUT + while time.time() < end: + s.poll() + if s.interp_state == linuxcnc.INTERP_IDLE and s.queue == 0 and s.inpos: + break + time.sleep(0.01) + else: + print("FAIL: '{}' did not finish".format(cmd)) + sys.exit(1) + err = e.poll() + if err: + print("FAIL: '{}' raised: {}".format(cmd, err[1].strip())) + sys.exit(1) + + +for cmd in ("G21 G90", "M3 $1 S600", "G0 Z5"): + mdi(cmd) + +mdi("G33 Z-5 K1 $1") +s.poll() +z = s.position[2] +revs = hal.get_value("spindle.1.revs") +print("after G33 $1: Z={:.4f} spindle.1.revs={:.3f}".format(z, revs)) +if abs(z + 5) > 1e-6: + print("FAIL: G33 $1 with no F word ended at Z={:.4f}, expected -5".format(z)) + sys.exit(1) +# the index reset zeroes revs when the move starts; K1 over 10 mm is 10 revs +if revs < 10: + print("FAIL: spindle 1 turned {:.3f} revs since the index, expected 10 or more".format(revs)) + sys.exit(1) + +mdi("M5 $1") +print("Completed successfully") +sys.exit(0) diff --git a/tests/motion/g33-spindle-select/test.ini b/tests/motion/g33-spindle-select/test.ini new file mode 100644 index 00000000000..301eb5a9c96 --- /dev/null +++ b/tests/motion/g33-spindle-select/test.ini @@ -0,0 +1,96 @@ +[EMC] +DEBUG = 0 +VERSION = 1.1 + +[DISPLAY] +DISPLAY = ./test-ui.py + +[TASK] +TASK = milltask +CYCLE_TIME = 0.001 + +[RS274NGC] +PARAMETER_FILE = sim.var + +[EMCMOT] +EMCMOT = motmod +BASE_PERIOD = 0 +SERVO_PERIOD = 1000000 + +[HAL] +HALFILE = ./spindles.hal + +[TRAJ] +NO_FORCE_HOMING = 1 +AXES = 3 +SPINDLES = 2 +COORDINATES = X Y Z +HOME = 0 0 0 +LINEAR_UNITS = mm +ANGULAR_UNITS = degree +DEFAULT_LINEAR_VELOCITY = 100 +MAX_LINEAR_VELOCITY = 500 + +[KINS] +KINEMATICS = trivkins +JOINTS = 3 + +[AXIS_X] +MIN_LIMIT = -1000.0 +MAX_LIMIT = 1000.0 +MAX_VELOCITY = 500 +MAX_ACCELERATION = 3000 + +[JOINT_0] +TYPE = LINEAR +HOME = 0.000 +MAX_VELOCITY = 500 +MAX_ACCELERATION = 3000 +BACKLASH = 0.000 +INPUT_SCALE = 4000 +OUTPUT_SCALE = 1.000 +MIN_LIMIT = -1000.0 +MAX_LIMIT = 1000.0 +FERROR = 0.050 +MIN_FERROR = 0.010 +HOME_SEQUENCE = 0 + +[AXIS_Y] +MIN_LIMIT = -1000.0 +MAX_LIMIT = 1000.0 +MAX_VELOCITY = 500 +MAX_ACCELERATION = 3000 + +[JOINT_1] +TYPE = LINEAR +HOME = 0.000 +MAX_VELOCITY = 500 +MAX_ACCELERATION = 3000 +BACKLASH = 0.000 +INPUT_SCALE = 4000 +OUTPUT_SCALE = 1.000 +MIN_LIMIT = -1000.0 +MAX_LIMIT = 1000.0 +FERROR = 0.050 +MIN_FERROR = 0.010 +HOME_SEQUENCE = 0 + +[AXIS_Z] +MIN_LIMIT = -500.0 +MAX_LIMIT = 500.0 +MAX_VELOCITY = 500 +MAX_ACCELERATION = 3000 + +[JOINT_2] +TYPE = LINEAR +HOME = 0.0 +MAX_VELOCITY = 500 +MAX_ACCELERATION = 3000 +BACKLASH = 0.000 +INPUT_SCALE = 4000 +OUTPUT_SCALE = 1.000 +MIN_LIMIT = -500.0 +MAX_LIMIT = 500.0 +FERROR = 0.050 +MIN_FERROR = 0.010 +HOME_SEQUENCE = 0 diff --git a/tests/motion/g33-spindle-select/test.sh b/tests/motion/g33-spindle-select/test.sh new file mode 100755 index 00000000000..87a3bca3260 --- /dev/null +++ b/tests/motion/g33-spindle-select/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash +if linuxcnc -r test.ini; then + echo "Completed successfully" > result +fi