1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-31 01:59:54 +02:00

Merge pull request #612 from bdring/PauseResumeFix

Pause resume fix
This commit is contained in:
Mitch Bradley
2020-09-23 08:24:56 -10:00
committed by GitHub
8 changed files with 41 additions and 24 deletions

View File

@@ -86,6 +86,7 @@ static void reset_variables() {
memset(sys_probe_position, 0, sizeof(sys_probe_position)); // Clear probe position.
sys_probe_state = 0;
sys_rt_exec_state = 0;
cycle_stop = false;
sys_rt_exec_motion_override = 0;
sys_rt_exec_accessory_override = 0;
system_clear_exec_alarm();

View File

@@ -202,7 +202,7 @@ void limits_go_home(uint8_t cycle_mask) {
}
st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us.
// Exit routines: No time to run protocol_execute_realtime() in this loop.
if (sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_STOP)) {
if ((sys_rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET)) || cycle_stop) {
uint8_t rt_exec = sys_rt_exec_state;
// Homing failure condition: Reset issued during cycle.
if (rt_exec & EXEC_RESET) {
@@ -217,7 +217,7 @@ void limits_go_home(uint8_t cycle_mask) {
system_set_exec_alarm(ExecAlarm::HomingFailPulloff);
}
// Homing failure condition: Limit switch not found during approach.
if (approach && (rt_exec & EXEC_CYCLE_STOP)) {
if (approach && cycle_stop) {
system_set_exec_alarm(ExecAlarm::HomingFailApproach);
}
@@ -228,7 +228,7 @@ void limits_go_home(uint8_t cycle_mask) {
return;
} else {
// Pull-off motion complete. Disable CYCLE_STOP from executing.
system_clear_exec_state_flag(EXEC_CYCLE_STOP);
cycle_stop = false;
break;
}
}
@@ -371,7 +371,7 @@ void limits_disable() {
// number in bit position, i.e. Z_AXIS is bit(2), and Y_AXIS is bit(1).
uint8_t limits_get_state() {
uint8_t pinMask = 0;
auto n_axis = number_axis->get();
auto n_axis = number_axis->get();
for (int axis = 0; axis < n_axis; axis++) {
for (int gang_index = 0; gang_index < 2; gang_index++) {
uint8_t pin = limit_pins[axis][gang_index];

View File

@@ -110,11 +110,27 @@ Socket #5
*/
// 4x Input Module in Socket #1
/*
// 4x Input Module in Socket #1
// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
#define X_LIMIT_PIN GPIO_NUM_33
#define Y_LIMIT_PIN GPIO_NUM_32
#define Z_LIMIT_PIN GPIO_NUM_35
*/
// 4x Input Module in Socket #2
// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
#define X_LIMIT_PIN GPIO_NUM_2
#define Y_LIMIT_PIN GPIO_NUM_25
#define Z_LIMIT_PIN GPIO_NUM_39
// 4x Input Module in Socket #3
// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
#define CONTROL_CYCLE_START_PIN GPIO_NUM_26
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_4
#define CONTROL_RESET_PIN GPIO_NUM_16
#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_27
//#define INVERT_CONTROL_PIN_MASK B0000
// ================= Setting Defaults ==========================

View File

@@ -271,7 +271,7 @@ void protocol_exec_rt_system() {
system_clear_exec_alarm(); // Clear alarm
}
uint8_t rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state.
if (rt_exec) {
if (rt_exec || cycle_stop) {
// Execute system abort.
if (rt_exec & EXEC_RESET) {
sys.abort = true; // Only place this is set true.
@@ -399,12 +399,12 @@ void protocol_exec_rt_system() {
}
system_clear_exec_state_flag(EXEC_CYCLE_START);
}
if (rt_exec & EXEC_CYCLE_STOP) {
if (cycle_stop) {
// Reinitializes the cycle plan and stepper system after a feed hold for a resume. Called by
// realtime command execution in the main program, ensuring that the planner re-plans safely.
// NOTE: Bresenham algorithm variables are still maintained through both the planner and stepper
// cycle reinitializations. The stepper path should continue exactly as if nothing has happened.
// NOTE: EXEC_CYCLE_STOP is set by the stepper subsystem when a cycle or feed hold completes.
// NOTE: cycle_stop is set by the stepper subsystem when a cycle or feed hold completes.
if ((sys.state == State::Hold || sys.state == State::SafetyDoor || sys.state == State::Sleep) && !(sys.soft_limit) &&
!(sys.suspend & SUSPEND_JOG_CANCEL)) {
// Hold complete. Set to indicate ready to resume. Remain in HOLD or DOOR states until user
@@ -433,7 +433,7 @@ void protocol_exec_rt_system() {
sys.state = State::Idle;
}
}
system_clear_exec_state_flag(EXEC_CYCLE_STOP);
cycle_stop = false;
}
}
// Execute overrides.

View File

@@ -296,9 +296,8 @@ static void stepper_pulse_func() {
spindle->set_rpm(0);
}
}
system_set_exec_state_flag(EXEC_CYCLE_STOP); // Flag main program for cycle end
return; // Nothing to do but exit.
cycle_stop = true;
return; // Nothing to do but exit.
}
}
// Check probing state.
@@ -362,8 +361,7 @@ static void stepper_pulse_func() {
st.counter_a -= st.exec_block->step_event_count;
if (st.exec_block->direction_bits & bit(A_AXIS)) {
sys_position[A_AXIS]--;
}
else {
} else {
sys_position[A_AXIS]++;
}
}
@@ -379,8 +377,7 @@ static void stepper_pulse_func() {
st.counter_b -= st.exec_block->step_event_count;
if (st.exec_block->direction_bits & bit(B_AXIS)) {
sys_position[B_AXIS]--;
}
else {
} else {
sys_position[B_AXIS]++;
}
}
@@ -396,8 +393,7 @@ static void stepper_pulse_func() {
st.counter_c -= st.exec_block->step_event_count;
if (st.exec_block->direction_bits & bit(C_AXIS)) {
sys_position[C_AXIS]--;
}
else {
} else {
sys_position[C_AXIS]++;
}
}
@@ -1229,8 +1225,10 @@ float st_get_realtime_rate() {
case State::Homing:
case State::Hold:
case State::Jog:
case State::SafetyDoor: return prep.current_speed;
default: return 0.0f;
case State::SafetyDoor:
return prep.current_speed;
default:
return 0.0f;
}
}

View File

@@ -30,6 +30,7 @@ volatile uint8_t sys_rt_exec_state; // Global realtime executor
volatile ExecAlarm sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
volatile bool cycle_stop; // For state transitions, instead of bitflag
#ifdef DEBUG
volatile uint8_t sys_rt_exec_debug;
#endif

View File

@@ -39,7 +39,7 @@ enum class State : uint8_t {
// Define global system variables
typedef struct {
State state; // Tracks the current system state of Grbl.
volatile State state; // Tracks the current system state of Grbl.
uint8_t abort; // System abort flag. Forces exit back to main loop for reset.
uint8_t suspend; // System suspend bitflag variable that manages holds, cancels, and safety door.
uint8_t soft_limit; // Tracks soft limit errors for the state machine. (boolean)
@@ -68,7 +68,7 @@ extern system_t sys;
// know when there is a realtime command to execute.
#define EXEC_STATUS_REPORT bit(0) // bitmask 00000001
#define EXEC_CYCLE_START bit(1) // bitmask 00000010
#define EXEC_CYCLE_STOP bit(2) // bitmask 00000100
// #define EXEC_CYCLE_STOP bit(2) // bitmask 00000100 moved to cycle_stop
#define EXEC_FEED_HOLD bit(3) // bitmask 00001000
#define EXEC_RESET bit(4) // bitmask 00010000
#define EXEC_SAFETY_DOOR bit(5) // bitmask 00100000
@@ -163,6 +163,7 @@ extern volatile uint8_t sys_rt_exec_state; // Global realtime executor bitfla
extern volatile ExecAlarm sys_rt_exec_alarm; // Global realtime executor bitflag variable for setting various alarms.
extern volatile uint8_t sys_rt_exec_motion_override; // Global realtime executor bitflag variable for motion-based overrides.
extern volatile uint8_t sys_rt_exec_accessory_override; // Global realtime executor bitflag variable for spindle/coolant overrides.
extern volatile bool cycle_stop;
#ifdef DEBUG
# define EXEC_DEBUG_REPORT bit(0)
@@ -228,5 +229,5 @@ bool sys_pwm_control(uint8_t io_num_mask, float duty, bool synchronized);
int8_t sys_get_next_RMT_chan_num();
int8_t sys_get_next_PWM_chan_num();
int8_t sys_get_next_PWM_chan_num();
uint8_t sys_calc_pwm_precision(uint32_t freq);

View File

@@ -2,7 +2,7 @@
# Grbl (CNC Controller) For ESP32
<img src="https://github.com/bdring/6-Pack_CNC_Controller/blob/master/images/20200711_120633.jpg" width="600">
<img src="https://user-images.githubusercontent.com/189677/93836185-74c27500-fc47-11ea-8bed-5d419974c196.jpg" width="600">
### Project Overview