Skip to content

Commit

Permalink
Level Corners with Probe option (MarlinFirmware#20241)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmariz authored and vgadreau committed Dec 9, 2020
1 parent 6c59e76 commit 6deb27b
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 69 deletions.
6 changes: 6 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,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

/**
Expand Down
10 changes: 4 additions & 6 deletions Marlin/src/feature/backlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 2 additions & 9 deletions Marlin/src/feature/bltouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/gcode/calibrate/G425.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
205 changes: 173 additions & 32 deletions Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#include "../feature/joystick.h"
#endif

#if HAS_BED_PROBE
#include "probe.h"
#endif

Endstops endstops;

// private:
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6deb27b

Please sign in to comment.