Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manual mesh bed levelling #5

Closed
wants to merge 11 commits into from
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ root = true
[{*.patch,syntax_test_*}]
trim_trailing_whitespace = false

[{*.c,*.cpp,*.h}]
[{*.c,*.cpp,*.h,*.ino}]
charset = utf-8

[{*.c,*.cpp,*.h,Makefile}]
[{*.c,*.cpp,*.h,*.ino,Makefile}]
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
Expand Down
6 changes: 5 additions & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@
* or (with LCD_BED_LEVELING) the LCD controller.
*/
//#define PROBE_MANUALLY
//#define MANUAL_PROBE_START_Z 0.2

/**
* A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
Expand Down Expand Up @@ -1409,6 +1408,11 @@
*/
//#define DEBUG_LEVELING_FEATURE

#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL, PROBE_MANUALLY)
// Set a height for the start of manual adjustment
#define MANUAL_PROBE_START_Z 0.2 // (mm) Comment out to use the last-measured height
#endif

#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL)
// Gradually reduce leveling correction until a set height is reached,
// at which point movement will be level to the machine's XY plane.
Expand Down
30 changes: 17 additions & 13 deletions Marlin/src/feature/bedlevel/bedlevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,28 @@ void reset_bed_level() {

void _manual_goto_xy(const xy_pos_t &pos) {

/**
* Get the Z final position for the point measurement
* MBL will use the current Z position (again) if there's any raise or
* a Z safe homing height, otherwise it will move across without any raise.
*/
#ifdef MANUAL_PROBE_START_Z
constexpr float startz = _MAX(0, MANUAL_PROBE_START_Z);
#if MANUAL_PROBE_HEIGHT > 0
do_blocking_move_to_xy_z(pos, MANUAL_PROBE_HEIGHT);
do_blocking_move_to_z(startz);
#else
do_blocking_move_to_xy_z(pos, startz);
#endif
#elif MANUAL_PROBE_HEIGHT > 0
const float prev_z = current_position.z;
do_blocking_move_to_xy_z(pos, MANUAL_PROBE_HEIGHT);
do_blocking_move_to_z(prev_z);
constexpr float finalz = _MAX(0, MANUAL_PROBE_START_Z);
#else
#warning "It's recommended to set some MANUAL_PROBE_START_Z value for manual leveling."
#if Z_CLEARANCE_BETWEEN_MANUAL_PROBES > 0
const float finalz = current_position.z;
#endif
#endif
#if Z_CLEARANCE_BETWEEN_MANUAL_PROBES > 0 // Move up, over, and back down
do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_MANUAL_PROBES);
do_blocking_move_to_z(finalz);
#elif defined(MANUAL_PROBE_START_Z) // Move over and back down
do_blocking_move_to_xy_z(pos, finalz);
#else // Move over
do_blocking_move_to_xy(pos);
#endif

current_position = pos;

TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
}

Expand Down
10 changes: 8 additions & 2 deletions Marlin/src/gcode/bedlevel/mbl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ void GcodeSuite::G29() {
_manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
}
else {
// One last "return to the bed" (as originally coded) at completion
current_position.z = MANUAL_PROBE_HEIGHT;
// Move to the after probing position
current_position.z = (
#ifdef Z_AFTER_PROBING
Z_AFTER_PROBING
#else
Z_CLEARANCE_BETWEEN_MANUAL_PROBES
#endif
);
line_to_current_position();
planner.synchronize();

Expand Down
15 changes: 6 additions & 9 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,6 @@
#endif
#endif // FILAMENT_RUNOUT_SENSOR

#if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
#undef PROBE_MANUALLY
#endif

#if ANY(HAS_BED_PROBE, PROBE_MANUALLY, MESH_BED_LEVELING)
#define PROBE_SELECTED 1
#endif

#if HAS_BED_PROBE
#if DISABLED(NOZZLE_AS_PROBE)
#define HAS_PROBE_XY_OFFSET 1
Expand Down Expand Up @@ -869,10 +861,15 @@
#define HAS_PROBING_PROCEDURE 1
#endif
#if !HAS_LEVELING
#undef PROBE_MANUALLY
#undef RESTORE_LEVELING_AFTER_G28
#undef ENABLE_LEVELING_AFTER_G28
#endif
#if !HAS_LEVELING || EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
#undef PROBE_MANUALLY
#endif
#if ANY(HAS_BED_PROBE, PROBE_MANUALLY, MESH_BED_LEVELING)
#define PROBE_SELECTED 1
#endif

#ifdef GRID_MAX_POINTS_X
#define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
Expand Down
14 changes: 10 additions & 4 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2910,9 +2910,9 @@
#define Z_CLEARANCE_BETWEEN_PROBES Z_HOMING_HEIGHT
#endif
#if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
#define MANUAL_PROBE_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_CLEARANCE_BETWEEN_PROBES
#else
#define MANUAL_PROBE_HEIGHT Z_HOMING_HEIGHT
#define Z_CLEARANCE_BETWEEN_MANUAL_PROBES Z_HOMING_HEIGHT
#endif
#ifndef Z_CLEARANCE_MULTI_PROBE
#define Z_CLEARANCE_MULTI_PROBE Z_CLEARANCE_BETWEEN_PROBES
Expand All @@ -2922,8 +2922,14 @@
#endif
#endif

#if !defined(MANUAL_PROBE_START_Z) && defined(Z_CLEARANCE_BETWEEN_PROBES)
#define MANUAL_PROBE_START_Z Z_CLEARANCE_BETWEEN_PROBES
// Define a starting height for measuring manual probe points
#ifndef MANUAL_PROBE_START_Z
#if EITHER(MESH_BED_LEVELING, PROBE_MANUALLY)
// Leave MANUAL_PROBE_START_Z undefined so the prior Z height will be used.
// Note: If Z_CLEARANCE_BETWEEN_MANUAL_PROBES is 0 there will be no raise between points
#elif ENABLED(AUTO_BED_LEVELING_UBL) && defined(Z_CLEARANCE_BETWEEN_PROBES)
#define MANUAL_PROBE_START_Z Z_CLEARANCE_BETWEEN_PROBES
#endif
#endif

#ifndef __SAM3X8E__ //todo: hal: broken hal encapsulation
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/menu/menu_bed_leveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@
// and allow the command queue to be processed.
//
// When G29 finishes the last move:
// - Raise Z to the "manual probe height"
// - Raise Z to the "Z after probing" height
// - Don't return until done.
//
// ** This blocks the command queue! **
//
void _lcd_level_bed_done() {
if (!ui.wait_for_move) {
#if MANUAL_PROBE_HEIGHT > 0 && DISABLED(MESH_BED_LEVELING)
#if Z_AFTER_PROBING > 0 && DISABLED(MESH_BED_LEVELING)
// Display "Done" screen and wait for moves to complete
line_to_z(MANUAL_PROBE_HEIGHT);
line_to_z(Z_AFTER_PROBING);
ui.synchronize(GET_TEXT(MSG_LEVEL_BED_DONE));
#endif
ui.goto_previous_screen_no_defer();
Expand Down
2 changes: 1 addition & 1 deletion ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ HAS_L64XX = Arduino-L6470@0.8.0
NEOPIXEL_LED = Adafruit NeoPixel@1.5.0
src_filter=+<src/feature/leds/neopixel.cpp>
TEMP_.+_IS_MAX31865 = Adafruit MAX31865 library@~1.1.0
USES_LIQUIDCRYSTAL = bitbucket-fmalpartida/LiquidCrystal@1.5.0
USES_LIQUIDCRYSTAL = arduino-libraries/LiquidCrystal@^1.0.7
USES_LIQUIDCRYSTAL_I2C = marcoschwartz/LiquidCrystal_I2C@1.1.4
USES_LIQUIDTWI2 = LiquidTWI2@1.2.7
HAS_WIRED_LCD = src_filter=+<src/lcd/lcdprint.cpp>
Expand Down
1 change: 0 additions & 1 deletion ini/lpc176x.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extra_scripts = ${common.extra_scripts}
src_filter = ${common.default_src_filter} +<src/HAL/LPC1768> +<src/HAL/shared/backtrace>
lib_deps = ${common.lib_deps}
Servo
custom_marlin.USES_LIQUIDCRYSTAL = arduino-libraries/LiquidCrystal@~1.0.7
custom_marlin.NEOPIXEL_LED = Adafruit NeoPixel=https://github.com/p3p/Adafruit_NeoPixel/archive/1.5.0.zip
build_flags = ${common.build_flags} -DU8G_HAL_LINKS -IMarlin/src/HAL/LPC1768/include -IMarlin/src/HAL/LPC1768/u8g
# debug options for backtrace
Expand Down
1 change: 0 additions & 1 deletion ini/stm32f1.ini
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ extra_scripts = ${common_stm32f1.extra_scripts}
platform = ${common_stm32f1.platform}
extends = common_stm32f1
board = genericSTM32F103RC
platform_packages = tool-stm32duino
extra_scripts = ${common_stm32f1.extra_scripts}
buildroot/share/PlatformIO/scripts/mks_robin_e3.py
build_flags = ${common_stm32f1.build_flags}
Expand Down