From 6954772ece00a5fa2fdd327a6af1a0d593d22723 Mon Sep 17 00:00:00 2001 From: Speaka <48431623+Speaka@users.noreply.github.com> Date: Sat, 7 Nov 2020 10:20:27 +0100 Subject: [PATCH] Tramming Wizard submenu option (#20000) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 4 +- Marlin/src/feature/tramming.h | 59 ++++++++++++ Marlin/src/gcode/bedlevel/G35.cpp | 26 +++--- Marlin/src/lcd/language/language_en.h | 6 +- Marlin/src/lcd/menu/menu_motion.cpp | 8 +- Marlin/src/lcd/menu/menu_tramming.cpp | 93 +++++++++++++++++++ .../PlatformIO/scripts/common-dependencies.h | 3 + buildroot/tests/DUE-tests | 2 +- platformio.ini | 2 + 9 files changed, 184 insertions(+), 19 deletions(-) create mode 100644 Marlin/src/feature/tramming.h create mode 100644 Marlin/src/lcd/menu/menu_tramming.cpp diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index b39e9e1722..cd8a055ffb 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -808,7 +808,9 @@ #define RESTORE_LEVELING_AFTER_G35 // Enable to restore leveling setup after operation //#define REPORT_TRAMMING_MM // Report Z deviation (mm) for each point relative to the first - //#define ASSISTED_TRAMMING_MENU_ITEM // Add a menu item for Assisted Tramming + + //#define ASSISTED_TRAMMING_MENU_ITEM // Add a menu item to run G35 Assisted Tramming (MarlinUI) + //#define ASSISTED_TRAMMING_WIZARD // Make the menu item open a Tramming Wizard sub-menu /** * Screw thread: diff --git a/Marlin/src/feature/tramming.h b/Marlin/src/feature/tramming.h new file mode 100644 index 0000000000..79f7407716 --- /dev/null +++ b/Marlin/src/feature/tramming.h @@ -0,0 +1,59 @@ +/** + * 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 . + * + */ + +#include "../inc/MarlinConfigPre.h" + +#if !WITHIN(TRAMMING_SCREW_THREAD, 30, 51) || TRAMMING_SCREW_THREAD % 10 > 1 + #error "TRAMMING_SCREW_THREAD must be equal to 30, 31, 40, 41, 50, or 51." +#endif + +constexpr xy_pos_t screws_tilt_adjust_pos[] = TRAMMING_POINT_XY; + +#define G35_PROBE_COUNT COUNT(screws_tilt_adjust_pos) +static_assert(G35_PROBE_COUNT >= 3, "TRAMMING_POINT_XY requires at least 3 XY positions."); + +extern const char point_name_1[], point_name_2[], point_name_3[] + #ifdef TRAMMING_POINT_NAME_4 + , point_name_4[] + #ifdef TRAMMING_POINT_NAME_5 + , point_name_5[] + #endif + #endif +; + +#define _NR_TRAM_NAMES 2 +#ifdef TRAMMING_POINT_NAME_3 + #undef _NR_TRAM_NAMES + #define _NR_TRAM_NAMES 3 + #ifdef TRAMMING_POINT_NAME_4 + #undef _NR_TRAM_NAMES + #define _NR_TRAM_NAMES 4 + #ifdef TRAMMING_POINT_NAME_5 + #undef _NR_TRAM_NAMES + #define _NR_TRAM_NAMES 5 + #endif + #endif +#endif +static_assert(_NR_TRAM_NAMES >= G35_PROBE_COUNT, "Define enough TRAMMING_POINT_NAME_s for all TRAMMING_POINT_XY entries."); +#undef _NR_TRAM_NAMES + +extern PGM_P const tramming_point_name[]; diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index b39a7b9ed8..f0abc543cb 100755 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -36,19 +36,23 @@ #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" -constexpr xy_pos_t screws_tilt_adjust_pos[] = TRAMMING_POINT_XY; +// +// Define tramming point names. +// -static PGMSTR(point_name_1, TRAMMING_POINT_NAME_1); -static PGMSTR(point_name_2, TRAMMING_POINT_NAME_2); -static PGMSTR(point_name_3, TRAMMING_POINT_NAME_3); +#include "../../feature/tramming.h" // Validate + +PGMSTR(point_name_1, TRAMMING_POINT_NAME_1); +PGMSTR(point_name_2, TRAMMING_POINT_NAME_2); +PGMSTR(point_name_3, TRAMMING_POINT_NAME_3); #ifdef TRAMMING_POINT_NAME_4 - static PGMSTR(point_name_4, TRAMMING_POINT_NAME_4); + PGMSTR(point_name_4, TRAMMING_POINT_NAME_4); #ifdef TRAMMING_POINT_NAME_5 - static PGMSTR(point_name_5, TRAMMING_POINT_NAME_5); + PGMSTR(point_name_5, TRAMMING_POINT_NAME_5); #endif #endif -static PGM_P const tramming_point_name[] PROGMEM = { +PGM_P const tramming_point_name[] PROGMEM = { point_name_1, point_name_2, point_name_3 #ifdef TRAMMING_POINT_NAME_4 , point_name_4 @@ -58,14 +62,6 @@ static PGM_P const tramming_point_name[] PROGMEM = { #endif }; -#define G35_PROBE_COUNT COUNT(screws_tilt_adjust_pos) - -#if !WITHIN(TRAMMING_SCREW_THREAD, 30, 51) || TRAMMING_SCREW_THREAD % 10 > 1 - #error "TRAMMING_SCREW_THREAD must be equal to 30, 31, 40, 41, 50, or 51." -#endif - -static_assert(G35_PROBE_COUNT > 2, "TRAMMING_POINT_XY requires at least 3 XY positions."); - /** * G35: Read bed corners to help adjust bed screws * diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 42954d79e5..2f50902bff 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -73,7 +73,6 @@ namespace Language_en { PROGMEM Language_Str MSG_AUTO_HOME_Y = _UxGT("Home Y"); PROGMEM Language_Str MSG_AUTO_HOME_Z = _UxGT("Home Z"); PROGMEM Language_Str MSG_AUTO_Z_ALIGN = _UxGT("Auto Z-Align"); - PROGMEM Language_Str MSG_ASSISTED_TRAMMING = _UxGT("Assisted Tramming"); PROGMEM Language_Str MSG_ITERATION = _UxGT("G34 Iteration: %i"); PROGMEM Language_Str MSG_DECREASING_ACCURACY = _UxGT("Accuracy Decreasing!"); PROGMEM Language_Str MSG_ACCURACY_ACHIEVED = _UxGT("Accuracy Achieved"); @@ -85,6 +84,10 @@ namespace Language_en { PROGMEM Language_Str MSG_SET_HOME_OFFSETS = _UxGT("Set Home Offsets"); PROGMEM Language_Str MSG_HOME_OFFSETS_APPLIED = _UxGT("Offsets Applied"); PROGMEM Language_Str MSG_SET_ORIGIN = _UxGT("Set Origin"); + PROGMEM Language_Str MSG_ASSISTED_TRAMMING = _UxGT("Assisted Tramming"); + PROGMEM Language_Str MSG_TRAMMING_WIZARD = _UxGT("Tramming Wizard"); + PROGMEM Language_Str MSG_SELECT_ORIGIN = _UxGT("Select Origin"); + PROGMEM Language_Str MSG_LAST_VALUE_SP = _UxGT("Last value "); #if PREHEAT_COUNT PROGMEM Language_Str MSG_PREHEAT_1 = _UxGT("Preheat ") PREHEAT_1_LABEL; PROGMEM Language_Str MSG_PREHEAT_1_H = _UxGT("Preheat ") PREHEAT_1_LABEL " ~"; @@ -666,6 +669,7 @@ namespace Language_en { PROGMEM Language_Str MSG_REHEATING = _UxGT("Reheating..."); PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Z Probe Wizard"); + PROGMEM Language_Str MSG_SOUND = _UxGT("Sound"); } diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 2972920f34..c681842e90 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -305,6 +305,10 @@ void menu_move() { void menu_bed_leveling(); #endif +#if ENABLED(ASSISTED_TRAMMING_WIZARD) + void goto_tramming_wizard(); +#endif + void menu_motion() { START_MENU(); @@ -346,7 +350,9 @@ void menu_motion() { // // Assisted Bed Tramming // - #if ENABLED(ASSISTED_TRAMMING_MENU_ITEM) + #if ENABLED(ASSISTED_TRAMMING_WIZARD) + SUBMENU(MSG_TRAMMING_WIZARD, goto_tramming_wizard); + #elif ENABLED(ASSISTED_TRAMMING_MENU_ITEM) GCODES_ITEM(MSG_ASSISTED_TRAMMING, PSTR("G35")); #endif diff --git a/Marlin/src/lcd/menu/menu_tramming.cpp b/Marlin/src/lcd/menu/menu_tramming.cpp new file mode 100644 index 0000000000..c01f983833 --- /dev/null +++ b/Marlin/src/lcd/menu/menu_tramming.cpp @@ -0,0 +1,93 @@ +/** + * 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 . + * + */ + +// +// Bed Tramming Wizard +// + +#include "../../inc/MarlinConfigPre.h" + +#if BOTH(HAS_LCD_MENU, ASSISTED_TRAMMING_WIZARD) + +#include "menu_item.h" + +#include "../../feature/tramming.h" + +#include "../../module/motion.h" +#include "../../module/probe.h" +#include "../../gcode/queue.h" + +//#define DEBUG_OUT 1 +#include "../../core/debug_out.h" + +float z_measured[G35_PROBE_COUNT] = { 0 }; +static uint8_t tram_index = 0; + +bool probe_single_point() { + const float z_probed_height = probe.probe_at_point(screws_tilt_adjust_pos[tram_index], PROBE_PT_RAISE, 0, true); + DEBUG_ECHOLNPAIR("probe_single_point: ", z_probed_height, "mm"); + z_measured[tram_index] = z_probed_height; + return !isnan(z_probed_height); +} + +void _menu_single_probe(const uint8_t point) { + tram_index = point; + DEBUG_ECHOLNPAIR("Screen: single probe screen Arg:", point); + START_MENU(); + STATIC_ITEM(MSG_LEVEL_CORNERS, SS_LEFT); + STATIC_ITEM(MSG_LAST_VALUE_SP, SS_LEFT, ftostr42_52(z_measured[0] - z_measured[point])); // Print diff + ACTION_ITEM(MSG_UBL_BC_INSERT2, []{ if (probe_single_point()) ui.refresh(); }); + ACTION_ITEM(MSG_BUTTON_DONE, []{ ui.goto_previous_screen_no_defer(); }); // Back + END_MENU(); +} + +void tramming_wizard_menu() { + DEBUG_ECHOLNPAIR("Screen: tramming_wizard_menu"); + START_MENU(); + STATIC_ITEM(MSG_SELECT_ORIGIN); + + // Draw a menu item for each tramming point + LOOP_L_N(i, G35_PROBE_COUNT) + SUBMENU_N_P(i, (char*)pgm_read_ptr(&tramming_point_name[i]), []{ _menu_single_probe(MenuItemBase::itemIndex); }); + + ACTION_ITEM(MSG_BUTTON_DONE, []{ ui.goto_previous_screen_no_defer(); }); + END_MENU(); +} + +// Init the wizard and enter the submenu +void goto_tramming_wizard() { + DEBUG_ECHOLNPAIR("Screen: goto_tramming_wizard", 1); + tram_index = 0; + ui.defer_status_screen(); + //probe_single_point(); // Probe first point to get differences + + // Inject G28, wait for homing to complete, + set_all_unhomed(); + queue.inject_P(G28_STR); + ui.goto_screen([]{ + _lcd_draw_homing(); + if (all_axes_homed()) + ui.goto_screen(tramming_wizard_menu); + }); +} + +#endif // HAS_LCD_MENU && ASSISTED_TRAMMING_WIZARD diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.h b/buildroot/share/PlatformIO/scripts/common-dependencies.h index f5b36c407e..ed2f46abae 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.h +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.h @@ -111,6 +111,9 @@ #if ENABLED(TOUCH_SCREEN_CALIBRATION) #define HAS_MENU_TOUCH_SCREEN #endif + #if ENABLED(ASSISTED_TRAMMING_WIZARD) + #define HAS_MENU_TRAMMING + #endif #if ENABLED(AUTO_BED_LEVELING_UBL) #define HAS_MENU_UBL #endif diff --git a/buildroot/tests/DUE-tests b/buildroot/tests/DUE-tests index 0da0d798d0..4a7c492d7b 100755 --- a/buildroot/tests/DUE-tests +++ b/buildroot/tests/DUE-tests @@ -14,7 +14,7 @@ opt_set TEMP_SENSOR_BED 2 opt_set GRID_MAX_POINTS_X 16 opt_set FANMUX0_PIN 53 opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \ - FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING ASSISTED_TRAMMING \ + FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING ASSISTED_TRAMMING ASSISTED_TRAMMING_WIZARD \ EEPROM_SETTINGS SDSUPPORT BINARY_FILE_TRANSFER \ BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \ NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_MENU \ diff --git a/platformio.ini b/platformio.ini index 07edbf3918..af7ce47a50 100644 --- a/platformio.ini +++ b/platformio.ini @@ -48,6 +48,7 @@ default_src_filter = + - - + - - - + - - - - - @@ -259,6 +260,7 @@ HAS_MENU_CUTTER = src_filter=+ HAS_MENU_TEMPERATURE = src_filter=+ HAS_MENU_TMC = src_filter=+ HAS_MENU_TOUCH_SCREEN = src_filter=+ +HAS_MENU_TRAMMING = src_filter=+ HAS_MENU_UBL = src_filter=+ ANYCUBIC_LCD_CHIRON = src_filter=+ + ANYCUBIC_LCD_I3MEGA = src_filter=+ +