2017-09-08 22:35:25 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-08 22:35:25 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-08 22:35:25 +02: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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-11-04 09:25:55 +01:00
|
|
|
#pragma once
|
2017-09-08 22:35:25 +02:00
|
|
|
|
|
|
|
/**
|
2020-02-01 11:21:36 +01:00
|
|
|
* module/probe.h - Move, deploy, enable, etc.
|
2017-09-08 22:35:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
2020-02-27 13:16:33 +01:00
|
|
|
#include "motion.h"
|
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#if HAS_BED_PROBE
|
2020-02-01 11:21:36 +01: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
|
|
|
|
PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
|
2018-04-12 04:14:48 +02:00
|
|
|
PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe
|
2018-03-21 07:01:43 +01:00
|
|
|
};
|
2020-02-01 11:21:36 +01:00
|
|
|
#endif
|
2019-09-25 04:29:21 +02:00
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
class Probe {
|
|
|
|
public:
|
2019-09-25 04:29:21 +02:00
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
#if HAS_BED_PROBE
|
2019-09-29 11:25:39 +02:00
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
static xyz_pos_t offset;
|
2019-09-25 04:29:21 +02:00
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
static bool set_deployed(const bool deploy);
|
|
|
|
|
2020-02-27 13:16:33 +01: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.
|
|
|
|
static inline bool can_reach(const float &rx, const float &ry) {
|
|
|
|
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go?
|
|
|
|
&& position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE)); // Can the nozzle also go near there?
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
FORCE_INLINE static bool can_reach(const float &rx, const float &ry) {
|
|
|
|
return position_is_reachable(rx, ry, MIN_PROBE_EDGE);
|
|
|
|
}
|
|
|
|
#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.
|
|
|
|
*/
|
|
|
|
static inline bool can_reach(const float &rx, const float &ry) {
|
|
|
|
return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
|
|
|
|
&& WITHIN(rx, min_x() - fslop, max_x() + fslop)
|
|
|
|
&& WITHIN(ry, min_y() - fslop, max_y() + fslop);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
#ifdef Z_AFTER_PROBING
|
|
|
|
static void move_z_after_probing();
|
|
|
|
#endif
|
2020-02-26 12:33:48 +01:00
|
|
|
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);
|
|
|
|
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) {
|
2020-02-28 02:58:35 +01:00
|
|
|
return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
|
2019-11-21 10:26:00 +01:00
|
|
|
}
|
2020-02-01 11:21:36 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2020-02-04 15:23:42 +01:00
|
|
|
static constexpr xyz_pos_t offset = xyz_pos_t({ 0, 0, 0 }); // See #16767
|
2020-02-01 11:21:36 +01:00
|
|
|
|
|
|
|
static bool set_deployed(const bool) { return false; }
|
|
|
|
|
2020-02-27 13:16:33 +01:00
|
|
|
FORCE_INLINE static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
|
|
|
|
|
2019-11-21 10:26:00 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-27 13:16:33 +01:00
|
|
|
FORCE_INLINE static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
|
|
|
|
|
|
|
|
FORCE_INLINE static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
|
|
|
|
return (
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
can_reach(lf.x, 0) && can_reach(rb.x, 0) && can_reach(0, lf.y) && can_reach(0, rb.y)
|
|
|
|
#else
|
|
|
|
can_reach(lf) && can_reach(rb)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-04 15:23:42 +01:00
|
|
|
// Use offset_xy for read only access
|
|
|
|
// More optimal the XY offset is known to always be zero.
|
|
|
|
#if HAS_PROBE_XY_OFFSET
|
|
|
|
static const xyz_pos_t &offset_xy;
|
|
|
|
#else
|
|
|
|
static constexpr xy_pos_t offset_xy = xy_pos_t({ 0, 0 }); // See #16767
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
static inline bool deploy() { return set_deployed(true); }
|
|
|
|
static inline bool stow() { return set_deployed(false); }
|
|
|
|
|
|
|
|
#if HAS_BED_PROBE || HAS_LEVELING
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
static constexpr float printable_radius = (
|
|
|
|
#if ENABLED(DELTA)
|
|
|
|
DELTA_PRINTABLE_RADIUS
|
|
|
|
#elif IS_SCARA
|
|
|
|
SCARA_PRINTABLE_RADIUS
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
static inline float probe_radius() {
|
|
|
|
return printable_radius - _MAX(MIN_PROBE_EDGE, HYPOT(offset_xy.x, offset_xy.y));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline float min_x() {
|
|
|
|
return (
|
2019-11-21 10:26:00 +01:00
|
|
|
#if IS_KINEMATIC
|
2020-02-01 11:21:36 +01:00
|
|
|
(X_CENTER) - probe_radius()
|
2019-11-21 10:26:00 +01:00
|
|
|
#else
|
2020-02-01 11:21:36 +01:00
|
|
|
_MAX((X_MIN_BED) + (MIN_PROBE_EDGE_LEFT), (X_MIN_POS) + offset_xy.x)
|
2019-11-21 10:26:00 +01:00
|
|
|
#endif
|
2020-02-01 11:21:36 +01:00
|
|
|
);
|
2019-11-21 10:26:00 +01:00
|
|
|
}
|
2020-02-01 11:21:36 +01:00
|
|
|
static inline float max_x() {
|
|
|
|
return (
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
(X_CENTER) + probe_radius()
|
|
|
|
#else
|
|
|
|
_MIN((X_MAX_BED) - (MIN_PROBE_EDGE_RIGHT), (X_MAX_POS) + offset_xy.x)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
static inline float min_y() {
|
|
|
|
return (
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
(Y_CENTER) - probe_radius()
|
|
|
|
#else
|
|
|
|
_MAX((Y_MIN_BED) + (MIN_PROBE_EDGE_FRONT), (Y_MIN_POS) + offset_xy.y)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
static inline float max_y() {
|
|
|
|
return (
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
(Y_CENTER) + probe_radius()
|
|
|
|
#else
|
|
|
|
_MIN((Y_MAX_BED) - (MIN_PROBE_EDGE_BACK), (Y_MAX_POS) + offset_xy.y)
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NEEDS_THREE_PROBE_POINTS
|
|
|
|
// Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used.
|
|
|
|
template <typename T>
|
|
|
|
static inline void get_three_points(T points[3]) {
|
2020-03-08 05:20:41 +01:00
|
|
|
#if HAS_FIXED_3POINT
|
2020-02-01 11:21:36 +01:00
|
|
|
points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y);
|
|
|
|
points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y);
|
|
|
|
points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y);
|
|
|
|
#else
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025,
|
|
|
|
COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5;
|
|
|
|
points[0].set((X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0);
|
|
|
|
points[1].set((X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120);
|
|
|
|
points[2].set((X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240);
|
|
|
|
#else
|
|
|
|
points[0].set(min_x(), min_y());
|
|
|
|
points[1].set(max_x(), min_y());
|
|
|
|
points[2].set((max_x() - min_x()) / 2, max_y());
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // HAS_BED_PROBE
|
|
|
|
|
|
|
|
#if HAS_Z_SERVO_PROBE
|
|
|
|
static void servo_probe_init();
|
2019-11-21 10:26:00 +01:00
|
|
|
#endif
|
2017-09-08 22:35:25 +02:00
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
#if QUIET_PROBING
|
|
|
|
static void set_probing_paused(const bool p);
|
|
|
|
#endif
|
2017-09-08 22:35:25 +02:00
|
|
|
|
2020-02-01 11:21:36 +01:00
|
|
|
private:
|
2020-02-09 00:47:54 +01:00
|
|
|
static bool probe_down_to_z(const float z, const feedRate_t fr_mm_s);
|
2020-02-01 11:21:36 +01:00
|
|
|
static void do_z_raise(const float z_raise);
|
2020-02-26 12:33:48 +01:00
|
|
|
static float run_z_probe(const bool sanity_check=true);
|
2020-02-01 11:21:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Probe probe;
|