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

Add initial support for probes requiring Tare and Enable pins #20379

Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
750bc64
Add initial support for probes requiring Tare and Enable pins
InsanityAutomation Dec 5, 2020
f583d93
Tweaks following PR thread
InsanityAutomation Dec 5, 2020
ae24cfa
Fix borked search / replace
InsanityAutomation Dec 5, 2020
48b61b7
It's not golf
thinkyhead Dec 6, 2020
e8e4a74
fix typo
thinkyhead Dec 6, 2020
5ccfbd4
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/20379
rhapsodyv Dec 7, 2020
0653027
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into PRR/20379_P…
sjasonsmith Dec 8, 2020
0bf9f04
Renames
sjasonsmith Dec 8, 2020
a870ebd
Add compile test for new feature
sjasonsmith Dec 8, 2020
5ed93ec
Only tare when homing if using probe
sjasonsmith Dec 8, 2020
d8fa698
Fix missed rename
sjasonsmith Dec 8, 2020
61a1fb7
Allow multiple endstops along with new feature, simplify code
sjasonsmith Dec 9, 2020
6ce0f3d
Fix inconsistent lambda return type
sjasonsmith Dec 9, 2020
524eae8
explicit return type
sjasonsmith Dec 9, 2020
9c97590
Add tare on M401, Endstop reporting, better handling for different pi…
InsanityAutomation Dec 14, 2020
68237a4
Merge branch 'bugfix-2.0.x' into ProbesRequiringEnablePin
InsanityAutomation Dec 18, 2020
4eba8b8
Rename QUIET_PROBING condition
thinkyhead Dec 19, 2020
e2e46d8
Adjust names
thinkyhead Dec 19, 2020
c8a10cb
Cleanup and fix
thinkyhead Dec 19, 2020
dc683f5
Fix, add sanity check
thinkyhead Dec 19, 2020
b357f13
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/20379
thinkyhead Dec 20, 2020
aafa034
Last touches
thinkyhead Dec 20, 2020
d4fa493
Adhere to standard
thinkyhead Dec 20, 2020
6624725
No probe-en in normal endstop report
thinkyhead Dec 20, 2020
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
27 changes: 27 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,33 @@
// Feedrate (mm/min) for the "accurate" probe of each point
#define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2)

/**
* Probe Activation Switch
* A switch indicating proper deployment, or an optical
* switch triggered when the carriage is near the bed.
*/
//#define PROBE_ACTIVATION_SWITCH
#if ENABLED(PROBE_ACTIVATION_SWITCH)
#define PROBE_ACTIVATION_SWITCH_STATE LOW // State indicating probe is active
//#define PROBE_ACTIVATION_SWITCH_PIN PC6 // Override default pin
#endif

/**
* Tare Probe (determine zero-point) prior to each probe.
* Useful for a strain gauge or piezo sensor that needs to factor out
* elements such as cables pulling on the carriage.
*/
//#define PROBE_TARE
#if ENABLED(PROBE_TARE)
#define PROBE_TARE_TIME 200 // (ms) Time to hold tare pin
#define PROBE_TARE_DELAY 200 // (ms) Delay after tare before
#define PROBE_TARE_STATE HIGH // State to write pin for tare
//#define PROBE_TARE_PIN PA5 // Override default pin
#if ENABLED(PROBE_ACTIVATION_SWITCH)
//#define PROBE_TARE_ONLY_WHILE_INACTIVE // Fail to tare/probe if PROBE_ACTIVATION_SWITCH is active
#endif
#endif

/**
* Multiple Probing
*
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/gcode/probe/M401_M402.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
void GcodeSuite::M401() {
probe.deploy();
TERN_(PROBE_TARE, probe.tare());
report_current_position();
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@
#endif

#if HAS_BED_PROBE && (EITHER(PROBING_HEATERS_OFF, PROBING_FANS_OFF) || DELAY_BEFORE_PROBING > 0)
#define QUIET_PROBING 1
#define HAS_QUIET_PROBING 1
#endif
#if EITHER(ADVANCED_PAUSE_FEATURE, PROBING_HEATERS_OFF)
#define HEATER_IDLE_HANDLER 1
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static int8_t bed_corner;
#if ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE)
bltouch.deploy(); // DEPLOY in LOW SPEED MODE on every probe action
#endif
TERN_(QUIET_PROBING, probe.set_probing_paused(true));
TERN_(HAS_QUIET_PROBING, probe.set_probing_paused(true));

// Move down until the probe is triggered
do_blocking_move_to_z(last_z - (LEVEL_CORNERS_PROBE_TOLERANCE), manual_feedrate_mm_s.z);
Expand Down Expand Up @@ -141,7 +141,7 @@ static int8_t bed_corner;
TERN_(LEVEL_CORNERS_VERIFY_RAISED, verify_corner = true);
}

TERN_(QUIET_PROBING, probe.set_probing_paused(false));
TERN_(HAS_QUIET_PROBING, probe.set_probing_paused(false));

#if ENABLED(BLTOUCH) && DISABLED(BLTOUCH_HS_MODE)
bltouch.stow();
Expand Down
19 changes: 15 additions & 4 deletions Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ void Endstops::init() {
#endif
#endif

#if PIN_EXISTS(PROBE_ACTIVATION_SWITCH)
SET_INPUT(PROBE_ACTIVATION_SWITCH_PIN);
#endif

TERN_(PROBE_TARE, probe.tare());

TERN_(ENDSTOP_INTERRUPTS_FEATURE, setup_endstop_interrupts());

// Enable endstops
Expand Down Expand Up @@ -458,6 +464,9 @@ void _O2 Endstops::report_states() {
#if HAS_Z4_MAX
ES_REPORT(Z4_MAX);
#endif
#if ENABLED(PROBE_ACTIVATION_SWITCH)
print_es_state(READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE, PSTR("Probe Enable Pin"));
#endif
#if HAS_CUSTOM_PROBE_PIN
print_es_state(PROBE_TRIGGERED(), PSTR(STR_Z_PROBE));
#endif
Expand Down Expand Up @@ -582,7 +591,7 @@ void Endstops::update() {
#endif
#endif

#if HAS_Z_MIN && !Z_SPI_SENSORLESS
#if HAS_Z_MIN && NONE(Z_SPI_SENSORLESS, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
UPDATE_ENDSTOP_BIT(Z, MIN);
#if ENABLED(Z_MULTI_ENDSTOPS)
#if HAS_Z2_MIN
Expand All @@ -607,10 +616,12 @@ void Endstops::update() {
#endif
#endif

// When closing the gap check the enabled probe
#if HAS_CUSTOM_PROBE_PIN
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
#if ENABLED(PROBE_ACTIVATION_SWITCH)
if (READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE)
#endif
{
UPDATE_ENDSTOP_BIT(Z, TERN(HAS_CUSTOM_PROBE_PIN, MIN_PROBE, MIN));
}

#if HAS_Z_MAX && !Z_SPI_SENSORLESS
// Check both Z dual endstops
Expand Down
15 changes: 10 additions & 5 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t

if (is_home_dir) {

#if HOMING_Z_WITH_PROBE && QUIET_PROBING
#if HOMING_Z_WITH_PROBE && HAS_QUIET_PROBING
if (axis == Z_AXIS) probe.set_probing_paused(true);
#endif

Expand Down Expand Up @@ -1360,7 +1360,7 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t

if (is_home_dir) {

#if HOMING_Z_WITH_PROBE && QUIET_PROBING
#if HOMING_Z_WITH_PROBE && HAS_QUIET_PROBING
if (axis == Z_AXIS) probe.set_probing_paused(false);
#endif

Expand Down Expand Up @@ -1589,9 +1589,14 @@ void homeaxis(const AxisEnum axis) {
// Fast move towards endstop until triggered
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home 1 Fast:");

#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH)
if (axis == Z_AXIS && bltouch.deploy()) return; // The initial DEPLOY
#endif
if (axis == Z_AXIS) {
#if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH)
if (bltouch.deploy()) return; // The initial DEPLOY
#endif
#if BOTH(HOMING_Z_WITH_PROBE, PROBE_TARE)
if (probe.tare()) return;
#endif
}

#if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM)
const xy_float_t backoff = SENSORLESS_BACKOFF_MM;
Expand Down
52 changes: 46 additions & 6 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#include "../feature/tmc_util.h"
#endif

#if QUIET_PROBING
#if HAS_QUIET_PROBING
#include "stepper/indirection.h"
#endif

Expand Down Expand Up @@ -236,7 +236,7 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()

#endif // Z_PROBE_ALLEN_KEY

#if QUIET_PROBING
#if HAS_QUIET_PROBING

void Probe::set_probing_paused(const bool p) {
TERN_(PROBING_HEATERS_OFF, thermalManager.pause(p));
Expand All @@ -254,7 +254,7 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()
);
}

#endif // QUIET_PROBING
#endif // HAS_QUIET_PROBING

/**
* Raise Z to a minimum height to make room for a probe to move
Expand Down Expand Up @@ -437,7 +437,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
endstops.enable(true);
#endif

TERN_(QUIET_PROBING, set_probing_paused(true));
TERN_(HAS_QUIET_PROBING, set_probing_paused(true));

// Move down until the probe is triggered
do_blocking_move_to_z(z, fr_mm_s);
Expand All @@ -451,7 +451,7 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
#endif
;

TERN_(QUIET_PROBING, set_probing_paused(false));
TERN_(HAS_QUIET_PROBING, set_probing_paused(false));

// Re-enable stealthChop if used. Disable diag1 pin on driver.
#if ENABLED(SENSORLESS_PROBING)
Expand Down Expand Up @@ -479,6 +479,34 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
return !probe_triggered;
}

#if ENABLED(PROBE_TARE)
/**
* @brief Tare the Z probe
*
* @details Signals to the probe to tare measurement
*
* @return TRUE if the tare cold not be completed
*/
bool Probe::tare() {
#if ENABLED(PROBE_TARE_ONLY_WHILE_INACTIVE)
if ((READ(PROBE_ACTIVATION_SWITCH_PIN) == PROBE_ACTIVATION_SWITCH_STATE)) {
SERIAL_ECHOLN("Cannot tare probe, already active");
return true;
}
#endif

SERIAL_ECHOLN("Taring the probe");
const uint8_t value = !PROBE_TARE_STATE ? HIGH : LOW;
OUT_WRITE(PROBE_TARE_PIN, PROBE_TARE_STATE);
delay(PROBE_TARE_TIME);
OUT_WRITE(PROBE_TARE_PIN, value);
delay(PROBE_TARE_DELAY);

endstops.hit_on_purpose();
return false;
}
#endif

/**
* @brief Probe at the current XY (possibly more than once) to find the bed Z.
*
Expand All @@ -490,8 +518,13 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
float Probe::run_z_probe(const bool sanity_check/*=true*/) {
DEBUG_SECTION(log_probe, "Probe::run_z_probe", DEBUGGING(LEVELING));

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) {
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 {
// Do a first probe at the fast speed

#if ENABLED(PROBE_TARE)
if (tare()) return true;
#endif

const bool probe_fail = probe_down_to_z(z_probe_low_point, fr_mm_s), // No probe trigger?
early_fail = (scheck && current_position.z > -offset.z + clearance); // Probe triggered too high?
#if ENABLED(DEBUG_LEVELING_FEATURE)
Expand All @@ -516,6 +549,10 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
#if TOTAL_PROBING == 2

// Do a first probe at the fast speed
#if ENABLED(PROBE_TARE)
if (tare()) return NAN;
#endif

if (try_to_probe(PSTR("FAST"), z_probe_low_point, z_probe_fast_mm_s,
sanity_check, Z_CLEARANCE_BETWEEN_PROBES) ) return NAN;

Expand Down Expand Up @@ -553,6 +590,9 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
)
#endif
{
// If the probe won't tare, return
if (TERN0(PROBE_TARE, tare()) return true;

// Probe downward slowly to find the bed
if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW),
sanity_check, Z_CLEARANCE_MULTI_PROBE) ) return NAN;
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ class Probe {
static void servo_probe_init();
#endif

#if QUIET_PROBING
#if HAS_QUIET_PROBING
static void set_probing_paused(const bool p);
#endif

#if ENABLED(PROBE_TARE)
static bool tare();
#endif

private:
static bool probe_down_to_z(const float z, const feedRate_t fr_mm_s);
static void do_z_raise(const float z_raise);
Expand Down
8 changes: 8 additions & 0 deletions buildroot/tests/STM32F103RET6_creality-tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ set -e
use_example_configs "Creality/Ender-3 V2"
opt_enable MARLIN_DEV_MODE
exec_test $1 $2 "Ender 3 v2" "$3"
restore_configs

use_example_configs "Creality/Ender-3 V2"
opt_disable CLASSIC_JERK
opt_add SDCARD_EEPROM_EMULATION
exec_test $1 $2 "Ender 3 v2, SD EEPROM, w/o CLASSIC_JERK" "$3"
restore_configs

opt_set SERIAL_PORT 1
opt_set MOTHERBOARD BOARD_CREALITY_V452
opt_disable NOZZLE_TO_PROBE_OFFSET
opt_enable NOZZLE_AS_PROBE Z_SAFE_HOMING Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
opt_enable PROBE_ACTIVATION_SWITCH PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE
exec_test $1 $2 "Creality V4.5.2 PROBE_ACTIVATION_SWITCH, Probe Tare" "$3"
restore_configs