diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 1878a6f258..e50e0cde89 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -897,12 +897,14 @@ //#define BLTOUCH_FORCE_MODE_SET /** - * Use "HIGH SPEED" mode for probing. + * Enable "HIGH SPEED" option for probing. * Danger: Disable if your probe sometimes fails. Only suitable for stable well-adjusted systems. * This feature was designed for Deltabots with very fast Z moves; however, higher speed Cartesians * might be able to use it. If the machine can't raise Z fast enough the BLTouch may go into ALARM. + * + * Set the default state here, change with 'M401 S' or UI, use M500 to save, M502 to reset. */ - //#define BLTOUCH_HS_MODE + //#define BLTOUCH_HS_MODE true // Safety: Enable voltage mode settings in the LCD menu. //#define BLTOUCH_LCD_VOLTAGE_MENU diff --git a/Marlin/src/feature/bltouch.cpp b/Marlin/src/feature/bltouch.cpp index 49a10f62b1..d3348e79f0 100644 --- a/Marlin/src/feature/bltouch.cpp +++ b/Marlin/src/feature/bltouch.cpp @@ -28,7 +28,12 @@ BLTouch bltouch; -bool BLTouch::last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain +bool BLTouch::od_5v_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain +#ifdef BLTOUCH_HS_MODE + bool BLTouch::high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed +#else + constexpr bool BLTouch::high_speed_mode; +#endif #include "../module/servo.h" #include "../module/probe.h" @@ -64,17 +69,14 @@ void BLTouch::init(const bool set_voltage/*=false*/) { #else if (DEBUGGING(LEVELING)) { - DEBUG_ECHOLNPGM("last_written_mode - ", last_written_mode); - DEBUG_ECHOLNPGM("config mode - " - #if ENABLED(BLTOUCH_SET_5V_MODE) - "BLTOUCH_SET_5V_MODE" - #else - "OD" - #endif - ); + PGMSTR(mode0, "OD"); + PGMSTR(mode1, "5V"); + DEBUG_ECHOPGM("BLTouch Mode: "); + DEBUG_ECHOPGM_P(bltouch.od_5v_mode ? mode1 : mode0); + DEBUG_ECHOLNPGM(" (Default " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD") ")"); } - const bool should_set = last_written_mode != ENABLED(BLTOUCH_SET_5V_MODE); + const bool should_set = od_5v_mode != ENABLED(BLTOUCH_SET_5V_MODE); #endif @@ -193,7 +195,7 @@ void BLTouch::mode_conv_proc(const bool M5V) { _mode_store(); if (M5V) _set_5V_mode(); else _set_OD_mode(); _stow(); - last_written_mode = M5V; + od_5v_mode = M5V; } #endif // BLTOUCH diff --git a/Marlin/src/feature/bltouch.h b/Marlin/src/feature/bltouch.h index 9ecccb4256..ae3ab66300 100644 --- a/Marlin/src/feature/bltouch.h +++ b/Marlin/src/feature/bltouch.h @@ -23,10 +23,6 @@ #include "../inc/MarlinConfigPre.h" -#if DISABLED(BLTOUCH_HS_MODE) - #define BLTOUCH_SLOW_MODE 1 -#endif - // BLTouch commands are sent as servo angles typedef unsigned char BLTCommand; @@ -70,8 +66,17 @@ typedef unsigned char BLTCommand; class BLTouch { public: + static void init(const bool set_voltage=false); - static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain + static bool od_5v_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain + + #ifdef BLTOUCH_HS_MODE + static bool high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed + #else + static constexpr bool high_speed_mode = false; + #endif + + static inline float z_extra_clearance() { return high_speed_mode ? 7 : 0; } // DEPLOY and STOW are wrapped for error handling - these are used by homing and by probing static bool deploy() { return deploy_proc(); } diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index e45e18b7fb..8cabb92382 100644 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -33,6 +33,10 @@ #include "../../module/tool_change.h" #endif +#if ENABLED(BLTOUCH) + #include "../../feature/bltouch.h" +#endif + #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" @@ -102,7 +106,7 @@ void GcodeSuite::G35() { // In BLTOUCH HS mode, the probe travels in a deployed state. // Users of G35 might have a badly misaligned bed, so raise Z by the // length of the deployed pin (BLTOUCH stroke < 7mm) - do_blocking_move_to_z(SUM_TERN(BLTOUCH_HS_MODE, Z_CLEARANCE_BETWEEN_PROBES, 7)); + do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance())); const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true); if (isnan(z_probed_height)) { diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 8f4eab2c97..328a40dbb4 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -45,6 +45,10 @@ #include "../../libs/least_squares_fit.h" #endif +#if ENABLED(BLTOUCH) + #include "../../feature/bltouch.h" +#endif + #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../../core/debug_out.h" @@ -149,7 +153,7 @@ void GcodeSuite::G34() { // In BLTOUCH HS mode, the probe travels in a deployed state. // Users of G34 might have a badly misaligned bed, so raise Z by the // length of the deployed pin (BLTOUCH stroke < 7mm) - #define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE)) + #define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance())) // Compute a worst-case clearance height to probe from. After the first // iteration this will be re-calculated based on the actual bed position diff --git a/Marlin/src/gcode/probe/M401_M402.cpp b/Marlin/src/gcode/probe/M401_M402.cpp index bd9bb44c40..7cbae76f4b 100644 --- a/Marlin/src/gcode/probe/M401_M402.cpp +++ b/Marlin/src/gcode/probe/M401_M402.cpp @@ -28,13 +28,27 @@ #include "../../module/motion.h" #include "../../module/probe.h" +#ifdef BLTOUCH_HS_MODE + #include "../../feature/bltouch.h" +#endif + /** * M401: Deploy and activate the Z probe + * + * With BLTOUCH_HS_MODE: + * S Set High Speed (HS) Mode and exit without deploy */ void GcodeSuite::M401() { - probe.deploy(); - TERN_(PROBE_TARE, probe.tare()); - report_current_position(); + if (parser.seen('S')) { + #ifdef BLTOUCH_HS_MODE + bltouch.high_speed_mode = parser.value_bool(); + #endif + } + else { + probe.deploy(); + TERN_(PROBE_TARE, probe.tare()); + report_current_position(); + } } /** diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index a809fad132..fbc0e3d1f0 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1577,6 +1577,9 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #endif + #if ENABLED(BLTOUCH_HS_MODE) && BLTOUCH_HS_MODE == 0 + #error "BLTOUCH_HS_MODE must now be defined as true or false, indicating the default state." + #endif #if BLTOUCH_DELAY < 200 #error "BLTOUCH_DELAY less than 200 is unsafe and is not supported." #endif diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 89b8fd7d77..1d8861b2c7 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -491,6 +491,7 @@ namespace Language_en { LSTR MSG_BLTOUCH_STOW = _UxGT("Stow"); LSTR MSG_BLTOUCH_DEPLOY = _UxGT("Deploy"); LSTR MSG_BLTOUCH_SW_MODE = _UxGT("SW-Mode"); + LSTR MSG_BLTOUCH_SPEED_MODE = _UxGT("High Speed"); LSTR MSG_BLTOUCH_5V_MODE = _UxGT("5V-Mode"); LSTR MSG_BLTOUCH_OD_MODE = _UxGT("OD-Mode"); LSTR MSG_BLTOUCH_MODE_STORE = _UxGT("Mode-Store"); diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 7bf247f40b..5740978639 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -217,13 +217,13 @@ static void _lcd_level_bed_corners_get_next_position() { bool _lcd_level_bed_corners_probe(bool verify=false) { if (verify) do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // do clearance if needed - TERN_(BLTOUCH_SLOW_MODE, bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action + TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action do_blocking_move_to_z(last_z - LEVEL_CORNERS_PROBE_TOLERANCE, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW)); // Move down to lower tolerance if (TEST(endstops.trigger_state(), Z_MIN_PROBE)) { // check if probe triggered endstops.hit_on_purpose(); set_current_from_steppers_for_axis(Z_AXIS); sync_plan_position(); - TERN_(BLTOUCH_SLOW_MODE, bltouch.stow()); // Stow in LOW SPEED MODE on every trigger + TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.stow()); // Stow in LOW SPEED MODE on every trigger // Triggered outside tolerance range? if (ABS(current_position.z - last_z) > LEVEL_CORNERS_PROBE_TOLERANCE) { last_z = current_position.z; // Above tolerance. Set a new Z for subsequent corners. @@ -249,7 +249,7 @@ static void _lcd_level_bed_corners_get_next_position() { } idle(); } - TERN_(BLTOUCH_SLOW_MODE, bltouch.stow()); + TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.stow()); ui.goto_screen(_lcd_draw_probing); return (probe_triggered); } @@ -263,13 +263,14 @@ static void _lcd_level_bed_corners_get_next_position() { do { ui.refresh(LCDVIEW_REDRAW_NOW); _lcd_draw_probing(); // update screen with # of good points - do_blocking_move_to_z(SUM_TERN(BLTOUCH_HS_MODE, current_position.z + LEVEL_CORNERS_Z_HOP, 7)); // clearance + + do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP + TERN0(BLTOUCH, bltouch.z_extra_clearance())); // clearance _lcd_level_bed_corners_get_next_position(); // Select next corner coordinates current_position -= probe.offset_xy; // Account for probe offsets do_blocking_move_to_xy(current_position); // Goto corner - TERN_(BLTOUCH_HS_MODE, bltouch.deploy()); // Deploy in HIGH SPEED MODE + TERN_(BLTOUCH, if (bltouch.high_speed_mode) bltouch.deploy()); // Deploy in HIGH SPEED MODE if (!_lcd_level_bed_corners_probe()) { // Probe down to tolerance if (_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed #if ENABLED(LEVEL_CORNERS_VERIFY_RAISED) // Verify @@ -290,10 +291,12 @@ static void _lcd_level_bed_corners_get_next_position() { } while (good_points < nr_edge_points); // loop until all points within tolerance - #if ENABLED(BLTOUCH_HS_MODE) - // In HIGH SPEED MODE do clearance and stow at the very end - do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); - bltouch.stow(); + #if ENABLED(BLTOUCH) + if (bltouch.high_speed_mode) + // In HIGH SPEED MODE do clearance and stow at the very end + do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); + bltouch.stow(); + } #endif ui.goto_screen(_lcd_draw_level_prompt); // prompt for bed leveling diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index cd8bad9c8b..19b3dcbafb 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -217,11 +217,14 @@ void menu_advanced_settings(); #if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU) void bltouch_report() { - SERIAL_ECHOLNPGM("EEPROM Last BLTouch Mode - ", bltouch.last_written_mode); - SERIAL_ECHOLNPGM("Configuration BLTouch Mode - " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD")); + PGMSTR(mode0, "OD"); + PGMSTR(mode1, "5V"); + SERIAL_ECHOPGM("BLTouch Mode: "); + SERIAL_ECHOPGM_P(bltouch.od_5v_mode ? mode1 : mode0); + SERIAL_ECHOLNPGM(" (Default " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD") ")"); char mess[21]; - strcpy_P(mess, PSTR("BLTouch Mode - ")); - strcpy_P(&mess[15], bltouch.last_written_mode ? PSTR("5V") : PSTR("OD")); + strcpy_P(mess, PSTR("BLTouch Mode: ")); + strcpy_P(&mess[15], bltouch.od_5v_mode ? mode1 : mode0); ui.set_status(mess); ui.return_to_status(); } @@ -235,6 +238,9 @@ void menu_advanced_settings(); ACTION_ITEM(MSG_BLTOUCH_DEPLOY, bltouch._deploy); ACTION_ITEM(MSG_BLTOUCH_STOW, bltouch._stow); ACTION_ITEM(MSG_BLTOUCH_SW_MODE, bltouch._set_SW_mode); + #ifdef BLTOUCH_HS_MODE + EDIT_ITEM(bool, MSG_BLTOUCH_SPEED_MODE, &bltouch.high_speed_mode); + #endif #if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU) CONFIRM_ITEM(MSG_BLTOUCH_5V_MODE, MSG_BLTOUCH_5V_MODE, MSG_BUTTON_CANCEL, bltouch._set_5V_mode, nullptr, GET_TEXT(MSG_BLTOUCH_MODE_CHANGE)); CONFIRM_ITEM(MSG_BLTOUCH_OD_MODE, MSG_BLTOUCH_OD_MODE, MSG_BUTTON_CANCEL, bltouch._set_OD_mode, nullptr, GET_TEXT(MSG_BLTOUCH_MODE_CHANGE)); diff --git a/Marlin/src/lcd/menu/menu_tramming.cpp b/Marlin/src/lcd/menu/menu_tramming.cpp index 8e9d4b3942..4033421b56 100644 --- a/Marlin/src/lcd/menu/menu_tramming.cpp +++ b/Marlin/src/lcd/menu/menu_tramming.cpp @@ -36,6 +36,10 @@ #include "../../module/probe.h" #include "../../gcode/queue.h" +#if ENABLED(BLTOUCH) + #include "../../feature/bltouch.h" +#endif + //#define DEBUG_OUT 1 #include "../../core/debug_out.h" @@ -51,7 +55,7 @@ static int8_t reference_index; // = 0 static bool probe_single_point() { do_blocking_move_to_z(TERN(BLTOUCH, Z_CLEARANCE_DEPLOY_PROBE, Z_CLEARANCE_BETWEEN_PROBES)); // Stow after each point with BLTouch "HIGH SPEED" mode for push-pin safety - const float z_probed_height = probe.probe_at_point(tramming_points[tram_index], TERN(BLTOUCH_HS_MODE, PROBE_PT_STOW, PROBE_PT_RAISE), 0, true); + const float z_probed_height = probe.probe_at_point(tramming_points[tram_index], TERN0(BLTOUCH, bltouch.high_speed_mode) ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, true); z_measured[tram_index] = z_probed_height; if (reference_index < 0) reference_index = tram_index; move_to_tramming_wait_pos(); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 9ff668bf30..2248c52d85 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -1803,8 +1803,8 @@ void prepare_line_to_destination() { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home Fast: ", move_length, "mm"); do_homing_move(axis, move_length, 0.0, !use_probe_bump); - #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE) - if (axis == Z_AXIS) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) + #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH) + if (axis == Z_AXIS && !bltouch.high_speed_mode) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) #endif // If a second homing move is configured... @@ -1837,8 +1837,9 @@ void prepare_line_to_destination() { } #endif - #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE) - if (axis == Z_AXIS && bltouch.deploy()) return; // Intermediate DEPLOY (in LOW SPEED MODE) + #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH) + if (axis == Z_AXIS && !bltouch.high_speed_mode && bltouch.deploy()) + return; // Intermediate DEPLOY (in LOW SPEED MODE) #endif // Slow move towards endstop until triggered diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 7e08db7a5b..540b4e1ae6 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -489,8 +489,10 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) { #if BOTH(HAS_TEMP_HOTEND, WAIT_FOR_HOTEND) thermalManager.wait_for_hotend_heating(active_extruder); #endif - - if (TERN0(BLTOUCH_SLOW_MODE, bltouch.deploy())) return true; // Deploy in LOW SPEED MODE on every probe action + #if ENABLED(BLTOUCH) + if (!bltouch.high_speed_mode && bltouch.deploy()) + return true; // Deploy in LOW SPEED MODE on every probe action + #endif // Disable stealthChop if used. Enable diag1 pin on driver. #if ENABLED(SENSORLESS_PROBING) @@ -531,8 +533,10 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) { set_homing_current(false); #endif - if (probe_triggered && TERN0(BLTOUCH_SLOW_MODE, bltouch.stow())) // Stow in LOW SPEED MODE on every trigger - return true; + #if ENABLED(BLTOUCH) + if (probe_triggered && !bltouch.high_speed_mode && bltouch.stow()) + return true; // Stow in LOW SPEED MODE on every trigger + #endif // Clear endstop flags endstops.hit_on_purpose(); @@ -762,8 +766,9 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai DEBUG_POS("", current_position); } - #if BOTH(BLTOUCH, BLTOUCH_HS_MODE) - if (bltouch.triggered()) bltouch._reset(); + #if ENABLED(BLTOUCH) + if (bltouch.high_speed_mode && bltouch.triggered()) + bltouch._reset(); #endif // On delta keep Z below clip height or do_blocking_move_to will abort diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index a9c771240c..8a32d4c57e 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -301,7 +301,10 @@ typedef struct SettingsDataStruct { // // BLTOUCH // - bool bltouch_last_written_mode; + bool bltouch_od_5v_mode; + #ifdef BLTOUCH_HS_MODE + bool bltouch_high_speed_mode; // M401 S + #endif // // Kinematic Settings @@ -918,9 +921,15 @@ void MarlinSettings::postprocess() { // BLTOUCH // { - _FIELD_TEST(bltouch_last_written_mode); - const bool bltouch_last_written_mode = TERN(BLTOUCH, bltouch.last_written_mode, false); - EEPROM_WRITE(bltouch_last_written_mode); + _FIELD_TEST(bltouch_od_5v_mode); + const bool bltouch_od_5v_mode = TERN0(BLTOUCH, bltouch.od_5v_mode); + EEPROM_WRITE(bltouch_od_5v_mode); + + #ifdef BLTOUCH_HS_MODE + _FIELD_TEST(bltouch_high_speed_mode); + const bool bltouch_high_speed_mode = TERN0(BLTOUCH, bltouch.high_speed_mode); + EEPROM_WRITE(bltouch_high_speed_mode); + #endif } // @@ -1810,13 +1819,23 @@ void MarlinSettings::postprocess() { // BLTOUCH // { - _FIELD_TEST(bltouch_last_written_mode); + _FIELD_TEST(bltouch_od_5v_mode); #if ENABLED(BLTOUCH) - const bool &bltouch_last_written_mode = bltouch.last_written_mode; + const bool &bltouch_od_5v_mode = bltouch.od_5v_mode; #else - bool bltouch_last_written_mode; + bool bltouch_od_5v_mode; + #endif + EEPROM_READ(bltouch_od_5v_mode); + + #ifdef BLTOUCH_HS_MODE + _FIELD_TEST(bltouch_high_speed_mode); + #if ENABLED(BLTOUCH) + const bool &bltouch_high_speed_mode = bltouch.high_speed_mode; + #else + bool bltouch_high_speed_mode; + #endif + EEPROM_READ(bltouch_high_speed_mode); #endif - EEPROM_READ(bltouch_last_written_mode); } // @@ -2827,11 +2846,11 @@ void MarlinSettings::reset() { TERN_(HAS_PTC, ptc.reset()); // - // BLTOUCH + // BLTouch // - //#if ENABLED(BLTOUCH) - // bltouch.last_written_mode; - //#endif + #ifdef BLTOUCH_HS_MODE + bltouch.high_speed_mode = ENABLED(BLTOUCH_HS_MODE); + #endif // // Kinematic settings