mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-03 11:22:38 +02:00
EXEC_ALARM -> enum class ExecAlarm
This commit is contained in:
@@ -89,9 +89,9 @@ 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;
|
||||
sys_rt_exec_alarm = 0;
|
||||
sys_rt_exec_motion_override = 0;
|
||||
sys_rt_exec_accessory_override = 0;
|
||||
system_clear_exec_alarm();
|
||||
// Reset Grbl primary systems.
|
||||
serial_reset_read_buffer(CLIENT_ALL); // Clear serial read buffer
|
||||
gc_init(); // Set g-code parser to default state
|
||||
|
@@ -46,7 +46,7 @@ void IRAM_ATTR isr_limit_switches() {
|
||||
// locked out until a homing cycle or a kill lock command. Allows the user to disable the hard
|
||||
// limit setting if their limits are constantly triggering after a reset and move their axes.
|
||||
if ((sys.state != STATE_ALARM) & (bit_isfalse(sys.state, STATE_HOMING))) {
|
||||
if (!(sys_rt_exec_alarm)) {
|
||||
if (sys_rt_exec_alarm == ExecAlarm::None) {
|
||||
#ifdef ENABLE_SOFTWARE_DEBOUNCE
|
||||
// we will start a task that will recheck the switches after a small delay
|
||||
int evt;
|
||||
@@ -56,11 +56,11 @@ void IRAM_ATTR isr_limit_switches() {
|
||||
// Check limit pin state.
|
||||
if (limits_get_state()) {
|
||||
mc_reset(); // Initiate system kill.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
|
||||
system_set_exec_alarm(ExecAlarm::HardLimit); // Indicate hard limit critical event
|
||||
}
|
||||
# else
|
||||
mc_reset(); // Initiate system kill.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
|
||||
system_set_exec_alarm(ExecAlarm::HardLimit); // Indicate hard limit critical event
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -188,22 +188,22 @@ void limits_go_home(uint8_t cycle_mask) {
|
||||
uint8_t rt_exec = sys_rt_exec_state;
|
||||
// Homing failure condition: Reset issued during cycle.
|
||||
if (rt_exec & EXEC_RESET) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET);
|
||||
system_set_exec_alarm(ExecAlarm::HomingFailReset);
|
||||
}
|
||||
// Homing failure condition: Safety door was opened.
|
||||
if (rt_exec & EXEC_SAFETY_DOOR) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_DOOR);
|
||||
system_set_exec_alarm(ExecAlarm::HomingFailDoor);
|
||||
}
|
||||
// Homing failure condition: Limit switch still engaged after pull-off motion
|
||||
if (!approach && (limits_get_state() & cycle_mask)) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_PULLOFF);
|
||||
system_set_exec_alarm(ExecAlarm::HomingFailPulloff);
|
||||
}
|
||||
// Homing failure condition: Limit switch not found during approach.
|
||||
if (approach && (rt_exec & EXEC_CYCLE_STOP)) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_APPROACH);
|
||||
system_set_exec_alarm(ExecAlarm::HomingFailApproach);
|
||||
}
|
||||
|
||||
if (sys_rt_exec_alarm) {
|
||||
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();
|
||||
@@ -394,7 +394,7 @@ void limits_soft_check(float* target) {
|
||||
} while (sys.state != STATE_IDLE);
|
||||
}
|
||||
mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown.
|
||||
system_set_exec_alarm(EXEC_ALARM_SOFT_LIMIT); // Indicate soft limit critical event
|
||||
system_set_exec_alarm(ExecAlarm::SoftLimit); // Indicate soft limit critical event
|
||||
protocol_execute_realtime(); // Execute to enter critical event loop and system abort
|
||||
return;
|
||||
}
|
||||
@@ -411,7 +411,7 @@ void limitCheckTask(void* pvParameters) {
|
||||
if (switch_state) {
|
||||
//grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Limit Switch State %08d", switch_state);
|
||||
mc_reset(); // Initiate system kill.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT); // Indicate hard limit critical event
|
||||
system_set_exec_alarm(ExecAlarm::HardLimit); // Indicate hard limit critical event
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -281,7 +281,7 @@ void mc_homing_cycle(uint8_t cycle_mask) {
|
||||
#ifdef LIMITS_TWO_SWITCHES_ON_AXES
|
||||
if (limits_get_state()) {
|
||||
mc_reset(); // Issue system reset and ensure spindle and coolant are shutdown.
|
||||
system_set_exec_alarm(EXEC_ALARM_HARD_LIMIT);
|
||||
system_set_exec_alarm(ExecAlarm::HardLimit);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -407,7 +407,7 @@ GCUpdatePos mc_probe_cycle(float* target, plan_line_data_t* pl_data, uint8_t par
|
||||
// After syncing, check if probe is already triggered. If so, halt and issue alarm.
|
||||
// NOTE: This probe initialization error applies to all probing cycles.
|
||||
if (probe_get_state()) { // Check probe pin state.
|
||||
system_set_exec_alarm(EXEC_ALARM_PROBE_FAIL_INITIAL);
|
||||
system_set_exec_alarm(ExecAlarm::ProbeFailInitial);
|
||||
protocol_execute_realtime();
|
||||
probe_configure_invert_mask(false); // Re-initialize invert mask before returning.
|
||||
return GCUpdatePos::None; // Nothing else to do but bail.
|
||||
@@ -430,7 +430,7 @@ GCUpdatePos mc_probe_cycle(float* target, plan_line_data_t* pl_data, uint8_t par
|
||||
if (is_no_error) {
|
||||
memcpy(sys_probe_position, sys_position, sizeof(sys_position));
|
||||
} else {
|
||||
system_set_exec_alarm(EXEC_ALARM_PROBE_FAIL_CONTACT);
|
||||
system_set_exec_alarm(ExecAlarm::ProbeFailContact);
|
||||
}
|
||||
} else {
|
||||
sys.probe_succeeded = true; // Indicate to system the probing cycle completed successfully.
|
||||
@@ -520,11 +520,11 @@ void mc_reset() {
|
||||
if ((sys.state & (STATE_CYCLE | STATE_HOMING | STATE_JOG)) ||
|
||||
(sys.step_control & (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION))) {
|
||||
if (sys.state == STATE_HOMING) {
|
||||
if (!sys_rt_exec_alarm) {
|
||||
system_set_exec_alarm(EXEC_ALARM_HOMING_FAIL_RESET);
|
||||
if (sys_rt_exec_alarm == ExecAlarm::None) {
|
||||
system_set_exec_alarm(ExecAlarm::HomingFailReset);
|
||||
}
|
||||
} else {
|
||||
system_set_exec_alarm(EXEC_ALARM_ABORT_CYCLE);
|
||||
system_set_exec_alarm(ExecAlarm::AbortCycle);
|
||||
}
|
||||
st_go_idle(); // Force kill steppers. Position has likely been lost.
|
||||
}
|
||||
|
@@ -246,16 +246,15 @@ void protocol_execute_realtime() {
|
||||
// machine and controls the various real-time features Grbl has to offer.
|
||||
// NOTE: Do not alter this unless you know exactly what you are doing!
|
||||
void protocol_exec_rt_system() {
|
||||
uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times.
|
||||
rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm.
|
||||
if (rt_exec) { // Enter only if any bit flag is true
|
||||
ExecAlarm alarm = sys_rt_exec_alarm; // Temp variable to avoid calling volatile multiple times.
|
||||
if (alarm != ExecAlarm::None) { // Enter only if an alarm is pending
|
||||
// System alarm. Everything has shutdown by something that has gone severely wrong. Report
|
||||
// the source of the error to the user. If critical, Grbl disables by entering an infinite
|
||||
// loop until system reset/abort.
|
||||
sys.state = STATE_ALARM; // Set system alarm state
|
||||
report_alarm_message(rt_exec);
|
||||
report_alarm_message(alarm);
|
||||
// Halt everything upon a critical event flag. Currently hard and soft limits flag this.
|
||||
if ((rt_exec == EXEC_ALARM_HARD_LIMIT) || (rt_exec == EXEC_ALARM_SOFT_LIMIT)) {
|
||||
if ((alarm == ExecAlarm::HardLimit) || (alarm == ExecAlarm::SoftLimit)) {
|
||||
report_feedback_message(Message::CriticalEvent);
|
||||
system_clear_exec_state_flag(EXEC_RESET); // Disable any existing reset
|
||||
do {
|
||||
@@ -268,7 +267,7 @@ void protocol_exec_rt_system() {
|
||||
}
|
||||
system_clear_exec_alarm(); // Clear alarm
|
||||
}
|
||||
rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state.
|
||||
uint8_t rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state.
|
||||
if (rt_exec) {
|
||||
// Execute system abort.
|
||||
if (rt_exec & EXEC_RESET) {
|
||||
|
@@ -242,8 +242,8 @@ void report_status_message(uint8_t status_code, uint8_t client) {
|
||||
}
|
||||
|
||||
// Prints alarm messages.
|
||||
void report_alarm_message(uint8_t alarm_code) {
|
||||
grbl_sendf(CLIENT_ALL, "ALARM:%d\r\n", alarm_code); // OK to send to all clients
|
||||
void report_alarm_message(ExecAlarm alarm_code) {
|
||||
grbl_sendf(CLIENT_ALL, "ALARM:%d\r\n", static_cast<int>(alarm_code)); // OK to send to all clients
|
||||
delay_ms(500); // Force delay to ensure message clears serial write buffer.
|
||||
}
|
||||
|
||||
|
@@ -88,17 +88,6 @@
|
||||
typedef uint8_t err_t; // For status codes
|
||||
const char* errorString(err_t errorNumber);
|
||||
|
||||
// Define Grbl alarm codes. Valid values (1-255). 0 is reserved.
|
||||
#define ALARM_HARD_LIMIT_ERROR EXEC_ALARM_HARD_LIMIT
|
||||
#define ALARM_SOFT_LIMIT_ERROR EXEC_ALARM_SOFT_LIMIT
|
||||
#define ALARM_ABORT_CYCLE EXEC_ALARM_ABORT_CYCLE
|
||||
#define ALARM_PROBE_FAIL_INITIAL EXEC_ALARM_PROBE_FAIL_INITIAL
|
||||
#define ALARM_PROBE_FAIL_CONTACT EXEC_ALARM_PROBE_FAIL_CONTACT
|
||||
#define ALARM_HOMING_FAIL_RESET EXEC_ALARM_HOMING_FAIL_RESET
|
||||
#define ALARM_HOMING_FAIL_DOOR EXEC_ALARM_HOMING_FAIL_DOOR
|
||||
#define ALARM_HOMING_FAIL_PULLOFF EXEC_ALARM_HOMING_FAIL_PULLOFF
|
||||
#define ALARM_HOMING_FAIL_APPROACH EXEC_ALARM_HOMING_FAIL_APPROACH
|
||||
|
||||
// Define Grbl feedback message codes. Valid values (0-255).
|
||||
enum class Message : uint8_t {
|
||||
CriticalEvent = 1,
|
||||
@@ -146,7 +135,7 @@ void report_status_message(uint8_t status_code, uint8_t client);
|
||||
void report_realtime_steps();
|
||||
|
||||
// Prints system alarm messages.
|
||||
void report_alarm_message(uint8_t alarm_code);
|
||||
void report_alarm_message(ExecAlarm alarm_code);
|
||||
|
||||
// Prints miscellaneous feedback messages.
|
||||
void report_feedback_message(Message message);
|
||||
|
@@ -194,7 +194,7 @@ namespace Spindles {
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Spindle RS485 Unresponsive %d", next_cmd.rx_length);
|
||||
if (next_cmd.critical) {
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Critical Spindle RS485 Unresponsive");
|
||||
system_set_exec_alarm(EXEC_ALARM_SPINDLE_CONTROL);
|
||||
system_set_exec_alarm(ExecAlarm::SpindleControl);
|
||||
}
|
||||
unresponsive = true;
|
||||
}
|
||||
|
@@ -716,11 +716,11 @@ void st_go_idle() {
|
||||
busy = false;
|
||||
|
||||
// Set stepper driver idle state, disabled or enabled, depending on settings and circumstances.
|
||||
if (((stepper_idle_lock_time->get() != 0xff) || sys_rt_exec_alarm || sys.state == STATE_SLEEP) && sys.state != STATE_HOMING) {
|
||||
if (((stepper_idle_lock_time->get() != 0xff) || sys_rt_exec_alarm != ExecAlarm::None || sys.state == STATE_SLEEP) && sys.state != STATE_HOMING) {
|
||||
// Force stepper dwell to lock axes for a defined amount of time to ensure the axes come to a complete
|
||||
// stop and not drift from residual inertial forces at the end of the last movement.
|
||||
|
||||
if (sys.state == STATE_SLEEP || sys_rt_exec_alarm) {
|
||||
if (sys.state == STATE_SLEEP || sys_rt_exec_alarm != ExecAlarm::None) {
|
||||
motors_set_disable(true);
|
||||
} else {
|
||||
stepper_idle = true; // esp32 work around for disable in main loop
|
||||
|
@@ -22,14 +22,14 @@
|
||||
#include "Config.h"
|
||||
|
||||
// Declare system global variable structure
|
||||
system_t sys;
|
||||
int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps.
|
||||
int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
||||
volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||
volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
volatile uint8_t 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.
|
||||
system_t sys;
|
||||
int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps.
|
||||
int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
||||
volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||
volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
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.
|
||||
#ifdef DEBUG
|
||||
volatile uint8_t sys_rt_exec_debug;
|
||||
#endif
|
||||
@@ -164,7 +164,7 @@ void system_clear_exec_state_flag(uint8_t mask) {
|
||||
//SREG = sreg;
|
||||
}
|
||||
|
||||
void system_set_exec_alarm(uint8_t code) {
|
||||
void system_set_exec_alarm(ExecAlarm code) {
|
||||
//uint8_t sreg = SREG;
|
||||
//cli();
|
||||
sys_rt_exec_alarm = code;
|
||||
@@ -174,7 +174,7 @@ void system_set_exec_alarm(uint8_t code) {
|
||||
void system_clear_exec_alarm() {
|
||||
//uint8_t sreg = SREG;
|
||||
//cli();
|
||||
sys_rt_exec_alarm = 0;
|
||||
sys_rt_exec_alarm = ExecAlarm::None;
|
||||
//SREG = sreg;
|
||||
}
|
||||
|
||||
|
@@ -61,16 +61,19 @@ extern system_t sys;
|
||||
#define EXEC_SLEEP bit(7) // bitmask 10000000
|
||||
|
||||
// Alarm executor codes. Valid values (1-255). Zero is reserved.
|
||||
#define EXEC_ALARM_HARD_LIMIT 1
|
||||
#define EXEC_ALARM_SOFT_LIMIT 2
|
||||
#define EXEC_ALARM_ABORT_CYCLE 3
|
||||
#define EXEC_ALARM_PROBE_FAIL_INITIAL 4
|
||||
#define EXEC_ALARM_PROBE_FAIL_CONTACT 5
|
||||
#define EXEC_ALARM_HOMING_FAIL_RESET 6
|
||||
#define EXEC_ALARM_HOMING_FAIL_DOOR 7
|
||||
#define EXEC_ALARM_HOMING_FAIL_PULLOFF 8
|
||||
#define EXEC_ALARM_HOMING_FAIL_APPROACH 9
|
||||
#define EXEC_ALARM_SPINDLE_CONTROL 10
|
||||
enum class ExecAlarm : uint8_t {
|
||||
None = 0,
|
||||
HardLimit = 1,
|
||||
SoftLimit = 2,
|
||||
AbortCycle = 3,
|
||||
ProbeFailInitial = 4,
|
||||
ProbeFailContact = 5,
|
||||
HomingFailReset = 6,
|
||||
HomingFailDoor = 7,
|
||||
HomingFailPulloff = 8,
|
||||
HomingFailApproach = 9,
|
||||
SpindleControl = 10,
|
||||
};
|
||||
|
||||
// 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.
|
||||
@@ -153,11 +156,11 @@ extern system_t sys;
|
||||
extern int32_t sys_position[N_AXIS]; // Real-time machine (aka home) position vector in steps.
|
||||
extern int32_t sys_probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
||||
|
||||
extern volatile uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||
extern volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
extern volatile uint8_t 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 uint8_t sys_probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||
extern volatile uint8_t sys_rt_exec_state; // Global realtime executor bitflag variable for state management. See EXEC bitmasks.
|
||||
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.
|
||||
|
||||
#ifdef DEBUG
|
||||
# define EXEC_DEBUG_REPORT bit(0)
|
||||
@@ -177,7 +180,7 @@ void isr_control_inputs();
|
||||
// Special handlers for setting and clearing Grbl's real-time execution flags.
|
||||
void system_set_exec_state_flag(uint8_t mask);
|
||||
void system_clear_exec_state_flag(uint8_t mask);
|
||||
void system_set_exec_alarm(uint8_t code);
|
||||
void system_set_exec_alarm(ExecAlarm code);
|
||||
void system_clear_exec_alarm();
|
||||
void system_set_exec_motion_override_flag(uint8_t mask);
|
||||
void system_set_exec_accessory_override_flag(uint8_t mask);
|
||||
@@ -204,7 +207,7 @@ uint8_t system_check_travel_limits(float* target);
|
||||
// Special handlers for setting and clearing Grbl's real-time execution flags.
|
||||
void system_set_exec_state_flag(uint8_t mask);
|
||||
void system_clear_exec_state_flag(uint8_t mask);
|
||||
void system_set_exec_alarm(uint8_t code);
|
||||
void system_set_exec_alarm(ExecAlarm code);
|
||||
void system_clear_exec_alarm();
|
||||
void system_set_exec_motion_override_flag(uint8_t mask);
|
||||
void system_set_exec_accessory_override_flag(uint8_t mask);
|
||||
|
Reference in New Issue
Block a user