diff --git a/docs/src/code/code-notes.adoc b/docs/src/code/code-notes.adoc index 8953da4a6f9..aff45bc9d35 100644 --- a/docs/src/code/code-notes.adoc +++ b/docs/src/code/code-notes.adoc @@ -638,37 +638,6 @@ planner accelerates at the joint accel limit at the beginning of the move, and will decelerate at the joint accel limit to stop at the target position. -=== JOG_ABS - -The JOG_ABS command initiates an absolute jog on a single joint. An -absolute jog is a simple move to a specific location, in joint -coordinates. Normally absolute jogs stop when they reach the desired -location, however they also stop when they hit a limit, or on an ABORT -command. - -==== Requirements - -The command handler will silently reject the JOG_ABS command if -machine is not in free mode, or if any joint is in motion -(GET_MOTION_INPOS_FLAG() == FALSE), or if motion is not enabled. It -will also silently ignore the command if the joint is already at or -beyond its limit and the commanded jog would make it worse. - -==== Results - -The free mode trajectory planner for the joint identified by -emcmotCommand\->axis is activated, the target position is set to -emcmotCommand\->offset, and the velocity limit is set to -emcmotCommand\->vel. The free mode trajectory planner will generate a -smooth trapezoidal move from the present position to the target -position. The planner can correctly handle changes in the target -position that happen while the move is in progress. If multiple JOG_ABS -commands are issued in quick succession, each new command changes the -target position and the machine goes to the final commanded position. -The free mode planner accelerates at the joint accel limit at the -beginning of the move, and will decelerate at the joint accel limit to -stop at the target position. - === SET_LINE The SET_LINE command adds a straight line to the trajectory planner diff --git a/docs/src/code/nml-messages.adoc b/docs/src/code/nml-messages.adoc index 307066ea39d..6271df5421b 100644 --- a/docs/src/code/nml-messages.adoc +++ b/docs/src/code/nml-messages.adoc @@ -24,12 +24,8 @@ EMC_JOINT_SET_JOINT_TYPE EMC_JOINT_SET_UNITS_TYPE EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE -EMC_JOINT_SET_FERROR_TYPE -EMC_JOINT_SET_HOMING_PARAMS_TYPE -EMC_JOINT_SET_MIN_FERROR_TYPE EMC_JOINT_SET_MAX_VELOCITY_TYPE EMC_JOINT_INIT_TYPE -EMC_JOINT_HALT_TYPE EMC_JOINT_ABORT_TYPE EMC_JOINT_ENABLE_TYPE EMC_JOINT_DISABLE_TYPE @@ -56,7 +52,6 @@ EMC_AXIS_STAT_TYPE ---- EMC_JOG_CONT_TYPE EMC_JOG_INCR_TYPE -EMC_JOG_ABS_TYPE EMC_JOG_STOP_TYPE ---- @@ -68,8 +63,6 @@ EMC_TRAJ_SET_AXES_TYPE EMC_TRAJ_SET_UNITS_TYPE EMC_TRAJ_SET_CYCLE_TIME_TYPE EMC_TRAJ_SET_MODE_TYPE -EMC_TRAJ_SET_VELOCITY_TYPE -EMC_TRAJ_SET_ACCELERATION_TYPE EMC_TRAJ_SET_MAX_VELOCITY_TYPE EMC_TRAJ_SET_MAX_ACCELERATION_TYPE EMC_TRAJ_SET_SCALE_TYPE diff --git a/include/nml_intf/emc.hh b/include/nml_intf/emc.hh index bb58f1319e7..767e0de79de 100644 --- a/include/nml_intf/emc.hh +++ b/include/nml_intf/emc.hh @@ -61,14 +61,9 @@ struct PM_CARTESIAN; #define EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE ((NMLTYPE) 107) #define EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE ((NMLTYPE) 108) -#define EMC_JOINT_SET_FERROR_TYPE ((NMLTYPE) 111) -#define EMC_JOINT_SET_HOMING_PARAMS_TYPE ((NMLTYPE) 112) -#define EMC_JOINT_SET_MIN_FERROR_TYPE ((NMLTYPE) 115) -#define EMC_JOINT_HALT_TYPE ((NMLTYPE) 119) #define EMC_JOINT_HOME_TYPE ((NMLTYPE) 123) #define EMC_JOG_CONT_TYPE ((NMLTYPE) 124) #define EMC_JOG_INCR_TYPE ((NMLTYPE) 125) -#define EMC_JOG_ABS_TYPE ((NMLTYPE) 126) #define EMC_JOINT_OVERRIDE_LIMITS_TYPE ((NMLTYPE) 129) #define EMC_JOINT_LOAD_COMP_TYPE ((NMLTYPE) 131) #define EMC_JOINT_SET_BACKLASH_TYPE ((NMLTYPE) 134) @@ -86,8 +81,6 @@ struct PM_CARTESIAN; #define EMC_TRAJ_TERM_COND_BLEND 2 #define EMC_TRAJ_SET_MODE_TYPE ((NMLTYPE) 204) -#define EMC_TRAJ_SET_VELOCITY_TYPE ((NMLTYPE) 205) -#define EMC_TRAJ_SET_ACCELERATION_TYPE ((NMLTYPE) 206) #define EMC_TRAJ_SET_MAX_VELOCITY_TYPE ((NMLTYPE) 207) #define EMC_TRAJ_SET_SCALE_TYPE ((NMLTYPE) 209) #define EMC_TRAJ_SET_RAPID_SCALE_TYPE ((NMLTYPE) 238) @@ -329,7 +322,6 @@ extern int emcJointLoadComp(int joint, const char *file, int type); extern int emcJogStop(int nr, int jjogmode); extern int emcJogCont(int nr, double vel, int jjogmode); extern int emcJogIncr(int nr, double incr, double vel, int jjogmode); -extern int emcJogAbs(int nr, double pos, double vel, int jjogmode); extern int emcJointUpdate(EMC_JOINT_STAT stat[], int numJoints); diff --git a/include/nml_intf/emc_nml.hh b/include/nml_intf/emc_nml.hh index c786f1a9ed5..5f66184fc64 100644 --- a/include/nml_intf/emc_nml.hh +++ b/include/nml_intf/emc_nml.hh @@ -246,93 +246,6 @@ class EMC_JOINT_SET_MAX_POSITION_LIMIT:public EMC_JOINT_CMD_MSG { double limit; }; -class EMC_JOINT_SET_FERROR:public EMC_JOINT_CMD_MSG { - public: - EMC_JOINT_SET_FERROR() - : EMC_JOINT_CMD_MSG(EMC_JOINT_SET_FERROR_TYPE, sizeof(EMC_JOINT_SET_FERROR)), - ferror(0.0) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); - - double ferror; -}; - -class EMC_JOINT_SET_MIN_FERROR:public EMC_JOINT_CMD_MSG { - public: - EMC_JOINT_SET_MIN_FERROR() - : EMC_JOINT_CMD_MSG (EMC_JOINT_SET_MIN_FERROR_TYPE, sizeof(EMC_JOINT_SET_MIN_FERROR)), - ferror(0.0) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); - - double ferror; -}; - -class EMC_JOINT_SET_HOMING_PARAMS:public EMC_JOINT_CMD_MSG { - public: - // False positive. Triggers on 'offset' - // cppcheck-suppress uninitMemberVar - EMC_JOINT_SET_HOMING_PARAMS() - : EMC_JOINT_CMD_MSG(EMC_JOINT_SET_HOMING_PARAMS_TYPE, sizeof(EMC_JOINT_SET_HOMING_PARAMS)), - home(0.0), - offset(0.0), - home_final_vel(0.0), - search_vel(0.0), - latch_vel(0.0), - search_dist(0.0), - latch_dist(0.0), - use_index(0), - encoder_does_not_reset(0), - ignore_limits(0), - is_shared(0), - home_sequence(0), - volatile_home(0), - locking_indexer(0), - absolute_encoder(0) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); - - double home; - double offset; - double home_final_vel; - double search_vel; - double latch_vel; - double search_dist; - double latch_dist; - int use_index; - int encoder_does_not_reset; - int ignore_limits; - int is_shared; - int home_sequence; - int volatile_home; - int locking_indexer; - int absolute_encoder; -}; - -class EMC_JOINT_HALT:public EMC_JOINT_CMD_MSG { - public: - EMC_JOINT_HALT() - : EMC_JOINT_CMD_MSG(EMC_JOINT_HALT_TYPE, sizeof(EMC_JOINT_HALT)) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); -}; - class EMC_JOINT_HOME:public EMC_JOINT_CMD_MSG { public: EMC_JOINT_HOME() @@ -393,25 +306,6 @@ class EMC_JOG_INCR:public EMC_JOG_CMD_MSG { int jjogmode; // 1==> joint jog, 0==> axis jog }; -class EMC_JOG_ABS:public EMC_JOG_CMD_MSG { - public: - EMC_JOG_ABS() - : EMC_JOG_CMD_MSG(EMC_JOG_ABS_TYPE, sizeof(EMC_JOG_ABS)), - pos(0.0), - vel(0.0), - jjogmode(0) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); - - double pos; - double vel; - int jjogmode; // 1==> joint jog, 0==> axis jog -}; - class EMC_JOG_STOP:public EMC_JOG_CMD_MSG { public: EMC_JOG_STOP() @@ -541,38 +435,6 @@ class EMC_TRAJ_SET_MODE:public EMC_TRAJ_CMD_MSG { EMC_TRAJ_MODE mode; }; -class EMC_TRAJ_SET_VELOCITY:public EMC_TRAJ_CMD_MSG { - public: - EMC_TRAJ_SET_VELOCITY() - : EMC_TRAJ_CMD_MSG(EMC_TRAJ_SET_VELOCITY_TYPE, sizeof(EMC_TRAJ_SET_VELOCITY)), - velocity(0.0), - ini_maxvel(0.0) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); - - double velocity; - double ini_maxvel; -}; - -class EMC_TRAJ_SET_ACCELERATION:public EMC_TRAJ_CMD_MSG { - public: - EMC_TRAJ_SET_ACCELERATION() - : EMC_TRAJ_CMD_MSG(EMC_TRAJ_SET_ACCELERATION_TYPE, sizeof(EMC_TRAJ_SET_ACCELERATION)), - acceleration(0.0) - {}; - - // For internal NML/CMS use only. - // Sub-class update() calls base-class update() - // cppcheck-suppress duplInheritedMember - void update(CMS * cms); - - double acceleration; -}; - class EMC_TRAJ_SET_MAX_VELOCITY:public EMC_TRAJ_CMD_MSG { public: EMC_TRAJ_SET_MAX_VELOCITY() diff --git a/src/emc/motion-logger/motion-logger.c b/src/emc/motion-logger/motion-logger.c index 28978ae80e8..86fe6c60b5c 100644 --- a/src/emc/motion-logger/motion-logger.c +++ b/src/emc/motion-logger/motion-logger.c @@ -449,10 +449,6 @@ int main(int argc, char* argv[]) { log_print("JOG_INCR\n"); break; - case EMCMOT_JOG_ABS: - log_print("JOG_ABS\n"); - break; - case EMCMOT_SET_LINE: log_print( "SET_LINE x=%.6g, y=%.6g, z=%.6g, a=%.6g, b=%.6g, c=%.6g, u=%.6g, v=%.6g, w=%.6g, id=%d, motion_type=%d, vel=%.6g, ini_maxvel=%.6g, acc=%.6g, turn=%d\n", diff --git a/src/emc/motion/axis.c b/src/emc/motion/axis.c index 6bbaf08ad16..af4107bb4a0 100644 --- a/src/emc/motion/axis.c +++ b/src/emc/motion/axis.c @@ -369,30 +369,6 @@ void axis_jog_incr(int axis_num, double offset, double vel, long servo_period) axis->teleop_tp.enable = 1; } -void axis_jog_abs(int axis_num, double offset, double vel) -{ - emcmot_axis_t *axis = &axis_array[axis_num]; - double tmp1, min_lim, max_lim; - - axis->kb_ajog_active = 1; - if (axis->wheel_ajog_active) { return; } - if (vel > 0.0) { - tmp1 = axis->teleop_tp.pos_cmd + offset; - } else { - tmp1 = axis->teleop_tp.pos_cmd - offset; - } - axis_jog_limits(axis_num, &min_lim, &max_lim); - if (tmp1 > max_lim) { return; } - if (tmp1 < min_lim) { return; } - axis->teleop_tp.pos_cmd = tmp1; - axis->teleop_tp.max_vel = fabs(vel); - axis->teleop_tp.max_acc = axis->acc_limit; - axis->teleop_vel_req = axis->teleop_tp.max_vel; - axis->teleop_acc_req = axis->teleop_tp.max_acc; - axis->kb_ajog_active = 1; - axis->teleop_tp.enable = 1; -} - bool axis_jog_abort(int axis_num, bool immediate) { bool aborted = 0; diff --git a/src/emc/motion/axis.h b/src/emc/motion/axis.h index bc00504570d..9f7c0a0fcd4 100644 --- a/src/emc/motion/axis.h +++ b/src/emc/motion/axis.h @@ -19,7 +19,6 @@ void axis_check_constraints(double pos[], int failing_axes[]); void axis_jog_cont(int axis_num, double vel, long servo_period); void axis_jog_incr(int axis_num, double offset, double vel, long servo_period); -void axis_jog_abs(int axis_num, double offset, double vel); bool axis_jog_abort_all(bool immediate); bool axis_jog_abort(int axis_num, bool immediate); bool axis_jog_is_active(void); diff --git a/src/emc/motion/command.c b/src/emc/motion/command.c index e026776ca9f..c820554a1f1 100644 --- a/src/emc/motion/command.c +++ b/src/emc/motion/command.c @@ -533,7 +533,6 @@ void emcmotCommandHandler_locked(void *arg, long servo_period) // example: attempt to jog locking indexer axis letter if ( emcmotCommand->command == EMCMOT_JOG_CONT || emcmotCommand->command == EMCMOT_JOG_INCR - || emcmotCommand->command == EMCMOT_JOG_ABS ) { if (GET_MOTION_TELEOP_FLAG() && (emcmotCommand->axis < 0)) { emsg = "command.com teleop: unexpected negative axis_num"; @@ -574,9 +573,6 @@ void emcmotCommandHandler_locked(void *arg, long servo_period) case EMCMOT_JOG_INCR: rtapi_print_msg(RTAPI_MSG_ERR,"JOG_INCR %s\n",emsg); break; - case EMCMOT_JOG_ABS: - rtapi_print_msg(RTAPI_MSG_ERR,"JOG_ABS %s\n",emsg); - break; default: break; } return; @@ -586,7 +582,6 @@ void emcmotCommandHandler_locked(void *arg, long servo_period) joint = &joints[joint_num]; if ( ( emcmotCommand->command == EMCMOT_JOG_CONT || emcmotCommand->command == EMCMOT_JOG_INCR - || emcmotCommand->command == EMCMOT_JOG_ABS ) && !(GET_MOTION_TELEOP_FLAG()) && get_home_is_synchronized(joint_num) @@ -1055,73 +1050,6 @@ void emcmotCommandHandler_locked(void *arg, long servo_period) } break; - case EMCMOT_JOG_ABS: - /* do an absolute jog */ - rtapi_print_msg(RTAPI_MSG_DBG, "JOG_ABS %d", joint_num); - if (joint == 0) { - break; - } - if (!GET_MOTION_ENABLE_FLAG()) { - reportError(_("Can't jog joint when not enabled.")); - SET_JOINT_ERROR_FLAG(joint, 1); - break; - } - // cannot jog if jog-inhibit is TRUE - if (hal_get_bool(emcmot_hal_data->jog_inhibit)){ - reportError(_("Cannot jog while jog-inhibit is active.")); - break; - } - if ( get_homing_is_active() ) { - reportError(_("Can't jog any joints while homing.")); - SET_JOINT_ERROR_FLAG(joint, 1); - break; - } - if (!GET_MOTION_TELEOP_FLAG()) { - // FREE JOG_ABS - if (joint->wheel_jjog_active) { - /* can't do two kinds of jog at once */ - break; - } - /* don't jog further onto limits */ - if (!joint_jog_ok(joint_num, emcmotCommand->vel)) { - SET_JOINT_ERROR_FLAG(joint, 1); - break; - } - /*! \todo FIXME-- use 'goal' instead */ - joint->free_tp.pos_cmd = emcmotCommand->offset; - /* don't jog past limits */ - refresh_jog_limits(joint,joint_num); - if (joint->free_tp.pos_cmd > joint->max_jog_limit) { - joint->free_tp.pos_cmd = joint->max_jog_limit; - } - if (joint->free_tp.pos_cmd < joint->min_jog_limit) { - joint->free_tp.pos_cmd = joint->min_jog_limit; - } - /* set velocity of jog */ - joint->free_tp.max_vel = fabs(emcmotCommand->vel); - /* use max joint accel */ - joint->free_tp.max_acc = joint->acc_limit; - /* lock out other jog sources */ - joint->kb_jjog_active = 1; - /* and let it go */ - joint->free_tp.enable = 1; - SET_JOINT_ERROR_FLAG(joint, 0); - /* clear joint homed flag(s) if we don't have forward kins. - Otherwise, a transition into coordinated mode will incorrectly - assume the homed position. Do all if they've all been moved - since homing, otherwise just do this one */ - clearHomes(joint_num); - } else { - // TELEOP JOG_ABS - axis_jog_abs(emcmotCommand->axis, emcmotCommand->offset, emcmotCommand->vel); - for (joint_num = 0; joint_num < ALL_JOINTS; joint_num++) { - joint = &joints[joint_num]; - if (joint != 0) { joint->free_tp.enable = 0; } - } - return; - } - break; - case EMCMOT_SET_TERM_COND: /* sets termination condition for motion emcmotInternal->coord_tp */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_TERM_COND"); diff --git a/src/emc/motion/motion.h b/src/emc/motion/motion.h index 2276bc116cd..4fed9ca8a75 100644 --- a/src/emc/motion/motion.h +++ b/src/emc/motion/motion.h @@ -153,7 +153,6 @@ extern "C" { EMCMOT_SET_PROBE_ERR_INHIBIT, EMCMOT_JOG_CONT, /* continuous jog */ EMCMOT_JOG_INCR, /* incremental jog */ - EMCMOT_JOG_ABS, /* absolute jog */ EMCMOT_JOG_ABORT, /* abort one joint num or axis num */ EMCMOT_JOINT_ACTIVATE, /* make joint active */ diff --git a/src/emc/nml_intf/emc.cc b/src/emc/nml_intf/emc.cc index cdd8b7f7743..4ae4c2deab9 100644 --- a/src/emc/nml_intf/emc.cc +++ b/src/emc/nml_intf/emc.cc @@ -49,9 +49,6 @@ int emcFormat(NMLTYPE type, void *buffer, CMS * cms) case EMC_AUX_STAT_TYPE: ((EMC_AUX_STAT *) buffer)->update(cms); break; - case EMC_JOINT_HALT_TYPE: - ((EMC_JOINT_HALT *) buffer)->update(cms); - break; case EMC_JOINT_HOME_TYPE: ((EMC_JOINT_HOME *) buffer)->update(cms); break; @@ -64,9 +61,6 @@ int emcFormat(NMLTYPE type, void *buffer, CMS * cms) case EMC_JOG_INCR_TYPE: ((EMC_JOG_INCR *) buffer)->update(cms); break; - case EMC_JOG_ABS_TYPE: - ((EMC_JOG_ABS *) buffer)->update(cms); - break; case EMC_JOG_STOP_TYPE: ((EMC_JOG_STOP *) buffer)->update(cms); break; @@ -76,21 +70,12 @@ int emcFormat(NMLTYPE type, void *buffer, CMS * cms) case EMC_JOINT_OVERRIDE_LIMITS_TYPE: ((EMC_JOINT_OVERRIDE_LIMITS *) buffer)->update(cms); break; - case EMC_JOINT_SET_FERROR_TYPE: - ((EMC_JOINT_SET_FERROR *) buffer)->update(cms); - break; case EMC_JOINT_SET_BACKLASH_TYPE: ((EMC_JOINT_SET_BACKLASH *) buffer)->update(cms); break; - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - ((EMC_JOINT_SET_HOMING_PARAMS *) buffer)->update(cms); - break; case EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE: ((EMC_JOINT_SET_MAX_POSITION_LIMIT *) buffer)->update(cms); break; - case EMC_JOINT_SET_MIN_FERROR_TYPE: - ((EMC_JOINT_SET_MIN_FERROR *) buffer)->update(cms); - break; case EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE: ((EMC_JOINT_SET_MIN_POSITION_LIMIT *) buffer)->update(cms); break; @@ -268,9 +253,6 @@ int emcFormat(NMLTYPE type, void *buffer, CMS * cms) case EMC_AUX_INPUT_WAIT_TYPE: ((EMC_AUX_INPUT_WAIT *) buffer)->update(cms); break; - case EMC_TRAJ_SET_ACCELERATION_TYPE: - ((EMC_TRAJ_SET_ACCELERATION *) buffer)->update(cms); - break; case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: ((EMC_TRAJ_SET_MAX_VELOCITY *) buffer)->update(cms); break; @@ -326,9 +308,6 @@ int emcFormat(NMLTYPE type, void *buffer, CMS * cms) ((EMC_TRAJ_SET_SPINDLESYNC *) buffer)->update(cms); break; break; - case EMC_TRAJ_SET_VELOCITY_TYPE: - ((EMC_TRAJ_SET_VELOCITY *) buffer)->update(cms); - break; case EMC_TRAJ_STAT_TYPE: ((EMC_TRAJ_STAT *) buffer)->update(cms); break; @@ -345,8 +324,6 @@ const char *emc_symbol_lookup(uint32_t type) switch (type) { case EMC_AUX_STAT_TYPE: return "EMC_AUX_STAT"; - case EMC_JOINT_HALT_TYPE: - return "EMC_JOINT_HALT"; case EMC_JOINT_HOME_TYPE: return "EMC_JOINT_HOME"; case EMC_JOINT_UNHOME_TYPE: @@ -355,24 +332,16 @@ const char *emc_symbol_lookup(uint32_t type) return "EMC_JOG_CONT"; case EMC_JOG_INCR_TYPE: return "EMC_JOG_INCR"; - case EMC_JOG_ABS_TYPE: - return "EMC_JOG_ABS"; case EMC_JOG_STOP_TYPE: return "EMC_JOG_STOP"; case EMC_JOINT_LOAD_COMP_TYPE: return "EMC_JOINT_LOAD_COMP"; case EMC_JOINT_OVERRIDE_LIMITS_TYPE: return "EMC_JOINT_OVERRIDE_LIMITS"; - case EMC_JOINT_SET_FERROR_TYPE: - return "EMC_JOINT_SET_FERROR"; case EMC_JOINT_SET_BACKLASH_TYPE: return "EMC_JOINT_SET_BACKLASH"; - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - return "EMC_JOINT_SET_HOMING_PARAMS"; case EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE: return "EMC_JOINT_SET_MAX_POSITION_LIMIT"; - case EMC_JOINT_SET_MIN_FERROR_TYPE: - return "EMC_JOINT_SET_MIN_FERROR"; case EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE: return "EMC_JOINT_SET_MIN_POSITION_LIMIT"; case EMC_JOINT_STAT_TYPE: @@ -495,8 +464,6 @@ const char *emc_symbol_lookup(uint32_t type) return "EMC_AUX_INPUT_WAIT"; case EMC_TRAJ_RIGID_TAP_TYPE: return "EMC_TRAJ_RIGID_TAP"; - case EMC_TRAJ_SET_ACCELERATION_TYPE: - return "EMC_TRAJ_SET_ACCELERATION"; case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: return "EMC_TRAJ_SET_MAX_VELOCITY"; case EMC_TRAJ_SET_MODE_TYPE: @@ -533,8 +500,6 @@ const char *emc_symbol_lookup(uint32_t type) return "EMC_TRAJ_SET_TERM_COND"; case EMC_TRAJ_SET_SPINDLESYNC_TYPE: return "EMC_TRAJ_SET_SPINDLESYNC"; - case EMC_TRAJ_SET_VELOCITY_TYPE: - return "EMC_TRAJ_SET_VELOCITY"; case EMC_TRAJ_STAT_TYPE: return "EMC_TRAJ_STAT"; default: @@ -677,19 +642,6 @@ void EMC_TRAJ_DELAY::update(CMS * cms) cms->update(delay); } -/* -* NML/CMS Update function for EMC_JOG_ABS -*/ -// cppcheck-suppress duplInheritedMember -void EMC_JOG_ABS::update(CMS * cms) -{ - EMC_JOG_CMD_MSG::update(cms); - cms->update(pos); - cms->update(vel); - cms->update(jjogmode); - -} - /* * NML/CMS Update function for EMC_JOG_STOP */ @@ -780,18 +732,6 @@ void PmCartesian_update(CMS * cms, PmCartesian * x) cms->update(x->z); } -/* -* NML/CMS Update function for EMC_JOINT_SET_FERROR -* Automatically generated by NML CodeGen Java Applet. -* on Sat Oct 11 13:45:16 UTC 2003 -*/ -// cppcheck-suppress duplInheritedMember -void EMC_JOINT_SET_FERROR::update(CMS * cms) -{ - EMC_JOINT_CMD_MSG::update(cms); - cms->update(ferror); -} - /* * NML/CMS Update function for EMC_JOINT_SET_MIN_POSITION_LIMIT * Automatically generated by NML CodeGen Java Applet. @@ -804,19 +744,6 @@ void EMC_JOINT_SET_MIN_POSITION_LIMIT::update(CMS * cms) cms->update(limit); } -/* -* NML/CMS Update function for EMC_TRAJ_SET_VELOCITY -* Automatically generated by NML CodeGen Java Applet. -* on Sat Oct 11 13:45:16 UTC 2003 -*/ -// cppcheck-suppress duplInheritedMember -void EMC_TRAJ_SET_VELOCITY::update(CMS * cms) -{ - EMC_TRAJ_CMD_MSG::update(cms); - cms->update(velocity); - cms->update(ini_maxvel); -} - /* * NML/CMS Update function for EMC_TASK_ABORT * Automatically generated by NML CodeGen Java Applet. @@ -839,18 +766,6 @@ void EMC_TASK_PLAN_INIT::update(CMS * cms) EMC_TASK_CMD_MSG::update(cms); } -/* -* NML/CMS Update function for EMC_TRAJ_SET_ACCELERATION -* Automatically generated by NML CodeGen Java Applet. -* on Sat Oct 11 13:45:16 UTC 2003 -*/ -// cppcheck-suppress duplInheritedMember -void EMC_TRAJ_SET_ACCELERATION::update(CMS * cms) -{ - EMC_TRAJ_CMD_MSG::update(cms); - cms->update(acceleration); -} - /* * NML/CMS Update function for EMC_AUX_STAT * Automatically generated by NML CodeGen Java Applet. @@ -1783,18 +1698,6 @@ void EMC_AUX_CMD_MSG::update(CMS * /*cms*/) } -/* -* NML/CMS Update function for EMC_JOINT_SET_MIN_FERROR -* Automatically generated by NML CodeGen Java Applet. -* on Sat Oct 11 13:45:17 UTC 2003 -*/ -// cppcheck-suppress duplInheritedMember -void EMC_JOINT_SET_MIN_FERROR::update(CMS * cms) -{ - EMC_JOINT_CMD_MSG::update(cms); - cms->update(ferror); -} - /* * NML/CMS Update function for EMC_NULL * Automatically generated by NML CodeGen Java Applet. @@ -1904,31 +1807,6 @@ void EMC_TASK_PLAN_OPEN::update(CMS * cms) cms->update(remote_buffer, sizeof(remote_buffer)); } -/* -* NML/CMS Update function for EMC_JOINT_SET_HOMING_PARAMS -* Manually generated - do not use NML CodeGen Java Applet. -*/ -// cppcheck-suppress duplInheritedMember -void EMC_JOINT_SET_HOMING_PARAMS::update(CMS * cms) -{ - EMC_JOINT_CMD_MSG::update(cms); - cms->update(home); - cms->update(offset); - cms->update(home_final_vel); - cms->update(search_vel); - cms->update(latch_vel); - cms->update(search_dist); - cms->update(latch_dist); - cms->update(use_index); - cms->update(encoder_does_not_reset); - cms->update(ignore_limits); - cms->update(is_shared); - cms->update(home_sequence); - cms->update(volatile_home); - cms->update(locking_indexer); - cms->update(absolute_encoder); -} - /* * NML/CMS Update function for EMC_TRAJ_SET_MODE * Automatically generated by NML CodeGen Java Applet. @@ -1989,17 +1867,6 @@ void EMC_TRAJ_SET_TELEOP_ENABLE::update(CMS * cms) cms->update(enable); } -/* -* NML/CMS Update function for EMC_JOINT_HALT -* Automatically generated by NML CodeGen Java Applet. -* on Sat Oct 11 13:45:17 UTC 2003 -*/ -// cppcheck-suppress duplInheritedMember -void EMC_JOINT_HALT::update(CMS * cms) -{ - EMC_JOINT_CMD_MSG::update(cms); -} - /* * NML/CMS Update function for EMC_TASK_PLAN_PAUSE * Automatically generated by NML CodeGen Java Applet. diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc index 23c6f7119c5..4760b36a073 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -374,36 +374,6 @@ int emcSystemCmd(char *s) return 0; } -// shorthand typecasting ptrs -static EMC_JOINT_HALT *joint_halt_msg; -static EMC_JOINT_HOME *home_msg; -static EMC_JOINT_UNHOME *unhome_msg; -static EMC_JOG_CONT *jog_cont_msg; -static EMC_JOG_STOP *jog_stop_msg; -static EMC_JOG_INCR *jog_incr_msg; -static EMC_JOG_ABS *jog_abs_msg; -static EMC_JOINT_SET_BACKLASH *set_backlash_msg; -static EMC_JOINT_SET_HOMING_PARAMS *set_homing_params_msg; -static EMC_JOINT_SET_FERROR *set_ferror_msg; -static EMC_JOINT_SET_MIN_FERROR *set_min_ferror_msg; -static EMC_JOINT_SET_MAX_POSITION_LIMIT *set_max_limit_msg; -static EMC_JOINT_SET_MIN_POSITION_LIMIT *set_min_limit_msg; -static EMC_JOINT_OVERRIDE_LIMITS *joint_lim_msg; -//static EMC_JOINT_SET_OUTPUT *axis_output_msg; -static EMC_JOINT_LOAD_COMP *joint_load_comp_msg; -//static EMC_AXIS_SET_STEP_PARAMS *set_step_params_msg; - -static EMC_TRAJ_SET_SCALE *emcTrajSetScaleMsg; -static EMC_TRAJ_SET_RAPID_SCALE *emcTrajSetRapidScaleMsg; -static EMC_TRAJ_SET_MAX_VELOCITY *emcTrajSetMaxVelocityMsg; -static EMC_TRAJ_SET_SPINDLE_SCALE *emcTrajSetSpindleScaleMsg; -static EMC_TRAJ_SET_VELOCITY *emcTrajSetVelocityMsg; -static EMC_TRAJ_SET_ACCELERATION *emcTrajSetAccelerationMsg; -static EMC_TRAJ_LINEAR_MOVE *emcTrajLinearMoveMsg; -static EMC_TRAJ_CIRCULAR_MOVE *emcTrajCircularMoveMsg; -static EMC_TRAJ_DELAY *emcTrajDelayMsg; -static EMC_TRAJ_SET_TERM_COND *emcTrajSetTermCondMsg; -static EMC_TRAJ_SET_SPINDLESYNC *emcTrajSetSpindlesyncMsg; // These classes are commented out because the compiler // complains that they are "defined but not used". @@ -437,7 +407,7 @@ static EMC_TRAJ_MODE homingPriorMode = EMC_TRAJ_MODE::FREE; // mode to restore o // interp_list. emcTaskIssueCommand() serves both that queued path and the // immediate commands emcTaskPlan() sends straight through (the GUI's Home // button, halui, linuxcncrsh), and only the queued path is followed by -// emcTaskCheckPostconditions() -- so only the queued path can ever reach +// the wait commandWaits() names -- so only the queued path can ever reach // EMC_TASK_EXEC::WAITING_FOR_HOMING to undo the FREE-mode dip and restore the // previous trajectory mode. Dipping on an immediate command would therefore // strand the machine in FREE for good. Gate the sequencing on this flag so @@ -449,33 +419,9 @@ static bool issuingQueuedCommand = false; // which would drop the MDI sent after it and run ON_ABORT_COMMAND twice. static bool queuedMdiAborted = false; -static EMC_SPINDLE_SPEED *spindle_speed_msg; -static EMC_SPINDLE_ORIENT *spindle_orient_msg; -static EMC_SPINDLE_WAIT_ORIENT_COMPLETE *wait_spindle_orient_complete_msg; -static EMC_SPINDLE_ON *spindle_on_msg; -static EMC_SPINDLE_OFF *spindle_off_msg; -static EMC_SPINDLE_BRAKE_ENGAGE *spindle_brake_engage_msg; -static EMC_SPINDLE_BRAKE_RELEASE *spindle_brake_release_msg; -static EMC_SPINDLE_INCREASE *spindle_increase_msg; -static EMC_SPINDLE_DECREASE *spindle_decrease_msg; -static EMC_SPINDLE_CONSTANT *spindle_constant_msg; -static EMC_TOOL_PREPARE *tool_prepare_msg; -static EMC_TOOL_LOAD_TOOL_TABLE *load_tool_table_msg; -static EMC_TOOL_SET_OFFSET *emc_tool_set_offset_msg; -static EMC_TOOL_SET_NUMBER *emc_tool_set_number_msg; -static EMC_TASK_SET_MODE *mode_msg; -static EMC_TASK_SET_STATE *state_msg; -static EMC_TASK_PLAN_RUN *run_msg; -static EMC_TASK_PLAN_EXECUTE *execute_msg; -static EMC_TASK_PLAN_OPEN *open_msg; -static EMC_TASK_PLAN_SET_OPTIONAL_STOP *os_msg; -static EMC_TASK_PLAN_SET_BLOCK_DELETE *bd_msg; - -static EMC_AUX_INPUT_WAIT *emcAuxInputWaitMsg; static int emcAuxInputWaitType = 0; static int emcAuxInputWaitIndex = -1; -static EMC_TRAJ_SELECT_KINS *kSwitch_msg; // commands we compose here static EMC_TASK_PLAN_RUN taskPlanRunCmd; // 16-Aug-1999 FMP @@ -501,49 +447,16 @@ static int mdi_execute_wait = 0; // Side queue to store MDI commands static NML_INTERP_LIST mdi_execute_queue; -// MDI input queue -static NML_INTERP_LIST mdi_input_queue; -#define MAX_MDI_QUEUE 10 -static int max_mdi_queued_commands = MAX_MDI_QUEUE; - -/* - checkInterpList(NML_INTERP_LIST *il, EMC_STAT *stat) takes a pointer - to an interpreter list and a pointer to the EMC status, pops each NML - message off the list, and checks it against limits, resource availability, - etc. in the status. - - It returns 0 if all messages check out, -1 if any of them fail. If one - fails, the rest of the list is not checked. - */ -static int checkInterpList(NML_INTERP_LIST * il, EMC_STAT * /*stat*/) +// Empty the interpreter list of a line that is being skipped over, but +// still show the operator errors it holds. +static void checkInterpList(NML_INTERP_LIST * il) { while (il->len() > 0) { auto cmd = il->get(); - - switch (cmd->_type) { - - case EMC_OPERATOR_ERROR_TYPE: { - auto error_msg = static_cast(cmd.get()); - emcOperatorError("%s", error_msg->error); - break; - } - - //FIXME: there was limit checking tests below, see if they were needed - case EMC_TRAJ_LINEAR_MOVE_TYPE: - break; - - case EMC_TRAJ_JOINT_MOVE_TYPE: - break; - - case EMC_TRAJ_CIRCULAR_MOVE_TYPE: - break; - - default: - break; + if (cmd->_type == EMC_OPERATOR_ERROR_TYPE) { + emcOperatorError("%s", static_cast(cmd.get())->error); } } - - return 0; } extern int emcTaskMopup(); @@ -639,20 +552,9 @@ void readahead_reading(void) emcTaskPlanLevel() == 0 && ( programStartLine < 0 || emcTaskPlanLine() <= programStartLine )) { - // we're stepping over lines, so check them - // for - // limits, etc. and clear then out - if (0 != checkInterpList(&interp_list, - emcStatus)) { - // problem with actions, so do same as we - // did - // for a bad read from emcTaskPlanRead() - // above - emcStatus->task.interpState = - EMC_TASK_INTERP::WAITING; - } - // and clear it regardless - interp_list.clear(); + // we're stepping over lines, so drop what + // they queued + checkInterpList(&interp_list); } if (emcStatus->task.readLine < programStartLine && @@ -752,8 +654,8 @@ static void mdi_execute_hook(void) !mdi_execute_next) { // finished. Check for dequeuing of queued MDI command is done in emcTaskPlan(). - log_debug(EMC_DEBUG_TASK_ISSUE, "mdi_execute_hook: MDI command '{}' done (remaining: {})\n", - emcStatus->task.command, mdi_input_queue.len()); + log_debug(EMC_DEBUG_TASK_ISSUE, "mdi_execute_hook: MDI command '{}' done\n", + emcStatus->task.command); emcStatus->task.command[0] = 0; emcStatus->task.interpState = EMC_TASK_INTERP::IDLE; } @@ -798,897 +700,354 @@ void readahead_waiting(void) } } -static bool allow_while_idle_type() { - // allow for EMC_TASK_MODE::AUTO, EMC_TASK_MODE::MDI - // expect immediate command - RCS_CMD_MSG *emcCommand; - emcCommand = emcCommandBuffer->get_address(); - switch(emcCommand->_type) { - case EMC_JOG_CONT_TYPE: - case EMC_JOG_INCR_TYPE: - case EMC_JOG_STOP_TYPE: - case EMC_JOG_ABS_TYPE: - case EMC_TRAJ_SET_TELEOP_ENABLE_TYPE: - return 1; - break; - } - return 0; +// The situation the planner decides by: the machine off (or in E-stop), or +// on and in one of the modes, Auto split by what the interpreter does. At +// most one of the fields after 'on' is set. +// +// emcTaskPlan() takes it once, before it handles the command, and goes by +// it for the rest of the cycle: handling a command can change task's state +// (a run starts, an abort ends one), and what the planner does after it +// (the readahead) must still go by the situation the command found. +struct Situation { + bool on; // the machine is on + bool manual; // on, in Manual + bool mdi; // on, in MDI + bool autoIdle; // on, in Auto, the interpreter idle + bool autoReading; // on, in Auto, the interpreter reading + bool autoPaused; // on, in Auto, the interpreter paused + bool autoWaiting; // on, in Auto, the interpreter waiting +}; + +static Situation situation() +{ + const EMC_TASK_STAT &task = emcStatus->task; + const bool machineOn = task.state == EMC_TASK_STATE::ON; + const bool inAuto = machineOn && task.mode == EMC_TASK_MODE::AUTO; + return { + .on = machineOn, + .manual = machineOn && task.mode == EMC_TASK_MODE::MANUAL, + .mdi = machineOn && task.mode == EMC_TASK_MODE::MDI, + .autoIdle = inAuto && task.interpState == EMC_TASK_INTERP::IDLE, + .autoReading = inAuto && task.interpState == EMC_TASK_INTERP::READING, + .autoPaused = inAuto && task.interpState == EMC_TASK_INTERP::PAUSED, + .autoWaiting = inAuto && task.interpState == EMC_TASK_INTERP::WAITING, + }; } /* - emcTaskPlan() + isImmediate() - Planner for NC code or manual mode operations + The commands emcTaskPlan() passes straight to emcTaskIssueCommand(), by + the state, mode and interpreter state task is in. Everything else is + handled, or refused, by the planner's table for that situation. */ -static int emcTaskPlan(void) +static bool isImmediate(NMLTYPE type, const Situation &s) { - NMLTYPE type; - int retval = 0; - - // check for new command - if (emcCommand->serial_number != emcStatus->echo_serial_number) { - // flag it here locally as a new command - type = emcCommand->_type; - } else { - // no new command-- reset local flag - type = 0; - } - - // Always display messages switch (type) { - case EMC_OPERATOR_ERROR_TYPE: - case EMC_OPERATOR_TEXT_TYPE: - case EMC_OPERATOR_DISPLAY_TYPE: - retval = emcTaskIssueCommand(emcCommand); - return retval; - } - - // handle any new command - switch (emcStatus->task.state) { - case EMC_TASK_STATE::OFF: - case EMC_TASK_STATE::ESTOP: - case EMC_TASK_STATE::ESTOP_RESET: - - // now switch on the mode - switch (emcStatus->task.mode) { - case EMC_TASK_MODE::MANUAL: - case EMC_TASK_MODE::AUTO: - case EMC_TASK_MODE::MDI: - - // now switch on the command - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_LOAD_COMP_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_TRAJ_SET_VELOCITY_TYPE: - case EMC_TRAJ_SET_ACCELERATION_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_PLAN_INIT_TYPE: - case EMC_TASK_PLAN_OPEN_TYPE: - case EMC_TASK_PLAN_CLOSE_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TASK_PLAN_SYNCH_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_MOTION_SET_DOUT_TYPE: - case EMC_MOTION_ADAPTIVE_TYPE: - case EMC_MOTION_SET_AOUT_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_TRAJ_SET_TELEOP_ENABLE_TYPE: - case EMC_SET_DEBUG_TYPE: - retval = emcTaskIssueCommand(emcCommand); - break; - - // one case where we need to be in manual mode - case EMC_JOINT_OVERRIDE_LIMITS_TYPE: - retval = 0; - if (emcStatus->task.mode == EMC_TASK_MODE::MANUAL) { - retval = emcTaskIssueCommand(emcCommand); - } - break; - - case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - case EMC_TOOL_SET_OFFSET_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - - case EMC_TOOL_SET_NUMBER_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - - default: - emcOperatorError(_("command (%s) cannot be executed until the machine is out of E-stop and turned on"), emc_symbol_lookup(type)); - retval = -1; - break; - - } // switch (type) - - default: - // invalid mode - break; - - } // switch (mode) - - break; // case EMC_TASK_STATE::OFF,ESTOP,ESTOP_RESET - - case EMC_TASK_STATE::ON: - /* we can do everything (almost) when the machine is on, so let's - switch on the execution mode */ - switch (emcStatus->task.mode) { - case EMC_TASK_MODE::MANUAL: // ON, MANUAL - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE: - case EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE: - case EMC_JOINT_HALT_TYPE: - case EMC_JOINT_HOME_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_JOG_CONT_TYPE: - case EMC_JOG_INCR_TYPE: - case EMC_JOG_ABS_TYPE: - case EMC_JOG_STOP_TYPE: - case EMC_JOINT_OVERRIDE_LIMITS_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_SPINDLE_SPEED_TYPE: - case EMC_SPINDLE_ON_TYPE: - case EMC_SPINDLE_OFF_TYPE: - case EMC_SPINDLE_BRAKE_RELEASE_TYPE: - case EMC_SPINDLE_BRAKE_ENGAGE_TYPE: - case EMC_SPINDLE_INCREASE_TYPE: - case EMC_SPINDLE_DECREASE_TYPE: - case EMC_SPINDLE_CONSTANT_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TASK_PLAN_OPEN_TYPE: - case EMC_TASK_PLAN_CLOSE_TYPE: - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_REVERSE_TYPE: - case EMC_TASK_PLAN_FORWARD_TYPE: - case EMC_TASK_PLAN_RESUME_TYPE: - case EMC_TASK_PLAN_INIT_TYPE: - case EMC_TASK_PLAN_SYNCH_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_MOTION_SET_DOUT_TYPE: - case EMC_MOTION_SET_AOUT_TYPE: - case EMC_MOTION_ADAPTIVE_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_TRAJ_SET_TELEOP_ENABLE_TYPE: - case EMC_SET_DEBUG_TYPE: - retval = emcTaskIssueCommand(emcCommand); - break; - - // queued commands - - case EMC_TASK_PLAN_EXECUTE_TYPE: - // resynch the interpreter, since we may have moved - // externally - emcTaskQueueTaskPlanSynchCmd(); - // and now call for interpreter execute - retval = emcTaskIssueCommand(emcCommand); - break; - - case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - case EMC_TOOL_SET_OFFSET_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - - case EMC_TOOL_SET_NUMBER_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - - case EMC_TASK_PLAN_RUN_TYPE: - if (GET_EXTERNAL_OFFSET_APPLIED()) { - // err here, fewer err reports - retval = -1; - } - break; - - // otherwise we can't handle it - default: - emcOperatorError(_("can't do that (%s:%d) in manual mode"), emc_symbol_lookup(type),(int) type); - retval = -1; - break; - - } // switch (type) in ON, MANUAL - - break; // case EMC_TASK_MODE::MANUAL - - case EMC_TASK_MODE::AUTO: // ON, AUTO - switch (emcStatus->task.interpState) { - case EMC_TASK_INTERP::IDLE: // ON, AUTO, IDLE - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_SPINDLE_SPEED_TYPE: - case EMC_SPINDLE_ORIENT_TYPE: - case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: - case EMC_SPINDLE_ON_TYPE: - case EMC_SPINDLE_OFF_TYPE: - case EMC_SPINDLE_BRAKE_RELEASE_TYPE: - case EMC_SPINDLE_BRAKE_ENGAGE_TYPE: - case EMC_SPINDLE_INCREASE_TYPE: - case EMC_SPINDLE_DECREASE_TYPE: - case EMC_SPINDLE_CONSTANT_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TASK_PLAN_INIT_TYPE: - case EMC_TASK_PLAN_OPEN_TYPE: - case EMC_TASK_PLAN_CLOSE_TYPE: - case EMC_TASK_PLAN_RUN_TYPE: - case EMC_TASK_PLAN_EXECUTE_TYPE: - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_REVERSE_TYPE: - case EMC_TASK_PLAN_FORWARD_TYPE: - case EMC_TASK_PLAN_RESUME_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_SET_DEBUG_TYPE: - retval = emcTaskIssueCommand(emcCommand); - break; - - case EMC_TASK_PLAN_STEP_TYPE: - // handles case where first action is to step the program - taskPlanRunCmd.line = 0; // run from start - /*! \todo FIXME-- can have GUI set this; send a run instead of a - step */ - retval = emcTaskIssueCommand(&taskPlanRunCmd); - if(retval != 0) break; - emcTrajPause(); - if (emcStatus->task.interpState != EMC_TASK_INTERP::PAUSED) { - interpResumeState = emcStatus->task.interpState; - } - emcStatus->task.interpState = EMC_TASK_INTERP::PAUSED; - emcStatus->task.task_paused = 1; - retval = 0; - break; - - case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - case EMC_TOOL_SET_OFFSET_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - - // otherwise we can't handle it - default: - //EMC_TASK_MODE::AUTO(2) && EMC_TASK_INTERP::IDLE(1) - if ( allow_while_idle_type() ) { - retval = emcTaskIssueCommand(emcCommand); - break; - } - emcOperatorError(_("can't do that (%s) in auto mode with the interpreter idle"), emc_symbol_lookup(type)); - retval = -1; - break; - - } // switch (type) in ON, AUTO, IDLE - - break; // EMC_TASK_INTERP::IDLE - - case EMC_TASK_INTERP::READING: // ON, AUTO, READING - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_SPINDLE_INCREASE_TYPE: - case EMC_SPINDLE_DECREASE_TYPE: - case EMC_SPINDLE_CONSTANT_TYPE: - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_REVERSE_TYPE: - case EMC_TASK_PLAN_FORWARD_TYPE: - case EMC_TASK_PLAN_RESUME_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_SET_DEBUG_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - retval = emcTaskIssueCommand(emcCommand); - return retval; - break; - - case EMC_TASK_PLAN_STEP_TYPE: - emcStatus->motion.traj.single_stepping = 1; - stepping = 1; // set stepping mode in case it's not - steppingWait = 0; // clear the wait - break; - - // otherwise we can't handle it - default: - emcOperatorError(_("can't do that (%s) in auto mode with the interpreter reading"), emc_symbol_lookup(type)); - retval = -1; - break; - - } // switch (type) in ON, AUTO, READING - - // handle interp readahead logic - readahead_reading(); - - break; // EMC_TASK_INTERP::READING - - case EMC_TASK_INTERP::PAUSED: // ON, AUTO, PAUSED - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_SPINDLE_SPEED_TYPE: - case EMC_SPINDLE_ORIENT_TYPE: - case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: - case EMC_SPINDLE_ON_TYPE: - case EMC_SPINDLE_OFF_TYPE: - case EMC_SPINDLE_BRAKE_RELEASE_TYPE: - case EMC_SPINDLE_BRAKE_ENGAGE_TYPE: - case EMC_SPINDLE_INCREASE_TYPE: - case EMC_SPINDLE_DECREASE_TYPE: - case EMC_SPINDLE_CONSTANT_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TASK_PLAN_EXECUTE_TYPE: - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_REVERSE_TYPE: - case EMC_TASK_PLAN_FORWARD_TYPE: - case EMC_TASK_PLAN_RESUME_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_SET_DEBUG_TYPE: - retval = emcTaskIssueCommand(emcCommand); - break; - - case EMC_TASK_PLAN_STEP_TYPE: - emcStatus->motion.traj.single_stepping = 1; - stepping = 1; - steppingWait = 0; - if (emcStatus->motion.traj.paused && - emcStatus->motion.traj.queue > 0) { - // there are pending motions paused; step them - emcTrajStep(); - } else { - emcStatus->task.interpState = interpResumeState; - } - emcStatus->task.task_paused = 1; - break; - - // otherwise we can't handle it - default: - emcOperatorError(_("can't do that (%s) in auto mode with the interpreter paused"), emc_symbol_lookup(type)); - retval = -1; - break; - - } // switch (type) in ON, AUTO, PAUSED - - break; // EMC_TASK_INTERP::PAUSED - - case EMC_TASK_INTERP::WAITING: - // interpreter ran to end - // handle input commands - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_SPINDLE_INCREASE_TYPE: - case EMC_SPINDLE_DECREASE_TYPE: - case EMC_SPINDLE_CONSTANT_TYPE: - case EMC_TASK_PLAN_EXECUTE_TYPE: - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_REVERSE_TYPE: - case EMC_TASK_PLAN_FORWARD_TYPE: - case EMC_TASK_PLAN_RESUME_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_SET_DEBUG_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - retval = emcTaskIssueCommand(emcCommand); - break; - - case EMC_TASK_PLAN_STEP_TYPE: - emcStatus->motion.traj.single_stepping = 1; - stepping = 1; // set stepping mode in case it's not - steppingWait = 0; // clear the wait - break; - - // otherwise we can't handle it - default: - emcOperatorError(_("can't do that (%s) in auto mode with the interpreter waiting"), emc_symbol_lookup(type)); - retval = -1; - break; - - } // switch (type) in ON, AUTO, WAITING - - // handle interp readahead logic - readahead_waiting(); - - break; // end of case EMC_TASK_INTERP::WAITING - - default: - // coding error - log_error("invalid mode({})", (int)emcStatus->task.mode); - retval = -1; - break; - - } // switch (mode) in ON, AUTO - - break; // case EMC_TASK_MODE::AUTO - - case EMC_TASK_MODE::MDI: // ON, MDI - switch (type) { - case 0: - case EMC_NULL_TYPE: - // no command - break; - - // immediate commands - - case EMC_JOINT_SET_BACKLASH_TYPE: - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - case EMC_JOINT_SET_FERROR_TYPE: - case EMC_JOINT_SET_MIN_FERROR_TYPE: - case EMC_JOINT_UNHOME_TYPE: - case EMC_TRAJ_SET_SCALE_TYPE: - case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - case EMC_SPINDLE_SPEED_TYPE: - case EMC_SPINDLE_ORIENT_TYPE: - case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: - case EMC_SPINDLE_ON_TYPE: - case EMC_SPINDLE_OFF_TYPE: - case EMC_SPINDLE_BRAKE_RELEASE_TYPE: - case EMC_SPINDLE_BRAKE_ENGAGE_TYPE: - case EMC_SPINDLE_INCREASE_TYPE: - case EMC_SPINDLE_DECREASE_TYPE: - case EMC_SPINDLE_CONSTANT_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - case EMC_TASK_SET_MODE_TYPE: - case EMC_TASK_SET_STATE_TYPE: - case EMC_TASK_PLAN_INIT_TYPE: - case EMC_TASK_PLAN_OPEN_TYPE: - case EMC_TASK_PLAN_CLOSE_TYPE: - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_REVERSE_TYPE: - case EMC_TASK_PLAN_FORWARD_TYPE: - case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - case EMC_TASK_PLAN_RESUME_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - case EMC_TASK_PLAN_SYNCH_TYPE: - case EMC_TASK_ABORT_TYPE: - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_PROBE_TYPE: - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_MOTION_SET_DOUT_TYPE: - case EMC_MOTION_SET_AOUT_TYPE: - case EMC_MOTION_ADAPTIVE_TYPE: - case EMC_TRAJ_RIGID_TAP_TYPE: - case EMC_SET_DEBUG_TYPE: - retval = emcTaskIssueCommand(emcCommand); - break; - - case EMC_TASK_PLAN_EXECUTE_TYPE: - // If there are no queued MDI commands, no commands in - // interp_list, and waitFlag isn't set, then this new - // incoming MDI command can just be issued directly. - // Otherwise we need to queue it and deal with it - // later. A kinematics switch task still waits on ends - // in a resynch: a line read before it is read under the - // old kinematics. The switch of an abort routine sets - // no waitFlag, so ask for it here. - if ( - (mdi_execute_queue.len() == 0) - && (interp_list.len() == 0) - && (emcTaskCommand == NULL) - && (emcTaskPlanIsWait() == 0) - && (emcStatus->task.execState != EMC_TASK_EXEC::WAITING_FOR_KINS_SWITCH) - ) { - retval = emcTaskIssueCommand(emcCommand); - } else { - auto cmd = std::make_unique(); - rtapi_strlcpy(cmd->command, static_cast(emcCommand)->command, sizeof(cmd->command)); - mdi_execute_queue.append(std::move(cmd)); - emcStatus->task.queuedMDIcommands = mdi_execute_queue.len(); - // not idle while an MDI waits its turn: the status - // that echoes it must not read as done - emcStatus->task.interpState = EMC_TASK_INTERP::READING; - retval = 0; - } - break; - - case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - case EMC_TOOL_SET_OFFSET_TYPE: { - // send to IO - emcTaskQueueCommand(std::make_unique(*static_cast(emcCommand))); - // signify no more reading - emcTaskPlanSetWait(); - // then resynch interpreter - emcTaskQueueTaskPlanSynchCmd(); - break; - } - - // otherwise we can't handle it - default: - //EMC_TASK_MODE::MDI(3) && EMC_TASK_INTERP::IDLE(1) - if ( allow_while_idle_type() ) { - retval = emcTaskIssueCommand(emcCommand); - break; - } - emcOperatorError(_("can't do that (%s:%d) in MDI mode"), emc_symbol_lookup(type),(int) type); + // in any state + case EMC_JOINT_SET_BACKLASH_TYPE: + case EMC_JOINT_UNHOME_TYPE: + case EMC_TRAJ_SET_SCALE_TYPE: + case EMC_TRAJ_SET_RAPID_SCALE_TYPE: + case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: + case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: + case EMC_TRAJ_SET_FO_ENABLE_TYPE: + case EMC_TRAJ_SET_FH_ENABLE_TYPE: + case EMC_TRAJ_SET_SO_ENABLE_TYPE: + case EMC_TASK_SET_MODE_TYPE: + case EMC_TASK_SET_STATE_TYPE: + case EMC_TASK_ABORT_TYPE: + case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: + case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: + case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: + case EMC_TRAJ_PROBE_TYPE: + case EMC_AUX_INPUT_WAIT_TYPE: + case EMC_TRAJ_RIGID_TAP_TYPE: + case EMC_SET_DEBUG_TYPE: + return true; - retval = -1; - break; + // only while the machine is off or in E-stop + case EMC_JOINT_LOAD_COMP_TYPE: + return !s.on; - } // switch (type) in ON, MDI - mdi_execute_hook(); + // once the machine is on, whatever runs + case EMC_SPINDLE_INCREASE_TYPE: + case EMC_SPINDLE_DECREASE_TYPE: + case EMC_SPINDLE_CONSTANT_TYPE: + case EMC_COOLANT_MIST_ON_TYPE: + case EMC_COOLANT_MIST_OFF_TYPE: + case EMC_COOLANT_FLOOD_ON_TYPE: + case EMC_COOLANT_FLOOD_OFF_TYPE: + case EMC_TASK_PLAN_PAUSE_TYPE: + case EMC_TASK_PLAN_REVERSE_TYPE: + case EMC_TASK_PLAN_FORWARD_TYPE: + case EMC_TASK_PLAN_RESUME_TYPE: + case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: + return s.on; - break; // case EMC_TASK_MODE::MDI + // once the machine is on, unless a program is reading or waiting + case EMC_SPINDLE_SPEED_TYPE: + case EMC_SPINDLE_ON_TYPE: + case EMC_SPINDLE_OFF_TYPE: + case EMC_SPINDLE_BRAKE_RELEASE_TYPE: + case EMC_SPINDLE_BRAKE_ENGAGE_TYPE: + return s.manual || s.mdi || s.autoIdle || s.autoPaused; - default: - break; + // the same, but not in Manual + case EMC_SPINDLE_ORIENT_TYPE: + case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: + return s.mdi || s.autoIdle || s.autoPaused; - } // switch (mode) + // unless a program runs + case EMC_TASK_PLAN_INIT_TYPE: + case EMC_TASK_PLAN_OPEN_TYPE: + case EMC_TASK_PLAN_CLOSE_TYPE: + return !s.on || s.manual || s.mdi || s.autoIdle; - break; // case EMC_TASK_STATE::ON + // not in Auto + case EMC_TASK_PLAN_SYNCH_TYPE: + case EMC_MOTION_SET_DOUT_TYPE: + case EMC_MOTION_SET_AOUT_TYPE: + case EMC_MOTION_ADAPTIVE_TYPE: + return !s.on || s.manual || s.mdi; - default: - break; + // Auto only + case EMC_TASK_PLAN_RUN_TYPE: + return s.autoIdle; + case EMC_TASK_PLAN_EXECUTE_TYPE: + return s.autoIdle || s.autoPaused || s.autoWaiting; - } // switch (task.state) + // Manual only + case EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE: + case EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE: + case EMC_JOINT_HOME_TYPE: + case EMC_JOINT_OVERRIDE_LIMITS_TYPE: + return s.manual; - return retval; + // jogs, and in Auto only while the interpreter is idle + case EMC_JOG_CONT_TYPE: + case EMC_JOG_INCR_TYPE: + case EMC_JOG_STOP_TYPE: + return s.manual || s.mdi || s.autoIdle; + case EMC_TRAJ_SET_TELEOP_ENABLE_TYPE: + return !s.on || s.manual || s.mdi || s.autoIdle; + } + return false; } -/* - emcTaskCheckPreconditions() is called for commands on the interp_list. - Immediate commands, i.e., commands sent from calls to emcTaskIssueCommand() - in emcTaskPlan() directly, are not handled here. - - The return value is a state for emcTaskExecute() to wait on, e.g., - EMC_TASK_EXEC::WAITING_FOR_MOTION, before the command can be sent out. - */ -static EMC_TASK_EXEC emcTaskCheckPreconditions(NMLmsg * cmd) +// The tool commands go through interp_list: no more reading until they +// are done, then the interpreter synchs. +static void queueToolCommand(NMLmsg *cmd) { - if (NULL == cmd) { - return EMC_TASK_EXEC::DONE; + switch (cmd->_type) { + case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: + emcTaskQueueCommand(std::make_unique(*static_cast(cmd))); + break; + case EMC_TOOL_SET_OFFSET_TYPE: + emcTaskQueueCommand(std::make_unique(*static_cast(cmd))); + break; + case EMC_TOOL_SET_NUMBER_TYPE: + emcTaskQueueCommand(std::make_unique(*static_cast(cmd))); + break; + default: + return; } + // signify no more reading + emcTaskPlanSetWait(); + // then resynch interpreter + emcTaskQueueTaskPlanSynchCmd(); +} +// What the planner does itself with a command in this situation, instead +// of passing it through or refusing it. False if there is nothing special. +static bool planSpecial(NMLmsg *cmd, const Situation &s, int &retval) +{ switch (cmd->_type) { - // operator messages, if queued, will go out when everything before - // them is done - case EMC_OPERATOR_ERROR_TYPE: - case EMC_OPERATOR_TEXT_TYPE: - case EMC_OPERATOR_DISPLAY_TYPE: - case EMC_SYSTEM_CMD_TYPE: - case EMC_TRAJ_PROBE_TYPE: // prevent blending of this - case EMC_TRAJ_RIGID_TAP_TYPE: //and this - case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: // and this - case EMC_AUX_INPUT_WAIT_TYPE: - case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; - - case EMC_TRAJ_LINEAR_MOVE_TYPE: - case EMC_TRAJ_JOINT_MOVE_TYPE: - case EMC_TRAJ_CIRCULAR_MOVE_TYPE: - case EMC_TRAJ_SET_VELOCITY_TYPE: - case EMC_TRAJ_SET_ACCELERATION_TYPE: - case EMC_TRAJ_SET_TERM_COND_TYPE: - case EMC_TRAJ_SET_SPINDLESYNC_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_IO; - break; - - case EMC_TRAJ_SET_OFFSET_TYPE: - // this applies the tool length offset variable after previous - // motions - case EMC_TRAJ_SET_G5X_TYPE: - case EMC_TRAJ_SET_G92_TYPE: - case EMC_TRAJ_SET_ROTATION_TYPE: - case EMC_TRAJ_SET_G68_TYPE: - // this applies the program origin after previous motions - return EMC_TASK_EXEC::WAITING_FOR_MOTION; - break; - - case EMC_TOOL_LOAD_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - case EMC_SPINDLE_SPEED_TYPE: - case EMC_SPINDLE_ON_TYPE: - case EMC_SPINDLE_OFF_TYPE: - case EMC_SPINDLE_ORIENT_TYPE: // not sure - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; - - case EMC_TOOL_PREPARE_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_IO; - break; + case EMC_JOINT_OVERRIDE_LIMITS_TYPE: + // with the machine off: in manual mode only, ignored otherwise + if (s.on) { + return false; + } + if (emcStatus->task.mode == EMC_TASK_MODE::MANUAL) { + retval = emcTaskIssueCommand(cmd); + } + return true; case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: case EMC_TOOL_SET_OFFSET_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; - case EMC_TOOL_SET_NUMBER_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_IO; - break; - - case EMC_TASK_PLAN_PAUSE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - /* pause on the interp list is queued, so wait until all are done */ - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; + if (!s.on || s.manual + || ((s.autoIdle || s.mdi) && cmd->_type != EMC_TOOL_SET_NUMBER_TYPE)) { + queueToolCommand(cmd); + return true; + } + return false; - case EMC_TASK_PLAN_END_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; + case EMC_TASK_PLAN_EXECUTE_TYPE: + if (s.manual) { + // resynch the interpreter, since we may have moved + // externally + emcTaskQueueTaskPlanSynchCmd(); + // and now call for interpreter execute + retval = emcTaskIssueCommand(cmd); + return true; + } + if (s.mdi) { + // If there are no queued MDI commands, no commands in + // interp_list, and waitFlag isn't set, then this new + // incoming MDI command can just be issued directly. + // Otherwise we need to queue it and deal with it + // later. A kinematics switch task still waits on ends + // in a resynch: a line read before it is read under the + // old kinematics. The switch of an abort routine sets + // no waitFlag, so ask for it here. + if ((mdi_execute_queue.len() == 0) + && (interp_list.len() == 0) + && (emcTaskCommand == NULL) + && (emcTaskPlanIsWait() == 0) + && (emcStatus->task.execState != EMC_TASK_EXEC::WAITING_FOR_KINS_SWITCH)) { + retval = emcTaskIssueCommand(cmd); + } else { + auto queued = std::make_unique(); + rtapi_strlcpy(queued->command, static_cast(cmd)->command, sizeof(queued->command)); + mdi_execute_queue.append(std::move(queued)); + emcStatus->task.queuedMDIcommands = mdi_execute_queue.len(); + // not idle while an MDI waits its turn: the status + // that echoes it must not read as done + emcStatus->task.interpState = EMC_TASK_INTERP::READING; + } + return true; + } + return false; - case EMC_TASK_PLAN_INIT_TYPE: case EMC_TASK_PLAN_RUN_TYPE: - case EMC_TASK_PLAN_SYNCH_TYPE: - case EMC_TASK_PLAN_EXECUTE_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; + if (!s.manual) { + return false; + } + if (GET_EXTERNAL_OFFSET_APPLIED()) { + // err here, fewer err reports + retval = -1; + } + return true; + + case EMC_TASK_PLAN_STEP_TYPE: + if (s.autoIdle) { + // handles case where first action is to step the program + taskPlanRunCmd.line = 0; // run from start + /*! \todo FIXME-- can have GUI set this; send a run instead of a + step */ + retval = emcTaskIssueCommand(&taskPlanRunCmd); + if (retval != 0) { + return true; + } + emcTrajPause(); + if (emcStatus->task.interpState != EMC_TASK_INTERP::PAUSED) { + interpResumeState = emcStatus->task.interpState; + } + emcStatus->task.interpState = EMC_TASK_INTERP::PAUSED; + emcStatus->task.task_paused = 1; + return true; + } + if (s.autoReading || s.autoWaiting) { + emcStatus->motion.traj.single_stepping = 1; + stepping = 1; // set stepping mode in case it's not + steppingWait = 0; // clear the wait + return true; + } + if (s.autoPaused) { + emcStatus->motion.traj.single_stepping = 1; + stepping = 1; + steppingWait = 0; + if (emcStatus->motion.traj.paused && + emcStatus->motion.traj.queue > 0) { + // there are pending motions paused; step them + emcTrajStep(); + } else { + emcStatus->task.interpState = interpResumeState; + } + emcStatus->task.task_paused = 1; + return true; + } + return false; + } + return false; +} - case EMC_TRAJ_DELAY_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; +static void refuse(NMLTYPE type, const Situation &s) +{ + const char *name = emc_symbol_lookup(type); + if (!s.on) { + emcOperatorError(_("command (%s) cannot be executed until the machine is out of E-stop and turned on"), name); + } else if (s.manual) { + emcOperatorError(_("can't do that (%s:%d) in manual mode"), name, (int) type); + } else if (s.mdi) { + emcOperatorError(_("can't do that (%s:%d) in MDI mode"), name, (int) type); + } else if (s.autoIdle) { + emcOperatorError(_("can't do that (%s) in auto mode with the interpreter idle"), name); + } else if (s.autoReading) { + emcOperatorError(_("can't do that (%s) in auto mode with the interpreter reading"), name); + } else if (s.autoPaused) { + emcOperatorError(_("can't do that (%s) in auto mode with the interpreter paused"), name); + } else if (s.autoWaiting) { + emcOperatorError(_("can't do that (%s) in auto mode with the interpreter waiting"), name); + } +} - case EMC_MOTION_SET_AOUT_TYPE: - if ((reinterpret_cast(cmd))->now) { - return EMC_TASK_EXEC::WAITING_FOR_MOTION; - } - return EMC_TASK_EXEC::DONE; - break; +/* + emcTaskPlan() - case EMC_MOTION_SET_DOUT_TYPE: - if ((reinterpret_cast(cmd))->now) { - return EMC_TASK_EXEC::WAITING_FOR_MOTION; - } - return EMC_TASK_EXEC::DONE; - break; + Planner for NC code or manual mode operations - case EMC_MOTION_ADAPTIVE_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION; - break; + cmd is the new command to handle this cycle, or NULL if there is none. + It is only used for the duration of the call. - case EMC_TRAJ_SELECT_KINS_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; - break; + A command is handled by the planner itself (planSpecial()), passed + straight through (isImmediate()), or refused. + */ +static int emcTaskPlan(NMLmsg *cmd) +{ + const NMLTYPE type = cmd ? cmd->_type : 0; + const Situation s = situation(); + int retval = 0; + + switch (type) { + case 0: + case EMC_NULL_TYPE: + // no command + break; - case EMC_JOINT_HOME_TYPE: // G28.2: program-order homing - // drain prior motion before homing; without this case a queued home - // hit default -> EMC_TASK_EXEC::ERROR and was silently dropped - // (never reached motion). - return EMC_TASK_EXEC::WAITING_FOR_MOTION; + // Always display messages + case EMC_OPERATOR_ERROR_TYPE: + case EMC_OPERATOR_TEXT_TYPE: + case EMC_OPERATOR_DISPLAY_TYPE: + return emcTaskIssueCommand(cmd); default: - // unrecognized command - if (emc_debug & EMC_DEBUG_TASK_ISSUE) { - log_error("preconditions: unrecognized command {}:{}\n", - (int)cmd->_type, emc_symbol_lookup(cmd->_type)); - } - return EMC_TASK_EXEC::ERROR; - break; + if (planSpecial(cmd, s, retval)) { + break; + } + if (isImmediate(type, s)) { + retval = emcTaskIssueCommand(cmd); + if (s.autoReading) { + // no readahead this cycle + return retval; + } + break; + } + refuse(type, s); + retval = -1; + break; } - return EMC_TASK_EXEC::DONE; + if (s.autoReading) { + readahead_reading(); + } else if (s.autoWaiting) { + readahead_waiting(); + } else if (s.mdi) { + mdi_execute_hook(); + } + + return retval; } // puts command on interp list @@ -1742,14 +1101,13 @@ static int emcTaskIssueCommand(NMLmsg * cmd) // joint commands case EMC_JOINT_HOME_TYPE: - home_msg = reinterpret_cast(cmd); homingWaiting = false; // default; set true below only if we actually issue a home { - const int target_joint = home_msg->joint; + const int target_joint = reinterpret_cast(cmd)->joint; if (!issuingQueuedCommand) { // Immediate command (the GUI Home button, halui, linuxcncrsh): // pass it straight through, exactly as before this sequencing - // existed. Nothing calls emcTaskCheckPostconditions() for an + // existed. Nothing waits as commandWaits() says for an // immediate command, so a mode dip taken here would never be // undone. See issuingQueuedCommand. retval = emcJointHome(target_joint); @@ -1792,129 +1150,87 @@ static int emcTaskIssueCommand(NMLmsg * cmd) // only arrive as an immediate command (the GUI, halui, linuxcncrsh), // never from the interpreter, so there is no queued path whose // trajectory mode would need dipping and restoring. - unhome_msg = reinterpret_cast(cmd); - retval = emcJointUnhome(unhome_msg->joint); + retval = emcJointUnhome(reinterpret_cast(cmd)->joint); break; - case EMC_JOG_CONT_TYPE: - jog_cont_msg = reinterpret_cast(cmd); + case EMC_JOG_CONT_TYPE: { + auto jog_cont_msg = reinterpret_cast(cmd); retval = emcJogCont(jog_cont_msg->joint_or_axis, jog_cont_msg->vel, jog_cont_msg->jjogmode); break; + } - case EMC_JOG_STOP_TYPE: - jog_stop_msg = reinterpret_cast(cmd); + case EMC_JOG_STOP_TYPE: { + auto jog_stop_msg = reinterpret_cast(cmd); retval = emcJogStop(jog_stop_msg->joint_or_axis, jog_stop_msg->jjogmode); break; + } - case EMC_JOG_INCR_TYPE: - jog_incr_msg = reinterpret_cast(cmd); + case EMC_JOG_INCR_TYPE: { + auto jog_incr_msg = reinterpret_cast(cmd); retval = emcJogIncr(jog_incr_msg->joint_or_axis, jog_incr_msg->incr, jog_incr_msg->vel, jog_incr_msg->jjogmode); break; + } - case EMC_JOG_ABS_TYPE: - jog_abs_msg = reinterpret_cast(cmd); - retval = emcJogAbs(jog_abs_msg->joint_or_axis, - jog_abs_msg->pos, - jog_abs_msg->vel, - jog_abs_msg->jjogmode); - break; - - case EMC_JOINT_SET_BACKLASH_TYPE: - set_backlash_msg = reinterpret_cast(cmd); + case EMC_JOINT_SET_BACKLASH_TYPE: { + auto set_backlash_msg = reinterpret_cast(cmd); retval = emcJointSetBacklash(set_backlash_msg->joint, set_backlash_msg->backlash); break; + } - case EMC_JOINT_SET_HOMING_PARAMS_TYPE: - set_homing_params_msg = reinterpret_cast(cmd); - retval = emcJointSetHomingParams(set_homing_params_msg->joint, - set_homing_params_msg->home, - set_homing_params_msg->offset, - set_homing_params_msg->home_final_vel, - set_homing_params_msg->search_vel, - set_homing_params_msg->latch_vel, - set_homing_params_msg->search_dist, - set_homing_params_msg->latch_dist, - set_homing_params_msg->use_index, - set_homing_params_msg->encoder_does_not_reset, - set_homing_params_msg->ignore_limits, - set_homing_params_msg->is_shared, - set_homing_params_msg->home_sequence, - set_homing_params_msg->volatile_home, - set_homing_params_msg->locking_indexer, - set_homing_params_msg->absolute_encoder); - break; - - case EMC_JOINT_SET_FERROR_TYPE: - set_ferror_msg = reinterpret_cast(cmd); - retval = emcJointSetFerror(set_ferror_msg->joint, - set_ferror_msg->ferror); - break; - - case EMC_JOINT_SET_MIN_FERROR_TYPE: - set_min_ferror_msg = reinterpret_cast(cmd); - retval = emcJointSetMinFerror(set_min_ferror_msg->joint, - set_min_ferror_msg->ferror); - break; - - case EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE: - set_max_limit_msg = reinterpret_cast(cmd); + case EMC_JOINT_SET_MAX_POSITION_LIMIT_TYPE: { + auto set_max_limit_msg = reinterpret_cast(cmd); retval = emcJointSetMaxPositionLimit(set_max_limit_msg->joint, set_max_limit_msg->limit); break; + } - case EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE: - set_min_limit_msg = reinterpret_cast(cmd); + case EMC_JOINT_SET_MIN_POSITION_LIMIT_TYPE: { + auto set_min_limit_msg = reinterpret_cast(cmd); retval = emcJointSetMinPositionLimit(set_min_limit_msg->joint, set_min_limit_msg->limit); break; - - case EMC_JOINT_HALT_TYPE: - joint_halt_msg = reinterpret_cast(cmd); - retval = emcJointHalt(joint_halt_msg->joint); - break; + } case EMC_JOINT_OVERRIDE_LIMITS_TYPE: - joint_lim_msg = reinterpret_cast(cmd); - retval = emcJointOverrideLimits(joint_lim_msg->joint); + retval = emcJointOverrideLimits(reinterpret_cast(cmd)->joint); break; - case EMC_JOINT_LOAD_COMP_TYPE: - joint_load_comp_msg = reinterpret_cast(cmd); + case EMC_JOINT_LOAD_COMP_TYPE: { + auto joint_load_comp_msg = reinterpret_cast(cmd); retval = emcJointLoadComp(joint_load_comp_msg->joint, joint_load_comp_msg->file, joint_load_comp_msg->type); break; + } // traj commands case EMC_TRAJ_SET_SCALE_TYPE: - emcTrajSetScaleMsg = reinterpret_cast(cmd); - retval = emcTrajSetScale(emcTrajSetScaleMsg->scale); + retval = emcTrajSetScale(reinterpret_cast(cmd)->scale); break; case EMC_TRAJ_SET_RAPID_SCALE_TYPE: - emcTrajSetRapidScaleMsg = reinterpret_cast(cmd); - retval = emcTrajSetRapidScale(emcTrajSetRapidScaleMsg->scale); + retval = emcTrajSetRapidScale(reinterpret_cast(cmd)->scale); break; case EMC_TRAJ_SET_MAX_VELOCITY_TYPE: - emcTrajSetMaxVelocityMsg = reinterpret_cast(cmd); - retval = emcTrajSetMaxVelocity(emcTrajSetMaxVelocityMsg->velocity); + retval = emcTrajSetMaxVelocity(reinterpret_cast(cmd)->velocity); break; - case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: - emcTrajSetSpindleScaleMsg = reinterpret_cast(cmd); + case EMC_TRAJ_SET_SPINDLE_SCALE_TYPE: { + auto emcTrajSetSpindleScaleMsg = reinterpret_cast(cmd); retval = emcTrajSetSpindleScale(emcTrajSetSpindleScaleMsg->spindle, emcTrajSetSpindleScaleMsg->scale); break; + } case EMC_TRAJ_SET_FO_ENABLE_TYPE: retval = emcTrajSetFOEnable((reinterpret_cast(cmd))->mode); // feed override enable/disable @@ -1928,26 +1244,16 @@ static int emcTaskIssueCommand(NMLmsg * cmd) retval = emcTrajSetSOEnable((reinterpret_cast(cmd))->mode); //spindle speed override enable/disable break; - case EMC_TRAJ_SET_VELOCITY_TYPE: - emcTrajSetVelocityMsg = reinterpret_cast(cmd); - retval = emcTrajSetVelocity(emcTrajSetVelocityMsg->velocity, - emcTrajSetVelocityMsg->ini_maxvel); - break; - - case EMC_TRAJ_SET_ACCELERATION_TYPE: - emcTrajSetAccelerationMsg = reinterpret_cast(cmd); - retval = emcTrajSetAcceleration(emcTrajSetAccelerationMsg->acceleration); - break; - - case EMC_TRAJ_LINEAR_MOVE_TYPE: + case EMC_TRAJ_LINEAR_MOVE_TYPE: { emcTrajUpdateTag((reinterpret_cast(cmd))->tag); - emcTrajLinearMoveMsg = reinterpret_cast(cmd); + auto emcTrajLinearMoveMsg = reinterpret_cast(cmd); retval = emcTrajLinearMove(emcTrajLinearMoveMsg->end, emcTrajLinearMoveMsg->type, emcTrajLinearMoveMsg->vel, emcTrajLinearMoveMsg->ini_maxvel, emcTrajLinearMoveMsg->acc, emcTrajLinearMoveMsg->ini_maxjerk, emcTrajLinearMoveMsg->vlimit_scale, emcTrajLinearMoveMsg->indexer_jnum); break; + } case EMC_TRAJ_JOINT_MOVE_TYPE: { EMC_TRAJ_JOINT_MOVE *jm = reinterpret_cast(cmd); @@ -1956,9 +1262,9 @@ static int emcTaskIssueCommand(NMLmsg * cmd) break; } - case EMC_TRAJ_CIRCULAR_MOVE_TYPE: + case EMC_TRAJ_CIRCULAR_MOVE_TYPE: { emcTrajUpdateTag((reinterpret_cast(cmd))->tag); - emcTrajCircularMoveMsg = reinterpret_cast(cmd); + auto emcTrajCircularMoveMsg = reinterpret_cast(cmd); retval = emcTrajCircularMove(emcTrajCircularMoveMsg->end, emcTrajCircularMoveMsg->center, emcTrajCircularMoveMsg->normal, emcTrajCircularMoveMsg->turn, emcTrajCircularMoveMsg->type, @@ -1967,16 +1273,16 @@ static int emcTaskIssueCommand(NMLmsg * cmd) emcTrajCircularMoveMsg->acc, emcTrajCircularMoveMsg->ini_maxjerk, emcTrajCircularMoveMsg->vlimit_scale); break; + } case EMC_TRAJ_DELAY_TYPE: - emcTrajDelayMsg = reinterpret_cast(cmd); // set the timeout clock to expire at 'now' + delay time - taskExecDelayTimeout = etime() + emcTrajDelayMsg->delay; + taskExecDelayTimeout = etime() + reinterpret_cast(cmd)->delay; retval = 0; break; - case EMC_TRAJ_SET_TERM_COND_TYPE: - emcTrajSetTermCondMsg = reinterpret_cast(cmd); + case EMC_TRAJ_SET_TERM_COND_TYPE: { + auto emcTrajSetTermCondMsg = reinterpret_cast(cmd); retval = emcTrajSetTermCond(emcTrajSetTermCondMsg->cond, emcTrajSetTermCondMsg->tolerance); /* G64_R_PLANNER: a G64 R word piggybacks the planner request here so it * is applied in program order. Sentinels (<0) mean "leave unchanged". @@ -2000,11 +1306,13 @@ static int emcTaskIssueCommand(NMLmsg * cmd) if (retval == 0 && emcTrajSetTermCondMsg->scurve_peak_scale >= 0.0) emcTrajSetScurvePeakScale(emcTrajSetTermCondMsg->scurve_peak_scale); break; + } - case EMC_TRAJ_SET_SPINDLESYNC_TYPE: - emcTrajSetSpindlesyncMsg = reinterpret_cast(cmd); + case EMC_TRAJ_SET_SPINDLESYNC_TYPE: { + auto emcTrajSetSpindlesyncMsg = reinterpret_cast(cmd); retval = emcTrajSetSpindleSync(emcTrajSetSpindlesyncMsg->spindle, emcTrajSetSpindlesyncMsg->feed_per_revolution, emcTrajSetSpindlesyncMsg->velocity_mode, emcTrajSetSpindlesyncMsg->angular_offset_degrees); break; + } case EMC_TRAJ_SET_OFFSET_TYPE: { // update tool offset @@ -2056,8 +1364,8 @@ static int emcTaskIssueCommand(NMLmsg * cmd) (reinterpret_cast(cmd))->probe_type); break; - case EMC_AUX_INPUT_WAIT_TYPE: - emcAuxInputWaitMsg = reinterpret_cast(cmd); + case EMC_AUX_INPUT_WAIT_TYPE: { + auto emcAuxInputWaitMsg = reinterpret_cast(cmd); if (emcAuxInputWaitMsg->timeout == WAIT_MODE_IMMEDIATE) { //nothing to do, CANON will get the needed value when asked by the interp emcStatus->task.input_timeout = 0; // no timeout can occur emcAuxInputWaitIndex = -1; @@ -2070,10 +1378,10 @@ static int emcTaskIssueCommand(NMLmsg * cmd) taskExecDelayTimeout = etime() + emcAuxInputWaitMsg->timeout; } break; + } case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: - wait_spindle_orient_complete_msg = reinterpret_cast(cmd); - taskExecDelayTimeout = etime() + wait_spindle_orient_complete_msg->timeout; + taskExecDelayTimeout = etime() + reinterpret_cast(cmd)->timeout; break; case EMC_TRAJ_RIGID_TAP_TYPE: @@ -2125,52 +1433,51 @@ static int emcTaskIssueCommand(NMLmsg * cmd) // IO commands - case EMC_SPINDLE_SPEED_TYPE: - spindle_speed_msg = reinterpret_cast(cmd); + case EMC_SPINDLE_SPEED_TYPE: { + auto spindle_speed_msg = reinterpret_cast(cmd); retval = emcSpindleSpeed(spindle_speed_msg->spindle, spindle_speed_msg->speed, spindle_speed_msg->factor, spindle_speed_msg->xoffset); break; + } - case EMC_SPINDLE_ORIENT_TYPE: - spindle_orient_msg = reinterpret_cast(cmd); + case EMC_SPINDLE_ORIENT_TYPE: { + auto spindle_orient_msg = reinterpret_cast(cmd); retval = emcSpindleOrient(spindle_orient_msg->spindle, spindle_orient_msg->orientation, spindle_orient_msg->mode); break; + } - case EMC_SPINDLE_ON_TYPE: - spindle_on_msg = reinterpret_cast(cmd); + case EMC_SPINDLE_ON_TYPE: { + auto spindle_on_msg = reinterpret_cast(cmd); retval = emcSpindleOn(spindle_on_msg->spindle, spindle_on_msg->speed, spindle_on_msg->factor, spindle_on_msg->xoffset, spindle_on_msg->wait_for_spindle_at_speed); break; + } - case EMC_SPINDLE_OFF_TYPE: - spindle_off_msg = reinterpret_cast(cmd); + case EMC_SPINDLE_OFF_TYPE: { + auto spindle_off_msg = reinterpret_cast(cmd); retval = emcSpindleOff(spindle_off_msg->spindle, spindle_off_msg->wait_for_spindle_at_speed); break; + } case EMC_SPINDLE_BRAKE_RELEASE_TYPE: - spindle_brake_release_msg = reinterpret_cast(cmd); - retval = emcSpindleBrakeRelease(spindle_brake_release_msg->spindle); + retval = emcSpindleBrakeRelease(reinterpret_cast(cmd)->spindle); break; case EMC_SPINDLE_INCREASE_TYPE: - spindle_increase_msg = reinterpret_cast(cmd); - retval = emcSpindleIncrease(spindle_increase_msg->spindle); + retval = emcSpindleIncrease(reinterpret_cast(cmd)->spindle); break; case EMC_SPINDLE_DECREASE_TYPE: - spindle_decrease_msg = reinterpret_cast(cmd); - retval = emcSpindleDecrease(spindle_decrease_msg->spindle); + retval = emcSpindleDecrease(reinterpret_cast(cmd)->spindle); break; case EMC_SPINDLE_CONSTANT_TYPE: - spindle_constant_msg = reinterpret_cast(cmd); - retval = emcSpindleConstant(spindle_constant_msg->spindle); + retval = emcSpindleConstant(reinterpret_cast(cmd)->spindle); break; case EMC_SPINDLE_BRAKE_ENGAGE_TYPE: - spindle_brake_engage_msg = reinterpret_cast(cmd); - retval = emcSpindleBrakeEngage(spindle_brake_engage_msg->spindle); + retval = emcSpindleBrakeEngage(reinterpret_cast(cmd)->spindle); break; case EMC_COOLANT_MIST_ON_TYPE: @@ -2190,8 +1497,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd) break; case EMC_TOOL_PREPARE_TYPE: - tool_prepare_msg = reinterpret_cast(cmd); - retval = emcToolPrepare(tool_prepare_msg->tool); + retval = emcToolPrepare(reinterpret_cast(cmd)->tool); break; case EMC_TOOL_LOAD_TYPE: @@ -2199,12 +1505,11 @@ static int emcTaskIssueCommand(NMLmsg * cmd) break; case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: - load_tool_table_msg = reinterpret_cast(cmd); - retval = emcToolLoadToolTable(load_tool_table_msg->file); + retval = emcToolLoadToolTable(reinterpret_cast(cmd)->file); break; - case EMC_TOOL_SET_OFFSET_TYPE: - emc_tool_set_offset_msg = reinterpret_cast(cmd); + case EMC_TOOL_SET_OFFSET_TYPE: { + auto emc_tool_set_offset_msg = reinterpret_cast(cmd); retval = emcToolSetOffset(emc_tool_set_offset_msg->toolno, emc_tool_set_offset_msg->offset, emc_tool_set_offset_msg->diameter, @@ -2212,10 +1517,10 @@ static int emcTaskIssueCommand(NMLmsg * cmd) emc_tool_set_offset_msg->backangle, emc_tool_set_offset_msg->orientation); break; + } case EMC_TOOL_SET_NUMBER_TYPE: - emc_tool_set_number_msg = reinterpret_cast(cmd); - retval = emcToolSetNumber(emc_tool_set_number_msg->tool); + retval = emcToolSetNumber(reinterpret_cast(cmd)->tool); break; // task commands @@ -2237,8 +1542,8 @@ static int emcTaskIssueCommand(NMLmsg * cmd) // mode and state commands - case EMC_TASK_SET_MODE_TYPE: - mode_msg = reinterpret_cast(cmd); + case EMC_TASK_SET_MODE_TYPE: { + auto mode_msg = reinterpret_cast(cmd); if (emcStatus->task.mode == EMC_TASK_MODE::AUTO && emcStatus->task.interpState != EMC_TASK_INTERP::IDLE && mode_msg->mode != EMC_TASK_MODE::AUTO) { @@ -2284,10 +1589,10 @@ static int emcTaskIssueCommand(NMLmsg * cmd) retval = emcTaskSetMode(mode_msg->mode); } break; + } case EMC_TASK_SET_STATE_TYPE: - state_msg = reinterpret_cast(cmd); - retval = emcTaskSetState(state_msg->state); + retval = emcTaskSetState(reinterpret_cast(cmd)->state); break; // interpreter commands @@ -2305,8 +1610,8 @@ static int emcTaskIssueCommand(NMLmsg * cmd) unlink(remote_tmpfilename); break; - case EMC_TASK_PLAN_OPEN_TYPE: - open_msg = reinterpret_cast(cmd); + case EMC_TASK_PLAN_OPEN_TYPE: { + auto open_msg = reinterpret_cast(cmd); /* receive file in chunks from remote process via open_msg->remote_buffer */ if(open_msg->remote_filesize > 0) { @@ -2367,12 +1672,13 @@ static int emcTaskIssueCommand(NMLmsg * cmd) retval = 0; } break; + } - case EMC_TASK_PLAN_EXECUTE_TYPE: + case EMC_TASK_PLAN_EXECUTE_TYPE: { emcStatus->motion.traj.single_stepping = 0; stepping = 0; steppingWait = 0; - execute_msg = reinterpret_cast(cmd); + auto execute_msg = reinterpret_cast(cmd); if (!all_homed() && !no_force_homing) { //!no_force_homing = force homing before MDI emcOperatorError(_("Can't issue MDI command when not homed")); retval = -1; @@ -2459,6 +1765,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd) } } break; + } case EMC_TASK_PLAN_RUN_TYPE: if (!all_homed() && !no_force_homing) { //!no_force_homing = force homing before Auto @@ -2472,8 +1779,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd) if (!taskplanopen && emcStatus->task.file[0] != 0) { emcTaskPlanOpen(emcStatus->task.file); } - run_msg = reinterpret_cast(cmd); - programStartLine = run_msg->line; + programStartLine = reinterpret_cast(cmd)->line; emcStatus->task.interpState = EMC_TASK_INTERP::READING; emcStatus->task.task_paused = 0; retval = 0; @@ -2540,20 +1846,17 @@ static int emcTaskIssueCommand(NMLmsg * cmd) break; case EMC_TASK_PLAN_SET_OPTIONAL_STOP_TYPE: - os_msg = reinterpret_cast(cmd); - emcTaskPlanSetOptionalStop(os_msg->state); + emcTaskPlanSetOptionalStop(reinterpret_cast(cmd)->state); retval = 0; break; case EMC_TASK_PLAN_SET_BLOCK_DELETE_TYPE: - bd_msg = reinterpret_cast(cmd); - emcTaskPlanSetBlockDelete(bd_msg->state); + emcTaskPlanSetBlockDelete(reinterpret_cast(cmd)->state); retval = 0; break; case EMC_TRAJ_SELECT_KINS_TYPE: - kSwitch_msg = static_cast(cmd); - retval = emcSelectKinsType(kSwitch_msg->switchkins_type); + retval = emcSelectKinsType(reinterpret_cast(cmd)->switchkins_type); break; default: @@ -2579,135 +1882,117 @@ static int emcTaskIssueCommand(NMLmsg * cmd) return retval; } -/* - emcTaskCheckPostconditions() is called for commands on the interp_list. - Immediate commands, i.e., commands sent from calls to emcTaskIssueCommand() - in emcTaskPlan() directly, are not handled here. - - The return value is a state for emcTaskExecute() to wait on, e.g., - EMC_TASK_EXEC::WAITING_FOR_MOTION, after the command has finished and - before any other commands can be sent out. - */ -static EMC_TASK_EXEC emcTaskCheckPostconditions(NMLmsg * cmd) +// What a command from interp_list waits for before it is issued, and what +// task waits for after it, before the next command goes out. Commands that +// emcTaskPlan() issues directly do not come through here. +struct Waits { + EMC_TASK_EXEC before; + EMC_TASK_EXEC after; +}; + +static Waits commandWaits(NMLmsg *cmd) { - if (NULL == cmd) { - return EMC_TASK_EXEC::DONE; - } + const EMC_TASK_EXEC DONE = EMC_TASK_EXEC::DONE; + const EMC_TASK_EXEC MOTION = EMC_TASK_EXEC::WAITING_FOR_MOTION; + const EMC_TASK_EXEC IO = EMC_TASK_EXEC::WAITING_FOR_IO; + const EMC_TASK_EXEC ALL = EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO; switch (cmd->_type) { + // these go out when everything before them is done; nothing blends + // into a probe or a rigid tap case EMC_OPERATOR_ERROR_TYPE: case EMC_OPERATOR_TEXT_TYPE: case EMC_OPERATOR_DISPLAY_TYPE: - return EMC_TASK_EXEC::DONE; - break; - - case EMC_SYSTEM_CMD_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_SYSTEM_CMD; - break; - - case EMC_TRAJ_JOINT_MOVE_TYPE: - case EMC_TRAJ_LINEAR_MOVE_TYPE: - case EMC_TRAJ_CIRCULAR_MOVE_TYPE: - case EMC_TRAJ_SET_VELOCITY_TYPE: - case EMC_TRAJ_SET_ACCELERATION_TYPE: - case EMC_TRAJ_SET_TERM_COND_TYPE: - case EMC_TRAJ_SET_SPINDLESYNC_TYPE: - case EMC_TRAJ_SET_OFFSET_TYPE: - case EMC_TRAJ_SET_G5X_TYPE: - case EMC_TRAJ_SET_G92_TYPE: - case EMC_TRAJ_SET_ROTATION_TYPE: - case EMC_TRAJ_SET_G68_TYPE: case EMC_TRAJ_PROBE_TYPE: case EMC_TRAJ_RIGID_TAP_TYPE: case EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG_TYPE: - case EMC_TRAJ_SET_TELEOP_ENABLE_TYPE: - case EMC_TRAJ_SET_FO_ENABLE_TYPE: - case EMC_TRAJ_SET_FH_ENABLE_TYPE: - case EMC_TRAJ_SET_SO_ENABLE_TYPE: - return EMC_TASK_EXEC::DONE; - break; - - case EMC_TOOL_PREPARE_TYPE: case EMC_TOOL_LOAD_TYPE: case EMC_TOOL_LOAD_TOOL_TABLE_TYPE: case EMC_TOOL_SET_OFFSET_TYPE: - case EMC_TOOL_SET_NUMBER_TYPE: + case EMC_COOLANT_MIST_ON_TYPE: + case EMC_COOLANT_MIST_OFF_TYPE: + case EMC_COOLANT_FLOOD_ON_TYPE: + case EMC_COOLANT_FLOOD_OFF_TYPE: case EMC_SPINDLE_SPEED_TYPE: case EMC_SPINDLE_ON_TYPE: case EMC_SPINDLE_OFF_TYPE: case EMC_SPINDLE_ORIENT_TYPE: - case EMC_COOLANT_MIST_ON_TYPE: - case EMC_COOLANT_MIST_OFF_TYPE: - case EMC_COOLANT_FLOOD_ON_TYPE: - case EMC_COOLANT_FLOOD_OFF_TYPE: - return EMC_TASK_EXEC::DONE; - break; - - case EMC_TASK_PLAN_RUN_TYPE: case EMC_TASK_PLAN_PAUSE_TYPE: + case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: case EMC_TASK_PLAN_END_TYPE: case EMC_TASK_PLAN_INIT_TYPE: + case EMC_TASK_PLAN_RUN_TYPE: case EMC_TASK_PLAN_SYNCH_TYPE: case EMC_TASK_PLAN_EXECUTE_TYPE: - case EMC_TASK_PLAN_OPTIONAL_STOP_TYPE: - return EMC_TASK_EXEC::DONE; - break; - - case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_SPINDLE_ORIENTED; - break; + return {ALL, DONE}; - case EMC_JOINT_HOME_TYPE: - // homingWaiting is false when the command was passed straight through - // as an immediate command (see issuingQueuedCommand) -- the sequencing - // did not run, so there is nothing to wait for. - return homingWaiting ? EMC_TASK_EXEC::WAITING_FOR_HOMING : EMC_TASK_EXEC::DONE; - break; + case EMC_SYSTEM_CMD_TYPE: + return {ALL, EMC_TASK_EXEC::WAITING_FOR_SYSTEM_CMD}; case EMC_TRAJ_DELAY_TYPE: case EMC_AUX_INPUT_WAIT_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_DELAY; - break; + return {ALL, EMC_TASK_EXEC::WAITING_FOR_DELAY}; + + case EMC_SPINDLE_WAIT_ORIENT_COMPLETE_TYPE: + return {ALL, EMC_TASK_EXEC::WAITING_FOR_SPINDLE_ORIENTED}; + + case EMC_TRAJ_SELECT_KINS_TYPE: + return {ALL, EMC_TASK_EXEC::WAITING_FOR_KINS_SWITCH}; + + // moves, and what travels with them, queue up in motion + case EMC_TRAJ_LINEAR_MOVE_TYPE: + case EMC_TRAJ_JOINT_MOVE_TYPE: + case EMC_TRAJ_CIRCULAR_MOVE_TYPE: + case EMC_TRAJ_SET_TERM_COND_TYPE: + case EMC_TRAJ_SET_SPINDLESYNC_TYPE: + case EMC_TRAJ_SET_FO_ENABLE_TYPE: + case EMC_TRAJ_SET_FH_ENABLE_TYPE: + case EMC_TRAJ_SET_SO_ENABLE_TYPE: + case EMC_TOOL_PREPARE_TYPE: + case EMC_TOOL_SET_NUMBER_TYPE: + return {IO, DONE}; + + // offsets apply after the motions before them + case EMC_TRAJ_SET_OFFSET_TYPE: + case EMC_TRAJ_SET_G5X_TYPE: + case EMC_TRAJ_SET_G92_TYPE: + case EMC_TRAJ_SET_ROTATION_TYPE: + case EMC_TRAJ_SET_G68_TYPE: + case EMC_MOTION_ADAPTIVE_TYPE: + return {MOTION, DONE}; + // an output that is not set "now" is queued in motion with the moves case EMC_MOTION_SET_AOUT_TYPE: + return {static_cast(cmd)->now ? MOTION : DONE, DONE}; case EMC_MOTION_SET_DOUT_TYPE: - case EMC_MOTION_ADAPTIVE_TYPE: - return EMC_TASK_EXEC::DONE; - break; + return {static_cast(cmd)->now ? MOTION : DONE, DONE}; - case EMC_TRAJ_SELECT_KINS_TYPE: - return EMC_TASK_EXEC::WAITING_FOR_KINS_SWITCH; - break; + // G28.2: drain the motion before it, then wait for the homing. + // homingWaiting is set when it is issued, see issuingQueuedCommand. + case EMC_JOINT_HOME_TYPE: + return {MOTION, homingWaiting ? EMC_TASK_EXEC::WAITING_FOR_HOMING : DONE}; + } - default: - // unrecognized command - if (emc_debug & EMC_DEBUG_TASK_ISSUE) { - log_error("postconditions: unrecognized command {}:{}\n", - (int)cmd->_type, emc_symbol_lookup(cmd->_type)); - } - return EMC_TASK_EXEC::DONE; - break; + if (emc_debug & EMC_DEBUG_TASK_ISSUE) { + log_error("execute: unrecognized command {}:{}\n", + (int)cmd->_type, emc_symbol_lookup(cmd->_type)); } - return EMC_TASK_EXEC::DONE; // unreached + return {EMC_TASK_EXEC::ERROR, DONE}; } -/* - STEPPING_CHECK() is a macro that prefaces a switch-case with a check - for stepping. If stepping is active, it waits until the step has been - given, then falls through to the rest of the case statement. -*/ - -#define STEPPING_CHECK() \ -if (stepping) { \ - if (! steppingWait) { \ - steppingWait = 1; \ - steppedLine = emcStatus->task.currentLine; \ - } \ - else { \ - if (emcStatus->task.currentLine != steppedLine) { \ - break; \ - } \ - } \ +// While stepping, everything holds once the step has moved on to another +// line, until the next step is given. +static bool steppingHolds() +{ + if (!stepping) { + return false; + } + if (!steppingWait) { + steppingWait = 1; + steppedLine = emcStatus->task.currentLine; + return false; + } + return emcStatus->task.currentLine != steppedLine; } // executor function @@ -2772,140 +2057,152 @@ static int emcTaskExecute(void) break; case EMC_TASK_EXEC::DONE: - STEPPING_CHECK(); - if (!emcStatus->motion.traj.queueFull && - emcStatus->task.interpState != EMC_TASK_INTERP::PAUSED) { - if (NULL == emcTaskCommand) { - // need a new command - emcTaskCommand = interp_list.get(); - // interp_list now has line number associated with this-- get - // it - if (NULL != emcTaskCommand) { - emcTaskEager = 1; - emcStatus->task.currentLine = interp_list.get_line_number(); - // callLevel is set by emcTaskUpdate() from the executing - // move's StateTag; the interpreter's live level at dequeue - // time leads motion by the whole read-ahead queue. - // and set it for all subsystems which use queued ids - emcTrajSetMotionId(emcStatus->task.currentLine); - if (emcStatus->motion.traj.queueFull) { - emcStatus->task.execState = - EMC_TASK_EXEC::WAITING_FOR_MOTION_QUEUE; - } else { - emcStatus->task.execState = emcTaskCheckPreconditions(emcTaskCommand.get()); - } - } - } else { - // have an outstanding command - // This is the one emcTaskIssueCommand() call site followed by - // emcTaskCheckPostconditions(), i.e. the only one whose commands - // can reach a WAITING_FOR_* state. See issuingQueuedCommand. - issuingQueuedCommand = true; - queuedMdiAborted = false; - const int issue_retval = emcTaskIssueCommand(emcTaskCommand.get()); - issuingQueuedCommand = false; - if (0 != issue_retval) { - emcStatus->task.execState = queuedMdiAborted ? - EMC_TASK_EXEC::DONE : EMC_TASK_EXEC::ERROR; - retval = -1; - } else { - emcStatus->task.execState = emcTaskCheckPostconditions(emcTaskCommand.get()); - emcTaskEager = 1; - } - emcTaskCommand = NULL; // reset it - } - } - break; + if (steppingHolds()) { + break; + } + if (!emcStatus->motion.traj.queueFull && + emcStatus->task.interpState != EMC_TASK_INTERP::PAUSED) { + if (NULL == emcTaskCommand) { + // need a new command + emcTaskCommand = interp_list.get(); + // interp_list now has line number associated with this-- get + // it + if (NULL != emcTaskCommand) { + emcTaskEager = 1; + emcStatus->task.currentLine = interp_list.get_line_number(); + // callLevel is set by emcTaskUpdate() from the executing + // move's StateTag; the interpreter's live level at dequeue + // time leads motion by the whole read-ahead queue. + // and set it for all subsystems which use queued ids + emcTrajSetMotionId(emcStatus->task.currentLine); + if (emcStatus->motion.traj.queueFull) { + emcStatus->task.execState = + EMC_TASK_EXEC::WAITING_FOR_MOTION_QUEUE; + } else { + emcStatus->task.execState = commandWaits(emcTaskCommand.get()).before; + } + } + } else { + // have an outstanding command + // This is the one emcTaskIssueCommand() call site followed by + // the wait commandWaits() names, i.e. the only one whose commands + // can reach a WAITING_FOR_* state. See issuingQueuedCommand. + issuingQueuedCommand = true; + queuedMdiAborted = false; + const int issue_retval = emcTaskIssueCommand(emcTaskCommand.get()); + issuingQueuedCommand = false; + if (0 != issue_retval) { + emcStatus->task.execState = queuedMdiAborted ? + EMC_TASK_EXEC::DONE : EMC_TASK_EXEC::ERROR; + retval = -1; + } else { + emcStatus->task.execState = commandWaits(emcTaskCommand.get()).after; + emcTaskEager = 1; + } + emcTaskCommand = NULL; // reset it + } + } + break; case EMC_TASK_EXEC::WAITING_FOR_MOTION_QUEUE: - STEPPING_CHECK(); - if (!emcStatus->motion.traj.queueFull) { - if (NULL != emcTaskCommand) { - emcStatus->task.execState = emcTaskCheckPreconditions(emcTaskCommand.get()); - emcTaskEager = 1; - } else { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcTaskEager = 1; - } - } - break; + if (steppingHolds()) { + break; + } + if (!emcStatus->motion.traj.queueFull) { + if (NULL != emcTaskCommand) { + emcStatus->task.execState = commandWaits(emcTaskCommand.get()).before; + emcTaskEager = 1; + } else { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcTaskEager = 1; + } + } + break; case EMC_TASK_EXEC::WAITING_FOR_MOTION: - STEPPING_CHECK(); - if (emcStatus->motion.status == RCS_STATUS::ERROR) { - // emcOperatorError(0, "error in motion controller"); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } else if (emcStatus->motion.status == RCS_STATUS::DONE) { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcTaskEager = 1; - } - break; + if (steppingHolds()) { + break; + } + if (emcStatus->motion.status == RCS_STATUS::ERROR) { + // emcOperatorError(0, "error in motion controller"); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } else if (emcStatus->motion.status == RCS_STATUS::DONE) { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcTaskEager = 1; + } + break; case EMC_TASK_EXEC::WAITING_FOR_IO: - STEPPING_CHECK(); - if (emcStatus->io.status == RCS_STATUS::ERROR) { - // emcOperatorError(0, "error in IO controller"); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } else if (emcStatus->io.status == RCS_STATUS::DONE) { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcTaskEager = 1; - } - break; + if (steppingHolds()) { + break; + } + if (emcStatus->io.status == RCS_STATUS::ERROR) { + // emcOperatorError(0, "error in IO controller"); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } else if (emcStatus->io.status == RCS_STATUS::DONE) { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcTaskEager = 1; + } + break; case EMC_TASK_EXEC::WAITING_FOR_MOTION_AND_IO: - STEPPING_CHECK(); - if (emcStatus->motion.status == RCS_STATUS::ERROR) { - // emcOperatorError(0, "error in motion controller"); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } else if (emcStatus->io.status == RCS_STATUS::ERROR) { - // emcOperatorError(0, "error in IO controller"); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } else if (emcStatus->motion.status == RCS_STATUS::DONE && - emcStatus->io.status == RCS_STATUS::DONE) { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcTaskEager = 1; - } - break; + if (steppingHolds()) { + break; + } + if (emcStatus->motion.status == RCS_STATUS::ERROR) { + // emcOperatorError(0, "error in motion controller"); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } else if (emcStatus->io.status == RCS_STATUS::ERROR) { + // emcOperatorError(0, "error in IO controller"); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } else if (emcStatus->motion.status == RCS_STATUS::DONE && + emcStatus->io.status == RCS_STATUS::DONE) { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcTaskEager = 1; + } + break; case EMC_TASK_EXEC::WAITING_FOR_SPINDLE_ORIENTED: - STEPPING_CHECK(); // not sure - {int state = 0; - for (int n = 0; n < emcStatus->motion.traj.spindles; n++){ - if (emcStatus->motion.spindle[n].orient_state > state) - state = emcStatus->motion.spindle[n].orient_state; - } - switch (state) { - case EMCMOT_ORIENT_NONE: - case EMCMOT_ORIENT_COMPLETE: - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcStatus->task.delayLeft = 0; - emcTaskEager = 1; - log_info("wait for orient complete: nothing to do\n"); - break; - - case EMCMOT_ORIENT_IN_PROGRESS: - emcStatus->task.delayLeft = taskExecDelayTimeout - etime(); - if (etime() >= taskExecDelayTimeout) { - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - emcStatus->task.delayLeft = 0; - emcTaskEager = 1; - emcOperatorError("wait for orient complete: TIMED OUT"); - } - break; - - case EMCMOT_ORIENT_FAULTED: - // actually the code in main() should trap this before we get here - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - emcStatus->task.delayLeft = 0; - emcTaskEager = 1; - for (int n = 0; n < emcStatus->motion.traj.spindles; n++){ - if (emcStatus->motion.spindle[n].orient_fault) - emcOperatorError("wait for orient complete: FAULTED code=%d", - emcStatus->motion.spindle[n].orient_fault); - } - } - } - break; + if (steppingHolds()) { // not sure + break; + } + {int state = 0; + for (int n = 0; n < emcStatus->motion.traj.spindles; n++){ + if (emcStatus->motion.spindle[n].orient_state > state) + state = emcStatus->motion.spindle[n].orient_state; + } + switch (state) { + case EMCMOT_ORIENT_NONE: + case EMCMOT_ORIENT_COMPLETE: + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcStatus->task.delayLeft = 0; + emcTaskEager = 1; + log_info("wait for orient complete: nothing to do\n"); + break; + + case EMCMOT_ORIENT_IN_PROGRESS: + emcStatus->task.delayLeft = taskExecDelayTimeout - etime(); + if (etime() >= taskExecDelayTimeout) { + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + emcStatus->task.delayLeft = 0; + emcTaskEager = 1; + emcOperatorError("wait for orient complete: TIMED OUT"); + } + break; + + case EMCMOT_ORIENT_FAULTED: + // actually the code in main() should trap this before we get here + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + emcStatus->task.delayLeft = 0; + emcTaskEager = 1; + for (int n = 0; n < emcStatus->motion.traj.spindles; n++){ + if (emcStatus->motion.spindle[n].orient_fault) + emcOperatorError("wait for orient complete: FAULTED code=%d", + emcStatus->motion.spindle[n].orient_fault); + } + } + } + break; case EMC_TASK_EXEC::WAITING_FOR_KINS_SWITCH: { @@ -2920,280 +2217,286 @@ static int emcTaskExecute(void) } case EMC_TASK_EXEC::WAITING_FOR_HOMING: - // G28.2 sequencing: wait for the joint home issued in - // emcTaskIssueCommand to actually run to completion (do_homing() only - // advances while motion is in FREE, which is why we dipped into it - // there), then restore the prior trajectory mode. See the - // homingWaiting block of static state near the top of this file. - STEPPING_CHECK(); - { - bool any_homing = false; - bool all_target_homed = true; // success criterion - int lo = (homingWaitJoint < 0) ? 0 : homingWaitJoint; - int hi = (homingWaitJoint < 0) ? (emcStatus->motion.traj.joints - 1) : homingWaitJoint; - for (int j = lo; j <= hi; j++) { - if (emcStatus->motion.joint[j].homing) { - any_homing = true; - } - if (!emcStatus->motion.joint[j].homed) { - all_target_homed = false; - } - } + // G28.2 sequencing: wait for the joint home issued in + // emcTaskIssueCommand to actually run to completion (do_homing() only + // advances while motion is in FREE, which is why we dipped into it + // there), then restore the prior trajectory mode. See the + // homingWaiting block of static state near the top of this file. + if (steppingHolds()) { + break; + } + { + bool any_homing = false; + bool all_target_homed = true; // success criterion + int lo = (homingWaitJoint < 0) ? 0 : homingWaitJoint; + int hi = (homingWaitJoint < 0) ? (emcStatus->motion.traj.joints - 1) : homingWaitJoint; + for (int j = lo; j <= hi; j++) { + if (emcStatus->motion.joint[j].homing) { + any_homing = true; + } + if (!emcStatus->motion.joint[j].homed) { + all_target_homed = false; + } + } - bool success; - // "Is homing still running?" must come from motion's aggregate - // homing_active, not from OR-ing the per-joint .homing flags. On a - // machine that homes in several HOME_SEQUENCE groups the sequence - // machine finishes one group and can spend a cycle or more before - // the next group raises .homing, so there is a window in which - // every joint reads .homing == false while the machine is still - // homing. Task samples far coarser than the servo cycle, so it can - // land in that window, conclude homing stopped, and score a - // perfectly good home-all as "did not complete". motion/homing.c - // documents the same deassertion lag in its own words ("The homing - // status variable turns false before homing_active state turns - // false") and guards against it internally for the same reason. - // - // Single-joint Pn and single-sequence machines never hit the gap, - // which is why this only shows up on a multi-sequence home-all. - // The per-joint OR is kept as a belt-and-braces term: it can only - // extend the "still running" window, never shorten it. - const bool homing_running = emcStatus->motion.homing_active || any_homing; - if (homing_running) { - homingStarted = true; - break; // still running; no timeout once started (see HOMING_START_TIMEOUT comment) - } - // A short run (homing in place takes a few servo cycles) can start - // and end between two of task's status reads. On a re-home the - // joints read homed before and after it, so only motion's run - // counter shows that it happened. - if (emcStatus->motion.homing_runs != homingRunsAtIssue) { - homingStarted = true; - } - if (!homingStarted) { - // Never observed homing go active: motion silently rejected - // it (a guard like "must be in joint mode", or - // motion.homing-inhibit, reports an operator error but does - // not fail the NML command -- see emcJointHome's caller), - // or this is the same task cycle it was issued in. Give it - // HOMING_START_TIMEOUT before concluding it was rejected. - if (etime() - homingIssueTime < HOMING_START_TIMEOUT) { - break; - } - emcOperatorError("G28.2 home did not start -- check machine mode, " - "motion.homing-inhibit, and whether a homing " - "cycle is already in progress"); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - emcTaskEager = 1; - homingWaiting = false; - // Nothing physically moved, so it's safe to restore the - // mode immediately instead of leaving the machine parked - // in FREE. - if (homingPriorMode != EMC_TRAJ_MODE::FREE) { - emcTrajSetMode(homingPriorMode); - } - break; - } - // It ran and has now stopped; did it reach the expected end state? - success = all_target_homed; - - homingWaiting = false; - emcTaskEager = 1; - - // Is it legal to hand the machine back to the coordinated mode it - // was in before the FREE dip? Motion refuses to (re-)enter TELEOP - // or COORD on non-identity kinematics unless *every* joint is - // homed -- switch_to_teleop_mode() (motion.c) and the EMCMOT_COORD - // case (command.c) both gate on - // "kinType != KINEMATICS_IDENTITY && !get_allhomed()". - // - // Restoring unconditionally means motion rejects the request, task - // still reports DONE, and the machine is stranded in FREE with the - // GUI's mode controls greyed out -- recoverable only by cycling the - // controller (PR #4172: Sigma1912's "g28.3 p0" on a gantry gave - // "all joints must be homed before going into coordinated mode", - // then needed F2). Mirror motion's own condition here and abort - // cleanly instead of wedging. - // - // With G28.3 gone from this PR the only command that reaches here - // is a home, which ends with its joints referenced, so on - // non-identity kinematics -- where a coordinated prior mode already - // implies the machine was fully homed -- this gate now guards a - // state no G-code can produce. It is kept because the alternative - // failure is silent: motion defers the COORD/TELEOP transition to - // its controller cycle, so a refused restore leaves no trace task - // could notice, and the operator gets a dead UI with no message. - // - // Mirroring the condition rather than issuing the restore and - // checking whether it took is deliberate: the COORD/TELEOP - // transition is deferred to the controller cycle (see - // "defer transition to controller cycle" in command.c), so an - // immediate read-back would race exactly the way the old - // .homing-based completion test did. - // - // Read the kinematics type from status, not from this file's - // static emcmotConfig: that copy is filled in once just before - // the main loop and never refreshed, while taskintf.cc re-reads - // the motion config whenever config_num changes and republishes - // it as traj.kinematics_type. The two agree today -- kinType is - // written exactly once, in init_comm_buffers() (motion.c), and a - // runtime switchkins change does not alter it (switchkins answers - // KINEMATICS_BOTH for every selectable type) -- so this is a - // matter of reading the copy that is maintained, not of avoiding - // a divergence that exists now. - const bool restore_ok = (homingPriorMode == EMC_TRAJ_MODE::FREE) - || (emcStatus->motion.traj.kinematics_type - == KINEMATICS_IDENTITY) - || all_homed(); - - if (success && !restore_ok) { - // The command itself did what was asked, but it left the - // machine partially referenced and motion will not take - // TELEOP/COORD back in that state. Stay in FREE and fail the - // program rather than report DONE and strand the operator. - emcOperatorError(_("G28.2 home succeeded but left the machine not " - "fully homed -- staying in joint mode, as " - "non-identity kinematics cannot re-enter " - "coordinated motion until every joint is homed")); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } else if (success) { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - if (homingPriorMode != EMC_TRAJ_MODE::FREE) { - emcTrajSetMode(homingPriorMode); - } - } else { - // Homing stopped without reaching the target state (aborted, - // faulted, ESTOP mid-cycle, ...) -- abort the program rather - // than let it continue unreferenced. Deliberately NOT restored to - // homingPriorMode here: an unhomed/partially-homed machine may - // not legally re-enter TELEOP/COORD, and FREE is the safe - // state to leave it in for an operator to intervene from. - emcOperatorError("G28.2 home did not complete for joint %s", - homingWaitJoint < 0 ? "ALL" : "requested"); - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } - } - break; + bool success; + // "Is homing still running?" must come from motion's aggregate + // homing_active, not from OR-ing the per-joint .homing flags. On a + // machine that homes in several HOME_SEQUENCE groups the sequence + // machine finishes one group and can spend a cycle or more before + // the next group raises .homing, so there is a window in which + // every joint reads .homing == false while the machine is still + // homing. Task samples far coarser than the servo cycle, so it can + // land in that window, conclude homing stopped, and score a + // perfectly good home-all as "did not complete". motion/homing.c + // documents the same deassertion lag in its own words ("The homing + // status variable turns false before homing_active state turns + // false") and guards against it internally for the same reason. + // + // Single-joint Pn and single-sequence machines never hit the gap, + // which is why this only shows up on a multi-sequence home-all. + // The per-joint OR is kept as a belt-and-braces term: it can only + // extend the "still running" window, never shorten it. + const bool homing_running = emcStatus->motion.homing_active || any_homing; + if (homing_running) { + homingStarted = true; + break; // still running; no timeout once started (see HOMING_START_TIMEOUT comment) + } + // A short run (homing in place takes a few servo cycles) can start + // and end between two of task's status reads. On a re-home the + // joints read homed before and after it, so only motion's run + // counter shows that it happened. + if (emcStatus->motion.homing_runs != homingRunsAtIssue) { + homingStarted = true; + } + if (!homingStarted) { + // Never observed homing go active: motion silently rejected + // it (a guard like "must be in joint mode", or + // motion.homing-inhibit, reports an operator error but does + // not fail the NML command -- see emcJointHome's caller), + // or this is the same task cycle it was issued in. Give it + // HOMING_START_TIMEOUT before concluding it was rejected. + if (etime() - homingIssueTime < HOMING_START_TIMEOUT) { + break; + } + emcOperatorError("G28.2 home did not start -- check machine mode, " + "motion.homing-inhibit, and whether a homing " + "cycle is already in progress"); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + emcTaskEager = 1; + homingWaiting = false; + // Nothing physically moved, so it's safe to restore the + // mode immediately instead of leaving the machine parked + // in FREE. + if (homingPriorMode != EMC_TRAJ_MODE::FREE) { + emcTrajSetMode(homingPriorMode); + } + break; + } + // It ran and has now stopped; did it reach the expected end state? + success = all_target_homed; + + homingWaiting = false; + emcTaskEager = 1; + + // Is it legal to hand the machine back to the coordinated mode it + // was in before the FREE dip? Motion refuses to (re-)enter TELEOP + // or COORD on non-identity kinematics unless *every* joint is + // homed -- switch_to_teleop_mode() (motion.c) and the EMCMOT_COORD + // case (command.c) both gate on + // "kinType != KINEMATICS_IDENTITY && !get_allhomed()". + // + // Restoring unconditionally means motion rejects the request, task + // still reports DONE, and the machine is stranded in FREE with the + // GUI's mode controls greyed out -- recoverable only by cycling the + // controller (PR #4172: Sigma1912's "g28.3 p0" on a gantry gave + // "all joints must be homed before going into coordinated mode", + // then needed F2). Mirror motion's own condition here and abort + // cleanly instead of wedging. + // + // With G28.3 gone from this PR the only command that reaches here + // is a home, which ends with its joints referenced, so on + // non-identity kinematics -- where a coordinated prior mode already + // implies the machine was fully homed -- this gate now guards a + // state no G-code can produce. It is kept because the alternative + // failure is silent: motion defers the COORD/TELEOP transition to + // its controller cycle, so a refused restore leaves no trace task + // could notice, and the operator gets a dead UI with no message. + // + // Mirroring the condition rather than issuing the restore and + // checking whether it took is deliberate: the COORD/TELEOP + // transition is deferred to the controller cycle (see + // "defer transition to controller cycle" in command.c), so an + // immediate read-back would race exactly the way the old + // .homing-based completion test did. + // + // Read the kinematics type from status, not from this file's + // static emcmotConfig: that copy is filled in once just before + // the main loop and never refreshed, while taskintf.cc re-reads + // the motion config whenever config_num changes and republishes + // it as traj.kinematics_type. The two agree today -- kinType is + // written exactly once, in init_comm_buffers() (motion.c), and a + // runtime switchkins change does not alter it (switchkins answers + // KINEMATICS_BOTH for every selectable type) -- so this is a + // matter of reading the copy that is maintained, not of avoiding + // a divergence that exists now. + const bool restore_ok = (homingPriorMode == EMC_TRAJ_MODE::FREE) + || (emcStatus->motion.traj.kinematics_type + == KINEMATICS_IDENTITY) + || all_homed(); + + if (success && !restore_ok) { + // The command itself did what was asked, but it left the + // machine partially referenced and motion will not take + // TELEOP/COORD back in that state. Stay in FREE and fail the + // program rather than report DONE and strand the operator. + emcOperatorError(_("G28.2 home succeeded but left the machine not " + "fully homed -- staying in joint mode, as " + "non-identity kinematics cannot re-enter " + "coordinated motion until every joint is homed")); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } else if (success) { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + if (homingPriorMode != EMC_TRAJ_MODE::FREE) { + emcTrajSetMode(homingPriorMode); + } + } else { + // Homing stopped without reaching the target state (aborted, + // faulted, ESTOP mid-cycle, ...) -- abort the program rather + // than let it continue unreferenced. Deliberately NOT restored to + // homingPriorMode here: an unhomed/partially-homed machine may + // not legally re-enter TELEOP/COORD, and FREE is the safe + // state to leave it in for an operator to intervene from. + emcOperatorError("G28.2 home did not complete for joint %s", + homingWaitJoint < 0 ? "ALL" : "requested"); + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } + } + break; case EMC_TASK_EXEC::WAITING_FOR_DELAY: - STEPPING_CHECK(); - // check if delay has passed - emcStatus->task.delayLeft = taskExecDelayTimeout - etime(); - if (etime() >= taskExecDelayTimeout) { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcStatus->task.delayLeft = 0; - if (emcStatus->task.input_timeout != 0) - emcStatus->task.input_timeout = 1; // timeout occurred - emcTaskEager = 1; - } - // delay can be also be because we wait for an input - // if the index is set (not -1) - if (emcAuxInputWaitIndex >= 0) { - switch (emcAuxInputWaitType) { - case WAIT_MODE_HIGH: - if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] != 0) { - emcStatus->task.input_timeout = 0; // clear timeout flag - emcAuxInputWaitIndex = -1; - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcStatus->task.delayLeft = 0; - } - break; - - case WAIT_MODE_RISE: - if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] == 0) { - emcAuxInputWaitType = WAIT_MODE_HIGH; - } - break; + if (steppingHolds()) { + break; + } + // check if delay has passed + emcStatus->task.delayLeft = taskExecDelayTimeout - etime(); + if (etime() >= taskExecDelayTimeout) { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcStatus->task.delayLeft = 0; + if (emcStatus->task.input_timeout != 0) + emcStatus->task.input_timeout = 1; // timeout occurred + emcTaskEager = 1; + } + // delay can be also be because we wait for an input + // if the index is set (not -1) + if (emcAuxInputWaitIndex >= 0) { + switch (emcAuxInputWaitType) { + case WAIT_MODE_HIGH: + if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] != 0) { + emcStatus->task.input_timeout = 0; // clear timeout flag + emcAuxInputWaitIndex = -1; + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcStatus->task.delayLeft = 0; + } + break; - case WAIT_MODE_LOW: - if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] == 0) { - emcStatus->task.input_timeout = 0; // clear timeout flag - emcAuxInputWaitIndex = -1; - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcStatus->task.delayLeft = 0; - } - break; + case WAIT_MODE_RISE: + if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] == 0) { + emcAuxInputWaitType = WAIT_MODE_HIGH; + } + break; + + case WAIT_MODE_LOW: + if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] == 0) { + emcStatus->task.input_timeout = 0; // clear timeout flag + emcAuxInputWaitIndex = -1; + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcStatus->task.delayLeft = 0; + } + break; - case WAIT_MODE_FALL: //FIXME: implement different fall mode if needed - if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] != 0) { - emcAuxInputWaitType = WAIT_MODE_LOW; - } - break; + case WAIT_MODE_FALL: //FIXME: implement different fall mode if needed + if (emcStatus->motion.synch_di[emcAuxInputWaitIndex] != 0) { + emcAuxInputWaitType = WAIT_MODE_LOW; + } + break; - case WAIT_MODE_IMMEDIATE: - emcStatus->task.input_timeout = 0; // clear timeout flag - emcAuxInputWaitIndex = -1; - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcStatus->task.delayLeft = 0; - break; + case WAIT_MODE_IMMEDIATE: + emcStatus->task.input_timeout = 0; // clear timeout flag + emcAuxInputWaitIndex = -1; + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcStatus->task.delayLeft = 0; + break; - default: - emcOperatorError("Unknown Wait Mode"); - } - } - break; + default: + emcOperatorError("Unknown Wait Mode"); + } + } + break; case EMC_TASK_EXEC::WAITING_FOR_SYSTEM_CMD: - STEPPING_CHECK(); + if (steppingHolds()) { + break; + } - // if we got here without a system command pending, say we're done - if (0 == emcSystemCmdPid) { - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - break; - } - // check the status of the system command - pid = waitpid(emcSystemCmdPid, &status, WNOHANG); + // if we got here without a system command pending, say we're done + if (0 == emcSystemCmdPid) { + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + break; + } + // check the status of the system command + pid = waitpid(emcSystemCmdPid, &status, WNOHANG); - if (0 == pid) { - // child is still executing - break; - } + if (0 == pid) { + // child is still executing + break; + } - if (-1 == pid) { - // execution error - log_debug(EMC_DEBUG_TASK_ISSUE, "emcSystemCmd: error waiting for {}\n", - emcSystemCmdPid); - emcSystemCmdPid = 0; - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - break; - } + if (-1 == pid) { + // execution error + log_debug(EMC_DEBUG_TASK_ISSUE, "emcSystemCmd: error waiting for {}\n", + emcSystemCmdPid); + emcSystemCmdPid = 0; + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + break; + } - if (emcSystemCmdPid != pid) { - // somehow some other child finished, which is a coding error - log_debug(EMC_DEBUG_TASK_ISSUE, "emcSystemCmd: error waiting for system command {}, we got {}\n", - emcSystemCmdPid, pid); - emcSystemCmdPid = 0; - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - break; - } - // else child has finished - if (WIFEXITED(status)) { - if (0 == WEXITSTATUS(status)) { - // child exited normally - emcSystemCmdPid = 0; - emcStatus->task.execState = EMC_TASK_EXEC::DONE; - emcTaskEager = 1; - } else { - // child exited with non-zero status - log_debug(EMC_DEBUG_TASK_ISSUE, "emcSystemCmd: system command {} exited abnormally with value {}\n", - emcSystemCmdPid, WEXITSTATUS(status)); - emcSystemCmdPid = 0; - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } - } else if (WIFSIGNALED(status)) { - // child exited with an uncaught signal - log_debug(EMC_DEBUG_TASK_ISSUE, "system command {} terminated with signal {}\n", - emcSystemCmdPid, WTERMSIG(status)); - emcSystemCmdPid = 0; - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } else if (WIFSTOPPED(status)) { - // child is currently being traced, so keep waiting - } else { - // some other status, we'll call this an error - emcSystemCmdPid = 0; - emcStatus->task.execState = EMC_TASK_EXEC::ERROR; - } - break; + if (emcSystemCmdPid != pid) { + // somehow some other child finished, which is a coding error + log_debug(EMC_DEBUG_TASK_ISSUE, "emcSystemCmd: error waiting for system command {}, we got {}\n", + emcSystemCmdPid, pid); + emcSystemCmdPid = 0; + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + break; + } + // else child has finished + if (WIFEXITED(status)) { + if (0 == WEXITSTATUS(status)) { + // child exited normally + emcSystemCmdPid = 0; + emcStatus->task.execState = EMC_TASK_EXEC::DONE; + emcTaskEager = 1; + } else { + // child exited with non-zero status + log_debug(EMC_DEBUG_TASK_ISSUE, "emcSystemCmd: system command {} exited abnormally with value {}\n", + emcSystemCmdPid, WEXITSTATUS(status)); + emcSystemCmdPid = 0; + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } + } else if (WIFSIGNALED(status)) { + // child exited with an uncaught signal + log_debug(EMC_DEBUG_TASK_ISSUE, "system command {} terminated with signal {}\n", + emcSystemCmdPid, WTERMSIG(status)); + emcSystemCmdPid = 0; + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } else if (WIFSTOPPED(status)) { + // child is currently being traced, so keep waiting + } else { + // some other status, we'll call this an error + emcSystemCmdPid = 0; + emcStatus->task.execState = EMC_TASK_EXEC::ERROR; + } + break; default: // coding error @@ -3480,11 +2783,6 @@ static int iniLoad(const char *filename) io_error = strdup(inistring->c_str()); } - // max number of queued MDI commands - if (auto inival = inifile.findSInt("MDI_QUEUED_COMMANDS", "TASK")) { - max_mdi_queued_commands = *inival; - } - return 0; } @@ -3601,21 +2899,31 @@ int main(int argc, char *argv[]) task_beat++; // Task's heartbeat check_ini_hal_items(emcStatus->motion.traj.joints); - // read command + // read command if (0 != emcCommandBuffer->read()) { // got a new command, so clear out errors taskPlanError = 0; taskExecuteError = 0; taskCommandDone = 0; } - // run control cycle - if (0 != emcTaskPlan()) { - taskPlanError = 1; - } - if (0 != emcTaskExecute()) { - taskExecuteError = 1; - } - emcAbortCleanupCheck(); + // run control cycle, with the new command if there is one. This is + // the test emcTaskPlan() used to make itself: a command whose serial + // task has not echoed yet is new. The echo is set at the end of this + // cycle, so the planner sees each command once, in the cycle it + // arrives, and handles it then: issues it, queues it (MDI queue, + // interp_list) or refuses it. One command at most per cycle; nothing + // is still being planned when the next one is read. + NMLmsg *newCommand = NULL; + if (emcCommand->serial_number != emcStatus->echo_serial_number) { + newCommand = emcCommand; + } + if (0 != emcTaskPlan(newCommand)) { + taskPlanError = 1; + } + if (0 != emcTaskExecute()) { + taskExecuteError = 1; + } + emcAbortCleanupCheck(); // update subordinate status emcMotionUpdate(&emcStatus->motion); diff --git a/src/emc/task/taskintf.cc b/src/emc/task/taskintf.cc index 29ae6412376..7f8f177f22f 100644 --- a/src/emc/task/taskintf.cc +++ b/src/emc/task/taskintf.cc @@ -895,34 +895,6 @@ int emcJogIncr(int nr, double incr, double vel, int jjogmode) return usrmotWriteEmcmotCommand(&emcmotCommand); } -int emcJogAbs(int nr, double pos, double vel, int jjogmode) -{ - if (jjogmode) { - if (nr < 0 || nr >= EMCMOT_MAX_JOINTS) { return 0; } - if (vel > JointConfig[nr].MaxVel) { - vel = JointConfig[nr].MaxVel; - } else if (vel < -JointConfig[nr].MaxVel) { - vel = -JointConfig[nr].MaxVel; - } - emcmotCommand.joint = nr; - emcmotCommand.axis = -1; //NA - } else { - if (nr < 0 || nr >= EMCMOT_MAX_AXIS) { return 0; } - if (vel > AxisConfig[nr].MaxVel) { - vel = AxisConfig[nr].MaxVel; - } else if (vel < -AxisConfig[nr].MaxVel) { - vel = -AxisConfig[nr].MaxVel; - } - emcmotCommand.joint = -1; //NA - emcmotCommand.axis = nr; - } - emcmotCommand.command = EMCMOT_JOG_ABS; - emcmotCommand.vel = vel; - emcmotCommand.offset = pos; - - return usrmotWriteEmcmotCommand(&emcmotCommand); -} - int emcJogStop(int nr, int jjogmode) { if (jjogmode) {