2017-09-08 20:35:25 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-08 20:35:25 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-08 20:35:25 +00:00
|
|
|
*
|
|
|
|
* 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
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-08 20:35:25 +00:00
|
|
|
*
|
|
|
|
*/
|
2018-11-04 08:25:55 +00:00
|
|
|
#pragma once
|
2017-09-08 20:35:25 +00:00
|
|
|
|
|
|
|
/**
|
2020-02-01 10:21:36 +00:00
|
|
|
* module/probe.h - Move, deploy, enable, etc.
|
2017-09-08 20:35:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2020-02-27 12:16:33 +00:00
|
|
|
#include "motion.h"
|
|
|
|
|
2017-09-08 20:35:25 +00:00
|
|
|
#if HAS_BED_PROBE
|
2020-02-01 10:21:36 +00:00
|
|
|
enum ProbePtRaise : uint8_t {
|
|
|
|
PROBE_PT_NONE, // No raise or stow after run_z_probe
|
|
|
|
PROBE_PT_STOW, // Do a complete stow after run_z_probe
|
2020-12-12 00:15:36 +00:00
|
|
|
PROBE_PT_LAST_STOW, // Stow for sure, even in BLTouch HS mode
|
2020-02-01 10:21:36 +00:00
|
|
|
PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
|
2018-04-12 02:14:48 +00:00
|
|
|
PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe
|
2018-03-21 06:01:43 +00:00
|
|
|
};
|
2020-02-01 10:21:36 +00:00
|
|
|
#endif
|
2019-09-25 02:29:21 +00:00
|
|
|
|
2021-07-29 04:24:30 +00:00
|
|
|
#if USES_Z_MIN_PROBE_PIN
|
2020-11-26 13:58:19 +00:00
|
|
|
#define PROBE_TRIGGERED() (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING)
|
|
|
|
#else
|
|
|
|
#define PROBE_TRIGGERED() (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)
|
|
|
|
#endif
|
|
|
|
|
2021-02-21 02:14:47 +00:00
|
|
|
#if ENABLED(PREHEAT_BEFORE_LEVELING)
|
|
|
|
#ifndef LEVELING_NOZZLE_TEMP
|
|
|
|
#define LEVELING_NOZZLE_TEMP 0
|
|
|
|
#endif
|
|
|
|
#ifndef LEVELING_BED_TEMP
|
|
|
|
#define LEVELING_BED_TEMP 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 10:21:36 +00:00
|
|
|
class Probe {
|
|
|
|
public:
|
2019-09-25 02:29:21 +00:00
|
|
|
|
2021-07-13 00:19:29 +00:00
|
|
|
#if ENABLED(SENSORLESS_PROBING)
|
|
|
|
typedef struct { bool x:1, y:1, z:1; } sense_bool_t;
|
|
|
|
static sense_bool_t test_sensitivity;
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 10:21:36 +00:00
|
|
|
#if HAS_BED_PROBE
|
2019-09-29 09:25:39 +00:00
|
|
|
|
2020-02-01 10:21:36 +00:00
|
|
|
static xyz_pos_t offset;
|
2019-09-25 02:29:21 +00:00
|
|
|
|
2020-12-20 04:02:38 +00:00
|
|
|
#if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING)
|
2021-04-24 00:14:49 +00:00
|
|
|
static void preheat_for_probing(const celsius_t hotend_temp, const celsius_t bed_temp);
|
2020-12-20 04:02:38 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-01 10:21:36 +00:00
|
|
|
static bool set_deployed(const bool deploy);
|
|
|
|
|
2020-02-27 12:16:33 +00:00
|
|
|
#if IS_KINEMATIC
|
|
|
|
|
|
|
|
#if HAS_PROBE_XY_OFFSET
|
|
|
|
// Return true if the both nozzle and the probe can reach the given point.
|
|
|
|
// Note: This won't work on SCARA since the probe offset rotates with the arm.
|
2021-04-01 22:59:57 +00:00
|
|
|
static bool can_reach(const_float_t rx, const_float_t ry) {
|
2020-02-27 12:16:33 +00:00
|
|
|
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go?
|
2020-06-03 01:41:50 +00:00
|
|
|
&& position_is_reachable(rx, ry, ABS(PROBING_MARGIN)); // Can the nozzle also go near there?
|
2020-02-27 12:16:33 +00:00
|
|
|
}
|
|
|
|
#else
|
2021-04-01 22:59:57 +00:00
|
|
|
static bool can_reach(const_float_t rx, const_float_t ry) {
|
2020-06-03 01:41:50 +00:00
|
|
|
return position_is_reachable(rx, ry, PROBING_MARGIN);
|
2020-02-27 12:16:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether the given position is within the bed, and whether the nozzle
|
|
|
|
* can reach the position required to put the probe at the given position.
|
|
|
|
*
|
|
|
|
* Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
|
|
|
|
* nozzle must be be able to reach +10,-10.
|
|
|
|
*/
|
2021-04-01 22:59:57 +00:00
|
|
|
static bool can_reach(const_float_t rx, const_float_t ry) {
|
2020-02-27 12:16:33 +00:00
|
|
|
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
|
2021-02-25 10:49:34 +00:00
|
|
|
&& COORDINATE_OKAY(rx, min_x() - fslop, max_x() + fslop)
|
|
|
|
&& COORDINATE_OKAY(ry, min_y() - fslop, max_y() + fslop);
|
2020-02-27 12:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-12-28 02:49:15 +00:00
|
|
|
static void move_z_after_probing() {
|
2020-07-09 02:44:21 +00:00
|
|
|
#ifdef Z_AFTER_PROBING
|
2021-02-25 16:09:00 +00:00
|
|
|
do_z_clearance(Z_AFTER_PROBING, true); // Move down still permitted
|
2020-07-09 02:44:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
2021-04-01 22:59:57 +00:00
|
|
|
static float probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true);
|
2020-12-28 02:49:15 +00:00
|
|
|
static 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) {
|
2020-02-28 01:58:35 +00:00
|
|
|
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
|
2019-11-21 09:26:00 +00:00
|
|
|
}
|
2020-02-01 10:21:36 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-06-05 07:18:47 +00:00
|
|
|
static constexpr xyz_pos_t offset = xyz_pos_t(LINEAR_AXIS_ARRAY(0, 0, 0, 0, 0, 0)); // See #16767
|
2020-02-01 10:21:36 +00:00
|
|
|
|
|
|
|
static bool set_deployed(const bool) { return false; }
|
|
|
|
|
2021-04-01 22:59:57 +00:00
|
|
|
static bool can_reach(const_float_t rx, const_float_t ry) { return position_is_reachable(rx, ry); }
|
2020-02-27 12:16:33 +00:00
|
|
|
|
2019-11-21 09:26:00 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-28 02:49:15 +00:00
|
|
|
static void move_z_after_homing() {
|
2020-10-04 21:47:06 +00:00
|
|
|
#ifdef Z_AFTER_HOMING
|
2021-02-25 16:09:00 +00:00
|
|
|
do_z_clearance(Z_AFTER_HOMING, true);
|
2020-12-28 02:49:15 +00:00
|
|
|
#elif BOTH(Z_AFTER_PROBING, HAS_BED_PROBE)
|
2020-10-04 21:47:06 +00:00
|
|
|
move_z_after_probing();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-28 02:49:15 +00:00
|
|
|
static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
|
2020-02-27 12:16:33 +00:00
|
|
|
|
2020-12-28 02:49:15 +00:00
|
|
|
static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
|
2020-02-27 12:16:33 +00:00
|
|
|
return (
|
|
|
|
#if IS_KINEMATIC
|
2020-11-24 23:38:13 +00:00
|
|
|
can_reach(lf.x, 0) && can_reach(rb.x, 0) && can_reach(0, lf.y) && can_reach(0, rb.y)
|
2020-02-27 12:16:33 +00:00
|
|
|
#else
|
2020-11-24 23:38:13 +00:00
|
|
|
can_reach(lf) && can_reach(rb)
|
2020-02-27 12:16:33 +00:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-04 14:23:42 +00:00
|
|
|
// Use offset_xy for read only access
|
|
|
|
// More optimal the XY offset is known to always be zero.
|
|
|
|
#if HAS_PROBE_XY_OFFSET
|
2020-11-24 23:38:13 +00:00
|
|
|
static const xy_pos_t &offset_xy;
|
2020-02-04 14:23:42 +00:00
|
|
|
#else
|
|
|
|
static constexpr xy_pos_t offset_xy = xy_pos_t({ 0, 0 }); // See #16767
|
|
|
|
#endif
|
|
|
|
|
2020-12-28 02:49:15 +00:00
|
|
|
static bool deploy() { return set_deployed(true); }
|
|
|
|
static bool stow() { return set_deployed(false); }
|
2020-02-01 10:21:36 +00:00
|
|
|
|
|
|
|
#if HAS_BED_PROBE || HAS_LEVELING
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
static constexpr float printable_radius = (
|
2020-10-18 20:53:12 +00:00
|
|
|
TERN_(DELTA, DELTA_PRINTABLE_RADIUS)
|
|
|
|
TERN_(IS_SCARA, SCARA_PRINTABLE_RADIUS)
|
2020-02-01 10:21:36 +00:00
|
|
|
);
|
2020-12-28 02:49:15 +00:00
|
|
|
static constexpr float probe_radius(const xy_pos_t &probe_offset_xy = offset_xy) {
|
|
|
|
return printable_radius - _MAX(PROBING_MARGIN, HYPOT(probe_offset_xy.x, probe_offset_xy.y));
|
2020-02-01 10:21:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-28 02:49:15 +00:00
|
|
|
static constexpr float _min_x(const xy_pos_t &probe_offset_xy = offset_xy) {
|
2020-10-18 20:53:12 +00:00
|
|
|
return TERN(IS_KINEMATIC,
|
2020-12-28 02:49:15 +00:00
|
|
|
(X_CENTER) - probe_radius(probe_offset_xy),
|
|
|
|
_MAX((X_MIN_BED) + (PROBING_MARGIN_LEFT), (X_MIN_POS) + probe_offset_xy.x)
|
|
|
|
);
|
2019-11-21 09:26:00 +00:00
|
|
|
}
|
2020-12-28 02:49:15 +00:00
|
|
|
static constexpr float _max_x(const xy_pos_t &probe_offset_xy = offset_xy) {
|
2020-10-18 20:53:12 +00:00
|
|
|
return TERN(IS_KINEMATIC,
|
2020-12-28 02:49:15 +00:00
|
|
|
(X_CENTER) + probe_radius(probe_offset_xy),
|
|
|
|
_MIN((X_MAX_BED) - (PROBING_MARGIN_RIGHT), (X_MAX_POS) + probe_offset_xy.x)
|
|
|
|
);
|
2020-02-01 10:21:36 +00:00
|
|
|
}
|
2020-12-28 02:49:15 +00:00
|
|
|
static constexpr float _min_y(const xy_pos_t &probe_offset_xy = offset_xy) {
|
2020-10-18 20:53:12 +00:00
|
|
|
return TERN(IS_KINEMATIC,
|
2020-12-28 02:49:15 +00:00
|
|
|
(Y_CENTER) - probe_radius(probe_offset_xy),
|
|
|
|
_MAX((Y_MIN_BED) + (PROBING_MARGIN_FRONT), (Y_MIN_POS) + probe_offset_xy.y)
|
|
|
|
);
|
2020-02-01 10:21:36 +00:00
|
|
|
}
|
2020-12-28 02:49:15 +00:00
|
|
|
static constexpr float _max_y(const xy_pos_t &probe_offset_xy = offset_xy) {
|
2020-10-18 20:53:12 +00:00
|
|
|
return TERN(IS_KINEMATIC,
|
2020-12-28 02:49:15 +00:00
|
|
|
(Y_CENTER) + probe_radius(probe_offset_xy),
|
|
|
|
_MIN((Y_MAX_BED) - (PROBING_MARGIN_BACK), (Y_MAX_POS) + probe_offset_xy.y)
|
|
|
|
);
|
2020-02-01 10:21:36 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:49:53 +00:00
|
|
|
static float min_x() { return _min_x() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.x)); }
|
|
|
|
static float max_x() { return _max_x() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.x)); }
|
|
|
|
static float min_y() { return _min_y() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.y)); }
|
|
|
|
static float max_y() { return _max_y() TERN_(NOZZLE_AS_PROBE, TERN_(HAS_HOME_OFFSET, - home_offset.y)); }
|
2020-12-28 02:49:15 +00:00
|
|
|
|
|
|
|
// constexpr helpers used in build-time static_asserts, relying on default probe offsets.
|
|
|
|
class build_time {
|
|
|
|
static constexpr xyz_pos_t default_probe_xyz_offset =
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
NOZZLE_TO_PROBE_OFFSET
|
|
|
|
#else
|
|
|
|
{ 0 }
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
static constexpr xy_pos_t default_probe_xy_offset = { default_probe_xyz_offset.x, default_probe_xyz_offset.y };
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr bool can_reach(float x, float y) {
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
return HYPOT2(x, y) <= sq(probe_radius(default_probe_xy_offset));
|
|
|
|
#else
|
2021-02-25 10:49:34 +00:00
|
|
|
return COORDINATE_OKAY(x, _min_x(default_probe_xy_offset) - fslop, _max_x(default_probe_xy_offset) + fslop)
|
|
|
|
&& COORDINATE_OKAY(y, _min_y(default_probe_xy_offset) - fslop, _max_y(default_probe_xy_offset) + fslop);
|
2020-12-28 02:49:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr bool can_reach(const xy_pos_t &point) { return can_reach(point.x, point.y); }
|
|
|
|
};
|
|
|
|
|
2020-02-01 10:21:36 +00:00
|
|
|
#if NEEDS_THREE_PROBE_POINTS
|
|
|
|
// Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used.
|
|
|
|
template <typename T>
|
2020-12-28 02:49:15 +00:00
|
|
|
static void get_three_points(T points[3]) {
|
2020-03-08 04:20:41 +00:00
|
|
|
#if HAS_FIXED_3POINT
|
2020-12-28 02:49:15 +00:00
|
|
|
#define VALIDATE_PROBE_PT(N) static_assert(Probe::build_time::can_reach(xy_pos_t{PROBE_PT_##N##_X, PROBE_PT_##N##_Y}), \
|
|
|
|
"PROBE_PT_" STRINGIFY(N) "_(X|Y) is unreachable using default NOZZLE_TO_PROBE_OFFSET and PROBING_MARGIN");
|
|
|
|
VALIDATE_PROBE_PT(1); VALIDATE_PROBE_PT(2); VALIDATE_PROBE_PT(3);
|
2021-06-05 07:18:47 +00:00
|
|
|
points[0] = xy_float_t({ PROBE_PT_1_X, PROBE_PT_1_Y });
|
|
|
|
points[1] = xy_float_t({ PROBE_PT_2_X, PROBE_PT_2_Y });
|
|
|
|
points[2] = xy_float_t({ PROBE_PT_3_X, PROBE_PT_3_Y });
|
2020-02-01 10:21:36 +00:00
|
|
|
#else
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025,
|
|
|
|
COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5;
|
2021-06-05 07:18:47 +00:00
|
|
|
points[0] = xy_float_t({ (X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0 });
|
|
|
|
points[1] = xy_float_t({ (X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120 });
|
|
|
|
points[2] = xy_float_t({ (X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240 });
|
2020-02-01 10:21:36 +00:00
|
|
|
#else
|
2021-06-05 07:18:47 +00:00
|
|
|
points[0] = xy_float_t({ min_x(), min_y() });
|
|
|
|
points[1] = xy_float_t({ max_x(), min_y() });
|
|
|
|
points[2] = xy_float_t({ (min_x() + max_x()) / 2, max_y() });
|
2020-02-01 10:21:36 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // HAS_BED_PROBE
|
|
|
|
|
|
|
|
#if HAS_Z_SERVO_PROBE
|
|
|
|
static void servo_probe_init();
|
2019-11-21 09:26:00 +00:00
|
|
|
#endif
|
2017-09-08 20:35:25 +00:00
|
|
|
|
2020-12-19 03:13:37 +00:00
|
|
|
#if HAS_QUIET_PROBING
|
2020-02-01 10:21:36 +00:00
|
|
|
static void set_probing_paused(const bool p);
|
|
|
|
#endif
|
2017-09-08 20:35:25 +00:00
|
|
|
|
2020-12-20 04:11:43 +00:00
|
|
|
#if ENABLED(PROBE_TARE)
|
2020-12-27 22:23:18 +00:00
|
|
|
static void tare_init();
|
2020-12-20 04:11:43 +00:00
|
|
|
static bool tare();
|
|
|
|
#endif
|
|
|
|
|
2021-07-13 00:19:29 +00:00
|
|
|
// Basic functions for Sensorless Homing and Probing
|
|
|
|
#if EITHER(SENSORLESS_HOMING, SENSORLESS_PROBING)
|
|
|
|
static void enable_stallguard_diag1();
|
|
|
|
static void disable_stallguard_diag1();
|
|
|
|
static void set_homing_current(const bool onoff);
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 10:21:36 +00:00
|
|
|
private:
|
2021-04-01 22:59:57 +00:00
|
|
|
static bool probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s);
|
2020-02-01 10:21:36 +00:00
|
|
|
static void do_z_raise(const float z_raise);
|
2020-02-26 11:33:48 +00:00
|
|
|
static float run_z_probe(const bool sanity_check=true);
|
2020-02-01 10:21:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Probe probe;
|