From 86f1a00bdc4b298aac7d0121eb3d7d2c3607d1e6 Mon Sep 17 00:00:00 2001 From: Elias-Ta <150538418+Elias-Ta@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:07:45 +0800 Subject: [PATCH 1/4] Add the posibility of setting home offset for seperate axis , and update the previous offset value rather than resetting it inM428.cpp this pull request adds two functions to M428: 1- by sending M428 marlin will set the homing offset in the current position for the mentioned axis, can be one or more axis like X, Y, Z, A, .... or XYABC. 2- by sending M428 P XYZ for example, marlin will add the last offset value for the mentioned axis to the current position and set it as the new homing offset, this function can be useful to set the physical zero position for the mentioned axis, and without using P marlin will just replace the old home offset value based the current position. example: G1 Z5 ;will move Z axis to position 5 M428 Z; will set the position 5 as the new zero and will deduct 5 from the overall length G28 Z ; home Z axis G1 Z0 ; will move Z axis to the physical position that used to be called 5 before. now here we have two ways to set the homing offset again: G428 ; will set the offset to 0 therefore the last offset will be just replaced. G428 P ; will update the homing offset and make the current position as the physical zero position no matter what is the current offset in the memory. --- Marlin/src/gcode/geometry/M206_M428.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index dcf19625be99..f856fe056a27 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -83,21 +83,25 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) { */ void GcodeSuite::M428() { if (homing_needed_error()) return; - xyz_float_t diff; LOOP_NUM_AXES(i) { - 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_MSG(STR_ERR_M428_TOO_FAR); - LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR); - ERR_BUZZ(); - return; + if (parser.seen_test(AXIS_CHAR(i))){ + 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_MSG(STR_ERR_M428_TOO_FAR); + LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR); + ERR_BUZZ(); + return; + } } + else {diff[i] = 0;} + } - LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]); + if (parser.seen_test('P')) {LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]+ home_offset[i]);} + else {LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]);} report_current_position(); LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED); OKAY_BUZZ(); From d789e46fd2657e32016eddb4543fa4ee04d949d7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 May 2024 00:35:42 -0500 Subject: [PATCH 2/4] misc. cleanup --- Marlin/src/gcode/geometry/M206_M428.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index f856fe056a27..33cab52cf6f6 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -83,12 +83,16 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) { */ void GcodeSuite::M428() { if (homing_needed_error()) return; + + const bool adding = parser.seen_test('P'), + no_axes = !parser.seen(STR_AXES_LOGICAL); xyz_float_t diff; LOOP_NUM_AXES(i) { - if (parser.seen_test(AXIS_CHAR(i))){ + if (no_axes || parser.seen_test(AXIS_CHAR(i))) { 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 the current position is too far, for min homing just set to the negative current position + if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0) diff[i] = -current_position[i]; + // If still too far report an error if (!WITHIN(diff[i], -20, 20)) { SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR); LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR); @@ -96,12 +100,12 @@ void GcodeSuite::M428() { return; } } - else {diff[i] = 0;} - + else + diff[i] = 0; } - if (parser.seen_test('P')) {LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]+ home_offset[i]);} - else {LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]);} + LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i] + adding ? home_offset[i] : 0); + report_current_position(); LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED); OKAY_BUZZ(); From 3825fe3834ab7702a3689dc8f4eb2cf5a42542c6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 May 2024 00:41:16 -0500 Subject: [PATCH 3/4] document --- Marlin/src/gcode/geometry/M206_M428.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index 33cab52cf6f6..2ae54a83afff 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -80,6 +80,10 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) { * M428 can't be used more than 2cm away from 0 or an endstop. * * Use M206 to set these values directly. + * + * Parameters: + * X, Y, Z, ... - Flags to set the home offset for only the specified axes + * P - Flag to add the distance to the existing home offset */ void GcodeSuite::M428() { if (homing_needed_error()) return; @@ -104,7 +108,7 @@ void GcodeSuite::M428() { diff[i] = 0; } - LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i] + adding ? home_offset[i] : 0); + LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i] + (adding ? home_offset[i] : 0)); report_current_position(); LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED); From 0a72920489dfb2b45ddab028bb38d0ec18468620 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 20 May 2024 01:13:21 -0500 Subject: [PATCH 4/4] group --- Marlin/src/gcode/geometry/M206_M428.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index 2ae54a83afff..4c159807c077 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -88,8 +88,7 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) { void GcodeSuite::M428() { if (homing_needed_error()) return; - const bool adding = parser.seen_test('P'), - no_axes = !parser.seen(STR_AXES_LOGICAL); + const bool no_axes = !parser.seen(STR_AXES_LOGICAL); xyz_float_t diff; LOOP_NUM_AXES(i) { if (no_axes || parser.seen_test(AXIS_CHAR(i))) { @@ -108,6 +107,7 @@ void GcodeSuite::M428() { diff[i] = 0; } + const bool adding = parser.seen_test('P'); LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i] + (adding ? home_offset[i] : 0)); report_current_position();