Skip to content

Commit 8e7b749

Browse files
InsanityAutomationthinkyhead
authored andcommitted
✨ BLTouch High Speed mode runtime configuration (MarlinFirmware#22916)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent 2a07c8d commit 8e7b749

14 files changed

+132
-59
lines changed

Marlin/Configuration_adv.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,14 @@
897897
//#define BLTOUCH_FORCE_MODE_SET
898898

899899
/**
900-
* Use "HIGH SPEED" mode for probing.
900+
* Enable "HIGH SPEED" option for probing.
901901
* Danger: Disable if your probe sometimes fails. Only suitable for stable well-adjusted systems.
902902
* This feature was designed for Deltabots with very fast Z moves; however, higher speed Cartesians
903903
* might be able to use it. If the machine can't raise Z fast enough the BLTouch may go into ALARM.
904+
*
905+
* Set the default state here, change with 'M401 S' or UI, use M500 to save, M502 to reset.
904906
*/
905-
//#define BLTOUCH_HS_MODE
907+
//#define BLTOUCH_HS_MODE true
906908

907909
// Safety: Enable voltage mode settings in the LCD menu.
908910
//#define BLTOUCH_LCD_VOLTAGE_MENU

Marlin/src/feature/bltouch.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828

2929
BLTouch bltouch;
3030

31-
bool BLTouch::last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
31+
bool BLTouch::od_5v_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
32+
#ifdef BLTOUCH_HS_MODE
33+
bool BLTouch::high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed
34+
#else
35+
constexpr bool BLTouch::high_speed_mode;
36+
#endif
3237

3338
#include "../module/servo.h"
3439
#include "../module/probe.h"
@@ -64,17 +69,14 @@ void BLTouch::init(const bool set_voltage/*=false*/) {
6469
#else
6570

6671
if (DEBUGGING(LEVELING)) {
67-
DEBUG_ECHOLNPGM("last_written_mode - ", last_written_mode);
68-
DEBUG_ECHOLNPGM("config mode - "
69-
#if ENABLED(BLTOUCH_SET_5V_MODE)
70-
"BLTOUCH_SET_5V_MODE"
71-
#else
72-
"OD"
73-
#endif
74-
);
72+
PGMSTR(mode0, "OD");
73+
PGMSTR(mode1, "5V");
74+
DEBUG_ECHOPGM("BLTouch Mode: ");
75+
DEBUG_ECHOPGM_P(bltouch.od_5v_mode ? mode1 : mode0);
76+
DEBUG_ECHOLNPGM(" (Default " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD") ")");
7577
}
7678

77-
const bool should_set = last_written_mode != ENABLED(BLTOUCH_SET_5V_MODE);
79+
const bool should_set = od_5v_mode != ENABLED(BLTOUCH_SET_5V_MODE);
7880

7981
#endif
8082

@@ -193,7 +195,7 @@ void BLTouch::mode_conv_proc(const bool M5V) {
193195
_mode_store();
194196
if (M5V) _set_5V_mode(); else _set_OD_mode();
195197
_stow();
196-
last_written_mode = M5V;
198+
od_5v_mode = M5V;
197199
}
198200

199201
#endif // BLTOUCH

Marlin/src/feature/bltouch.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

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

26-
#if DISABLED(BLTOUCH_HS_MODE)
27-
#define BLTOUCH_SLOW_MODE 1
28-
#endif
29-
3026
// BLTouch commands are sent as servo angles
3127
typedef unsigned char BLTCommand;
3228

@@ -70,8 +66,17 @@ typedef unsigned char BLTCommand;
7066

7167
class BLTouch {
7268
public:
69+
7370
static void init(const bool set_voltage=false);
74-
static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
71+
static bool od_5v_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
72+
73+
#ifdef BLTOUCH_HS_MODE
74+
static bool high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed
75+
#else
76+
static constexpr bool high_speed_mode = false;
77+
#endif
78+
79+
static inline float z_extra_clearance() { return high_speed_mode ? 7 : 0; }
7580

7681
// DEPLOY and STOW are wrapped for error handling - these are used by homing and by probing
7782
static bool deploy() { return deploy_proc(); }

Marlin/src/gcode/bedlevel/G35.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include "../../module/tool_change.h"
3434
#endif
3535

36+
#if ENABLED(BLTOUCH)
37+
#include "../../feature/bltouch.h"
38+
#endif
39+
3640
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
3741
#include "../../core/debug_out.h"
3842

@@ -102,7 +106,7 @@ void GcodeSuite::G35() {
102106
// In BLTOUCH HS mode, the probe travels in a deployed state.
103107
// Users of G35 might have a badly misaligned bed, so raise Z by the
104108
// length of the deployed pin (BLTOUCH stroke < 7mm)
105-
do_blocking_move_to_z(SUM_TERN(BLTOUCH_HS_MODE, Z_CLEARANCE_BETWEEN_PROBES, 7));
109+
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance()));
106110
const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true);
107111

108112
if (isnan(z_probed_height)) {

Marlin/src/gcode/calibrate/G34_M422.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#include "../../libs/least_squares_fit.h"
4646
#endif
4747

48+
#if ENABLED(BLTOUCH)
49+
#include "../../feature/bltouch.h"
50+
#endif
51+
4852
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
4953
#include "../../core/debug_out.h"
5054

@@ -149,7 +153,7 @@ void GcodeSuite::G34() {
149153
// In BLTOUCH HS mode, the probe travels in a deployed state.
150154
// Users of G34 might have a badly misaligned bed, so raise Z by the
151155
// length of the deployed pin (BLTOUCH stroke < 7mm)
152-
#define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE))
156+
#define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance()))
153157

154158
// Compute a worst-case clearance height to probe from. After the first
155159
// iteration this will be re-calculated based on the actual bed position

Marlin/src/gcode/probe/M401_M402.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,27 @@
2828
#include "../../module/motion.h"
2929
#include "../../module/probe.h"
3030

31+
#ifdef BLTOUCH_HS_MODE
32+
#include "../../feature/bltouch.h"
33+
#endif
34+
3135
/**
3236
* M401: Deploy and activate the Z probe
37+
*
38+
* With BLTOUCH_HS_MODE:
39+
* S<bool> Set High Speed (HS) Mode and exit without deploy
3340
*/
3441
void GcodeSuite::M401() {
35-
probe.deploy();
36-
TERN_(PROBE_TARE, probe.tare());
37-
report_current_position();
42+
if (parser.seen('S')) {
43+
#ifdef BLTOUCH_HS_MODE
44+
bltouch.high_speed_mode = parser.value_bool();
45+
#endif
46+
}
47+
else {
48+
probe.deploy();
49+
TERN_(PROBE_TARE, probe.tare());
50+
report_current_position();
51+
}
3852
}
3953

4054
/**

Marlin/src/inc/SanityCheck.h

+3
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,9 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
15771577
#endif
15781578
#endif
15791579

1580+
#if ENABLED(BLTOUCH_HS_MODE) && BLTOUCH_HS_MODE == 0
1581+
#error "BLTOUCH_HS_MODE must now be defined as true or false, indicating the default state."
1582+
#endif
15801583
#if BLTOUCH_DELAY < 200
15811584
#error "BLTOUCH_DELAY less than 200 is unsafe and is not supported."
15821585
#endif

Marlin/src/lcd/language/language_en.h

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ namespace Language_en {
491491
LSTR MSG_BLTOUCH_STOW = _UxGT("Stow");
492492
LSTR MSG_BLTOUCH_DEPLOY = _UxGT("Deploy");
493493
LSTR MSG_BLTOUCH_SW_MODE = _UxGT("SW-Mode");
494+
LSTR MSG_BLTOUCH_SPEED_MODE = _UxGT("High Speed");
494495
LSTR MSG_BLTOUCH_5V_MODE = _UxGT("5V-Mode");
495496
LSTR MSG_BLTOUCH_OD_MODE = _UxGT("OD-Mode");
496497
LSTR MSG_BLTOUCH_MODE_STORE = _UxGT("Mode-Store");

Marlin/src/lcd/menu/menu_bed_corners.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ static void _lcd_level_bed_corners_get_next_position() {
217217

218218
bool _lcd_level_bed_corners_probe(bool verify=false) {
219219
if (verify) do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // do clearance if needed
220-
TERN_(BLTOUCH_SLOW_MODE, bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action
220+
TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action
221221
do_blocking_move_to_z(last_z - LEVEL_CORNERS_PROBE_TOLERANCE, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW)); // Move down to lower tolerance
222222
if (TEST(endstops.trigger_state(), Z_MIN_PROBE)) { // check if probe triggered
223223
endstops.hit_on_purpose();
224224
set_current_from_steppers_for_axis(Z_AXIS);
225225
sync_plan_position();
226-
TERN_(BLTOUCH_SLOW_MODE, bltouch.stow()); // Stow in LOW SPEED MODE on every trigger
226+
TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.stow()); // Stow in LOW SPEED MODE on every trigger
227227
// Triggered outside tolerance range?
228228
if (ABS(current_position.z - last_z) > LEVEL_CORNERS_PROBE_TOLERANCE) {
229229
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() {
249249
}
250250
idle();
251251
}
252-
TERN_(BLTOUCH_SLOW_MODE, bltouch.stow());
252+
TERN_(BLTOUCH, if (!bltouch.high_speed_mode) bltouch.stow());
253253
ui.goto_screen(_lcd_draw_probing);
254254
return (probe_triggered);
255255
}
@@ -263,13 +263,14 @@ static void _lcd_level_bed_corners_get_next_position() {
263263
do {
264264
ui.refresh(LCDVIEW_REDRAW_NOW);
265265
_lcd_draw_probing(); // update screen with # of good points
266-
do_blocking_move_to_z(SUM_TERN(BLTOUCH_HS_MODE, current_position.z + LEVEL_CORNERS_Z_HOP, 7)); // clearance
266+
267+
do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP + TERN0(BLTOUCH, bltouch.z_extra_clearance())); // clearance
267268

268269
_lcd_level_bed_corners_get_next_position(); // Select next corner coordinates
269270
current_position -= probe.offset_xy; // Account for probe offsets
270271
do_blocking_move_to_xy(current_position); // Goto corner
271272

272-
TERN_(BLTOUCH_HS_MODE, bltouch.deploy()); // Deploy in HIGH SPEED MODE
273+
TERN_(BLTOUCH, if (bltouch.high_speed_mode) bltouch.deploy()); // Deploy in HIGH SPEED MODE
273274
if (!_lcd_level_bed_corners_probe()) { // Probe down to tolerance
274275
if (_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed
275276
#if ENABLED(LEVEL_CORNERS_VERIFY_RAISED) // Verify
@@ -290,10 +291,12 @@ static void _lcd_level_bed_corners_get_next_position() {
290291

291292
} while (good_points < nr_edge_points); // loop until all points within tolerance
292293

293-
#if ENABLED(BLTOUCH_HS_MODE)
294-
// In HIGH SPEED MODE do clearance and stow at the very end
295-
do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP);
296-
bltouch.stow();
294+
#if ENABLED(BLTOUCH)
295+
if (bltouch.high_speed_mode)
296+
// In HIGH SPEED MODE do clearance and stow at the very end
297+
do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP);
298+
bltouch.stow();
299+
}
297300
#endif
298301

299302
ui.goto_screen(_lcd_draw_level_prompt); // prompt for bed leveling

Marlin/src/lcd/menu/menu_configuration.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,14 @@ void menu_advanced_settings();
217217

218218
#if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU)
219219
void bltouch_report() {
220-
SERIAL_ECHOLNPGM("EEPROM Last BLTouch Mode - ", bltouch.last_written_mode);
221-
SERIAL_ECHOLNPGM("Configuration BLTouch Mode - " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD"));
220+
PGMSTR(mode0, "OD");
221+
PGMSTR(mode1, "5V");
222+
SERIAL_ECHOPGM("BLTouch Mode: ");
223+
SERIAL_ECHOPGM_P(bltouch.od_5v_mode ? mode1 : mode0);
224+
SERIAL_ECHOLNPGM(" (Default " TERN(BLTOUCH_SET_5V_MODE, "5V", "OD") ")");
222225
char mess[21];
223-
strcpy_P(mess, PSTR("BLTouch Mode - "));
224-
strcpy_P(&mess[15], bltouch.last_written_mode ? PSTR("5V") : PSTR("OD"));
226+
strcpy_P(mess, PSTR("BLTouch Mode: "));
227+
strcpy_P(&mess[15], bltouch.od_5v_mode ? mode1 : mode0);
225228
ui.set_status(mess);
226229
ui.return_to_status();
227230
}
@@ -235,6 +238,9 @@ void menu_advanced_settings();
235238
ACTION_ITEM(MSG_BLTOUCH_DEPLOY, bltouch._deploy);
236239
ACTION_ITEM(MSG_BLTOUCH_STOW, bltouch._stow);
237240
ACTION_ITEM(MSG_BLTOUCH_SW_MODE, bltouch._set_SW_mode);
241+
#ifdef BLTOUCH_HS_MODE
242+
EDIT_ITEM(bool, MSG_BLTOUCH_SPEED_MODE, &bltouch.high_speed_mode);
243+
#endif
238244
#if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU)
239245
CONFIRM_ITEM(MSG_BLTOUCH_5V_MODE, MSG_BLTOUCH_5V_MODE, MSG_BUTTON_CANCEL, bltouch._set_5V_mode, nullptr, GET_TEXT(MSG_BLTOUCH_MODE_CHANGE));
240246
CONFIRM_ITEM(MSG_BLTOUCH_OD_MODE, MSG_BLTOUCH_OD_MODE, MSG_BUTTON_CANCEL, bltouch._set_OD_mode, nullptr, GET_TEXT(MSG_BLTOUCH_MODE_CHANGE));

Marlin/src/lcd/menu/menu_tramming.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include "../../module/probe.h"
3737
#include "../../gcode/queue.h"
3838

39+
#if ENABLED(BLTOUCH)
40+
#include "../../feature/bltouch.h"
41+
#endif
42+
3943
//#define DEBUG_OUT 1
4044
#include "../../core/debug_out.h"
4145

@@ -51,7 +55,7 @@ static int8_t reference_index; // = 0
5155
static bool probe_single_point() {
5256
do_blocking_move_to_z(TERN(BLTOUCH, Z_CLEARANCE_DEPLOY_PROBE, Z_CLEARANCE_BETWEEN_PROBES));
5357
// Stow after each point with BLTouch "HIGH SPEED" mode for push-pin safety
54-
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);
58+
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);
5559
z_measured[tram_index] = z_probed_height;
5660
if (reference_index < 0) reference_index = tram_index;
5761
move_to_tramming_wait_pos();

Marlin/src/module/motion.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,8 @@ void prepare_line_to_destination() {
18031803
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home Fast: ", move_length, "mm");
18041804
do_homing_move(axis, move_length, 0.0, !use_probe_bump);
18051805

1806-
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE)
1807-
if (axis == Z_AXIS) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE)
1806+
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH)
1807+
if (axis == Z_AXIS && !bltouch.high_speed_mode) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE)
18081808
#endif
18091809

18101810
// If a second homing move is configured...
@@ -1837,8 +1837,9 @@ void prepare_line_to_destination() {
18371837
}
18381838
#endif
18391839

1840-
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE)
1841-
if (axis == Z_AXIS && bltouch.deploy()) return; // Intermediate DEPLOY (in LOW SPEED MODE)
1840+
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH)
1841+
if (axis == Z_AXIS && !bltouch.high_speed_mode && bltouch.deploy())
1842+
return; // Intermediate DEPLOY (in LOW SPEED MODE)
18421843
#endif
18431844

18441845
// Slow move towards endstop until triggered

Marlin/src/module/probe.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,10 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
489489
#if BOTH(HAS_TEMP_HOTEND, WAIT_FOR_HOTEND)
490490
thermalManager.wait_for_hotend_heating(active_extruder);
491491
#endif
492-
493-
if (TERN0(BLTOUCH_SLOW_MODE, bltouch.deploy())) return true; // Deploy in LOW SPEED MODE on every probe action
492+
#if ENABLED(BLTOUCH)
493+
if (!bltouch.high_speed_mode && bltouch.deploy())
494+
return true; // Deploy in LOW SPEED MODE on every probe action
495+
#endif
494496

495497
// Disable stealthChop if used. Enable diag1 pin on driver.
496498
#if ENABLED(SENSORLESS_PROBING)
@@ -531,8 +533,10 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) {
531533
set_homing_current(false);
532534
#endif
533535

534-
if (probe_triggered && TERN0(BLTOUCH_SLOW_MODE, bltouch.stow())) // Stow in LOW SPEED MODE on every trigger
535-
return true;
536+
#if ENABLED(BLTOUCH)
537+
if (probe_triggered && !bltouch.high_speed_mode && bltouch.stow())
538+
return true; // Stow in LOW SPEED MODE on every trigger
539+
#endif
536540

537541
// Clear endstop flags
538542
endstops.hit_on_purpose();
@@ -762,8 +766,9 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
762766
DEBUG_POS("", current_position);
763767
}
764768

765-
#if BOTH(BLTOUCH, BLTOUCH_HS_MODE)
766-
if (bltouch.triggered()) bltouch._reset();
769+
#if ENABLED(BLTOUCH)
770+
if (bltouch.high_speed_mode && bltouch.triggered())
771+
bltouch._reset();
767772
#endif
768773

769774
// On delta keep Z below clip height or do_blocking_move_to will abort

0 commit comments

Comments
 (0)