From 7581a0971f24406797a2fd3b4e22330c1d8e79ed Mon Sep 17 00:00:00 2001 From: kisslorand Date: Wed, 2 Nov 2022 22:45:38 +0200 Subject: [PATCH 1/4] G30 Rework --- Marlin/src/gcode/probe/G30.cpp | 45 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index e474ffe9d689..af8cd18631a6 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -51,23 +51,33 @@ * E Engage the probe for each probe (default 1) * C Enable probe temperature compensation (0 or 1, default 1) */ -void GcodeSuite::G30() { - +void GcodeSuite::G30() +{ #if HAS_MULTI_HOTEND const uint8_t old_tool_index = active_extruder; tool_change(0); #endif - const xy_pos_t pos = { parser.linearval('X', current_position.x + probe.offset_xy.x), - parser.linearval('Y', current_position.y + probe.offset_xy.y) }; - - if (!probe.can_reach(pos)) { - #if ENABLED(DWIN_LCD_PROUI) - SERIAL_ECHOLNF(GET_EN_TEXT_F(MSG_ZPROBE_OUT)); - LCD_MESSAGE(MSG_ZPROBE_OUT); - #endif - } - else { + const xy_pos_t pos = {parser.seenval('X') ? parser.value_linear_units() + #if HAS_POSITION_SHIFT + - position_shift.x + #endif + #if HAS_HOME_OFFSET + - home_offset.x + #endif + : current_position.x, + parser.seenval('Y') ? parser.value_linear_units() + #if HAS_POSITION_SHIFT + - position_shift.y + #endif + #if HAS_HOME_OFFSET + - home_offset.y + #endif + : current_position.y}; + + + if (probe.can_reach(pos)) + { // Disable leveling so the planner won't mess with us TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); @@ -80,10 +90,10 @@ void GcodeSuite::G30() { const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE; TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool())); - const float measured_z = probe.probe_at_point(pos, raise_after, 1); + const float measured_z = probe.probe_at_point(pos, raise_after, true, true); TERN_(HAS_PTC, ptc.set_enabled(true)); if (!isnan(measured_z)) { - SERIAL_ECHOLNPGM("Bed X: ", pos.x, " Y: ", pos.y, " Z: ", measured_z); + SERIAL_ECHOLNPGM("Bed X: ", pos.asLogical().x, " Y: ", pos.asLogical().y, " Z: ", measured_z); #if EITHER(DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI) char msg[31], str_1[6], str_2[6], str_3[6]; sprintf_P(msg, PSTR("X:%s, Y:%s, Z:%s"), @@ -102,6 +112,13 @@ void GcodeSuite::G30() { report_current_position(); } + #if ENABLED(DWIN_LCD_PROUI) + else + { + SERIAL_ECHOLNF(GET_EN_TEXT_F(MSG_ZPROBE_OUT)); + LCD_MESSAGE(MSG_ZPROBE_OUT); + } + #endif // Restore the active tool TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index)); From 92e18954d1e605fa50b980abf77b7ca4435b731a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 13 Nov 2022 23:19:00 -0600 Subject: [PATCH 2/4] fix some things --- Marlin/src/gcode/probe/G30.cpp | 49 +++++++++++++--------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index af8cd18631a6..956707824901 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -51,33 +51,23 @@ * E Engage the probe for each probe (default 1) * C Enable probe temperature compensation (0 or 1, default 1) */ -void GcodeSuite::G30() -{ +void GcodeSuite::G30() { + #if HAS_MULTI_HOTEND const uint8_t old_tool_index = active_extruder; tool_change(0); #endif - const xy_pos_t pos = {parser.seenval('X') ? parser.value_linear_units() - #if HAS_POSITION_SHIFT - - position_shift.x - #endif - #if HAS_HOME_OFFSET - - home_offset.x - #endif - : current_position.x, - parser.seenval('Y') ? parser.value_linear_units() - #if HAS_POSITION_SHIFT - - position_shift.y - #endif - #if HAS_HOME_OFFSET - - home_offset.y - #endif - : current_position.y}; - - - if (probe.can_reach(pos)) - { + const xy_pos_t pos = { + parser.seenval('X') + ? parser.value_linear_units() TERN_(HAS_POSITION_SHIFT, - position_shift.x) TERN_(HAS_HOME_OFFSET, - home_offset.x) + : current_position.x, + parser.seenval('Y') + ? parser.value_linear_units() TERN_(HAS_POSITION_SHIFT, - position_shift.y) TERN_(HAS_HOME_OFFSET, - home_offset.y) + : current_position.y + }; + + if (probe.can_reach(pos)) { // Disable leveling so the planner won't mess with us TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); @@ -90,7 +80,7 @@ void GcodeSuite::G30() const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE; TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool())); - const float measured_z = probe.probe_at_point(pos, raise_after, true, true); + const float measured_z = probe.probe_at_point(pos, raise_after, 1, true, true); TERN_(HAS_PTC, ptc.set_enabled(true)); if (!isnan(measured_z)) { SERIAL_ECHOLNPGM("Bed X: ", pos.asLogical().x, " Y: ", pos.asLogical().y, " Z: ", measured_z); @@ -112,13 +102,12 @@ void GcodeSuite::G30() report_current_position(); } - #if ENABLED(DWIN_LCD_PROUI) - else - { - SERIAL_ECHOLNF(GET_EN_TEXT_F(MSG_ZPROBE_OUT)); - LCD_MESSAGE(MSG_ZPROBE_OUT); - } - #endif + else { + #if ENABLED(DWIN_LCD_PROUI) + SERIAL_ECHOLNF(GET_EN_TEXT_F(MSG_ZPROBE_OUT)); + LCD_MESSAGE(MSG_ZPROBE_OUT); + #endif + } // Restore the active tool TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index)); From f7ae9f4b000d9605173aa5163d9a8f018ef07422 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 13 Nov 2022 23:25:22 -0600 Subject: [PATCH 3/4] true, true is the default --- Marlin/src/gcode/probe/G30.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index 956707824901..51465b8de9de 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -80,7 +80,7 @@ void GcodeSuite::G30() { const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE; TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool())); - const float measured_z = probe.probe_at_point(pos, raise_after, 1, true, true); + const float measured_z = probe.probe_at_point(pos, raise_after, 1); TERN_(HAS_PTC, ptc.set_enabled(true)); if (!isnan(measured_z)) { SERIAL_ECHOLNPGM("Bed X: ", pos.asLogical().x, " Y: ", pos.asLogical().y, " Z: ", measured_z); From 5d0b49da79849a94493ab28d8454b1543efc87a0 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 13 Nov 2022 23:31:36 -0600 Subject: [PATCH 4/4] use RAW_*_POSITION macros --- Marlin/src/core/types.h | 6 +++--- Marlin/src/gcode/probe/G30.cpp | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index 4497ff49af43..2bd4cf402921 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -307,9 +307,9 @@ typedef abce_float_t abce_pos_t; void toLogical(xy_pos_t &raw); void toLogical(xyz_pos_t &raw); void toLogical(xyze_pos_t &raw); -void toNative(xy_pos_t &raw); -void toNative(xyz_pos_t &raw); -void toNative(xyze_pos_t &raw); +void toNative(xy_pos_t &lpos); +void toNative(xyz_pos_t &lpos); +void toNative(xyze_pos_t &lpos); // // Paired XY coordinates, counters, flags, etc. diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp index 51465b8de9de..6893d4bec284 100644 --- a/Marlin/src/gcode/probe/G30.cpp +++ b/Marlin/src/gcode/probe/G30.cpp @@ -58,13 +58,10 @@ void GcodeSuite::G30() { tool_change(0); #endif + // Convert the given logical position to native position const xy_pos_t pos = { - parser.seenval('X') - ? parser.value_linear_units() TERN_(HAS_POSITION_SHIFT, - position_shift.x) TERN_(HAS_HOME_OFFSET, - home_offset.x) - : current_position.x, - parser.seenval('Y') - ? parser.value_linear_units() TERN_(HAS_POSITION_SHIFT, - position_shift.y) TERN_(HAS_HOME_OFFSET, - home_offset.y) - : current_position.y + parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x, + parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y }; if (probe.can_reach(pos)) {