From 566e655f07e761114c25b7943829c97628542b0e Mon Sep 17 00:00:00 2001 From: david mueller Date: Wed, 3 Jun 2026 15:30:22 +0200 Subject: [PATCH] fix(interp): reset G52/G92 offsets on prog_stop when DISABLE_G92_PERSISTENCE=1 This fixes #4096 - Adds canonical command to actually reset applied G92/G52 offset on M2,M30 with [RS274NGC] 'DISABLE_G92_PERSISTENCE = 1' - Updates INI documentation on DISABLE_G92_PERSISTENCE to reflect new behavior and agree with 'GCODE' documentation - Modify the 'g92-offset-persistence' test to account for the added 'SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)' - Change type to 'bool' rather than 'int' --- docs/src/config/ini-config.adoc | 2 +- src/emc/rs274ngc/interp_convert.cc | 24 ++++++++++++++++++- src/emc/rs274ngc/interp_internal.hh | 2 +- src/emc/rs274ngc/interp_setup.cc | 2 +- .../g52/g92-offset-persistence/expected | 7 +++--- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/src/config/ini-config.adoc b/docs/src/config/ini-config.adoc index 8cb14ddb65f..8f1e8d09d56 100644 --- a/docs/src/config/ini-config.adoc +++ b/docs/src/config/ini-config.adoc @@ -633,7 +633,7 @@ The maximum number of `USER_M_PATH` directories is defined at compile time (typ: Preserve case in O-word names within comments if set, enables reading of mixed-case HAL items in structured comments like `(debug, #<_hal[MixedCaseItem])`. * `OWORD_WARNONLY = 0` (Default: 0) + Warn rather than error in case of errors in O-word subroutines. -* `DISABLE_G92_PERSISTENCE = 0` (Default: 0) +* `DISABLE_G92_PERSISTENCE = 0` (bool, Default: 0) Allow to clear the G92 offset automatically when config start-up. * `DISABLE_AUTO_G54 = 0` (bool, Default: 0) + When set M2 and M30 will no longer automatically reset the active WCS to 'G54'. diff --git a/src/emc/rs274ngc/interp_convert.cc b/src/emc/rs274ngc/interp_convert.cc index 779ed700956..8f8573cab2f 100644 --- a/src/emc/rs274ngc/interp_convert.cc +++ b/src/emc/rs274ngc/interp_convert.cc @@ -5262,10 +5262,32 @@ int Interp::convert_stop(block_pointer block, //!< pointer to a block of RS27 } /*10*/ - if (settings->disable_g92_persistence) + if (settings->disable_g92_persistence) { // Clear G92/G52 offset for (index=5210; index<=5219; index++) settings->parameters[index] = 0; + settings->current_x = settings->current_x + settings->axis_offset_x; + settings->current_y = settings->current_y + settings->axis_offset_y; + settings->current_z = settings->current_z + settings->axis_offset_z; + settings->AA_current = (settings->AA_current + settings->AA_axis_offset); + settings->BB_current = (settings->BB_current + settings->BB_axis_offset); + settings->CC_current = (settings->CC_current + settings->CC_axis_offset); + settings->u_current = (settings->u_current + settings->u_axis_offset); + settings->v_current = (settings->v_current + settings->v_axis_offset); + settings->w_current = (settings->w_current + settings->w_axis_offset); + + SET_G92_OFFSET(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + settings->axis_offset_x = 0.0; + settings->axis_offset_y = 0.0; + settings->axis_offset_z = 0.0; + settings->AA_axis_offset = 0.0; + settings->BB_axis_offset = 0.0; + settings->CC_axis_offset = 0.0; + settings->u_axis_offset = 0.0; + settings->v_axis_offset = 0.0; + settings->w_axis_offset = 0.0; + } if (block->m_modes[4] == 30) PALLET_SHUTTLE(); diff --git a/src/emc/rs274ngc/interp_internal.hh b/src/emc/rs274ngc/interp_internal.hh index b734b66ee82..22268854211 100644 --- a/src/emc/rs274ngc/interp_internal.hh +++ b/src/emc/rs274ngc/interp_internal.hh @@ -824,7 +824,7 @@ struct setup // control to skip to beginning of file bool loop_on_main_m99; - int disable_g92_persistence; + bool disable_g92_persistence; bool disable_auto_g54; // add new geometric fields for our new tags diff --git a/src/emc/rs274ngc/interp_setup.cc b/src/emc/rs274ngc/interp_setup.cc index 0999d6b7d94..365e4682d6c 100644 --- a/src/emc/rs274ngc/interp_setup.cc +++ b/src/emc/rs274ngc/interp_setup.cc @@ -186,7 +186,7 @@ setup::setup() : feature_set(0), disable_fanuc_style_sub(false), loop_on_main_m99(false), - disable_g92_persistence(0), + disable_g92_persistence(false), disable_auto_g54(false), heading(0.0), radius(0.0), diff --git a/tests/interp/g52/g92-offset-persistence/expected b/tests/interp/g52/g92-offset-persistence/expected index 00ee574cff6..aa9cfa80a07 100644 --- a/tests/interp/g52/g92-offset-persistence/expected +++ b/tests/interp/g52/g92-offset-persistence/expected @@ -53,6 +53,7 @@ G92 params: 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.00 12 N..... SET_FEED_RATE(0.0000) 13 N..... STOP_SPINDLE_TURNING(0) 14 N..... SET_SPINDLE_MODE(0 0.0000) - 15 N..... PALLET_SHUTTLE() - 16 N..... PROGRAM_END() - 17 N..... ON_RESET() + 15 N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) + 16 N..... PALLET_SHUTTLE() + 17 N..... PROGRAM_END() + 18 N..... ON_RESET()