Level Corners with Probe option (#20241)

This commit is contained in:
wmariz 2020-11-26 10:58:19 -03:00 committed by Scott Lahteine
parent 7c9c897dac
commit 747bde7e64
11 changed files with 211 additions and 69 deletions

View File

@ -1392,6 +1392,12 @@
#define LEVEL_CORNERS_HEIGHT 0.0 // (mm) Z height of nozzle at leveling points
#define LEVEL_CORNERS_Z_HOP 4.0 // (mm) Z height of nozzle between leveling points
//#define LEVEL_CENTER_TOO // Move to the center after the last corner
//#define LEVEL_CORNERS_USE_PROBE
#if ENABLED(LEVEL_CORNERS_USE_PROBE)
#define LEVEL_CORNERS_PROBE_TOLERANCE 0.1
#define LEVEL_CORNERS_VERIFY_RAISED // After adjustment triggers the probe, re-probe to verify
//#define LEVEL_CORNERS_AUDIO_FEEDBACK
#endif
#endif
/**

View File

@ -123,24 +123,22 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
}
#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
#if HAS_CUSTOM_PROBE_PIN
#define TEST_PROBE_PIN (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING)
#else
#define TEST_PROBE_PIN (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)
#endif
#include "../module/probe.h"
// Measure Z backlash by raising nozzle in increments until probe deactivates
void Backlash::measure_with_probe() {
if (measured_count.z == 255) return;
const float start_height = current_position.z;
while (current_position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && TEST_PROBE_PIN)
while (current_position.z < (start_height + BACKLASH_MEASUREMENT_LIMIT) && PROBE_TRIGGERED())
do_blocking_move_to_z(current_position.z + BACKLASH_MEASUREMENT_RESOLUTION, MMM_TO_MMS(BACKLASH_MEASUREMENT_FEEDRATE));
// The backlash from all probe points is averaged, so count the number of measurements
measured_mm.z += current_position.z - start_height;
measured_count.z++;
}
#endif
#endif // BACKLASH_COMPENSATION

View File

@ -31,6 +31,7 @@ BLTouch bltouch;
bool BLTouch::last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
#include "../module/servo.h"
#include "../module/probe.h"
void stop();
@ -90,15 +91,7 @@ void BLTouch::clear() {
_stow(); // STOW to be ready for meaningful work. Could fail, don't care
}
bool BLTouch::triggered() {
return (
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING
#else
READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING
#endif
);
}
bool BLTouch::triggered() { return PROBE_TRIGGERED(); }
bool BLTouch::deploy_proc() {
// Do a DEPLOY

View File

@ -143,14 +143,16 @@ inline void park_above_object(measurements_t &m, const float uncertainty) {
#endif
#if !PIN_EXISTS(CALIBRATION)
#include "../../module/probe.h"
#endif
inline bool read_calibration_pin() {
return (
#if PIN_EXISTS(CALIBRATION)
READ(CALIBRATION_PIN) != CALIBRATION_PIN_INVERTING
#elif HAS_CUSTOM_PROBE_PIN
READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING
#else
READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING
PROBE_TRIGGERED()
#endif
);
}

View File

@ -357,6 +357,8 @@
#error "LEVEL_CORNERS_INSET is now LEVEL_CORNERS_INSET_LFRB."
#elif ENABLED(LEVEL_BED_CORNERS) && !defined(LEVEL_CORNERS_INSET_LFRB)
#error "LEVEL_BED_CORNERS requires LEVEL_CORNERS_INSET_LFRB values."
#elif BOTH(LEVEL_CORNERS_USE_PROBE, SENSORLESS_PROBING)
#error "LEVEL_CORNERS_USE_PROBE is incompatible with SENSORLESS_PROBING."
#elif defined(BEZIER_JERK_CONTROL)
#error "BEZIER_JERK_CONTROL is now S_CURVE_ACCELERATION."
#elif HAS_JUNCTION_DEVIATION && defined(JUNCTION_DEVIATION_FACTOR)
@ -1603,7 +1605,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
* Allen Key
* Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis.
*/
#if ENABLED(Z_PROBE_ALLEN_KEY) && (Z_HOME_DIR < 0) && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
#if BOTH(Z_PROBE_ALLEN_KEY, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && (Z_HOME_DIR < 0)
#error "You can't home to a Z min endstop with a Z_PROBE_ALLEN_KEY."
#endif

View File

@ -125,6 +125,8 @@ namespace Language_en {
PROGMEM Language_Str MSG_BED_LEVELING = _UxGT("Bed Leveling");
PROGMEM Language_Str MSG_LEVEL_BED = _UxGT("Level Bed");
PROGMEM Language_Str MSG_LEVEL_CORNERS = _UxGT("Level Corners");
PROGMEM Language_Str MSG_LEVEL_CORNERS_RAISE = _UxGT("Raise Bed Until Probe Triggered");
PROGMEM Language_Str MSG_LEVEL_CORNERS_IN_RANGE = _UxGT("All Corners Within Tolerance. Level Bed");
PROGMEM Language_Str MSG_NEXT_CORNER = _UxGT("Next Corner");
PROGMEM Language_Str MSG_MESH_EDITOR = _UxGT("Mesh Editor");
PROGMEM Language_Str MSG_EDIT_MESH = _UxGT("Edit Mesh");
@ -379,6 +381,7 @@ namespace Language_en {
PROGMEM Language_Str MSG_BUTTON_DONE = _UxGT("Done");
PROGMEM Language_Str MSG_BUTTON_BACK = _UxGT("Back");
PROGMEM Language_Str MSG_BUTTON_PROCEED = _UxGT("Proceed");
PROGMEM Language_Str MSG_BUTTON_SKIP = _UxGT("Skip");
PROGMEM Language_Str MSG_PAUSING = _UxGT("Pausing...");
PROGMEM Language_Str MSG_PAUSE_PRINT = _UxGT("Pause Print");
PROGMEM Language_Str MSG_RESUME_PRINT = _UxGT("Resume Print");

View File

@ -44,53 +44,187 @@
#define LEVEL_CORNERS_HEIGHT 0.0
#endif
#if ENABLED(LEVEL_CORNERS_USE_PROBE)
#include "../../module/probe.h"
#include "../../module/endstops.h"
#if ENABLED(BLTOUCH)
#include "../../feature/bltouch.h"
#endif
#ifndef LEVEL_CORNERS_PROBE_TOLERANCE
#define LEVEL_CORNERS_PROBE_TOLERANCE 0.1
#endif
#if ENABLED(LEVEL_CORNERS_AUDIO_FEEDBACK)
#include "../../libs/buzzer.h"
#define PROBE_BUZZ() BUZZ(200, 600)
#else
#define PROBE_BUZZ() NOOP
#endif
static float last_z;
static bool corner_probing_done;
static bool verify_corner;
static int good_points;
#endif
static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration.");
extern const char G28_STR[];
#if HAS_LEVELING
static bool leveling_was_active = false;
#endif
static int8_t bed_corner;
/**
* Level corners, starting in the front-left corner.
*/
static int8_t bed_corner;
static inline void _lcd_goto_next_corner() {
constexpr float lfrb[4] = LEVEL_CORNERS_INSET_LFRB;
constexpr xy_pos_t lf { (X_MIN_BED) + lfrb[0], (Y_MIN_BED) + lfrb[1] },
rb { (X_MAX_BED) - lfrb[2], (Y_MAX_BED) - lfrb[3] };
line_to_z(LEVEL_CORNERS_Z_HOP);
switch (bed_corner) {
case 0: current_position = lf; break; // copy xy
case 1: current_position.x = rb.x; break;
case 2: current_position.y = rb.y; break;
case 3: current_position.x = lf.x; break;
#if ENABLED(LEVEL_CENTER_TOO)
case 4: current_position.set(X_CENTER, Y_CENTER); break;
#if ENABLED(LEVEL_CORNERS_USE_PROBE)
static inline void _lcd_level_bed_corners_probing() {
ui.goto_screen([]{ MenuItem_static::draw((LCD_HEIGHT - 1) / 2, GET_TEXT(MSG_PROBING_MESH)); });
float lfrb[4] = LEVEL_CORNERS_INSET_LFRB;
xy_pos_t lf { (X_MIN_BED) + lfrb[0] - probe.offset_xy.x , (Y_MIN_BED) + lfrb[1] - probe.offset_xy.y },
rb { (X_MAX_BED) - lfrb[2] - probe.offset_xy.x , (Y_MAX_BED) - lfrb[3] - probe.offset_xy.y };
do_blocking_move_to_z(LEVEL_CORNERS_Z_HOP - probe.offset.z);
switch (bed_corner) {
case 0: current_position = lf; break; // copy xy
case 1: current_position.x = rb.x; break;
case 2: current_position.y = rb.y; break;
case 3: current_position.x = lf.x; break;
#if ENABLED(LEVEL_CENTER_TOO)
case 4: current_position.set(X_CENTER - probe.offset_xy.x, Y_CENTER - probe.offset_xy.y); good_points--; break;
#endif
}
do_blocking_move_to_xy(current_position);
#if ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE)
bltouch.deploy(); // DEPLOY in LOW SPEED MODE on every probe action
#endif
TERN_(QUIET_PROBING, probe.set_probing_paused(true));
// Move down until the probe is triggered
do_blocking_move_to_z(last_z - (LEVEL_CORNERS_PROBE_TOLERANCE), manual_feedrate_mm_s.z);
// Check to see if the probe was triggered
bool probe_triggered = TEST(endstops.trigger_state(), TERN(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, Z_MIN, Z_MIN_PROBE));
if (!probe_triggered) {
static bool wait_for_probe;
ui.goto_screen([]{
MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_DONE), GET_TEXT(MSG_BUTTON_SKIP)
, []{ corner_probing_done = true;
wait_for_probe = false;
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
ui.goto_previous_screen_no_defer();
}
, []{ wait_for_probe = false; }
, GET_TEXT(MSG_LEVEL_CORNERS_RAISE)
, (const char*)nullptr, PSTR("")
);
});
ui.set_selection(true);
wait_for_probe = true;
while (wait_for_probe && !probe_triggered) {
probe_triggered = PROBE_TRIGGERED();
if (probe_triggered) PROBE_BUZZ();
idle();
}
wait_for_probe = false;
TERN_(LEVEL_CORNERS_VERIFY_RAISED, verify_corner = true);
}
TERN_(QUIET_PROBING, probe.set_probing_paused(false));
#if ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE)
bltouch.stow();
#endif
if (probe_triggered) {
endstops.hit_on_purpose();
if (!WITHIN(current_position.z, last_z - (LEVEL_CORNERS_PROBE_TOLERANCE), last_z + (LEVEL_CORNERS_PROBE_TOLERANCE))) {
last_z = current_position.z;
good_points = 0;
}
if (!verify_corner) good_points++;
}
if (!corner_probing_done) {
if (!verify_corner) bed_corner++;
if (bed_corner > 3) bed_corner = 0;
verify_corner = false;
if (good_points < 4)
_lcd_level_bed_corners_probing();
else {
ui.goto_screen([]{
MenuItem_confirm::confirm_screen(
[]{ ui.goto_previous_screen_no_defer();
queue.inject_P(TERN(HAS_LEVELING, PSTR("G28\nG29"), G28_STR));
}
, []{ ui.goto_previous_screen_no_defer(); }
, GET_TEXT(MSG_LEVEL_CORNERS_IN_RANGE)
, (const char*)nullptr, PSTR("?")
);
});
ui.set_selection(true);
}
}
}
line_to_current_position(manual_feedrate_mm_s.x);
line_to_z(LEVEL_CORNERS_HEIGHT);
if (++bed_corner > 3 + ENABLED(LEVEL_CENTER_TOO)) bed_corner = 0;
}
#else
static inline void _lcd_goto_next_corner() {
constexpr float lfrb[4] = LEVEL_CORNERS_INSET_LFRB;
constexpr xy_pos_t lf { (X_MIN_BED) + lfrb[0], (Y_MIN_BED) + lfrb[1] },
rb { (X_MAX_BED) - lfrb[2], (Y_MAX_BED) - lfrb[3] };
line_to_z(LEVEL_CORNERS_Z_HOP);
switch (bed_corner) {
case 0: current_position = lf; break; // copy xy
case 1: current_position.x = rb.x; break;
case 2: current_position.y = rb.y; break;
case 3: current_position.x = lf.x; break;
#if ENABLED(LEVEL_CENTER_TOO)
case 4: current_position.set(X_CENTER, Y_CENTER); break;
#endif
}
line_to_current_position(manual_feedrate_mm_s.x);
line_to_z(LEVEL_CORNERS_HEIGHT);
if (++bed_corner > 3 + ENABLED(LEVEL_CENTER_TOO)) bed_corner = 0;
}
#endif
static inline void _lcd_level_bed_corners_homing() {
_lcd_draw_homing();
if (all_axes_homed()) {
bed_corner = 0;
ui.goto_screen([]{
MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE)
, _lcd_goto_next_corner
, []{
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
ui.goto_previous_screen_no_defer();
}
, GET_TEXT(TERN(LEVEL_CENTER_TOO, MSG_LEVEL_BED_NEXT_POINT, MSG_NEXT_CORNER))
, (const char*)nullptr, PSTR("?")
);
});
ui.set_selection(true);
_lcd_goto_next_corner();
#if ENABLED(LEVEL_CORNERS_USE_PROBE)
TERN_(LEVEL_CENTER_TOO, bed_corner = 4);
endstops.enable_z_probe(true);
ui.goto_screen(_lcd_level_bed_corners_probing);
#else
bed_corner = 0;
ui.goto_screen([]{
MenuItem_confirm::select_screen(
GET_TEXT(MSG_BUTTON_NEXT), GET_TEXT(MSG_BUTTON_DONE)
, _lcd_goto_next_corner
, []{
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
ui.goto_previous_screen_no_defer();
}
, GET_TEXT(TERN(LEVEL_CENTER_TOO, MSG_LEVEL_BED_NEXT_POINT, MSG_NEXT_CORNER))
, (const char*)nullptr, PSTR("?")
);
});
ui.set_selection(true);
_lcd_goto_next_corner();
#endif
}
}
@ -107,6 +241,13 @@ void _lcd_level_bed_corners() {
set_bed_leveling_enabled(false);
#endif
#if ENABLED(LEVEL_CORNERS_USE_PROBE)
last_z = LEVEL_CORNERS_HEIGHT;
corner_probing_done = false;
verify_corner = false;
good_points = 0;
#endif
ui.goto_screen(_lcd_level_bed_corners_homing);
}

View File

@ -48,6 +48,10 @@
#include "../feature/joystick.h"
#endif
#if HAS_BED_PROBE
#include "probe.h"
#endif
Endstops endstops;
// private:
@ -455,7 +459,7 @@ void _O2 Endstops::report_states() {
ES_REPORT(Z4_MAX);
#endif
#if HAS_CUSTOM_PROBE_PIN
print_es_state(READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING, PSTR(STR_Z_PROBE));
print_es_state(PROBE_TRIGGERED(), PSTR(STR_Z_PROBE));
#endif
#if HAS_FILAMENT_SENSOR
#if NUM_RUNOUT_SENSORS == 1

View File

@ -270,13 +270,7 @@ FORCE_INLINE void probe_specific_action(const bool deploy) {
#if ENABLED(PAUSE_BEFORE_DEPLOY_STOW)
do {
#if ENABLED(PAUSE_PROBE_DEPLOY_WHEN_TRIGGERED)
if (deploy == (
#if HAS_CUSTOM_PROBE_PIN
READ(Z_MIN_PROBE_PIN) == Z_MIN_PROBE_ENDSTOP_INVERTING
#else
READ(Z_MIN_PIN) == Z_MIN_ENDSTOP_INVERTING
#endif
)) break;
if (deploy == PROBE_TRIGGERED()) break;
#endif
BUZZ(100, 659);
@ -375,23 +369,15 @@ bool Probe::set_deployed(const bool deploy) {
const xy_pos_t old_xy = current_position;
#if ENABLED(PROBE_TRIGGERED_WHEN_STOWED_TEST)
#if HAS_CUSTOM_PROBE_PIN
#define PROBE_STOWED() (READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING)
#else
#define PROBE_STOWED() (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)
#endif
#endif
#ifdef PROBE_STOWED
// Only deploy/stow if needed
if (PROBE_STOWED() == deploy) {
if (PROBE_TRIGGERED() == deploy) {
if (!deploy) endstops.enable_z_probe(false); // Switch off triggered when stowed probes early
// otherwise an Allen-Key probe can't be stowed.
probe_specific_action(deploy);
}
if (PROBE_STOWED() == deploy) { // Unchanged after deploy/stow action?
if (PROBE_TRIGGERED() == deploy) { // Unchanged after deploy/stow action?
if (IsRunning()) {
SERIAL_ERROR_MSG("Z-Probe failed");
LCD_ALERTMESSAGEPGM_P(PSTR("Err: ZPROBE"));

View File

@ -38,6 +38,12 @@
};
#endif
#if HAS_CUSTOM_PROBE_PIN
#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
class Probe {
public:

View File

@ -19,6 +19,7 @@ opt_set TEMP_SENSOR_1 -1
opt_set TEMP_SENSOR_BED 5
opt_enable VIKI2 SDSUPPORT ADAPTIVE_FAN_SLOWING NO_FAN_SLOWING_IN_PID_TUNING \
FIX_MOUNTED_PROBE AUTO_BED_LEVELING_BILINEAR G29_RETRY_AND_RECOVER Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \
LEVEL_BED_CORNERS LEVEL_CORNERS_USE_PROBE LEVEL_CORNERS_VERIFY_RAISED \
BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET BABYSTEP_ZPROBE_GFX_OVERLAY \
PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE SLOW_PWM_HEATERS PIDTEMPBED EEPROM_SETTINGS INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT \
Z_SAFE_HOMING ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE \