1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-25 15:31:06 +02:00

Probe cleanup (#625)

* Cleanup probing code

* Update Grbl.h

* Update after review
This commit is contained in:
bdring
2020-10-04 17:22:30 -05:00
committed by GitHub
parent 5df1e5eb59
commit 885f57e970
7 changed files with 41 additions and 43 deletions

View File

@@ -599,6 +599,10 @@
# define USER_ANALOG_PIN_3 UNDEFINED_PIN # define USER_ANALOG_PIN_3 UNDEFINED_PIN
#endif #endif
#ifndef PROBE_PIN
# define PROBE_PIN UNDEFINED_PIN
#endif
#ifndef USER_ANALOG_PIN_0_FREQ #ifndef USER_ANALOG_PIN_0_FREQ
# define USER_ANALOG_PIN_0_FREQ 5000 # define USER_ANALOG_PIN_0_FREQ 5000
#endif #endif

View File

@@ -271,10 +271,11 @@ Error gc_execute_line(char* line, uint8_t client) {
mg_word_bit = ModalGroup::MG1; mg_word_bit = ModalGroup::MG1;
break; break;
case 38: // G38 - probe case 38: // G38 - probe
#ifndef PROBE_PIN //only allow G38 "Probe" commands if a probe pin is defined. //only allow G38 "Probe" commands if a probe pin is defined.
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "No probe pin defined"); if (PROBE_PIN == UNDEFINED_PIN) {
FAIL(Error::GcodeUnsupportedCommand); // [Unsupported G command] grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "No probe pin defined");
#endif FAIL(Error::GcodeUnsupportedCommand); // [Unsupported G command]
}
// Check for G0/1/2/3/38 being called with G10/28/30/92 on same block. // Check for G0/1/2/3/38 being called with G10/28/30/92 on same block.
// * G43.1 is also an axis command but is not explicitly defined this way. // * G43.1 is also an axis command but is not explicitly defined this way.
if (axis_command != AxisCommand::None) { if (axis_command != AxisCommand::None) {

View File

@@ -23,7 +23,7 @@
// Grbl versioning system // Grbl versioning system
const char* const GRBL_VERSION = "1.3a"; const char* const GRBL_VERSION = "1.3a";
const char* const GRBL_VERSION_BUILD = "20201001"; const char* const GRBL_VERSION_BUILD = "20201004";
//#include <sdkconfig.h> //#include <sdkconfig.h>
#include <Arduino.h> #include <Arduino.h>

View File

@@ -375,14 +375,13 @@ GCUpdatePos mc_probe_cycle(float* target, plan_line_data_t* pl_data, uint8_t par
uint8_t is_probe_away = bit_istrue(parser_flags, GCParserProbeIsAway); uint8_t is_probe_away = bit_istrue(parser_flags, GCParserProbeIsAway);
uint8_t is_no_error = bit_istrue(parser_flags, GCParserProbeIsNoError); uint8_t is_no_error = bit_istrue(parser_flags, GCParserProbeIsNoError);
sys.probe_succeeded = false; // Re-initialize probe history before beginning cycle. sys.probe_succeeded = false; // Re-initialize probe history before beginning cycle.
probe_configure_invert_mask(is_probe_away); set_probe_direction(is_probe_away);
// After syncing, check if probe is already triggered. If so, halt and issue alarm. // After syncing, check if probe is already triggered. If so, halt and issue alarm.
// NOTE: This probe initialization error applies to all probing cycles. // NOTE: This probe initialization error applies to all probing cycles.
if (probe_get_state()) { // Check probe pin state. if (probe_get_state() ^ is_probe_away) { // Check probe pin state.
system_set_exec_alarm(ExecAlarm::ProbeFailInitial); system_set_exec_alarm(ExecAlarm::ProbeFailInitial);
protocol_execute_realtime(); protocol_execute_realtime();
probe_configure_invert_mask(false); // Re-initialize invert mask before returning. return GCUpdatePos::None; // Nothing else to do but bail.
return GCUpdatePos::None; // Nothing else to do but bail.
} }
// Setup and queue probing motion. Auto cycle-start should not start the cycle. // Setup and queue probing motion. Auto cycle-start should not start the cycle.
mc_line(target, pl_data); mc_line(target, pl_data);
@@ -407,9 +406,8 @@ GCUpdatePos mc_probe_cycle(float* target, plan_line_data_t* pl_data, uint8_t par
} else { } else {
sys.probe_succeeded = true; // Indicate to system the probing cycle completed successfully. sys.probe_succeeded = true; // Indicate to system the probing cycle completed successfully.
} }
sys_probe_state = PROBE_OFF; // Ensure probe state monitor is disabled. sys_probe_state = PROBE_OFF; // Ensure probe state monitor is disabled.
probe_configure_invert_mask(false); // Re-initialize invert mask. protocol_execute_realtime(); // Check and execute run-time commands
protocol_execute_realtime(); // Check and execute run-time commands
// Reset the stepper and planner buffers to remove the remainder of the probe motion. // Reset the stepper and planner buffers to remove the remainder of the probe motion.
st_reset(); // Reset step segment buffer. st_reset(); // Reset step segment buffer.
plan_reset(); // Reset planner buffer. Zero planner positions. Ensure probing motion is cleared. plan_reset(); // Reset planner buffer. Zero planner positions. Ensure probing motion is cleared.

View File

@@ -24,47 +24,40 @@
#include "Grbl.h" #include "Grbl.h"
// Inverts the probe pin state depending on user settings and probing cycle mode. // Inverts the probe pin state depending on user settings and probing cycle mode.
uint8_t probe_invert_mask; static bool is_probe_away;
// Probe pin initialization routine. // Probe pin initialization routine.
void probe_init() { void probe_init() {
#ifdef PROBE_PIN static bool show_init_msg = true; // used to show message only once.
# ifdef DISABLE_PROBE_PIN_PULL_UP
pinMode(PROBE_PIN, INPUT); if (PROBE_PIN != UNDEFINED_PIN) {
# else #ifdef DISABLE_PROBE_PIN_PULL_UP
pinMode(PROBE_PIN, INPUT_PULLUP); // Enable internal pull-up resistors. Normal high operation. pinMode(PROBE_PIN, INPUT);
# endif #else
probe_configure_invert_mask(false); // Initialize invert mask. pinMode(PROBE_PIN, INPUT_PULLUP); // Enable internal pull-up resistors. Normal high operation.
#endif #endif
if (show_init_msg) {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Probe on pin %s", pinName(PROBE_PIN).c_str());
show_init_msg = false;
}
}
} }
// Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to void set_probe_direction(bool is_away) {
// appropriately set the pin logic according to setting for normal-high/normal-low operation is_probe_away = is_away;
// and the probing cycle modes for toward-workpiece/away-from-workpiece.
void probe_configure_invert_mask(uint8_t is_probe_away) {
probe_invert_mask = 0; // Initialize as zero.
if (probe_invert->get()) {
probe_invert_mask ^= PROBE_MASK;
}
if (is_probe_away) {
probe_invert_mask ^= PROBE_MASK;
}
} }
// Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor.
uint8_t probe_get_state() { bool probe_get_state() {
#ifdef PROBE_PIN return digitalRead(PROBE_PIN) ^ probe_invert->get();
return digitalRead(PROBE_PIN) ^ probe_invert_mask;
#else
return false;
#endif
} }
// Monitors probe pin state and records the system position when detected. Called by the // Monitors probe pin state and records the system position when detected. Called by the
// stepper ISR per ISR tick. // stepper ISR per ISR tick.
// NOTE: This function must be extremely efficient as to not bog down the stepper ISR. // NOTE: This function must be extremely efficient as to not bog down the stepper ISR.
void probe_state_monitor() { void probe_state_monitor() {
if (probe_get_state()) { if (probe_get_state() ^ is_probe_away) {
sys_probe_state = PROBE_OFF; sys_probe_state = PROBE_OFF;
memcpy(sys_probe_position, sys_position, sizeof(sys_position)); memcpy(sys_probe_position, sys_position, sizeof(sys_position));
bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL);

View File

@@ -30,13 +30,11 @@ const int PROBE_ACTIVE = 1; // Actively watching the input pin.
// Probe pin initialization routine. // Probe pin initialization routine.
void probe_init(); void probe_init();
// Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to // setup probing direction G38.2 vs. G38.4
// appropriately set the pin logic according to setting for normal-high/normal-low operation void set_probe_direction(bool is_away);
// and the probing cycle modes for toward-workpiece/away-from-workpiece.
void probe_configure_invert_mask(uint8_t is_probe_away);
// Returns probe pin state. Triggered = true. Called by gcode parser and probe state monitor. // Returns probe pin state. Triggered = true. Called by gcode parser and probe state monitor.
uint8_t probe_get_state(); bool probe_get_state();
// Monitors probe pin state and records the system position when detected. Called by the // Monitors probe pin state and records the system position when detected. Called by the
// stepper ISR per ISR tick. // stepper ISR per ISR tick.

View File

@@ -537,6 +537,10 @@ void FlagSetting::setDefault() {
Error FlagSetting::setStringValue(char* s) { Error FlagSetting::setStringValue(char* s) {
s = trim(s); s = trim(s);
Error err = check(s);
if (err != Error::Ok) {
return err;
}
_currentValue = (strcasecmp(s, "on") == 0) || (strcasecmp(s, "true") == 0) || (strcasecmp(s, "enabled") == 0) || _currentValue = (strcasecmp(s, "on") == 0) || (strcasecmp(s, "true") == 0) || (strcasecmp(s, "enabled") == 0) ||
(strcasecmp(s, "yes") == 0) || (strcasecmp(s, "1") == 0); (strcasecmp(s, "yes") == 0) || (strcasecmp(s, "1") == 0);
// _storedValue is -1, 0, or 1 // _storedValue is -1, 0, or 1