From 2104c8b82dd6dc1ff0282615b0d02c04e3481e3d Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Tue, 25 Aug 2026 07:27:01 +0800 Subject: [PATCH] interp: don't restore spindle speed on abort state restore On abort, restore_from_tag() executes a G-code string built from the difference between the motion state tag and the interpreter readahead state. gen_settings() unconditionally appends the saved S word, so after an early abort the restore queued EMC_SPINDLE_SPEED onto the interp_list and it was issued after the abort's spindle stop, turning the spindle back on. Late aborts were unaffected because tag and readahead state agree by then and no restore command is generated. Exclude the spindle speed from the abort restore, as is already done for M codes. The M72 restore_settings() path keeps restoring it, since there the S word must take effect mid-program. --- src/emc/rs274ngc/interp_convert.cc | 16 ++++++++++------ src/emc/rs274ngc/rs274ngc_interp.hh | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/emc/rs274ngc/interp_convert.cc b/src/emc/rs274ngc/interp_convert.cc index f01a359652d..9a42be3769e 100644 --- a/src/emc/rs274ngc/interp_convert.cc +++ b/src/emc/rs274ngc/interp_convert.cc @@ -2850,7 +2850,8 @@ int Interp::convert_length_units(int g_code, //!< g_code being executed (mus int Interp::gen_settings( int *int_current, int *int_saved, // G-codes double *float_current, double *float_saved, // S, F, other - std::string &cmd) // command buffer + std::string &cmd, // command buffer + bool include_spindle_speed) { FORCE_LC_NUMERIC_C; int i, val; @@ -2871,8 +2872,11 @@ int Interp::gen_settings( cmd += buf; break; case GM_FIELD_FLOAT_SPEED: - snprintf(buf,sizeof(buf)," S%.0f", float_saved[i]); - cmd += buf; + // No S word on abort restore: the spindle was just stopped + if (include_spindle_speed) { + snprintf(buf,sizeof(buf)," S%.0f", float_saved[i]); + cmd += buf; + } break; case GM_FIELD_FLOAT_PATH_TOLERANCE: case GM_FIELD_FLOAT_NAIVE_CAM_TOLERANCE: @@ -3061,13 +3065,13 @@ int Interp::gen_restore_cmd(int *current_g, cmd.c_str()); } + // M codes and spindle speed should not be restored during an abort if ((res = gen_settings( - current_g, saved_g, current_settings, saved_settings, cmd))) { + current_g, saved_g, current_settings, saved_settings, cmd, false))) { logStateTags("gen_restore_cmd(): error restoring settings (%d)", res); return INTERP_ERROR; } - // M codes should not be restored during an abort with gen_m_codes() return INTERP_OK; } @@ -3135,7 +3139,7 @@ int Interp::restore_settings(setup_pointer settings, (int *)settings->sub_context[from_level].saved_g_codes, (double *)settings->active_settings, (double *)settings->sub_context[from_level].saved_settings, - cmd); + cmd, true); gen_m_codes( (int *) settings->active_m_codes, (int *)settings->sub_context[from_level].saved_m_codes, diff --git a/src/emc/rs274ngc/rs274ngc_interp.hh b/src/emc/rs274ngc/rs274ngc_interp.hh index 4165ea8cfd5..05055260604 100644 --- a/src/emc/rs274ngc/rs274ngc_interp.hh +++ b/src/emc/rs274ngc/rs274ngc_interp.hh @@ -475,7 +475,8 @@ int read_dollar(char *line, int *counter, block_pointer block, int gen_settings( int *int_current, int *int_saved, double *float_current, double *float_saved, - std::string &cmd); + std::string &cmd, + bool include_spindle_speed); int gen_m_codes(int *current, int *saved, std::string &cmd); int gen_restore_cmd(int *current_g, int *current_m,