Skip to content

Commit af09514

Browse files
InsanityAutomationthinkyheadrhapsodyvsjasonsmith
committed
Probe Tare, Probe Activation Switch (MarlinFirmware#20379)
Co-authored-by: Scott Lahteine <[email protected]> Co-authored-by: Victor Mateus Oliveira <[email protected]> Co-authored-by: Jason Smith <[email protected]>
1 parent 622af13 commit af09514

File tree

9 files changed

+108
-7
lines changed

9 files changed

+108
-7
lines changed

Marlin/Configuration.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,33 @@
10051005
// Feedrate (mm/min) for the "accurate" probe of each point
10061006
#define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2)
10071007

1008+
/**
1009+
* Probe Activation Switch
1010+
* A switch indicating proper deployment, or an optical
1011+
* switch triggered when the carriage is near the bed.
1012+
*/
1013+
//#define PROBE_ACTIVATION_SWITCH
1014+
#if ENABLED(PROBE_ACTIVATION_SWITCH)
1015+
#define PROBE_ACTIVATION_SWITCH_STATE LOW // State indicating probe is active
1016+
//#define PROBE_ACTIVATION_SWITCH_PIN PC6 // Override default pin
1017+
#endif
1018+
1019+
/**
1020+
* Tare Probe (determine zero-point) prior to each probe.
1021+
* Useful for a strain gauge or piezo sensor that needs to factor out
1022+
* elements such as cables pulling on the carriage.
1023+
*/
1024+
//#define PROBE_TARE
1025+
#if ENABLED(PROBE_TARE)
1026+
#define PROBE_TARE_TIME 200 // (ms) Time to hold tare pin
1027+
#define PROBE_TARE_DELAY 200 // (ms) Delay after tare before
1028+
#define PROBE_TARE_STATE HIGH // State to write pin for tare
1029+
//#define PROBE_TARE_PIN PA5 // Override default pin
1030+
#if ENABLED(PROBE_ACTIVATION_SWITCH)
1031+
//#define PROBE_TARE_ONLY_WHILE_INACTIVE // Fail to tare/probe if PROBE_ACTIVATION_SWITCH is active
1032+
#endif
1033+
#endif
1034+
10081035
/**
10091036
* Multiple Probing
10101037
*

Marlin/src/core/language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
#define STR_Z4_MIN "z4_min"
155155
#define STR_Z4_MAX "z4_max"
156156
#define STR_Z_PROBE "z_probe"
157+
#define STR_PROBE_EN "probe_en"
157158
#define STR_FILAMENT_RUNOUT_SENSOR "filament"
158159
#define STR_PROBE_OFFSET "Probe Offset"
159160
#define STR_SKEW_MIN "min_skew_factor: "

Marlin/src/gcode/probe/M401_M402.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434
void GcodeSuite::M401() {
3535
probe.deploy();
36+
TERN_(PROBE_TARE, probe.tare());
3637
report_current_position();
3738
}
3839

Marlin/src/inc/SanityCheck.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,14 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
14141414
#error "Z_SAFE_HOMING is recommended when homing with a probe. Enable it or comment out this line to continue."
14151415
#endif
14161416

1417+
#if ENABLED(PROBE_ACTIVATION_SWITCH)
1418+
#ifndef PROBE_ACTIVATION_SWITCH_STATE
1419+
#error "PROBE_ACTIVATION_SWITCH_STATE is required for PROBE_ACTIVATION_SWITCH."
1420+
#elif !PIN_EXISTS(PROBE_ACTIVATION_SWITCH)
1421+
#error "A PROBE_ACTIVATION_SWITCH_PIN is required for PROBE_ACTIVATION_SWITCH."
1422+
#endif
1423+
#endif
1424+
14171425
#else
14181426

14191427
/**

Marlin/src/module/endstops.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ void Endstops::init() {
280280
#endif
281281
#endif
282282

283+
#if ENABLED(PROBE_ACTIVATION_SWITCH)
284+
SET_INPUT(PROBE_ACTIVATION_SWITCH_PIN);
285+
#endif
286+
287+
TERN_(PROBE_TARE, probe.tare());
288+
283289
TERN_(ENDSTOP_INTERRUPTS_FEATURE, setup_endstop_interrupts());
284290

285291
// Enable endstops
@@ -458,6 +464,9 @@ void _O2 Endstops::report_states() {
458464
#if HAS_Z4_MAX
459465
ES_REPORT(Z4_MAX);
460466
#endif
467+
#if BOTH(MARLIN_DEV_MODE, PROBE_ACTIVATION_SWITCH)
468+
print_es_state(READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE, PSTR(STR_PROBE_EN));
469+
#endif
461470
#if HAS_CUSTOM_PROBE_PIN
462471
print_es_state(PROBE_TRIGGERED(), PSTR(STR_Z_PROBE));
463472
#endif
@@ -582,7 +591,7 @@ void Endstops::update() {
582591
#endif
583592
#endif
584593

585-
#if HAS_Z_MIN && !Z_SPI_SENSORLESS
594+
#if HAS_Z_MIN && NONE(Z_SPI_SENSORLESS, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
586595
UPDATE_ENDSTOP_BIT(Z, MIN);
587596
#if ENABLED(Z_MULTI_ENDSTOPS)
588597
#if HAS_Z2_MIN
@@ -607,9 +616,13 @@ void Endstops::update() {
607616
#endif
608617
#endif
609618

610-
// When closing the gap check the enabled probe
611-
#if HAS_CUSTOM_PROBE_PIN
612-
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
619+
#if HAS_BED_PROBE
620+
// When closing the gap check the enabled probe
621+
if (true
622+
#if ENABLED(PROBE_ACTIVATION_SWITCH)
623+
|| READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE
624+
#endif
625+
) UPDATE_ENDSTOP_BIT(Z, TERN(HAS_CUSTOM_PROBE_PIN, MIN_PROBE, MIN));
613626
#endif
614627

615628
#if HAS_Z_MAX && !Z_SPI_SENSORLESS

Marlin/src/module/motion.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,11 @@ void homeaxis(const AxisEnum axis) {
15881588
// Fast move towards endstop until triggered
15891589
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home 1 Fast:");
15901590

1591-
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH)
1592-
if (axis == Z_AXIS && bltouch.deploy()) return; // The initial DEPLOY
1591+
#if HOMING_Z_WITH_PROBE
1592+
if (axis == Z_AXIS) {
1593+
if (TERN0(BLTOUCH, bltouch.deploy())) return;
1594+
if (TERN0(PROBE_TARE, probe.tare())) return;
1595+
}
15931596
#endif
15941597

15951598
#if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM)

Marlin/src/module/probe.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,33 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
524524
return !probe_triggered;
525525
}
526526

527+
#if ENABLED(PROBE_TARE)
528+
/**
529+
* @brief Tare the Z probe
530+
*
531+
* @details Signal to the probe to tare itself
532+
*
533+
* @return TRUE if the tare cold not be completed
534+
*/
535+
bool Probe::tare() {
536+
#if BOTH(PROBE_ACTIVATION_SWITCH, PROBE_TARE_ONLY_WHILE_INACTIVE)
537+
if (READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE) {
538+
SERIAL_ECHOLNPGM("Cannot tare an active probe");
539+
return true;
540+
}
541+
#endif
542+
543+
SERIAL_ECHOLNPGM("Taring probe");
544+
OUT_WRITE(PROBE_TARE_PIN, PROBE_TARE_STATE);
545+
delay(PROBE_TARE_TIME);
546+
OUT_WRITE(PROBE_TARE_PIN, !PROBE_TARE_STATE);
547+
delay(PROBE_TARE_DELAY);
548+
549+
endstops.hit_on_purpose();
550+
return false;
551+
}
552+
#endif
553+
527554
/**
528555
* @brief Probe at the current XY (possibly more than once) to find the bed Z.
529556
*
@@ -535,8 +562,11 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
535562
float Probe::run_z_probe(const bool sanity_check/*=true*/) {
536563
DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING));
537564

538-
auto try_to_probe = [&](PGM_P const plbl, const float &z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck, const float clearance) {
565+
auto try_to_probe = [&](PGM_P const plbl, const float &z_probe_low_point, const feedRate_t fr_mm_s, const bool scheck, const float clearance) -> bool {
539566
// Do a first probe at the fast speed
567+
568+
if (TERN0(PROBE_TARE, tare())) return true;
569+
540570
const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger?
541571
early_fail = (scheck && current_position.z > -offset.z + clearance); // Probe triggered too high?
542572
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -561,6 +591,8 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
561591
#if TOTAL_PROBING == 2
562592

563593
// Do a first probe at the fast speed
594+
if (TERN0(PROBE_TARE, tare())) return NAN;
595+
564596
if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
565597
sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;
566598

@@ -598,6 +630,9 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
598630
)
599631
#endif
600632
{
633+
// If the probe won't tare, return
634+
if (TERN0(PROBE_TARE, tare())) return true;
635+
601636
// Probe downward slowly to find the bed
602637
if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW),
603638
sanity_check, Z_CLEARANCE_MULTI_PROBE) ) return NAN;

Marlin/src/module/probe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ class Probe {
210210
static void set_probing_paused(const bool p);
211211
#endif
212212

213+
#if ENABLED(PROBE_TARE)
214+
static bool tare();
215+
#endif
216+
213217
private:
214218
static bool probe_down_to_z(const float z, const feedRate_t fr_mm_s);
215219
static void do_z_raise(const float z_raise);

buildroot/tests/STM32F103RET6_creality-tests

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ opt_add SDCARD_EEPROM_EMULATION
1919
exec_test $1 $2 "Ender 3 v2, SD EEPROM, w/o CLASSIC_JERK" "$3"
2020

2121
restore_configs
22+
opt_set SERIAL_PORT 1
23+
opt_set MOTHERBOARD BOARD_CREALITY_V452
24+
opt_disable NOZZLE_TO_PROBE_OFFSET
25+
opt_enable NOZZLE_AS_PROBE Z_SAFE_HOMING Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
26+
opt_enable PROBE_ACTIVATION_SWITCH PROBE_ACTIVATION_SWITCH_PIN PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE
27+
exec_test $1 $2 "Creality V4.5.2 PROBE_ACTIVATION_SWITCH, Probe Tare" "$3"
28+
29+
# clean up
30+
restore_configs

0 commit comments

Comments
 (0)