ESC: Switch boot time and lockout timer to Timeouts

This commit is contained in:
Rob Giseburt
2020-01-10 19:25:11 -06:00
parent 7bacdd0d4b
commit aa5f8f8399
4 changed files with 47 additions and 47 deletions
+8 -6
View File
@@ -299,14 +299,13 @@ void canonical_machine_reset(cmMachine_t *_cm)
_cm->cycle_type = CYCLE_NONE;
_cm->motion_state = MOTION_STOP;
_cm->hold_state = FEEDHOLD_OFF;
// _cm->esc_boot_timer.set(???); // no longer used?
_cm->gmx.block_delete_switch = true;
_cm->gm.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE; // never start in a motion mode
_cm->machine_state = MACHINE_READY;
#ifdef ENABLE_INTERLOCK_AND_ESTOP
_cm->safety_state = _cm->estop_state = 0;
_cm->esc_boot_timer = Motate::SysTickTimer.getValue();
_cm->esc_boot_timer.set(ESC_BOOT_TIME);
_cm->safety_state = SAFETY_ESC_REBOOTING;
#endif
@@ -2157,12 +2156,15 @@ stat_t cm_get_frmo(nvObj_t *nv) { return(_get_msg_helper(nv, msg_frmo, cm_get_fe
#ifdef ENABLE_INTERLOCK_AND_ESTOP
stat_t cm_get_safe(nvObj_t *nv) {
uint8_t safe = 0;
if((cm->safety_state & SAFETY_INTERLOCK_MASK) != 0)
if ((cm->safety_state & SAFETY_INTERLOCK_MASK) != 0) {
safe |= 0x1;
if((cm->safety_state & SAFETY_ESC_MASK) != 0)
}
if ((cm->safety_state & SAFETY_ESC_MASK) != 0) {
safe |= 0x2;
return(_get_msg_helper(nv, msg_safe, safe)); }
stat_t cm_get_estp(nvObj_t *nv) { return(_get_msg_helper(nv, msg_estp, (cm->estop_state & 0x3))); }
}
return (_get_msg_helper(nv, msg_safe, safe));
}
stat_t cm_get_estp(nvObj_t *nv) { return (_get_msg_helper(nv, msg_estp, (cm->estop_state & 0x3))); }
#endif
stat_t cm_get_toolv(nvObj_t *nv) { return(get_integer(nv, cm_get_tool(ACTIVE_MODEL))); }
+6 -6
View File
@@ -203,11 +203,12 @@ typedef enum {
SAFETY_INTERLOCK_MASK = 0x1,
SAFETY_ESC_MASK = 0xE,
#endif
#else
SAFETY_INTERLOCK_ENGAGED = 0, // meaning the interlock input is CLOSED (low)
SAFETY_INTERLOCK_DISENGAGING, // meaning the interlock opened and we're dealing with it
SAFETY_INTERLOCK_DISENGAGED,
SAFETY_INTERLOCK_ENGAGING
#endif
} cmSafetyState;
typedef enum { // feed override state machine
@@ -340,7 +341,6 @@ typedef struct cmMachine { // struct to manage canonical machin
uint8_t safety_interlock_disengaged; // set non-zero to start interlock processing (value is input number)
uint8_t safety_interlock_reengaged; // set non-zero to end interlock processing (value is input number)
cmSafetyState safety_interlock_state; // safety interlock state
// Motate::Timeout esc_boot_timer; // timer for Electronic Speed Control (Spindle electronics) to boot
cmHomingState homing_state; // home: homing cycle sub-state machine
uint8_t homed[AXES]; // individual axis homing flags
@@ -361,10 +361,10 @@ typedef struct cmMachine { // struct to manage canonical machin
GCodeState_t *am; // active Gcode model is maintained by state management
#ifdef ENABLE_INTERLOCK_AND_ESTOP
uint8_t safety_state; // Tracks whether interlock has been triggered, whether esc is rebooting, etc
uint8_t estop_state; // Whether estop has been triggered
uint32_t esc_boot_timer; // When the ESC last booted up
uint32_t esc_lockout_timer; // When the ESC lockout last triggered
uint8_t safety_state; // Tracks whether interlock has been triggered, whether esc is rebooting, etc
uint8_t estop_state; // Whether estop has been triggered
Motate::Timeout esc_boot_timer; // When the ESC last booted up
Motate::Timeout esc_lockout_timer; // When the ESC lockout last triggered
#endif
GCodeState_t gm; // core gcode model state
+33 -28
View File
@@ -565,72 +565,77 @@ static stat_t _limit_switch_handler(void)
}
#ifdef ENABLE_INTERLOCK_AND_ESTOP
static stat_t _interlock_estop_handler(void)
{
static stat_t _interlock_estop_handler(void) {
bool report = false;
//Process E-Stop and Interlock signals
if((cm->safety_state & SAFETY_INTERLOCK_MASK) == SAFETY_INTERLOCK_CLOSED && gpio_read_input(INTERLOCK_SWITCH_INPUT) == INPUT_ACTIVE) {
// Process E-Stop and Interlock signals
if ((cm->safety_state & SAFETY_INTERLOCK_MASK) == SAFETY_INTERLOCK_CLOSED &&
gpio_read_input(INTERLOCK_SWITCH_INPUT) == INPUT_ACTIVE) {
cm->safety_state |= SAFETY_INTERLOCK_OPEN;
if(spindle.state != SPINDLE_OFF) {
if(mp_get_run_buffer() != NULL)
cm_request_feedhold(FEEDHOLD_TYPE_ACTIONS, FEEDHOLD_EXIT_INTERLOCK); // may have already requested STOP as INPUT_ACTION
if (spindle.state != SPINDLE_OFF) {
if (mp_get_run_buffer() != NULL)
cm_request_feedhold(FEEDHOLD_TYPE_HOLD,
FEEDHOLD_EXIT_STOP); // may have already requested STOP as INPUT_ACTION
else {
cm_cycle_start();
cm_request_cycle_start(); // proper way to restart the cycle
spindle_control_immediate(spindle.state);
}
}
//If we just entered interlock and we're not off, start the lockout timer
if((cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_ONLINE || (cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_REBOOTING) {
cm->esc_lockout_timer = Motate::SysTickTimer.getValue();
// If we just entered interlock and we're not off, start the lockout timer
if ((cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_ONLINE ||
(cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_REBOOTING) {
cm->esc_lockout_timer.set(ESC_LOCKOUT_TIME);
cm->safety_state |= SAFETY_ESC_LOCKOUT;
}
report = true;
} else if((cm->safety_state & SAFETY_INTERLOCK_MASK) == SAFETY_INTERLOCK_OPEN && gpio_read_input(INTERLOCK_SWITCH_INPUT) == INPUT_INACTIVE) {
} else if ((cm->safety_state & SAFETY_INTERLOCK_MASK) == SAFETY_INTERLOCK_OPEN &&
gpio_read_input(INTERLOCK_SWITCH_INPUT) == INPUT_INACTIVE) {
cm->safety_state &= ~SAFETY_INTERLOCK_OPEN;
//If we just left interlock, stop the lockout timer
if((cm->safety_state & SAFETY_ESC_LOCKOUT) == SAFETY_ESC_LOCKOUT)
cm->safety_state &= ~SAFETY_ESC_LOCKOUT;
// If we just left interlock, stop the lockout timer
if ((cm->safety_state & SAFETY_ESC_LOCKOUT) == SAFETY_ESC_LOCKOUT) cm->safety_state &= ~SAFETY_ESC_LOCKOUT;
report = true;
}
if((cm->estop_state & ESTOP_PRESSED_MASK) == ESTOP_RELEASED && gpio_read_input(ESTOP_SWITCH_INPUT) == INPUT_ACTIVE) {
if ((cm->estop_state & ESTOP_PRESSED_MASK) == ESTOP_RELEASED &&
gpio_read_input(ESTOP_SWITCH_INPUT) == INPUT_ACTIVE) {
cm->estop_state = ESTOP_PRESSED | ESTOP_UNACKED | ESTOP_ACTIVE;
cm_shutdown(STAT_SHUTDOWN, "e-stop pressed");
//E-stop always sets the ESC to off
// E-stop always sets the ESC to off
cm->safety_state &= ~SAFETY_ESC_MASK;
cm->safety_state |= SAFETY_ESC_OFFLINE;
report = true;
} else if((cm->estop_state & ESTOP_PRESSED_MASK) == ESTOP_PRESSED && gpio_read_input(ESTOP_SWITCH_INPUT) == INPUT_INACTIVE) {
} else if ((cm->estop_state & ESTOP_PRESSED_MASK) == ESTOP_PRESSED &&
gpio_read_input(ESTOP_SWITCH_INPUT) == INPUT_INACTIVE) {
cm->estop_state &= ~ESTOP_PRESSED;
report = true;
}
//if E-Stop and Interlock are both 0, and we're off, go into "ESC Reboot"
if((cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_OFFLINE && (cm->estop_state & ESTOP_PRESSED) == 0 && (cm->safety_state & SAFETY_INTERLOCK_OPEN) == 0) {
// if E-Stop and Interlock are both 0, and we're off, go into "ESC Reboot"
if ((cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_OFFLINE && (cm->estop_state & ESTOP_PRESSED) == 0 &&
(cm->safety_state & SAFETY_INTERLOCK_OPEN) == 0) {
cm->safety_state &= ~SAFETY_ESC_MASK;
cm->safety_state |= SAFETY_ESC_REBOOTING;
cm->esc_boot_timer = Motate::SysTickTimer.getValue();
cm->esc_boot_timer.set(ESC_BOOT_TIME);
report = true;
}
//Check if ESC lockout timer or reboot timer have expired
uint32_t now = Motate::SysTickTimer.getValue();
if((cm->safety_state & SAFETY_ESC_LOCKOUT) != 0 && (now - cm->esc_lockout_timer) > ESC_LOCKOUT_TIME) {
// Check if ESC lockout timer or reboot timer have expired
if ((cm->safety_state & SAFETY_ESC_LOCKOUT) != 0 && cm->esc_lockout_timer.isPast()) {
cm->safety_state &= ~SAFETY_ESC_MASK;
cm->safety_state |= SAFETY_ESC_OFFLINE;
report = true;
}
if((cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_REBOOTING && (now - cm->esc_boot_timer) > ESC_BOOT_TIME) {
if ((cm->safety_state & SAFETY_ESC_MASK) == SAFETY_ESC_REBOOTING && cm->esc_boot_timer.isPast()) {
cm->safety_state &= ~SAFETY_ESC_MASK;
report = true;
}
//If we've successfully ended all the ESTOP conditions, then end ESTOP
if(cm->estop_state == ESTOP_ACTIVE) {
// If we've successfully ended all the ESTOP conditions, then end ESTOP
if (cm->estop_state == ESTOP_ACTIVE) {
cm->estop_state = 0;
report = true;
}
if(report)
if (report) {
sr_request_status_report(SR_REQUEST_IMMEDIATE);
}
return (STAT_OK);
}
#else
-7
View File
@@ -96,13 +96,6 @@ typedef struct spSpindle {
bool override_enable; // {spoe:} TRUE = spindle speed override enabled (see also m48_enable in canonical machine)
float override_factor; // {spo:} 1.0000 x S spindle speed. Go up or down from there
// No longer used?
// // Spindle speed controller variables
// ESCState esc_state; // state management for ESC controller
// uint32_t esc_boot_timer; // When the ESC last booted up
// uint32_t esc_lockout_timer; // When the ESC lockout last triggered
} spSpindle_t;
extern spSpindle_t spindle;