diff --git a/Marlin/src/gcode/geometry/G53-G59.cpp b/Marlin/src/gcode/geometry/G53-G59.cpp index 149c50250..a00a65b6c 100644 --- a/Marlin/src/gcode/geometry/G53-G59.cpp +++ b/Marlin/src/gcode/geometry/G53-G59.cpp @@ -27,7 +27,7 @@ #if ENABLED(CNC_COORDINATE_SYSTEMS) /** - * Select a coordinate system and update the current position. + * Select a coordinate system and update the workspace offset. * System index -1 is used to specify machine-native. */ bool GCodeSuite::select_coordinate_system(const int8_t _new) { @@ -39,16 +39,13 @@ if (WITHIN(_new, 0, MAX_COORDINATE_SYSTEMS - 1)) COPY(new_offset, coordinate_system[_new]); active_coordinate_system = _new; - bool didXYZ = false; LOOP_XYZ(i) { const float diff = new_offset[i] - old_offset[i]; if (diff) { position_shift[i] += diff; update_software_endstops((AxisEnum)i); - didXYZ = true; } } - if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC(); return true; } diff --git a/Marlin/src/gcode/geometry/G92.cpp b/Marlin/src/gcode/geometry/G92.cpp index 535ca3714..0b10aab5b 100644 --- a/Marlin/src/gcode/geometry/G92.cpp +++ b/Marlin/src/gcode/geometry/G92.cpp @@ -58,7 +58,12 @@ void GcodeSuite::G92() { #define IS_G92_0 true #endif - bool didXYZ = false, didE = false; + bool didE = false; + #if IS_SCARA || !HAS_POSITION_SHIFT + bool didXYZ = false; + #else + constexpr bool didXYZ = false; + #endif if (IS_G92_0) LOOP_XYZE(i) { if (parser.seenval(axis_codes[i])) { @@ -66,18 +71,18 @@ void GcodeSuite::G92() { v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i), d = v - current_position[i]; if (!NEAR_ZERO(d)) { - if (i == E_AXIS) didE = true; else didXYZ = true; - #if IS_SCARA - current_position[i] = v; // For SCARA just set the position directly + #if IS_SCARA || !HAS_POSITION_SHIFT + if (i == E_AXIS) didE = true; else didXYZ = true; + current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior #elif HAS_POSITION_SHIFT - if (i == E_AXIS) + if (i == E_AXIS) { + didE = true; current_position[E_AXIS] = v; // When using coordinate spaces, only E is set directly + } else { position_shift[i] += d; // Other axes simply offset the coordinate space update_software_endstops((AxisEnum)i); } - #else - current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior #endif } } diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index 1de0f004e..4d15fb56b 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -47,7 +47,6 @@ void GcodeSuite::M206() { if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_linear_units()); // Psi #endif - SYNC_PLAN_POSITION_KINEMATIC(); report_current_position(); } @@ -63,32 +62,27 @@ void GcodeSuite::M206() { * Use M206 to set these values directly. */ void GcodeSuite::M428() { - bool err = false; + if (axis_unhomed_error()) return; + + float diff[XYZ]; LOOP_XYZ(i) { - if (axis_homed[i]) { - const float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0, - diff = base - current_position[i]; - if (WITHIN(diff, -20, 20)) { - set_home_offset((AxisEnum)i, diff); - } - else { - SERIAL_ERROR_START(); - SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR); - LCD_ALERTMESSAGEPGM("Err: Too far!"); - BUZZ(200, 40); - err = true; - break; - } + diff[i] = base_home_pos((AxisEnum)i) - current_position[i]; + if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0) + diff[i] = -current_position[i]; + if (!WITHIN(diff[i], -20, 20)) { + SERIAL_ERROR_START(); + SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR); + LCD_ALERTMESSAGEPGM("Err: Too far!"); + BUZZ(200, 40); + return; } } - if (!err) { - SYNC_PLAN_POSITION_KINEMATIC(); - report_current_position(); - LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED); - BUZZ(100, 659); - BUZZ(100, 698); - } + LOOP_XYZ(i) set_home_offset((AxisEnum)i, diff[i]); + report_current_position(); + LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED); + BUZZ(100, 659); + BUZZ(100, 698); } #endif // HAS_M206_COMMAND diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 826091c8c..7edbd29b3 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -173,6 +173,7 @@ void clean_up_after_endstop_or_probe_move(); || ENABLED(NOZZLE_CLEAN_FEATURE) \ || ENABLED(NOZZLE_PARK_FEATURE) \ || (ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(HOME_BEFORE_FILAMENT_CHANGE)) \ + || HAS_M206_COMMAND \ ) || ENABLED(NO_MOTION_BEFORE_HOMING) #if HAS_AXIS_UNHOMED_ERR