Skip to content

Commit

Permalink
Consolidate probe clearance, add section debug (MarlinFirmware#18576)
Browse files Browse the repository at this point in the history
* Better section / function log
* Add do_z_clearance motion function
  • Loading branch information
thinkyhead committed Jul 9, 2020
1 parent 0eab9fc commit 73fc077
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 131 deletions.
9 changes: 9 additions & 0 deletions Marlin/src/core/debug_out.h
Expand Up @@ -26,6 +26,7 @@
// (or not) in a given .cpp file
//

#undef DEBUG_SECTION
#undef DEBUG_PRINT_P
#undef DEBUG_ECHO_START
#undef DEBUG_ERROR_START
Expand Down Expand Up @@ -53,6 +54,10 @@
#undef DEBUG_DELAY

#if DEBUG_OUT

#include "debug_section.h"
#define DEBUG_SECTION(N,S,D) SectionLog N(PSTR(S),D)

#define DEBUG_PRINT_P(P) serialprintPGM(P)
#define DEBUG_ECHO_START SERIAL_ECHO_START
#define DEBUG_ERROR_START SERIAL_ERROR_START
Expand All @@ -78,7 +83,10 @@
#define DEBUG_POS SERIAL_POS
#define DEBUG_XYZ SERIAL_XYZ
#define DEBUG_DELAY(ms) serial_delay(ms)

#else

#define DEBUG_SECTION(...) NOOP
#define DEBUG_PRINT_P(P) NOOP
#define DEBUG_ECHO_START() NOOP
#define DEBUG_ERROR_START() NOOP
Expand All @@ -104,6 +112,7 @@
#define DEBUG_POS(...) NOOP
#define DEBUG_XYZ(...) NOOP
#define DEBUG_DELAY(...) NOOP

#endif

#undef DEBUG_OUT
49 changes: 49 additions & 0 deletions Marlin/src/core/debug_section.h
@@ -0,0 +1,49 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "serial.h"
#include "../module/motion.h"

class SectionLog {
public:
SectionLog(PGM_P const msg=nullptr, bool inbug=true) {
the_msg = msg;
if ((debug = inbug)) echo_msg(PSTR(">>>"));
}

~SectionLog() { if (debug) echo_msg(PSTR("<<<")); }

private:
PGM_P the_msg;
bool debug;

void echo_msg(PGM_P const pre) {
serialprintPGM(pre);
if (the_msg) {
SERIAL_CHAR(' ');
serialprintPGM(the_msg);
}
SERIAL_CHAR(' ');
print_xyz(current_position);
}
};
21 changes: 7 additions & 14 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Expand Up @@ -462,7 +462,7 @@
// Manually Probe Mesh in areas that can't be reached by the probe
//
SERIAL_ECHOLNPGM("Manually probing unreachable points.");
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);

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

Expand Down Expand Up @@ -780,9 +780,7 @@
probe.stow();
TERN_(HAS_LCD_MENU, ui.capture());

#ifdef Z_AFTER_PROBING
probe.move_z_after_probing();
#endif
probe.move_z_after_probing();

restore_ubl_active_state_and_leave();

Expand Down Expand Up @@ -858,7 +856,6 @@
echo_and_take_a_measurement();

const float z2 = measure_point_with_encoder();

do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);

const float thickness = ABS(z1 - z2);
Expand Down Expand Up @@ -899,7 +896,7 @@
LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);

do_blocking_move_to(ppos);
do_blocking_move_to_z(z_clearance);
do_z_clearance(z_clearance);

KEEPALIVE_STATE(PAUSED_FOR_USER);
ui.capture();
Expand All @@ -915,7 +912,7 @@

if (click_and_hold()) {
SERIAL_ECHOLNPGM("\nMesh only partially populated.");
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
return restore_ubl_active_state_and_leave();
}

Expand All @@ -940,7 +937,7 @@

void abort_fine_tune() {
ui.return_to_status();
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED));
}

Expand Down Expand Up @@ -1415,9 +1412,7 @@
}

probe.stow();
#ifdef Z_AFTER_PROBING
probe.move_z_after_probing();
#endif
probe.move_z_after_probing();

if (abort_flag) {
SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
Expand Down Expand Up @@ -1478,9 +1473,7 @@
}
}
probe.stow();
#ifdef Z_AFTER_PROBING
probe.move_z_after_probing();
#endif
probe.move_z_after_probing();

if (abort_flag || finish_incremental_LSF(&lsf_results)) {
SERIAL_ECHOPGM("Could not complete LSF!");
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/gcode/bedlevel/G26.cpp
Expand Up @@ -622,8 +622,7 @@ void GcodeSuite::G26() {
*/
set_bed_leveling_enabled(!parser.seen('D'));

if (current_position.z < Z_CLEARANCE_BETWEEN_PROBES)
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);

#if DISABLED(NO_VOLUMETRICS)
bool volumetric_was_enabled = parser.volumetric_enabled;
Expand Down
9 changes: 3 additions & 6 deletions Marlin/src/gcode/bedlevel/G35.cpp
Expand Up @@ -75,10 +75,9 @@ static_assert(G35_PROBE_COUNT > 2, "TRAMMING_POINT_XY requires at least 3 XY pos
* 51 - Counter-Clockwise M5
**/
void GcodeSuite::G35() {
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOLNPGM(">>> G35");
log_machine_info();
}
DEBUG_SECTION(log_G35, "G35", DEBUGGING(LEVELING));

if (DEBUGGING(LEVELING)) log_machine_info();

float z_measured[G35_PROBE_COUNT] = { 0 };

Expand Down Expand Up @@ -181,8 +180,6 @@ void GcodeSuite::G35() {

// Home Z after the alignment procedure
process_subcommands_now_P(PSTR("G28Z"));

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G35");
}

#endif // ASSISTED_TRAMMING
14 changes: 5 additions & 9 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Expand Up @@ -172,10 +172,8 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
const uint8_t old_debug_flags = marlin_debug_flags;
if (seenQ) marlin_debug_flags |= MARLIN_DEBUG_LEVELING;
if (DEBUGGING(LEVELING)) {
DEBUG_POS(">>> G29", current_position);
log_machine_info();
}
DEBUG_SECTION(log_G29, "G29", DEBUGGING(LEVELING));
if (DEBUGGING(LEVELING)) log_machine_info();
marlin_debug_flags = old_debug_flags;
if (DISABLED(PROBE_MANUALLY) && seenQ) G29_RETURN(false);
#endif
Expand All @@ -188,7 +186,7 @@ G29_TYPE GcodeSuite::G29() {
if (axis_unhomed_error()) G29_RETURN(false);

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

Expand Down Expand Up @@ -416,7 +414,7 @@ G29_TYPE GcodeSuite::G29() {
// Deploy certain probes before starting probing
#if HAS_BED_PROBE
if (ENABLED(BLTOUCH))
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
else if (probe.deploy()) {
set_bed_leveling_enabled(abl_should_enable);
G29_RETURN(false);
Expand Down Expand Up @@ -884,7 +882,7 @@ G29_TYPE GcodeSuite::G29() {
// Sync the planner from the current_position
if (planner.leveling_active) sync_plan_position();

#if HAS_BED_PROBE && defined(Z_AFTER_PROBING)
#if HAS_BED_PROBE
probe.move_z_after_probing();
#endif

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

report_current_position();

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");

G29_RETURN(isnan(measured_z));
}

Expand Down
49 changes: 13 additions & 36 deletions Marlin/src/gcode/calibrate/G28.cpp
Expand Up @@ -115,11 +115,11 @@
#if ENABLED(Z_SAFE_HOMING)

inline void home_z_safely() {
DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING));

// Disallow Z homing if X or Y homing is needed
if (axis_unhomed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return;

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("home_z_safely >>>");

sync_plan_position();

/**
Expand All @@ -146,8 +146,6 @@
LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
SERIAL_ECHO_MSG(STR_ZPROBE_OUT_SER);
}

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< home_z_safely");
}

#endif // Z_SAFE_HOMING
Expand Down Expand Up @@ -197,15 +195,10 @@
*
*/
void GcodeSuite::G28() {
DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
if (DEBUGGING(LEVELING)) log_machine_info();

if (DEBUGGING(LEVELING)) {
DEBUG_ECHOLNPGM(">>> G28");
log_machine_info();
}

#if ENABLED(LASER_MOVE_G28_OFF)
cutter.set_inline_enabled(false); // turn off laser
#endif
TERN_(LASER_MOVE_G28_OFF, cutter.set_inline_enabled(false)); // turn off laser

TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);

Expand All @@ -220,14 +213,13 @@ void GcodeSuite::G28() {
sync_plan_position();
SERIAL_ECHOLNPGM("Simulated Homing");
report_current_position();
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");
return;
}
#endif

// Home (O)nly if position is unknown
if (!homing_needed() && parser.boolval('O')) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip\n<<< G28");
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip");
return;
}

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

destination = current_position;

#if Z_HOME_DIR > 0 // If homing away from BED do Z first

if (doZ) homeaxis(Z_AXIS);

#endif

const float z_homing_height =
(DISABLED(UNKNOWN_Z_NO_RAISE) || TEST(axis_known_position, Z_AXIS))
? (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
: 0;
ENABLED(UNKNOWN_Z_NO_RAISE) && TEST(axis_known_position, Z_AXIS)
? 0
: (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT);

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

#if ENABLED(QUICK_HOME)
Expand Down Expand Up @@ -387,15 +374,7 @@ void GcodeSuite::G28() {

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

#if HOMING_Z_WITH_PROBE && defined(Z_AFTER_PROBING)
#if Z_AFTER_HOMING > Z_AFTER_PROBING
do_blocking_move_to_z(Z_AFTER_HOMING);
#else
probe.move_z_after_probing();
#endif
#elif defined(Z_AFTER_HOMING)
do_blocking_move_to_z(Z_AFTER_HOMING);
#endif
probe.move_z_after_homing();

} // doZ

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

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G28");

#if HAS_L64XX
// Set L6470 absolute position registers to counts
// constexpr *might* move this to PROGMEM.
Expand Down
8 changes: 2 additions & 6 deletions Marlin/src/gcode/calibrate/G34_M422.cpp
Expand Up @@ -56,10 +56,8 @@
* R<recalculate> points based on current probe offsets
*/
void GcodeSuite::G34() {
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOLNPGM(">>> G34");
log_machine_info();
}
DEBUG_SECTION(log_G34, "G34", DEBUGGING(LEVELING));
if (DEBUGGING(LEVELING)) log_machine_info();

do { // break out on error

Expand Down Expand Up @@ -367,8 +365,6 @@ void GcodeSuite::G34() {
#endif

}while(0);

if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G34");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G76_M871.cpp
Expand Up @@ -104,7 +104,7 @@ void GcodeSuite::G76() {
};

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

0 comments on commit 73fc077

Please sign in to comment.