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

Z Probe Offset Calibration Menu #18866

Merged
merged 20 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,18 @@
//#define PROBE_PT_3_Y 20
#endif


/**
* Add a menu to adjust the z probe offset, after homing the offset will be set to
* PROBE_OFFSE_START then the user can move the nozzle to required position and
* the offset will be calculated, which can then be stored.
*/
#if ENABLED(HAS_BED_PROBE)
#define PROBE_OFFSET_MENU
// #define PROBE_OFFSET_START -4.0
#endif


/**
* Probing Margins
*
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 @@ -637,6 +637,9 @@ namespace Language_en {
PROGMEM Language_Str MSG_HEATER_TIMEOUT = _UxGT("Heater Timeout");
PROGMEM Language_Str MSG_REHEAT = _UxGT("Reheat");
PROGMEM Language_Str MSG_REHEATING = _UxGT("Reheating...");

PROGMEM Language_Str MSG_PROBE_OFFSET = _UxGT("Cal Z Probe Offset");

}

#if FAN_COUNT == 1
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ class MenuItem_bool : public MenuEditItemBase {
#define EDIT_ITEM_FAST_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, true, PLABEL, ##V)
#define EDIT_ITEM_FAST(TYPE, LABEL, V...) EDIT_ITEM_FAST_P(TYPE, GET_TEXT(LABEL), ##V)

#define VALUE_ITEM(MSG, VALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy(msg + 2, VALUE); STATIC_ITEM(MSG, STYL, msg); }while(0)
#define VALUE_ITEM_P(MSG, PVALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy_P(msg + 2, PSTR(PVALUE)); STATIC_ITEM(MSG, STYL, msg); }while(0)

#define _CONFIRM_ITEM_INNER_P(PLABEL, V...) do { \
if (encoderLine == _thisItemNr && ui.use_click()) { \
ui.goto_screen([]{MenuItem_confirm::select_screen(V);}); \
Expand Down Expand Up @@ -626,6 +629,10 @@ void _lcd_draw_homing();
void _lcd_level_bed_corners();
#endif

#if ENABLED(PROBE_OFFSET_MENU)
void _lcd_probe_offset();
#endif

#if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
void _lcd_toggle_bed_leveling();
#endif
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/menu/menu_bed_leveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ void menu_bed_leveling() {
SUBMENU(MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
#endif

#if ENABLED(PROBE_OFFSET_MENU)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
SUBMENU(MSG_PROBE_OFFSET, _lcd_probe_offset);
#endif

#if ENABLED(EEPROM_SETTINGS)
ACTION_ITEM(MSG_LOAD_EEPROM, ui.load_settings);
ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings);
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/lcd/menu/menu_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "game/game.h"
#endif

#define VALUE_ITEM(MSG, VALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy(msg + 2, VALUE); STATIC_ITEM(MSG, STYL, msg); }while(0)
#define VALUE_ITEM_P(MSG, PVALUE, STYL) do{ char msg[21]; strcpy_P(msg, PSTR(": ")); strcpy_P(msg + 2, PSTR(PVALUE)); STATIC_ITEM(MSG, STYL, msg); }while(0)

#if ENABLED(PRINTCOUNTER)

#include "../../module/printcounter.h"
Expand Down
158 changes: 158 additions & 0 deletions Marlin/src/lcd/menu/menu_probe_offset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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/>.
*
*/

//
// Calibrate Probe offset menu.
//

#include "../../inc/MarlinConfigPre.h"

#if BOTH(HAS_LCD_MENU, PROBE_OFFSET_MENU) && DISABLED(BABYSTEP_ZPROBE_OFFSET)

#include "menu.h"
#include "menu_addon.h"
#include "../../module/motion.h"
#include "../../module/planner.h"

#if HAS_LEVELING
#include "../../feature/bedlevel/bedlevel.h"
#endif

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

#ifndef PROBE_OFFSET_START
#define PROBE_OFFSET_START -4.0
#endif

static_assert(PROBE_OFFSET_START < 0, "PROBE_OFFSET_START must be < 0. Please update your configuration.");

#if HAS_LEVELING
static bool leveling_was_active = false;
#endif

#if HAS_SOFTWARE_ENDSTOPS
bool store_soft_endstops_enabled;
#endif
float store_z_offset;
float calculated_z_offset;

static void _lcd_probe_offset_move_undo(){
#if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = store_soft_endstops_enabled;
#endif
probe.offset.z = store_z_offset;
ui.goto_previous_screen_no_defer();

}

static void _lcd_probe_offset_move_done(){
probe.offset.z = calculated_z_offset;
#if HAS_SOFTWARE_ENDSTOPS
soft_endstops_enabled = store_soft_endstops_enabled;
#endif

#if HAS_LEVELING
set_bed_leveling_enabled(leveling_was_active);
#endif
#if Z_AFTER_HOMING
do_z_clearance(Z_AFTER_HOMING);
#else
do_z_clearance(20.0);
#endif

ui.goto_previous_screen_no_defer();
};

void _goto_manual_move_z(const float scale) {
ui.defer_status_screen();
ui.manual_move.menu_scale = scale;
ui.goto_screen(lcd_move_z);
}

static void _lcd_probe_offset_move_z() {
_lcd_draw_homing();
if (all_axes_homed()) {
ui.goto_screen([]{
ui.defer_status_screen();
START_MENU();
calculated_z_offset = probe.offset.z + current_position.z;

if (LCD_HEIGHT >= 4) {
STATIC_ITEM(MSG_MOVE_Z, SS_CENTER|SS_INVERT);
}

VALUE_ITEM(MSG_ZPROBE_ZOFFSET, ftostr42_52(calculated_z_offset), SS_LEFT);

SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
char tmp[20], numstr[10];

if ((SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
extern const char NUL_STR[];
SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(SHORT_MANUAL_Z_MOVE)); });
MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD));
// Determine digits needed right of decimal
const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
!UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
sprintf_P(tmp, GET_TEXT(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
lcd_put_u8str(tmp);
MENU_ITEM_ADDON_END();
}

ACTION_ITEM(MSG_BUTTON_DONE, _lcd_probe_offset_move_done);
ACTION_ITEM(MSG_BUTTON_CANCEL, _lcd_probe_offset_move_undo);

END_MENU();
});
}
}

void _lcd_probe_offset() {
ui.defer_status_screen();

if (!all_axes_known()) {
set_all_unhomed();
queue.inject_P(G28_STR);
}

store_z_offset = probe.offset.z;
probe.offset.z = PROBE_OFFSET_START;


// Disable leveling so the planner won't mess with us
#if HAS_LEVELING
leveling_was_active = planner.leveling_active;
set_bed_leveling_enabled(false);
#endif

#if HAS_SOFTWARE_ENDSTOPS
store_soft_endstops_enabled = soft_endstops_enabled;
soft_endstops_enabled = false;
#endif

ui.goto_screen(_lcd_probe_offset_move_z);

}

#endif // HAS_LCD_MENU && PROBE_OFFSET_MENU
16 changes: 16 additions & 0 deletions buildroot/tests/mega2560-tests
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,21 @@ exec_test $1 $2 "RAMPS | SCARA | Mixed TMC | EEPROM"
#use_example_configs tvrrug/Round2
#exec_test $1 $2 "Stuff"

# Delta Config (generic) + ABL bilinear + BLTOUCH + PROBE_OFFSET_MENU
use_example_configs delta/generic
opt_set LCD_LANGUAGE cz
opt_set X_DRIVER_TYPE L6470
opt_set Y_DRIVER_TYPE L6470
opt_set Z_DRIVER_TYPE L6470
opt_add L6470_CHAIN_SCK_PIN 53
opt_add L6470_CHAIN_MISO_PIN 49
opt_add L6470_CHAIN_MOSI_PIN 40
opt_add L6470_CHAIN_SS_PIN 42
opt_add "ENABLE_RESET_L64XX_CHIPS(V) NOOP"
opt_add PROBE_OFFSET_MENU
opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER DELTA_CALIBRATION_MENU AUTO_BED_LEVELING_BILINEAR LCD_BED_LEVELING BLTOUCH PROBE_OFFSET_MENU
exec_test $1 $2 "DELTA | L6470 | RRD LCD | ABL Bilinear | BLTOUCH | LCD_BED_LEVELING | PROBE_OFFSET_MENU"


# clean up
restore_configs