From aa5f8f839982ca2f681262af14013e2940c6a0df Mon Sep 17 00:00:00 2001 From: Rob Giseburt Date: Thu, 7 Nov 2019 12:11:59 -0500 Subject: [PATCH] ESC: Switch boot time and lockout timer to Timeouts --- g2core/canonical_machine.cpp | 14 +++++---- g2core/canonical_machine.h | 12 +++---- g2core/controller.cpp | 61 +++++++++++++++++++----------------- g2core/spindle.h | 7 ----- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/g2core/canonical_machine.cpp b/g2core/canonical_machine.cpp index 2861b8aa..b805ca58 100644 --- a/g2core/canonical_machine.cpp +++ b/g2core/canonical_machine.cpp @@ -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))); } diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index e35e7a41..faf609aa 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -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 diff --git a/g2core/controller.cpp b/g2core/controller.cpp index dca32bea..6461c666 100644 --- a/g2core/controller.cpp +++ b/g2core/controller.cpp @@ -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 diff --git a/g2core/spindle.h b/g2core/spindle.h index 5b2eb07a..9858d6bc 100644 --- a/g2core/spindle.h +++ b/g2core/spindle.h @@ -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;