Skip to content

Commit c1f4b6c

Browse files
authored
Merge pull request #4160 from grandixximo/spindle-atspeed-m5
motion: wait for spindle at-speed after M5 spindle stop
2 parents 75c139e + f57448c commit c1f4b6c

12 files changed

Lines changed: 47 additions & 10 deletions

File tree

src/emc/motion/command.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,22 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
507507
if (GET_MOTION_TELEOP_FLAG()) {
508508
axis_jog_abort_all(0);
509509
} else if (GET_MOTION_COORD_FLAG()) {
510+
/* If motion was being held waiting for spindle at-speed, the
511+
operator most likely aborted because the machine sat idle
512+
with no obvious reason. Tell them why, loudly. A wait that
513+
never released after a spindle stop almost always means
514+
spindle.N.at-speed is not wired, or does not go true once the
515+
spindle has actually stopped. */
516+
if (MOTION_ID_VALID(emcmotInternal->coord_tp.spindle.waiting_for_atspeed)) {
517+
for (spindle_num = 0; spindle_num < emcmotConfig->numSpindles; spindle_num++) {
518+
if (emcmotStatus->spindle_status[spindle_num].state == 0 && !emcmotStatus->spindle_status[spindle_num].at_speed) {
519+
reportError(_("Aborted while waiting for spindle %d at-speed after a spindle stop. "
520+
"Check that spindle.%d.at-speed is connected and goes true once the spindle has stopped."),
521+
spindle_num, spindle_num);
522+
break;
523+
}
524+
}
525+
}
510526
tpAbort(&emcmotInternal->coord_tp);
511527
} else {
512528
for (joint_num = 0; joint_num < ALL_JOINTS; joint_num++) {
@@ -530,6 +546,8 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
530546
SET_JOINT_FAULT_FLAG(joint, 0);
531547
}
532548
emcmotStatus->paused = 0;
549+
/* Drop any pending at-speed barrier so it can't strand a later move. */
550+
emcmotStatus->atspeed_next_feed = 0;
533551
// Clear pins on abort so tests see a clean state
534552
if (emcmot_hal_data) {
535553
*(emcmot_hal_data->interp_arc_radius) = 0.0;
@@ -1496,6 +1514,14 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
14961514
}
14971515
}
14981516

1517+
/* A probe is a feed-type move, so honor any pending at-speed
1518+
barrier just like G1: wait for spindle.N.at-speed (spin-up after
1519+
M3, or stop after M5) before the probe starts. */
1520+
if (emcmotStatus->atspeed_next_feed) {
1521+
issue_atspeed = 1;
1522+
emcmotStatus->atspeed_next_feed = 0;
1523+
}
1524+
14991525
/* append it to the emcmotInternal->coord_tp */
15001526
tpSetId(&emcmotInternal->coord_tp, emcmotCommand->id);
15011527
if (-1 == tpAddLine(&emcmotInternal->coord_tp,
@@ -1506,7 +1532,7 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
15061532
emcmotCommand->acc,
15071533
emcmotCommand->ini_maxjerk,
15081534
emcmotStatus->enables_new,
1509-
0,
1535+
issue_atspeed,
15101536
-1,
15111537
emcmotCommand->tag)) {
15121538
reportError(_("can't add probe move"));
@@ -1702,6 +1728,10 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
17021728
*(emcmot_hal_data->spindle[n].spindle_orient) = 0;
17031729
emcmotStatus->spindle_status[n].orient_state = EMCMOT_ORIENT_NONE;
17041730
}
1731+
/* Optionally make the spindle stop an at-speed barrier: the next feed
1732+
move waits until at-speed reflects the stopped state. Safe when
1733+
unwired since at-speed defaults to 1 (see motion.c). */
1734+
emcmotStatus->atspeed_next_feed = emcmotCommand->wait_for_spindle_at_speed;
17051735
break;
17061736

17071737
case EMCMOT_SPINDLE_ORIENT:

src/emc/motion/motion.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ static int export_spindle(int num, spindle_hal_t * addr){
776776
if ((retval = hal_pin_float_newf(HAL_IN, &(addr->spindle_revs), mot_comp_id, "spindle.%d.revs", num)) != 0) return retval;
777777
if ((retval = hal_pin_float_newf(HAL_IN, &(addr->spindle_speed_in), mot_comp_id, "spindle.%d.speed-in", num)) != 0) return retval;
778778
if ((retval = hal_pin_bit_newf(HAL_IN, &(addr->spindle_is_atspeed), mot_comp_id, "spindle.%d.at-speed", num)) != 0) return retval;
779+
/* Default 1: an unwired at-speed pin must never block motion. Do not
780+
change to 0 or machines without at-speed wired would idle forever. */
779781
*(addr->spindle_is_atspeed) = 1;
780782
/* restore saved message level */
781783
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
@@ -639,7 +639,7 @@ This is usually given in rpm and refers to the rate of spindle
639639
rotation. If the spindle is already turning and is at a different
640640
speed, change to the speed given with this command. */
641641

642-
extern void STOP_SPINDLE_TURNING(int spindle);
642+
extern void STOP_SPINDLE_TURNING(int spindle, int wait_for_atspeed = 1);
643643

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

src/emc/nml_intf/emc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ void EMC_SPINDLE_OFF::update(CMS * cms)
734734
{
735735
EMC_SPINDLE_CMD_MSG::update(cms);
736736
cms->update(spindle);
737+
cms->update(wait_for_spindle_at_speed);
737738
}
738739

739740
/*

src/emc/nml_intf/emc.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ extern int emcSpindleAbort(int spindle);
423423
extern int emcSpindleSpeed(int spindle, double speed, double factor, double xoffset);
424424
extern int emcSpindleOn(int spindle, double speed, double factor, double xoffset,int wait_for_atspeed = 1);
425425
extern int emcSpindleOrient(int spindle, double orientation, int direction);
426-
extern int emcSpindleOff(int spindle);
426+
extern int emcSpindleOff(int spindle, int wait_for_atspeed = 0);
427427
extern int emcSpindleIncrease(int spindle);
428428
extern int emcSpindleDecrease(int spindle);
429429
extern int emcSpindleConstant(int spindle);

src/emc/nml_intf/emc_nml.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,8 @@ class EMC_SPINDLE_OFF:public EMC_SPINDLE_CMD_MSG {
18011801
public:
18021802
EMC_SPINDLE_OFF()
18031803
: EMC_SPINDLE_CMD_MSG(EMC_SPINDLE_OFF_TYPE, sizeof(EMC_SPINDLE_OFF)),
1804-
spindle(0)
1804+
spindle(0),
1805+
wait_for_spindle_at_speed(0)
18051806
{};
18061807

18071808
// For internal NML/CMS use only.
@@ -1810,6 +1811,7 @@ class EMC_SPINDLE_OFF:public EMC_SPINDLE_CMD_MSG {
18101811
void update(CMS * cms);
18111812

18121813
int spindle; // the spindle to be turned off
1814+
int wait_for_spindle_at_speed; // wait for at-speed (spindle stopped) before next feed
18131815
};
18141816

18151817
class EMC_SPINDLE_INCREASE:public EMC_SPINDLE_CMD_MSG {

src/emc/rs274ngc/gcodemodule.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void STOP_SPEED_FEED_SYNCH() {}
551551
void START_SPINDLE_COUNTERCLOCKWISE(int /*spindle*/, int /*wait_for_at_speed*/) {}
552552
void START_SPINDLE_CLOCKWISE(int /*spindle*/, int /*wait_for_at_speed*/) {}
553553
void SET_SPINDLE_MODE(int /*spindle*/, double) {}
554-
void STOP_SPINDLE_TURNING(int /*spindle*/) {}
554+
void STOP_SPINDLE_TURNING(int /*spindle*/, int /*wait_for_at_speed*/) {}
555555
void SET_SPINDLE_SPEED(int /*spindle*/, double /*rpm*/) {}
556556
void ORIENT_SPINDLE(int /*spindle*/, double /*d*/, int /*i*/) {}
557557
void WAIT_SPINDLE_ORIENT_COMPLETE(int /*s*/, double /*timeout*/) {}

src/emc/sai/saicanon.cc

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

488-
void STOP_SPINDLE_TURNING(int spindle)
488+
void STOP_SPINDLE_TURNING(int spindle, int /*wait_for_atspeed*/)
489489
{
490490
PRINT("STOP_SPINDLE_TURNING(%i)\n", spindle);
491491
_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
@@ -3017,12 +3017,13 @@ void SET_SPINDLE_SPEED(int s, double speed_rpm)
30173017
interp_list.append(SPINDLE_SPEED_<EMC_SPINDLE_SPEED>(s, 0, speed_rpm));
30183018
}
30193019

3020-
void STOP_SPINDLE_TURNING(int s)
3020+
void STOP_SPINDLE_TURNING(int s, int wait_for_atspeed)
30213021
{
30223022
auto emc_spindle_off_msg = std::make_unique<EMC_SPINDLE_OFF>();
30233023

30243024
flush_segments();
30253025
emc_spindle_off_msg->spindle = s;
3026+
emc_spindle_off_msg->wait_for_spindle_at_speed = wait_for_atspeed;
30263027
interp_list.append(std::move(emc_spindle_off_msg));
30273028
// 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
30283029
canon.spindle[s].dir = 0;

src/emc/task/emctaskmain.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd)
19951995

19961996
case EMC_SPINDLE_OFF_TYPE:
19971997
spindle_off_msg = reinterpret_cast<EMC_SPINDLE_OFF *>(cmd);
1998-
retval = emcSpindleOff(spindle_off_msg->spindle);
1998+
retval = emcSpindleOff(spindle_off_msg->spindle, spindle_off_msg->wait_for_spindle_at_speed);
19991999
break;
20002000

20012001
case EMC_SPINDLE_BRAKE_RELEASE_TYPE:

0 commit comments

Comments
 (0)