Skip to content

Commit 65f09e9

Browse files
committed
chore: backport of PR LinuxCNC#4160
This is basically a clipped down version of 203abbf and 344395e. Signed-off-by: wucke13 <wucke13+github@gmail.com>
1 parent 39bfc18 commit 65f09e9

11 files changed

Lines changed: 57 additions & 20 deletions

File tree

src/emc/motion/command.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,22 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
505505
if (GET_MOTION_TELEOP_FLAG()) {
506506
axis_jog_abort_all(0);
507507
} else if (GET_MOTION_COORD_FLAG()) {
508+
/* If motion was being held waiting for spindle at-speed, the
509+
operator most likely aborted because the machine sat idle
510+
with no obvious reason. Tell them why, loudly. A wait that
511+
never released after a spindle stop almost always means
512+
spindle.N.at-speed is not wired, or does not go true once the
513+
spindle has actually stopped. */
514+
if (MOTION_ID_VALID(emcmotInternal->coord_tp.spindle.waiting_for_atspeed)) {
515+
for (spindle_num = 0; spindle_num < emcmotConfig->numSpindles; spindle_num++) {
516+
if (emcmotStatus->spindle_status[spindle_num].state == 0 && !emcmotStatus->spindle_status[spindle_num].at_speed) {
517+
reportError(_("Aborted while waiting for spindle %d at-speed after a spindle stop. "
518+
"Check that spindle.%d.at-speed is connected and goes true once the spindle has stopped."),
519+
spindle_num, spindle_num);
520+
break;
521+
}
522+
}
523+
}
508524
tpAbort(&emcmotInternal->coord_tp);
509525
} else {
510526
for (joint_num = 0; joint_num < ALL_JOINTS; joint_num++) {
@@ -528,6 +544,8 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
528544
SET_JOINT_FAULT_FLAG(joint, 0);
529545
}
530546
emcmotStatus->paused = 0;
547+
/* Drop any pending at-speed barrier so it can't strand a later move. */
548+
emcmotStatus->atspeed_next_feed = 0;
531549
break;
532550

533551
case EMCMOT_JOG_ABORT:
@@ -1452,6 +1470,14 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
14521470
}
14531471
}
14541472

1473+
/* A probe is a feed-type move, so honor any pending at-speed
1474+
barrier just like G1: wait for spindle.N.at-speed (spin-up after
1475+
M3, or stop after M5) before the probe starts. */
1476+
if (emcmotStatus->atspeed_next_feed) {
1477+
issue_atspeed = 1;
1478+
emcmotStatus->atspeed_next_feed = 0;
1479+
}
1480+
14551481
/* append it to the emcmotInternal->coord_tp */
14561482
tpSetId(&emcmotInternal->coord_tp, emcmotCommand->id);
14571483
if (-1 == tpAddLine(&emcmotInternal->coord_tp,
@@ -1461,7 +1487,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
14611487
emcmotCommand->ini_maxvel,
14621488
emcmotCommand->acc,
14631489
emcmotStatus->enables_new,
1464-
0,
1490+
issue_atspeed,
14651491
-1,
14661492
emcmotCommand->tag)) {
14671493
reportError(_("can't add probe move"));
@@ -1656,6 +1682,10 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
16561682
*(emcmot_hal_data->spindle[n].spindle_orient) = 0;
16571683
emcmotStatus->spindle_status[n].orient_state = EMCMOT_ORIENT_NONE;
16581684
}
1685+
/* Optionally make the spindle stop an at-speed barrier: the next feed
1686+
move waits until at-speed reflects the stopped state. Safe when
1687+
unwired since at-speed defaults to 1 (see motion.c). */
1688+
emcmotStatus->atspeed_next_feed = emcmotCommand->wait_for_spindle_at_speed;
16591689
break;
16601690

16611691
case EMCMOT_SPINDLE_ORIENT:

src/emc/motion/motion.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ static int export_spindle(int num, spindle_hal_t * addr){
733733
if ((retval = hal_pin_float_newf(HAL_IN, &(addr->spindle_revs), mot_comp_id, "spindle.%d.revs", num)) != 0) return retval;
734734
if ((retval = hal_pin_float_newf(HAL_IN, &(addr->spindle_speed_in), mot_comp_id, "spindle.%d.speed-in", num)) != 0) return retval;
735735
if ((retval = hal_pin_bit_newf(HAL_IN, &(addr->spindle_is_atspeed), mot_comp_id, "spindle.%d.at-speed", num)) != 0) return retval;
736+
/* Default 1: an unwired at-speed pin must never block motion. Do not
737+
change to 0 or machines without at-speed wired would idle forever. */
736738
*(addr->spindle_is_atspeed) = 1;
737739
/* restore saved message level */
738740
rtapi_set_msg_level(msg);

src/emc/nml_intf/canon.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ This is usually given in rpm and refers to the rate of spindle
542542
rotation. If the spindle is already turning and is at a different
543543
speed, change to the speed given with this command. */
544544

545-
extern void STOP_SPINDLE_TURNING(int spindle);
545+
extern void STOP_SPINDLE_TURNING(int spindle, int wait_for_atspeed = 1);
546546

547547
/* Stop the spindle from turning. If the spindle is already stopped, this
548548
command may be given, but it will have no effect. */

src/emc/nml_intf/emc.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,8 @@ void EMC_SPINDLE_OFF::update(CMS * cms)
10271027
{
10281028

10291029
EMC_SPINDLE_CMD_MSG::update(cms);
1030-
1030+
cms->update(spindle);
1031+
cms->update(wait_for_spindle_at_speed);
10311032
}
10321033

10331034
/*

src/emc/nml_intf/emc.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ extern int emcSpindleAbort(int spindle);
491491
extern int emcSpindleSpeed(int spindle, double speed, double factor, double xoffset);
492492
extern int emcSpindleOn(int spindle, double speed, double factor, double xoffset,int wait_for_atspeed = 1);
493493
extern int emcSpindleOrient(int spindle, double orientation, int direction);
494-
extern int emcSpindleWaitOrientComplete(double timout);
495-
extern int emcSpindleOff(int spindle);
494+
extern int emcSpindleOff(int spindle, int wait_for_atspeed = 0);
496495
extern int emcSpindleIncrease(int spindle);
497496
extern int emcSpindleDecrease(int spindle);
498497
extern int emcSpindleConstant(int spindle);

src/emc/nml_intf/emc_nml.hh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,14 +1829,17 @@ class EMC_SPINDLE_ON:public EMC_SPINDLE_CMD_MSG {
18291829

18301830
class EMC_SPINDLE_OFF:public EMC_SPINDLE_CMD_MSG {
18311831
public:
1832-
EMC_SPINDLE_OFF():EMC_SPINDLE_CMD_MSG(EMC_SPINDLE_OFF_TYPE,
1833-
sizeof(EMC_SPINDLE_OFF)) {
1834-
};
1832+
EMC_SPINDLE_OFF()
1833+
: EMC_SPINDLE_CMD_MSG(EMC_SPINDLE_OFF_TYPE, sizeof(EMC_SPINDLE_OFF)),
1834+
spindle(0),
1835+
wait_for_spindle_at_speed(0)
1836+
{};
18351837

18361838
// For internal NML/CMS use only.
18371839
void update(CMS * cms);
18381840

18391841
int spindle; // the spindle to be turned off
1842+
int wait_for_spindle_at_speed; // wait for at-speed (spindle stopped) before next feed
18401843
};
18411844

18421845
class EMC_SPINDLE_INCREASE:public EMC_SPINDLE_CMD_MSG {

src/emc/rs274ngc/gcodemodule.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,13 @@ void STOP_CUTTER_RADIUS_COMPENSATION(int direction) {}
408408
void START_SPEED_FEED_SYNCH() {}
409409
void START_SPEED_FEED_SYNCH(int spindle, double sync, bool vel) {}
410410
void STOP_SPEED_FEED_SYNCH() {}
411-
void START_SPINDLE_COUNTERCLOCKWISE(int spindle, int wait_for_at_speed) {}
412-
void START_SPINDLE_CLOCKWISE(int spindle, int wait_for_at_speed) {}
413-
void SET_SPINDLE_MODE(int spindle, double) {}
414-
void STOP_SPINDLE_TURNING(int spindle) {}
415-
void SET_SPINDLE_SPEED(int spindle, double rpm) {}
416-
void ORIENT_SPINDLE(int spindle, double d, int i) {}
417-
void WAIT_SPINDLE_ORIENT_COMPLETE(int s, double timeout) {}
411+
void START_SPINDLE_COUNTERCLOCKWISE(int /*spindle*/, int /*wait_for_at_speed*/) {}
412+
void START_SPINDLE_CLOCKWISE(int /*spindle*/, int /*wait_for_at_speed*/) {}
413+
void SET_SPINDLE_MODE(int /*spindle*/, double) {}
414+
void STOP_SPINDLE_TURNING(int /*spindle*/, int /*wait_for_at_speed*/) {}
415+
void SET_SPINDLE_SPEED(int /*spindle*/, double /*rpm*/) {}
416+
void ORIENT_SPINDLE(int /*spindle*/, double /*d*/, int /*i*/) {}
417+
void WAIT_SPINDLE_ORIENT_COMPLETE(int /*s*/, double /*timeout*/) {}
418418
void PROGRAM_STOP() {}
419419
void PROGRAM_END() {}
420420
void FINISH() {}

src/emc/sai/saicanon.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ void SET_SPINDLE_SPEED(int spindle, double rpm)
482482
_sai._spindle_speed[spindle] = rpm;
483483
}
484484

485-
void STOP_SPINDLE_TURNING(int spindle)
485+
void STOP_SPINDLE_TURNING(int spindle, int /*wait_for_atspeed*/)
486486
{
487487
PRINT("STOP_SPINDLE_TURNING(%i)\n", spindle);
488488
_sai._spindle_turning[spindle] = CANON_STOPPED;

src/emc/task/emccanon.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,12 +1942,13 @@ void SET_SPINDLE_SPEED(int s, double r)
19421942
interp_list.append(emc_spindle_speed_msg);
19431943
}
19441944

1945-
void STOP_SPINDLE_TURNING(int s)
1945+
void STOP_SPINDLE_TURNING(int s, int wait_for_atspeed)
19461946
{
19471947
EMC_SPINDLE_OFF emc_spindle_off_msg;
19481948

19491949
flush_segments();
19501950
emc_spindle_off_msg.spindle = s;
1951+
emc_spindle_off_msg.wait_for_spindle_at_speed = wait_for_atspeed;
19511952
interp_list.append(emc_spindle_off_msg);
19521953
// Added by atp 6/1/18 not sure this is right. There is a problem that the _second_ S word starts the spindle without M3/M4
19531954
canon.spindle[s].dir = 0;

src/emc/task/emctaskmain.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,8 @@ static int emcTaskIssueCommand(NMLmsg * cmd)
20082008
break;
20092009

20102010
case EMC_SPINDLE_OFF_TYPE:
2011-
spindle_off_msg = (EMC_SPINDLE_OFF *) cmd;
2012-
retval = emcSpindleOff(spindle_off_msg->spindle);
2011+
spindle_off_msg = reinterpret_cast<EMC_SPINDLE_OFF *>(cmd);
2012+
retval = emcSpindleOff(spindle_off_msg->spindle, spindle_off_msg->wait_for_spindle_at_speed);
20132013
break;
20142014

20152015
case EMC_SPINDLE_BRAKE_RELEASE_TYPE:

0 commit comments

Comments
 (0)