motion: add ability to have gcode s0 while m3/4 is active

Usually in linuxcnc, setting s0 would set spindle off;
Setting m3/4 before s was above 0 would not allow s to be set after.
This commit fixes those problems.
tested on a real machine with two spinldes - one as an indexer

It's common in other machines to be able to set S and m3/4/5 separately.
This allows using the extra spindles in unique ways such as indexers.
(s setting can represent position)
This may help laser users with laser intensity etc.

If users relied on setting s to 0 to turn off the spindle will need to change their programs.
One could argue the were not using the code properly anyways.
This commit is contained in:
Chris Morley 2020-08-10 18:47:08 -07:00
parent cbf19fefad
commit 095d08c85c
5 changed files with 15 additions and 6 deletions

View file

@ -1770,6 +1770,8 @@ void emcmotCommandHandler(void *arg, long period)
/* tpAbort(&emcmotDebug->tp); */ /* tpAbort(&emcmotDebug->tp); */
/* SET_MOTION_ERROR_FLAG(1); */ /* SET_MOTION_ERROR_FLAG(1); */
/* } else {...} */ /* } else {...} */
rtapi_print( "command state %d\n", emcmotCommand->state);
emcmotStatus->spindle_status[n].state = emcmotCommand->state;
emcmotStatus->spindle_status[n].speed = emcmotCommand->vel; emcmotStatus->spindle_status[n].speed = emcmotCommand->vel;
emcmotStatus->spindle_status[n].css_factor = emcmotCommand->ini_maxvel; emcmotStatus->spindle_status[n].css_factor = emcmotCommand->ini_maxvel;
emcmotStatus->spindle_status[n].xoffset = emcmotCommand->acc; emcmotStatus->spindle_status[n].xoffset = emcmotCommand->acc;
@ -1804,6 +1806,7 @@ void emcmotCommandHandler(void *arg, long period)
} }
for (n = s0; n<=s1; n++){ for (n = s0; n<=s1; n++){
emcmotStatus->spindle_status[n].state = 0;
emcmotStatus->spindle_status[n].speed = 0; emcmotStatus->spindle_status[n].speed = 0;
emcmotStatus->spindle_status[n].direction = 0; emcmotStatus->spindle_status[n].direction = 0;
emcmotStatus->spindle_status[n].brake = 1; // engage brake emcmotStatus->spindle_status[n].brake = 1; // engage brake

View file

@ -1897,7 +1897,7 @@ static void output_to_hal(void)
*(emcmot_hal_data->spindle[spindle_num].spindle_speed_cmd_rps) = *(emcmot_hal_data->spindle[spindle_num].spindle_speed_cmd_rps) =
emcmotStatus->spindle_status[spindle_num].speed / 60.; emcmotStatus->spindle_status[spindle_num].speed / 60.;
*(emcmot_hal_data->spindle[spindle_num].spindle_on) = *(emcmot_hal_data->spindle[spindle_num].spindle_on) =
((emcmotStatus->spindle_status[spindle_num].speed * ((emcmotStatus->spindle_status[spindle_num].state *
emcmotStatus->spindle_status[spindle_num].net_scale) != 0) ? 1 : 0; emcmotStatus->spindle_status[spindle_num].net_scale) != 0) ? 1 : 0;
*(emcmot_hal_data->spindle[spindle_num].spindle_forward) = *(emcmot_hal_data->spindle[spindle_num].spindle_forward) =
(*emcmot_hal_data->spindle[spindle_num].spindle_speed_out > 0) ? 1 : 0; (*emcmot_hal_data->spindle[spindle_num].spindle_speed_out > 0) ? 1 : 0;

View file

@ -262,6 +262,7 @@ extern "C" {
int probe_home_err_inhibit; // setting to inhibit probe tripped while homeing error. int probe_home_err_inhibit; // setting to inhibit probe tripped while homeing error.
EmcPose tool_offset; /* TLO */ EmcPose tool_offset; /* TLO */
double orientation; /* angle for spindle orient */ double orientation; /* angle for spindle orient */
int state; /*spindle state*/
char direction; /* CANON_DIRECTION flag for spindle orient */ char direction; /* CANON_DIRECTION flag for spindle orient */
double timeout; /* of wait for spindle orient to complete */ double timeout; /* of wait for spindle orient to complete */
unsigned char wait_for_spindle_at_speed; // EMCMOT_SPINDLE_ON now carries this, for next feed move unsigned char wait_for_spindle_at_speed; // EMCMOT_SPINDLE_ON now carries this, for next feed move
@ -544,6 +545,7 @@ Suggestion: Split this in to an Error and a Status flag register..
double net_scale; // scale or zero if inhibited double net_scale; // scale or zero if inhibited
double css_factor; double css_factor;
double xoffset; double xoffset;
int state;
int direction; // 0 stopped, 1 forward, -1 reverse int direction; // 0 stopped, 1 forward, -1 reverse
int brake; // 0 released, 1 engaged int brake; // 0 released, 1 engaged
int locked; // spindle lock engaged after orient int locked; // spindle lock engaged after orient

View file

@ -1197,6 +1197,7 @@ class EMC_SPINDLE_STAT:public EMC_SPINDLE_STAT_MSG {
double spindle_scale; // spindle over-ride double spindle_scale; // spindle over-ride
double css_maximum; double css_maximum;
double css_factor; // CSS Status double css_factor; // CSS Status
int state;
int direction; // 0 stopped, 1 forward, -1 reverse int direction; // 0 stopped, 1 forward, -1 reverse
int brake; // 0 released, 1 engaged int brake; // 0 released, 1 engaged
int increasing; // 1 increasing, -1 decreasing, 0 neither int increasing; // 1 increasing, -1 decreasing, 0 neither

View file

@ -1840,10 +1840,12 @@ int emcSpindleAbort(int spindle)
int emcSpindleSpeed(int spindle, double speed, double css_factor, double offset) int emcSpindleSpeed(int spindle, double speed, double css_factor, double offset)
{ {
if (emcmotStatus.spindle_status[spindle].speed == 0){ emcmotCommand.command = EMCMOT_SPINDLE_ON;
return 0;} //spindle stopped, not updating speed */ emcmotCommand.spindle = spindle;
emcmotCommand.vel = speed;
return emcSpindleOn(spindle, speed, css_factor, offset); emcmotCommand.ini_maxvel = css_factor;
emcmotCommand.acc = offset;
return usrmotWriteEmcmotCommand(&emcmotCommand);
} }
int emcSpindleOrient(int spindle, double orientation, int mode) int emcSpindleOrient(int spindle, double orientation, int mode)
@ -1858,9 +1860,9 @@ int emcSpindleOrient(int spindle, double orientation, int mode)
int emcSpindleOn(int spindle, double speed, double css_factor, double offset, int wait_for_at_speed) int emcSpindleOn(int spindle, double speed, double css_factor, double offset, int wait_for_at_speed)
{ {
emcmotCommand.command = EMCMOT_SPINDLE_ON; emcmotCommand.command = EMCMOT_SPINDLE_ON;
emcmotCommand.spindle = spindle; emcmotCommand.spindle = spindle;
emcmotCommand.state = 1;
emcmotCommand.vel = speed; emcmotCommand.vel = speed;
emcmotCommand.ini_maxvel = css_factor; emcmotCommand.ini_maxvel = css_factor;
emcmotCommand.acc = offset; emcmotCommand.acc = offset;
@ -1871,6 +1873,7 @@ int emcSpindleOn(int spindle, double speed, double css_factor, double offset, in
int emcSpindleOff(int spindle) int emcSpindleOff(int spindle)
{ {
emcmotCommand.command = EMCMOT_SPINDLE_OFF; emcmotCommand.command = EMCMOT_SPINDLE_OFF;
emcmotCommand.state = 0;
emcmotCommand.spindle = spindle; emcmotCommand.spindle = spindle;
return usrmotWriteEmcmotCommand(&emcmotCommand); return usrmotWriteEmcmotCommand(&emcmotCommand);
} }