Consolidate probe clearance, add section debug (#18576)
* Better section / function log * Add do_z_clearance motion function
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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 };
 | 
			
		||||
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -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);
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
@@ -900,8 +898,6 @@ G29_TYPE GcodeSuite::G29() {
 | 
			
		||||
 | 
			
		||||
  report_current_position();
 | 
			
		||||
 | 
			
		||||
  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
 | 
			
		||||
 | 
			
		||||
  G29_RETURN(isnan(measured_z));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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);
 | 
			
		||||
 | 
			
		||||
@@ -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;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -313,8 +305,6 @@ 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);
 | 
			
		||||
@@ -322,17 +312,14 @@ void GcodeSuite::G28() {
 | 
			
		||||
    #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)
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
@@ -367,8 +365,6 @@ void GcodeSuite::G34() {
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
  }while(0);
 | 
			
		||||
 | 
			
		||||
  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G34");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -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.");
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@
 | 
			
		||||
   * M666: Set delta endstop adjustment
 | 
			
		||||
   */
 | 
			
		||||
  void GcodeSuite::M666() {
 | 
			
		||||
    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> M666");
 | 
			
		||||
    DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING));
 | 
			
		||||
    LOOP_XYZ(i) {
 | 
			
		||||
      if (parser.seen(XYZ_CHAR(i))) {
 | 
			
		||||
        const float v = parser.value_linear_units();
 | 
			
		||||
@@ -46,7 +46,6 @@
 | 
			
		||||
        if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", XYZ_CHAR(i), "] = ", delta_endstop_adj[i]);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< M666");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#elif HAS_EXTRA_ENDSTOPS
 | 
			
		||||
 
 | 
			
		||||
@@ -48,10 +48,8 @@
 | 
			
		||||
 */
 | 
			
		||||
void GcodeSuite::T(const uint8_t tool_index) {
 | 
			
		||||
 | 
			
		||||
  if (DEBUGGING(LEVELING)) {
 | 
			
		||||
    DEBUG_ECHOLNPAIR(">>> T(", tool_index, ")");
 | 
			
		||||
    DEBUG_POS("BEFORE", current_position);
 | 
			
		||||
  }
 | 
			
		||||
  DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
 | 
			
		||||
  if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("...(", tool_index, ")");
 | 
			
		||||
 | 
			
		||||
  // Count this command as movement / activity
 | 
			
		||||
  reset_stepper_timeout();
 | 
			
		||||
@@ -75,9 +73,4 @@ void GcodeSuite::T(const uint8_t tool_index) {
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  if (DEBUGGING(LEVELING)) {
 | 
			
		||||
    DEBUG_POS("AFTER", current_position);
 | 
			
		||||
    DEBUG_ECHOLNPGM("<<< T()");
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -57,9 +57,8 @@ void GcodeSuite::G30() {
 | 
			
		||||
 | 
			
		||||
  restore_feedrate_and_scaling();
 | 
			
		||||
 | 
			
		||||
  #ifdef Z_AFTER_PROBING
 | 
			
		||||
    if (raise_after == PROBE_PT_STOW) probe.move_z_after_probing();
 | 
			
		||||
  #endif
 | 
			
		||||
  if (raise_after == PROBE_PT_STOW)
 | 
			
		||||
    probe.move_z_after_probing();
 | 
			
		||||
 | 
			
		||||
  report_current_position();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -41,9 +41,7 @@ void GcodeSuite::M401() {
 | 
			
		||||
 */
 | 
			
		||||
void GcodeSuite::M402() {
 | 
			
		||||
  probe.stow();
 | 
			
		||||
  #ifdef Z_AFTER_PROBING
 | 
			
		||||
    probe.move_z_after_probing();
 | 
			
		||||
  #endif
 | 
			
		||||
  probe.move_z_after_probing();
 | 
			
		||||
  report_current_position();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user