Skip to content

Commit e0b0224

Browse files
mwinters-stuffvgadreau
authored andcommitted
Z Probe Offset Wizard (MarlinFirmware#18866)
1 parent 926b20c commit e0b0224

File tree

6 files changed

+162
-1
lines changed

6 files changed

+162
-1
lines changed

Marlin/Configuration_adv.h

+8
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,14 @@
10481048

10491049
#if HAS_LCD_MENU
10501050

1051+
// Add Probe Z Offset calibration to the Bed Leveling menu
1052+
#if HAS_BED_PROBE
1053+
//#define PROBE_OFFSET_WIZARD
1054+
#if ENABLED(PROBE_OFFSET_WIZARD)
1055+
#define PROBE_OFFSET_START -4.0 // Estimated nozzle-to-probe Z offset, plus a little extra
1056+
#endif
1057+
#endif
1058+
10511059
// Include a page of printer information in the LCD Main Menu
10521060
//#define LCD_INFO_MENU
10531061
#if ENABLED(LCD_INFO_MENU)

Marlin/src/lcd/language/language_en.h

+3
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ namespace Language_en {
445445
PROGMEM Language_Str MSG_ZPROBE_XOFFSET = _UxGT("Probe X Offset");
446446
PROGMEM Language_Str MSG_ZPROBE_YOFFSET = _UxGT("Probe Y Offset");
447447
PROGMEM Language_Str MSG_ZPROBE_ZOFFSET = _UxGT("Probe Z Offset");
448+
PROGMEM Language_Str MSG_MOVE_NOZZLE_TO_BED = _UxGT("Move Nozzle to Bed");
448449
PROGMEM Language_Str MSG_BABYSTEP_X = _UxGT("Babystep X");
449450
PROGMEM Language_Str MSG_BABYSTEP_Y = _UxGT("Babystep Y");
450451
PROGMEM Language_Str MSG_BABYSTEP_Z = _UxGT("Babystep Z");
@@ -653,6 +654,8 @@ namespace Language_en {
653654
#endif
654655
PROGMEM Language_Str MSG_REHEAT = _UxGT("Reheat");
655656
PROGMEM Language_Str MSG_REHEATING = _UxGT("Reheating...");
657+
658+
PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Z Probe Wizard");
656659
}
657660

658661
#if FAN_COUNT == 1

Marlin/src/lcd/menu/menu.h

+4
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ void _lcd_draw_homing();
219219
void _lcd_zoffset_overlay_gfx(const float zvalue);
220220
#endif
221221

222+
#if ENABLED(PROBE_OFFSET_WIZARD)
223+
void goto_probe_offset_wizard();
224+
#endif
225+
222226
#if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
223227
void _lcd_toggle_bed_leveling();
224228
#endif

Marlin/src/lcd/menu/menu_bed_leveling.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ void menu_bed_leveling() {
283283
EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
284284
#endif
285285

286+
#if ENABLED(PROBE_OFFSET_WIZARD)
287+
SUBMENU(MSG_PROBE_WIZARD, goto_probe_offset_wizard);
288+
#endif
289+
286290
#if ENABLED(LEVEL_BED_CORNERS)
287291
SUBMENU(MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
288292
#endif
+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
//
24+
// Calibrate Probe offset menu.
25+
//
26+
27+
#include "../../inc/MarlinConfigPre.h"
28+
29+
#if ENABLED(PROBE_OFFSET_WIZARD)
30+
31+
#ifndef PROBE_OFFSET_START
32+
#error "PROBE_OFFSET_WIZARD requires a PROBE_OFFSET_START with a negative value."
33+
#else
34+
static_assert(PROBE_OFFSET_START < 0, "PROBE_OFFSET_START must be < 0. Please update your configuration.");
35+
#endif
36+
37+
#include "menu_item.h"
38+
#include "menu_addon.h"
39+
#include "../../module/motion.h"
40+
#include "../../module/planner.h"
41+
#include "../../module/probe.h"
42+
43+
#if HAS_LEVELING
44+
#include "../../feature/bedlevel/bedlevel.h"
45+
#endif
46+
47+
// Global storage
48+
float z_offset_backup, calculated_z_offset;
49+
50+
TERN_(HAS_LEVELING, bool leveling_was_active);
51+
TERN_(HAS_SOFTWARE_ENDSTOPS, bool store_soft_endstops_enabled);
52+
53+
void prepare_for_calibration() {
54+
z_offset_backup = probe.offset.z;
55+
56+
// Disable soft endstops for free Z movement
57+
#if HAS_SOFTWARE_ENDSTOPS
58+
store_soft_endstops_enabled = soft_endstops_enabled;
59+
soft_endstops_enabled = false;
60+
#endif
61+
62+
// Disable leveling for raw planner motion
63+
#if HAS_LEVELING
64+
leveling_was_active = planner.leveling_active;
65+
set_bed_leveling_enabled(false);
66+
#endif
67+
}
68+
69+
void set_offset_and_go_back(const float &z) {
70+
probe.offset.z = z;
71+
TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = store_soft_endstops_enabled);
72+
TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
73+
ui.goto_previous_screen_no_defer();
74+
}
75+
76+
void _goto_manual_move_z(const float scale) {
77+
ui.manual_move.menu_scale = scale;
78+
ui.goto_screen(lcd_move_z);
79+
}
80+
81+
void probe_offset_wizard_menu() {
82+
START_MENU();
83+
calculated_z_offset = probe.offset.z + current_position.z;
84+
85+
if (LCD_HEIGHT >= 4)
86+
STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
87+
88+
STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
89+
STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
90+
91+
SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
92+
SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
93+
94+
if ((SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
95+
extern const char NUL_STR[];
96+
SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(SHORT_MANUAL_Z_MOVE)); });
97+
MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD));
98+
char tmp[20], numstr[10];
99+
// Determine digits needed right of decimal
100+
const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
101+
!UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
102+
sprintf_P(tmp, GET_TEXT(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
103+
lcd_put_u8str(tmp);
104+
MENU_ITEM_ADDON_END();
105+
}
106+
107+
ACTION_ITEM(MSG_BUTTON_DONE, []{
108+
set_offset_and_go_back(calculated_z_offset);
109+
do_z_clearance(20.0
110+
#ifdef Z_AFTER_HOMING
111+
- 20.0 + Z_AFTER_HOMING
112+
#endif
113+
);
114+
});
115+
116+
ACTION_ITEM(MSG_BUTTON_CANCEL, []{
117+
set_offset_and_go_back(z_offset_backup);
118+
});
119+
120+
END_MENU();
121+
}
122+
123+
void goto_probe_offset_wizard() {
124+
ui.defer_status_screen();
125+
126+
prepare_for_calibration();
127+
128+
probe.offset.z = PROBE_OFFSET_START;
129+
130+
set_all_unhomed();
131+
queue.inject_P(G28_STR);
132+
133+
ui.goto_screen([]{
134+
_lcd_draw_homing();
135+
if (all_axes_homed()) {
136+
ui.goto_screen(probe_offset_wizard_menu);
137+
ui.defer_status_screen();
138+
}
139+
});
140+
}
141+
142+
#endif // PROBE_OFFSET_WIZARD

buildroot/tests/mega2560-tests

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ opt_enable COREYX USE_XMAX_PLUG MIXING_EXTRUDER GRADIENT_MIX \
139139
BABYSTEPPING BABYSTEP_DISPLAY_TOTAL FILAMENT_LCD_DISPLAY \
140140
REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER MENU_ADDAUTOSTART SDSUPPORT SDCARD_SORT_ALPHA \
141141
ENDSTOP_NOISE_THRESHOLD FAN_SOFT_PWM \
142-
FIX_MOUNTED_PROBE AUTO_BED_LEVELING_LINEAR DEBUG_LEVELING_FEATURE FILAMENT_WIDTH_SENSOR \
142+
FIX_MOUNTED_PROBE AUTO_BED_LEVELING_LINEAR DEBUG_LEVELING_FEATURE FILAMENT_WIDTH_SENSOR PROBE_OFFSET_WIZARD \
143143
Z_SAFE_HOMING SHOW_TEMP_ADC_VALUES HOME_Y_BEFORE_X EMERGENCY_PARSER \
144144
SD_ABORT_ON_ENDSTOP_HIT HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT ADVANCED_OK M114_DETAIL \
145145
VOLUMETRIC_DEFAULT_ON NO_WORKSPACE_OFFSETS EXTRA_FAN_SPEED FWRETRACT \

0 commit comments

Comments
 (0)