Skip to content

Commit 73fc077

Browse files
authoredJul 9, 2020
Consolidate probe clearance, add section debug (MarlinFirmware#18576)
* Better section / function log * Add do_z_clearance motion function
1 parent 0eab9fc commit 73fc077

File tree

18 files changed

+132
-131
lines changed

18 files changed

+132
-131
lines changed
 

‎Marlin/src/core/debug_out.h

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// (or not) in a given .cpp file
2727
//
2828

29+
#undef DEBUG_SECTION
2930
#undef DEBUG_PRINT_P
3031
#undef DEBUG_ECHO_START
3132
#undef DEBUG_ERROR_START
@@ -53,6 +54,10 @@
5354
#undef DEBUG_DELAY
5455

5556
#if DEBUG_OUT
57+
58+
#include "debug_section.h"
59+
#define DEBUG_SECTION(N,S,D) SectionLog N(PSTR(S),D)
60+
5661
#define DEBUG_PRINT_P(P) serialprintPGM(P)
5762
#define DEBUG_ECHO_START SERIAL_ECHO_START
5863
#define DEBUG_ERROR_START SERIAL_ERROR_START
@@ -78,7 +83,10 @@
7883
#define DEBUG_POS SERIAL_POS
7984
#define DEBUG_XYZ SERIAL_XYZ
8085
#define DEBUG_DELAY(ms) serial_delay(ms)
86+
8187
#else
88+
89+
#define DEBUG_SECTION(...) NOOP
8290
#define DEBUG_PRINT_P(P) NOOP
8391
#define DEBUG_ECHO_START() NOOP
8492
#define DEBUG_ERROR_START() NOOP
@@ -104,6 +112,7 @@
104112
#define DEBUG_POS(...) NOOP
105113
#define DEBUG_XYZ(...) NOOP
106114
#define DEBUG_DELAY(...) NOOP
115+
107116
#endif
108117

109118
#undef DEBUG_OUT

‎Marlin/src/core/debug_section.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
#pragma once
23+
24+
#include "serial.h"
25+
#include "../module/motion.h"
26+
27+
class SectionLog {
28+
public:
29+
SectionLog(PGM_P const msg=nullptr, bool inbug=true) {
30+
the_msg = msg;
31+
if ((debug = inbug)) echo_msg(PSTR(">>>"));
32+
}
33+
34+
~SectionLog() { if (debug) echo_msg(PSTR("<<<")); }
35+
36+
private:
37+
PGM_P the_msg;
38+
bool debug;
39+
40+
void echo_msg(PGM_P const pre) {
41+
serialprintPGM(pre);
42+
if (the_msg) {
43+
SERIAL_CHAR(' ');
44+
serialprintPGM(the_msg);
45+
}
46+
SERIAL_CHAR(' ');
47+
print_xyz(current_position);
48+
}
49+
};

‎Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp

+7-14
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
// Manually Probe Mesh in areas that can't be reached by the probe
463463
//
464464
SERIAL_ECHOLNPGM("Manually probing unreachable points.");
465-
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
465+
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
466466

467467
if (parser.seen('C') && !xy_seen) {
468468

@@ -780,9 +780,7 @@
780780
probe.stow();
781781
TERN_(HAS_LCD_MENU, ui.capture());
782782

783-
#ifdef Z_AFTER_PROBING
784-
probe.move_z_after_probing();
785-
#endif
783+
probe.move_z_after_probing();
786784

787785
restore_ubl_active_state_and_leave();
788786

@@ -858,7 +856,6 @@
858856
echo_and_take_a_measurement();
859857

860858
const float z2 = measure_point_with_encoder();
861-
862859
do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);
863860

864861
const float thickness = ABS(z1 - z2);
@@ -899,7 +896,7 @@
899896
LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);
900897

901898
do_blocking_move_to(ppos);
902-
do_blocking_move_to_z(z_clearance);
899+
do_z_clearance(z_clearance);
903900

904901
KEEPALIVE_STATE(PAUSED_FOR_USER);
905902
ui.capture();
@@ -915,7 +912,7 @@
915912

916913
if (click_and_hold()) {
917914
SERIAL_ECHOLNPGM("\nMesh only partially populated.");
918-
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
915+
do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
919916
return restore_ubl_active_state_and_leave();
920917
}
921918

@@ -940,7 +937,7 @@
940937

941938
void abort_fine_tune() {
942939
ui.return_to_status();
943-
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
940+
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
944941
set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED));
945942
}
946943

@@ -1415,9 +1412,7 @@
14151412
}
14161413

14171414
probe.stow();
1418-
#ifdef Z_AFTER_PROBING
1419-
probe.move_z_after_probing();
1420-
#endif
1415+
probe.move_z_after_probing();
14211416

14221417
if (abort_flag) {
14231418
SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
@@ -1478,9 +1473,7 @@
14781473
}
14791474
}
14801475
probe.stow();
1481-
#ifdef Z_AFTER_PROBING
1482-
probe.move_z_after_probing();
1483-
#endif
1476+
probe.move_z_after_probing();
14841477

14851478
if (abort_flag || finish_incremental_LSF(&lsf_results)) {
14861479
SERIAL_ECHOPGM("Could not complete LSF!");

‎Marlin/src/gcode/bedlevel/G26.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,7 @@ void GcodeSuite::G26() {
622622
*/
623623
set_bed_leveling_enabled(!parser.seen('D'));
624624

625-
if (current_position.z < Z_CLEARANCE_BETWEEN_PROBES)
626-
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
625+
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
627626

628627
#if DISABLED(NO_VOLUMETRICS)
629628
bool volumetric_was_enabled = parser.volumetric_enabled;

‎Marlin/src/gcode/bedlevel/G35.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ static_assert(G35_PROBE_COUNT > 2, "TRAMMING_POINT_XY requires at least 3 XY pos
7575
* 51 - Counter-Clockwise M5
7676
**/
7777
void GcodeSuite::G35() {
78-
if (DEBUGGING(LEVELING)) {
79-
DEBUG_ECHOLNPGM(">>> G35");
80-
log_machine_info();
81-
}
78+
DEBUG_SECTION(log_G35, "G35", DEBUGGING(LEVELING));
79+
80+
if (DEBUGGING(LEVELING)) log_machine_info();
8281

8382
float z_measured[G35_PROBE_COUNT] = { 0 };
8483

@@ -181,8 +180,6 @@ void GcodeSuite::G35() {
181180

182181
// Home Z after the alignment procedure
183182
process_subcommands_now_P(PSTR("G28Z"));
184-
185-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G35");
186183
}
187184

188185
#endif // ASSISTED_TRAMMING

‎Marlin/src/gcode/bedlevel/abl/G29.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ G29_TYPE GcodeSuite::G29() {
172172
#if ENABLED(DEBUG_LEVELING_FEATURE)
173173
const uint8_t old_debug_flags = marlin_debug_flags;
174174
if (seenQ) marlin_debug_flags |= MARLIN_DEBUG_LEVELING;
175-
if (DEBUGGING(LEVELING)) {
176-
DEBUG_POS(">>> G29", current_position);
177-
log_machine_info();
178-
}
175+
DEBUG_SECTION(log_G29, "G29", DEBUGGING(LEVELING));
176+
if (DEBUGGING(LEVELING)) log_machine_info();
179177
marlin_debug_flags = old_debug_flags;
180178
if (DISABLED(PROBE_MANUALLY) && seenQ) G29_RETURN(false);
181179
#endif
@@ -188,7 +186,7 @@ G29_TYPE GcodeSuite::G29() {
188186
if (axis_unhomed_error()) G29_RETURN(false);
189187

190188
if (!no_action && planner.leveling_active && parser.boolval('O')) { // Auto-level only if needed
191-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Auto-level not needed, skip\n<<< G29");
189+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> Auto-level not needed, skip");
192190
G29_RETURN(false);
193191
}
194192

@@ -416,7 +414,7 @@ G29_TYPE GcodeSuite::G29() {
416414
// Deploy certain probes before starting probing
417415
#if HAS_BED_PROBE
418416
if (ENABLED(BLTOUCH))
419-
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
417+
do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
420418
else if (probe.deploy()) {
421419
set_bed_leveling_enabled(abl_should_enable);
422420
G29_RETURN(false);
@@ -884,7 +882,7 @@ G29_TYPE GcodeSuite::G29() {
884882
// Sync the planner from the current_position
885883
if (planner.leveling_active) sync_plan_position();
886884

887-
#if HAS_BED_PROBE && defined(Z_AFTER_PROBING)
885+
#if HAS_BED_PROBE
888886
probe.move_z_after_probing();
889887
#endif
890888

@@ -900,8 +898,6 @@ G29_TYPE GcodeSuite::G29() {
900898

901899
report_current_position();
902900

903-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
904-
905901
G29_RETURN(isnan(measured_z));
906902
}
907903

‎Marlin/src/gcode/calibrate/G28.cpp

+13-36
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@
115115
#if ENABLED(Z_SAFE_HOMING)
116116

117117
inline void home_z_safely() {
118+
DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING));
119+
118120
// Disallow Z homing if X or Y homing is needed
119121
if (axis_unhomed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return;
120122

121-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("home_z_safely >>>");
122-
123123
sync_plan_position();
124124

125125
/**
@@ -146,8 +146,6 @@
146146
LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
147147
SERIAL_ECHO_MSG(STR_ZPROBE_OUT_SER);
148148
}
149-
150-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< home_z_safely");
151149
}
152150

153151
#endif // Z_SAFE_HOMING
@@ -197,15 +195,10 @@
197195
*
198196
*/
199197
void GcodeSuite::G28() {
198+
DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
199+
if (DEBUGGING(LEVELING)) log_machine_info();
200200

201-
if (DEBUGGING(LEVELING)) {
202-
DEBUG_ECHOLNPGM(">>> G28");
203-
log_machine_info();
204-
}
205-
206-
#if ENABLED(LASER_MOVE_G28_OFF)
207-
cutter.set_inline_enabled(false); // turn off laser
208-
#endif
201+
TERN_(LASER_MOVE_G28_OFF, cutter.set_inline_enabled(false)); // turn off laser
209202

210203
TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);
211204

@@ -220,14 +213,13 @@ void GcodeSuite::G28() {
220213
sync_plan_position();
221214
SERIAL_ECHOLNPGM("Simulated Homing");
222215
report_current_position();
223-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
224216
return;
225217
}
226218
#endif
227219

228220
// Home (O)nly if position is unknown
229221
if (!homing_needed() && parser.boolval('O')) {
230-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip\n<<< G28");
222+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip");
231223
return;
232224
}
233225

@@ -313,26 +305,21 @@ void GcodeSuite::G28() {
313305
home_all = homeX == homeY && homeX == homeZ, // All or None
314306
doX = home_all || homeX, doY = home_all || homeY, doZ = home_all || homeZ;
315307

316-
destination = current_position;
317-
318308
#if Z_HOME_DIR > 0 // If homing away from BED do Z first
319309

320310
if (doZ) homeaxis(Z_AXIS);
321311

322312
#endif
323313

324314
const float z_homing_height =
325-
(DISABLED(UNKNOWN_Z_NO_RAISE) || TEST(axis_known_position, Z_AXIS))
326-
? (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
327-
: 0;
315+
ENABLED(UNKNOWN_Z_NO_RAISE) && TEST(axis_known_position, Z_AXIS)
316+
? 0
317+
: (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT);
328318

329-
if (z_homing_height && (doX || doY || ENABLED(Z_SAFE_HOMING))) {
319+
if (z_homing_height && (doX || doY || (ENABLED(Z_SAFE_HOMING) && doZ))) {
330320
// Raise Z before homing any other axes and z is not already high enough (never lower z)
331-
destination.z = z_homing_height + (TEST(axis_known_position, Z_AXIS) ? 0.0f : current_position.z);
332-
if (destination.z > current_position.z) {
333-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) to ", destination.z);
334-
do_blocking_move_to_z(destination.z);
335-
}
321+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) by ", z_homing_height);
322+
do_z_clearance(z_homing_height, TEST(axis_known_position, Z_AXIS), DISABLED(UNKNOWN_Z_NO_RAISE));
336323
}
337324

338325
#if ENABLED(QUICK_HOME)
@@ -387,15 +374,7 @@ void GcodeSuite::G28() {
387374

388375
TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS));
389376

390-
#if HOMING_Z_WITH_PROBE && defined(Z_AFTER_PROBING)
391-
#if Z_AFTER_HOMING > Z_AFTER_PROBING
392-
do_blocking_move_to_z(Z_AFTER_HOMING);
393-
#else
394-
probe.move_z_after_probing();
395-
#endif
396-
#elif defined(Z_AFTER_HOMING)
397-
do_blocking_move_to_z(Z_AFTER_HOMING);
398-
#endif
377+
probe.move_z_after_homing();
399378

400379
} // doZ
401380

@@ -485,8 +464,6 @@ void GcodeSuite::G28() {
485464
if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
486465
SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
487466

488-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
489-
490467
#if HAS_L64XX
491468
// Set L6470 absolute position registers to counts
492469
// constexpr *might* move this to PROGMEM.

‎Marlin/src/gcode/calibrate/G34_M422.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@
5656
* R<recalculate> points based on current probe offsets
5757
*/
5858
void GcodeSuite::G34() {
59-
if (DEBUGGING(LEVELING)) {
60-
DEBUG_ECHOLNPGM(">>> G34");
61-
log_machine_info();
62-
}
59+
DEBUG_SECTION(log_G34, "G34", DEBUGGING(LEVELING));
60+
if (DEBUGGING(LEVELING)) log_machine_info();
6361

6462
do { // break out on error
6563

@@ -367,8 +365,6 @@ void GcodeSuite::G34() {
367365
#endif
368366

369367
}while(0);
370-
371-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G34");
372368
}
373369

374370
/**

‎Marlin/src/gcode/calibrate/G76_M871.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void GcodeSuite::G76() {
104104
};
105105

106106
auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
107-
do_blocking_move_to_z(5.0); // Raise nozzle before probing
107+
do_z_clearance(5.0); // Raise nozzle before probing
108108
const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false); // verbose=0, probe_relative=false
109109
if (isnan(measured_z))
110110
SERIAL_ECHOLNPGM("!Received NAN. Aborting.");

‎Marlin/src/gcode/calibrate/M666.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@
3838
* M666: Set delta endstop adjustment
3939
*/
4040
void GcodeSuite::M666() {
41-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> M666");
41+
DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING));
4242
LOOP_XYZ(i) {
4343
if (parser.seen(XYZ_CHAR(i))) {
4444
const float v = parser.value_linear_units();
4545
if (v * Z_HOME_DIR <= 0) delta_endstop_adj[i] = v;
4646
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", XYZ_CHAR(i), "] = ", delta_endstop_adj[i]);
4747
}
4848
}
49-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< M666");
5049
}
5150

5251
#elif HAS_EXTRA_ENDSTOPS

‎Marlin/src/gcode/control/T.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
*/
4949
void GcodeSuite::T(const uint8_t tool_index) {
5050

51-
if (DEBUGGING(LEVELING)) {
52-
DEBUG_ECHOLNPAIR(">>> T(", tool_index, ")");
53-
DEBUG_POS("BEFORE", current_position);
54-
}
51+
DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
52+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("...(", tool_index, ")");
5553

5654
// Count this command as movement / activity
5755
reset_stepper_timeout();
@@ -75,9 +73,4 @@ void GcodeSuite::T(const uint8_t tool_index) {
7573
);
7674

7775
#endif
78-
79-
if (DEBUGGING(LEVELING)) {
80-
DEBUG_POS("AFTER", current_position);
81-
DEBUG_ECHOLNPGM("<<< T()");
82-
}
8376
}

‎Marlin/src/gcode/probe/G30.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ void GcodeSuite::G30() {
5757

5858
restore_feedrate_and_scaling();
5959

60-
#ifdef Z_AFTER_PROBING
61-
if (raise_after == PROBE_PT_STOW) probe.move_z_after_probing();
62-
#endif
60+
if (raise_after == PROBE_PT_STOW)
61+
probe.move_z_after_probing();
6362

6463
report_current_position();
6564
}

‎Marlin/src/gcode/probe/M401_M402.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ void GcodeSuite::M401() {
4141
*/
4242
void GcodeSuite::M402() {
4343
probe.stow();
44-
#ifdef Z_AFTER_PROBING
45-
probe.move_z_after_probing();
46-
#endif
44+
probe.move_z_after_probing();
4745
report_current_position();
4846
}
4947

‎Marlin/src/module/delta.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3)
233233
* This is like quick_home_xy() but for 3 towers.
234234
*/
235235
void home_delta() {
236-
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> home_delta", current_position);
236+
DEBUG_SECTION(log_home_delta, "home_delta", DEBUGGING(LEVELING));
237+
237238
// Init the current position of all carriages to 0,0,0
238239
current_position.reset();
239240
destination.reset();
@@ -283,8 +284,6 @@ void home_delta() {
283284
line_to_current_position(homing_feedrate(Z_AXIS));
284285
}
285286
#endif
286-
287-
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< home_delta", current_position);
288287
}
289288

290289
#endif // DELTA

‎Marlin/src/module/motion.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ void _internal_move_to_destination(const feedRate_t &fr_mm_s/*=0.0f*/
387387
* Plan a move to (X, Y, Z) and set the current_position
388388
*/
389389
void do_blocking_move_to(const float rx, const float ry, const float rz, const feedRate_t &fr_mm_s/*=0.0*/) {
390-
if (DEBUGGING(LEVELING)) DEBUG_XYZ(">>> do_blocking_move_to", rx, ry, rz);
390+
DEBUG_SECTION(log_move, "do_blocking_move_to", DEBUGGING(LEVELING));
391+
if (DEBUGGING(LEVELING)) DEBUG_XYZ("> ", rx, ry, rz);
391392

392393
const feedRate_t z_feedrate = fr_mm_s ?: homing_feedrate(Z_AXIS),
393394
xy_feedrate = fr_mm_s ?: feedRate_t(XY_PROBE_FEEDRATE_MM_S);
@@ -471,8 +472,6 @@ void do_blocking_move_to(const float rx, const float ry, const float rz, const f
471472

472473
#endif
473474

474-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< do_blocking_move_to");
475-
476475
planner.synchronize();
477476
}
478477

@@ -507,6 +506,13 @@ void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float &z, const feedRat
507506
do_blocking_move_to(raw.x, raw.y, z, fr_mm_s);
508507
}
509508

509+
void do_z_clearance(const float &zclear, const bool z_known/*=true*/, const bool raise_on_unknown/*=true*/, const bool lower_allowed/*=false*/) {
510+
const bool rel = raise_on_unknown && !z_known;
511+
float zdest = zclear + (rel ? current_position.z : 0.0f);
512+
if (!lower_allowed) NOLESS(zdest, current_position.z);
513+
do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(Z_PROBE_SPEED_FAST));
514+
}
515+
510516
//
511517
// Prepare to do endstop or probe moves with custom feedrates.
512518
// - Save / restore current feedrate and multiplier
@@ -1272,11 +1278,12 @@ feedRate_t get_homing_bump_feedrate(const AxisEnum axis) {
12721278
* Home an individual linear axis
12731279
*/
12741280
void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0) {
1281+
DEBUG_SECTION(log_move, "do_homing_move", DEBUGGING(LEVELING));
12751282

12761283
const feedRate_t real_fr_mm_s = fr_mm_s ?: homing_feedrate(axis);
12771284

12781285
if (DEBUGGING(LEVELING)) {
1279-
DEBUG_ECHOPAIR(">>> do_homing_move(", axis_codes[axis], ", ", distance, ", ");
1286+
DEBUG_ECHOPAIR("...(", axis_codes[axis], ", ", distance, ", ");
12801287
if (fr_mm_s)
12811288
DEBUG_ECHO(fr_mm_s);
12821289
else
@@ -1349,8 +1356,6 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t
13491356
// Re-enable stealthChop if used. Disable diag1 pin on driver.
13501357
TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states));
13511358
}
1352-
1353-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< do_homing_move(", axis_codes[axis], ")");
13541359
}
13551360

13561361
/**

‎Marlin/src/module/motion.h

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ void remember_feedrate_and_scaling();
234234
void remember_feedrate_scaling_off();
235235
void restore_feedrate_and_scaling();
236236

237+
void do_z_clearance(const float &zclear, const bool z_known=true, const bool raise_on_unknown=true, const bool lower_allowed=false);
238+
237239
//
238240
// Homing
239241
//

‎Marlin/src/module/probe.cpp

+7-28
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,10 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()
260260
* Raise Z to a minimum height to make room for a probe to move
261261
*/
262262
void Probe::do_z_raise(const float z_raise) {
263-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probe::move_z(", z_raise, ")");
264-
263+
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probe::do_z_raise(", z_raise, ")");
265264
float z_dest = z_raise;
266265
if (offset.z < 0) z_dest -= offset.z;
267-
268-
NOMORE(z_dest, Z_MAX_POS);
269-
270-
if (z_dest > current_position.z)
271-
do_blocking_move_to_z(z_dest);
266+
do_z_clearance(z_dest);
272267
}
273268

274269
FORCE_INLINE void probe_specific_action(const bool deploy) {
@@ -410,16 +405,6 @@ bool Probe::set_deployed(const bool deploy) {
410405
return false;
411406
}
412407

413-
#ifdef Z_AFTER_PROBING
414-
// After probing move to a preferred Z position
415-
void Probe::move_z_after_probing() {
416-
if (current_position.z != Z_AFTER_PROBING) {
417-
do_blocking_move_to_z(Z_AFTER_PROBING);
418-
current_position.z = Z_AFTER_PROBING;
419-
}
420-
}
421-
#endif
422-
423408
/**
424409
* @brief Used by run_z_probe to do a single Z probe move.
425410
*
@@ -439,7 +424,7 @@ bool Probe::set_deployed(const bool deploy) {
439424
* @return TRUE if the probe failed to trigger.
440425
*/
441426
bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
442-
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::probe_down_to_z", current_position);
427+
DEBUG_SECTION(log_probe, "Probe::probe_down_to_z", DEBUGGING(LEVELING));
443428

444429
#if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
445430
thermalManager.wait_for_bed_heating();
@@ -499,8 +484,6 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
499484
// Tell the planner where we actually are
500485
sync_plan_position();
501486

502-
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< Probe::probe_down_to_z", current_position);
503-
504487
return !probe_triggered;
505488
}
506489

@@ -513,8 +496,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
513496
* @return The Z position of the bed at the current XY or NAN on error.
514497
*/
515498
float Probe::run_z_probe(const bool sanity_check/*=true*/) {
516-
517-
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> Probe::run_z_probe", current_position);
499+
DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING));
518500

519501
auto try_to_probe = [&](PGM_P const plbl, const float &z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck, const float clearance) {
520502
// Do a first probe at the fast speed
@@ -527,7 +509,6 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
527509
if (probe_fail) DEBUG_ECHOPGM(" No trigger.");
528510
if (early_fail) DEBUG_ECHOPGM(" Triggered early.");
529511
DEBUG_EOL();
530-
DEBUG_POS("<<< run_z_probe", current_position);
531512
}
532513
#else
533514
UNUSED(plbl);
@@ -651,8 +632,6 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
651632

652633
#endif
653634

654-
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
655-
656635
return measured_z;
657636
}
658637

@@ -666,9 +645,11 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
666645
* - Return the probed Z position
667646
*/
668647
float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after/*=PROBE_PT_NONE*/, const uint8_t verbose_level/*=0*/, const bool probe_relative/*=true*/, const bool sanity_check/*=true*/) {
648+
DEBUG_SECTION(log_probe, "Probe::probe_at_point", DEBUGGING(LEVELING));
649+
669650
if (DEBUGGING(LEVELING)) {
670651
DEBUG_ECHOLNPAIR(
671-
">>> Probe::probe_at_point(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry),
652+
"...(", LOGICAL_X_POSITION(rx), ", ", LOGICAL_Y_POSITION(ry),
672653
", ", raise_after == PROBE_PT_RAISE ? "raise" : raise_after == PROBE_PT_STOW ? "stow" : "none",
673654
", ", int(verbose_level),
674655
", ", probe_relative ? "probe" : "nozzle", "_relative)"
@@ -729,8 +710,6 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
729710
#endif
730711
}
731712

732-
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< Probe::probe_at_point");
733-
734713
return measured_z;
735714
}
736715

‎Marlin/src/module/probe.h

+14-3
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,27 @@ class Probe {
7979

8080
#endif
8181

82-
#ifdef Z_AFTER_PROBING
83-
static void move_z_after_probing();
84-
#endif
82+
static inline void move_z_after_probing() {
83+
#ifdef Z_AFTER_PROBING
84+
do_z_clearance(Z_AFTER_PROBING, true, true, true); // Move down still permitted
85+
#endif
86+
}
87+
static inline void move_z_after_homing() {
88+
#ifdef Z_AFTER_HOMING
89+
do_z_clearance(Z_AFTER_HOMING, true, true, true);
90+
#elif defined(Z_AFTER_PROBING)
91+
move_z_after_probing();
92+
#endif
93+
}
8594
static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true);
8695
static inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true) {
8796
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
8897
}
8998

9099
#else
91100

101+
FORCE_INLINE static void move_z_after_homing() {}
102+
92103
static constexpr xyz_pos_t offset = xyz_pos_t({ 0, 0, 0 }); // See #16767
93104

94105
static bool set_deployed(const bool) { return false; }

0 commit comments

Comments
 (0)
Please sign in to comment.