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

Protocol race #719

Open
wants to merge 5 commits into
base: Devt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 15 additions & 20 deletions Grbl_Esp32/Custom/CoreXY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool user_defined_homing(uint8_t cycle_mask) {
// convert back to motor steps
inverse_kinematics(target);

pl_data->feed_rate = homing_rate; // feed or seek rates
pl_data->feed_rate = homing_rate; // Set current homing rate.
plan_buffer_line(target, pl_data); // Bypass mc_line(). Directly plan homing motion.
sys.step_control = {};
sys.step_control.executeSysMotion = true; // Set to execute homing motion and clear existing flags.
Expand All @@ -147,36 +147,31 @@ bool user_defined_homing(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.bit.safetyDoor || sys_rt_exec_state.bit.reset || cycle_stop) {
ExecState rt_exec_state;
rt_exec_state.value = sys_rt_exec_state.value;
// Homing failure condition: Reset issued during cycle.
if (rt_exec_state.bit.reset) {
if (sys_safetyDoor || sys_reset || sys_cycleStop) {
if (sys_reset) {
// Homing failure condition: Reset issued during cycle.
sys_rt_exec_alarm = ExecAlarm::HomingFailReset;
}
// Homing failure condition: Safety door was opened.
if (rt_exec_state.bit.safetyDoor) {
} else if (sys_safetyDoor) {
// Homing failure condition: Safety door was opened.
sys_rt_exec_alarm = ExecAlarm::HomingFailDoor;
}
// Homing failure condition: Limit switch still engaged after pull-off motion
if (!approach && (limits_get_state() & cycle_mask)) {
sys_rt_exec_alarm = ExecAlarm::HomingFailPulloff;
}
// Homing failure condition: Limit switch not found during approach.
if (approach && cycle_stop) {
} else if (approach) { // sys_cycleStop must be true if we get this far
// Homing failure condition: Limit switch not found during approach.
sys_rt_exec_alarm = ExecAlarm::HomingFailApproach;
} else if (limits_get_state() & cycle_mask) {
// Homing failure condition: Limit switch still engaged after pull-off motion
sys_rt_exec_alarm = ExecAlarm::HomingFailPulloff;
}

if (sys_rt_exec_alarm != ExecAlarm::None) {
motors_set_homing_mode(cycle_mask, false); // tell motors homing is done...failed
mc_reset(); // Stop motors, if they are running.
protocol_execute_realtime();
return true;
} else {
// Pull-off motion complete. Disable CYCLE_STOP from executing.
cycle_stop = false;
break;
}

// Pull-off motion complete. Disable CYCLE_STOP from executing.
sys_cycleStop = false;
break;
}
} while (!switch_touched);

Expand Down
23 changes: 0 additions & 23 deletions Grbl_Esp32/src/Exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@

#include <map>

// System executor bit map. Used internally by realtime protocol as realtime command flags,
// which notifies the main program to execute the specified realtime command asynchronously.
// NOTE: The system executor uses an unsigned 8-bit volatile variable (8 flag limit.) The default
// flags are always false, so the realtime protocol only needs to check for a non-zero value to
// know when there is a realtime command to execute.
struct ExecStateBits {
uint8_t statusReport : 1;
uint8_t cycleStart : 1;
uint8_t cycleStop : 1; // Unused, per cycle_stop variable
uint8_t feedHold : 1;
uint8_t reset : 1;
uint8_t safetyDoor : 1;
uint8_t motionCancel : 1;
uint8_t sleep : 1;
};

union ExecState {
uint8_t value;
ExecStateBits bit;
};

static_assert(sizeof(ExecStateBits) == sizeof(uint8_t), "ExecStateBits is not an uint8");

// Override bit maps. Realtime bitflags to control feed, rapid, spindle, and coolant overrides.
// Spindle/coolant and feed/rapids are separated into two controlling flag variables.

Expand Down
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ Error gc_execute_line(char* line, uint8_t client) {
case ProgramFlow::Paused:
protocol_buffer_synchronize(); // Sync and finish all remaining buffered motions before moving on.
if (sys.state != State::CheckMode) {
sys_rt_exec_state.bit.feedHold = true; // Use feed hold for program pause.
sys_feedHold = true; // Use feed hold for program pause.
protocol_execute_realtime(); // Execute suspend.
}
break;
Expand Down
12 changes: 10 additions & 2 deletions Grbl_Esp32/src/Grbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ static void reset_variables() {
memset(sys_probe_position, 0, sizeof(sys_probe_position)); // Clear probe position.

sys_probe_state = Probe::Off;
sys_rt_exec_state.value = 0;

sys_statusReport = false;
sys_cycleStart = false;
sys_cycleStop = false;
sys_feedHold = false;
sys_reset = false;
sys_safetyDoor = false;
sys_motionCancel = false;
sys_sleep = false;

sys_rt_exec_accessory_override.value = 0;
sys_rt_exec_alarm = ExecAlarm::None;
cycle_stop = false;
sys_rt_f_override = FeedOverride::Default;
sys_rt_r_override = RapidOverride::Default;
sys_rt_s_override = SpindleSpeedOverride::Default;
Expand Down
35 changes: 15 additions & 20 deletions Grbl_Esp32/src/Limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,31 @@ 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.bit.safetyDoor || sys_rt_exec_state.bit.reset || cycle_stop) {
ExecState rt_exec_state;
rt_exec_state.value = sys_rt_exec_state.value;
// Homing failure condition: Reset issued during cycle.
if (rt_exec_state.bit.reset) {
if (sys_safetyDoor || sys_reset || sys_cycleStop) {
if (sys_reset) {
// Homing failure condition: Reset issued during cycle.
sys_rt_exec_alarm = ExecAlarm::HomingFailReset;
}
// Homing failure condition: Safety door was opened.
if (rt_exec_state.bit.safetyDoor) {
} else if (sys_safetyDoor) {
// Homing failure condition: Safety door was opened.
sys_rt_exec_alarm = ExecAlarm::HomingFailDoor;
}
// Homing failure condition: Limit switch still engaged after pull-off motion
if (!approach && (limits_get_state() & cycle_mask)) {
sys_rt_exec_alarm = ExecAlarm::HomingFailPulloff;
}
// Homing failure condition: Limit switch not found during approach.
if (approach && cycle_stop) {
} else if (approach) { // sys_cycleStop must be true if we get this far
// Homing failure condition: Limit switch not found during approach.
sys_rt_exec_alarm = ExecAlarm::HomingFailApproach;
} else if (limits_get_state() & cycle_mask) {
// Homing failure condition: Limit switch still engaged after pull-off motion
sys_rt_exec_alarm = ExecAlarm::HomingFailPulloff;
}

if (sys_rt_exec_alarm != ExecAlarm::None) {
motors_set_homing_mode(cycle_mask, false); // tell motors homing is done...failed
mc_reset(); // Stop motors, if they are running.
protocol_execute_realtime();
return;
} else {
// Pull-off motion complete. Disable CYCLE_STOP from executing.
cycle_stop = false;
break;
}

// Pull-off motion complete. Disable CYCLE_STOP from executing.
sys_cycleStop = false;
break;
}
} while (STEP_MASK & axislock);
#ifdef USE_I2S_STEPS
Expand Down Expand Up @@ -343,7 +338,7 @@ void limits_soft_check(float* target) {
// workspace volume so just come to a controlled stop so position is not lost. When complete
// enter alarm mode.
if (sys.state == State::Cycle) {
sys_rt_exec_state.bit.feedHold = true;
sys_feedHold = true;
do {
protocol_execute_realtime();
if (sys.abort) {
Expand Down
6 changes: 3 additions & 3 deletions Grbl_Esp32/src/MotionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ GCUpdatePos mc_probe_cycle(float* target, plan_line_data_t* pl_data, uint8_t par
// Activate the probing state monitor in the stepper module.
sys_probe_state = Probe::Active;
// Perform probing cycle. Wait here until probe is triggered or motion completes.
sys_rt_exec_state.bit.cycleStart = true;
sys_cycleStart = true;
do {
protocol_execute_realtime();
if (sys.abort) {
Expand Down Expand Up @@ -498,8 +498,8 @@ void mc_override_ctrl_update(uint8_t override_state) {
// realtime abort command and hard limits. So, keep to a minimum.
void mc_reset() {
// Only this function can set the system reset. Helps prevent multiple kill calls.
if (!sys_rt_exec_state.bit.reset) {
sys_rt_exec_state.bit.reset = true;
if (!sys_reset) {
sys_reset = true;
// Kill spindle and coolant.
spindle->stop();
coolant_stop();
Expand Down
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/Probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ void probe_state_monitor() {
if (probe_get_state() ^ is_probe_away) {
sys_probe_state = Probe::Off;
memcpy(sys_probe_position, sys_position, sizeof(sys_position));
sys_rt_exec_state.bit.motionCancel = true;
sys_motionCancel = true;
}
}
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Error home_c(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ES
return home(bit(C_AXIS));
}
Error sleep_grbl(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) {
sys_rt_exec_state.bit.sleep = true;
sys_sleep = true;
return Error::Ok;
}
Error get_report_build_info(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) {
Expand Down
Loading