I'm trying to port GRBL 1.1 to the STM32F746 chip. Tell me the solution, thanks.
grbl/protocol.c@0:9dcf85d9b2f3, 2017-09-04 (annotated)
- Committer:
- Sergunb
- Date:
- Mon Sep 04 12:05:05 2017 +0000
- Revision:
- 0:9dcf85d9b2f3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:9dcf85d9b2f3 | 1 | /* |
Sergunb | 0:9dcf85d9b2f3 | 2 | protocol.c - controls Grbl execution protocol and procedures |
Sergunb | 0:9dcf85d9b2f3 | 3 | Part of Grbl |
Sergunb | 0:9dcf85d9b2f3 | 4 | |
Sergunb | 0:9dcf85d9b2f3 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC |
Sergunb | 0:9dcf85d9b2f3 | 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud |
Sergunb | 0:9dcf85d9b2f3 | 7 | |
Sergunb | 0:9dcf85d9b2f3 | 8 | Grbl is free software: you can redistribute it and/or modify |
Sergunb | 0:9dcf85d9b2f3 | 9 | it under the terms of the GNU General Public License as published by |
Sergunb | 0:9dcf85d9b2f3 | 10 | the Free Software Foundation, either version 3 of the License, or |
Sergunb | 0:9dcf85d9b2f3 | 11 | (at your option) any later version. |
Sergunb | 0:9dcf85d9b2f3 | 12 | |
Sergunb | 0:9dcf85d9b2f3 | 13 | Grbl is distributed in the hope that it will be useful, |
Sergunb | 0:9dcf85d9b2f3 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:9dcf85d9b2f3 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:9dcf85d9b2f3 | 16 | GNU General Public License for more details. |
Sergunb | 0:9dcf85d9b2f3 | 17 | |
Sergunb | 0:9dcf85d9b2f3 | 18 | You should have received a copy of the GNU General Public License |
Sergunb | 0:9dcf85d9b2f3 | 19 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
Sergunb | 0:9dcf85d9b2f3 | 20 | */ |
Sergunb | 0:9dcf85d9b2f3 | 21 | |
Sergunb | 0:9dcf85d9b2f3 | 22 | #include "grbl.h" |
Sergunb | 0:9dcf85d9b2f3 | 23 | |
Sergunb | 0:9dcf85d9b2f3 | 24 | // Define line flags. Includes comment type tracking and line overflow detection. |
Sergunb | 0:9dcf85d9b2f3 | 25 | #define LINE_FLAG_OVERFLOW bit(0) |
Sergunb | 0:9dcf85d9b2f3 | 26 | #define LINE_FLAG_COMMENT_PARENTHESES bit(1) |
Sergunb | 0:9dcf85d9b2f3 | 27 | #define LINE_FLAG_COMMENT_SEMICOLON bit(2) |
Sergunb | 0:9dcf85d9b2f3 | 28 | |
Sergunb | 0:9dcf85d9b2f3 | 29 | |
Sergunb | 0:9dcf85d9b2f3 | 30 | static char line[LINE_BUFFER_SIZE]; // Line to be executed. Zero-terminated. |
Sergunb | 0:9dcf85d9b2f3 | 31 | #ifdef LEDBLINK |
Sergunb | 0:9dcf85d9b2f3 | 32 | void LedBlink(void); |
Sergunb | 0:9dcf85d9b2f3 | 33 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 34 | |
Sergunb | 0:9dcf85d9b2f3 | 35 | static void protocol_exec_rt_suspend(); |
Sergunb | 0:9dcf85d9b2f3 | 36 | |
Sergunb | 0:9dcf85d9b2f3 | 37 | |
Sergunb | 0:9dcf85d9b2f3 | 38 | /* |
Sergunb | 0:9dcf85d9b2f3 | 39 | GRBL PRIMARY LOOP: |
Sergunb | 0:9dcf85d9b2f3 | 40 | */ |
Sergunb | 0:9dcf85d9b2f3 | 41 | void protocol_main_loop() |
Sergunb | 0:9dcf85d9b2f3 | 42 | { |
Sergunb | 0:9dcf85d9b2f3 | 43 | // Perform some machine checks to make sure everything is good to go. |
Sergunb | 0:9dcf85d9b2f3 | 44 | #ifdef CHECK_LIMITS_AT_INIT |
Sergunb | 0:9dcf85d9b2f3 | 45 | if (bit_istrue(settings.flags, BITFLAG_HARD_LIMIT_ENABLE)) { |
Sergunb | 0:9dcf85d9b2f3 | 46 | if (limits_get_state()) { |
Sergunb | 0:9dcf85d9b2f3 | 47 | sys.state = STATE_ALARM; // Ensure alarm state is active. |
Sergunb | 0:9dcf85d9b2f3 | 48 | report_feedback_message(MESSAGE_CHECK_LIMITS); |
Sergunb | 0:9dcf85d9b2f3 | 49 | } |
Sergunb | 0:9dcf85d9b2f3 | 50 | } |
Sergunb | 0:9dcf85d9b2f3 | 51 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 52 | // Check for and report alarm state after a reset, error, or an initial power up. |
Sergunb | 0:9dcf85d9b2f3 | 53 | // NOTE: Sleep mode disables the stepper drivers and position can't be guaranteed. |
Sergunb | 0:9dcf85d9b2f3 | 54 | // Re-initialize the sleep state as an ALARM mode to ensure user homes or acknowledges. |
Sergunb | 0:9dcf85d9b2f3 | 55 | if (sys.state & (STATE_ALARM | STATE_SLEEP)) { |
Sergunb | 0:9dcf85d9b2f3 | 56 | report_feedback_message(MESSAGE_ALARM_LOCK); |
Sergunb | 0:9dcf85d9b2f3 | 57 | sys.state = STATE_ALARM; // Ensure alarm state is set. |
Sergunb | 0:9dcf85d9b2f3 | 58 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 59 | // Check if the safety door is open. |
Sergunb | 0:9dcf85d9b2f3 | 60 | sys.state = STATE_IDLE; |
Sergunb | 0:9dcf85d9b2f3 | 61 | if (system_check_safety_door_ajar()) { |
Sergunb | 0:9dcf85d9b2f3 | 62 | bit_true(sys_rt_exec_state, EXEC_SAFETY_DOOR); |
Sergunb | 0:9dcf85d9b2f3 | 63 | protocol_execute_realtime(); // Enter safety door mode. Should return as IDLE state. |
Sergunb | 0:9dcf85d9b2f3 | 64 | } |
Sergunb | 0:9dcf85d9b2f3 | 65 | // All systems go! |
Sergunb | 0:9dcf85d9b2f3 | 66 | system_execute_startup(line); // Execute startup script. |
Sergunb | 0:9dcf85d9b2f3 | 67 | } |
Sergunb | 0:9dcf85d9b2f3 | 68 | |
Sergunb | 0:9dcf85d9b2f3 | 69 | // --------------------------------------------------------------------------------- |
Sergunb | 0:9dcf85d9b2f3 | 70 | // Primary loop! Upon a system abort, this exits back to main() to reset the system. |
Sergunb | 0:9dcf85d9b2f3 | 71 | // This is also where Grbl idles while waiting for something to do. |
Sergunb | 0:9dcf85d9b2f3 | 72 | // --------------------------------------------------------------------------------- |
Sergunb | 0:9dcf85d9b2f3 | 73 | |
Sergunb | 0:9dcf85d9b2f3 | 74 | uint8_t line_flags = 0; |
Sergunb | 0:9dcf85d9b2f3 | 75 | uint8_t char_counter = 0; |
Sergunb | 0:9dcf85d9b2f3 | 76 | uint8_t c; |
Sergunb | 0:9dcf85d9b2f3 | 77 | for (;;) { |
Sergunb | 0:9dcf85d9b2f3 | 78 | |
Sergunb | 0:9dcf85d9b2f3 | 79 | // Process one line of incoming serial data, as the data becomes available. Performs an |
Sergunb | 0:9dcf85d9b2f3 | 80 | // initial filtering by removing spaces and comments and capitalizing all letters. |
Sergunb | 0:9dcf85d9b2f3 | 81 | while((c = serial_read()) != SERIAL_NO_DATA) { |
Sergunb | 0:9dcf85d9b2f3 | 82 | if ((c == '\n') || (c == '\r')) { // End of line reached |
Sergunb | 0:9dcf85d9b2f3 | 83 | |
Sergunb | 0:9dcf85d9b2f3 | 84 | protocol_execute_realtime(); // Runtime command check point. |
Sergunb | 0:9dcf85d9b2f3 | 85 | if (sys.abort) { return; } // Bail to calling function upon system abort |
Sergunb | 0:9dcf85d9b2f3 | 86 | |
Sergunb | 0:9dcf85d9b2f3 | 87 | line[char_counter] = 0; // Set string termination character. |
Sergunb | 0:9dcf85d9b2f3 | 88 | #ifdef LEDBLINK |
Sergunb | 0:9dcf85d9b2f3 | 89 | LedBlink(); |
Sergunb | 0:9dcf85d9b2f3 | 90 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 91 | #ifdef REPORT_ECHO_LINE_RECEIVED |
Sergunb | 0:9dcf85d9b2f3 | 92 | report_echo_line_received(line); |
Sergunb | 0:9dcf85d9b2f3 | 93 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 94 | |
Sergunb | 0:9dcf85d9b2f3 | 95 | // Direct and execute one line of formatted input, and report status of execution. |
Sergunb | 0:9dcf85d9b2f3 | 96 | if (line_flags & LINE_FLAG_OVERFLOW) { |
Sergunb | 0:9dcf85d9b2f3 | 97 | // Report line overflow error. |
Sergunb | 0:9dcf85d9b2f3 | 98 | report_status_message(STATUS_OVERFLOW); |
Sergunb | 0:9dcf85d9b2f3 | 99 | } else if (line[0] == 0) { |
Sergunb | 0:9dcf85d9b2f3 | 100 | // Empty or comment line. For syncing purposes. |
Sergunb | 0:9dcf85d9b2f3 | 101 | report_status_message(STATUS_OK); |
Sergunb | 0:9dcf85d9b2f3 | 102 | } else if (line[0] == '$') { |
Sergunb | 0:9dcf85d9b2f3 | 103 | // Grbl '$' system command |
Sergunb | 0:9dcf85d9b2f3 | 104 | report_status_message(system_execute_line(line)); |
Sergunb | 0:9dcf85d9b2f3 | 105 | } else if (sys.state & (STATE_ALARM | STATE_JOG)) { |
Sergunb | 0:9dcf85d9b2f3 | 106 | // Everything else is gcode. Block if in alarm or jog mode. |
Sergunb | 0:9dcf85d9b2f3 | 107 | report_status_message(STATUS_SYSTEM_GC_LOCK); |
Sergunb | 0:9dcf85d9b2f3 | 108 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 109 | // Parse and execute g-code block. |
Sergunb | 0:9dcf85d9b2f3 | 110 | report_status_message(gc_execute_line(line)); |
Sergunb | 0:9dcf85d9b2f3 | 111 | } |
Sergunb | 0:9dcf85d9b2f3 | 112 | |
Sergunb | 0:9dcf85d9b2f3 | 113 | // Reset tracking data for next line. |
Sergunb | 0:9dcf85d9b2f3 | 114 | line_flags = 0; |
Sergunb | 0:9dcf85d9b2f3 | 115 | char_counter = 0; |
Sergunb | 0:9dcf85d9b2f3 | 116 | |
Sergunb | 0:9dcf85d9b2f3 | 117 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 118 | |
Sergunb | 0:9dcf85d9b2f3 | 119 | if (line_flags) { |
Sergunb | 0:9dcf85d9b2f3 | 120 | // Throw away all (except EOL) comment characters and overflow characters. |
Sergunb | 0:9dcf85d9b2f3 | 121 | if (c == ')') { |
Sergunb | 0:9dcf85d9b2f3 | 122 | // End of '()' comment. Resume line allowed. |
Sergunb | 0:9dcf85d9b2f3 | 123 | if (line_flags & LINE_FLAG_COMMENT_PARENTHESES) { line_flags &= ~(LINE_FLAG_COMMENT_PARENTHESES); } |
Sergunb | 0:9dcf85d9b2f3 | 124 | } |
Sergunb | 0:9dcf85d9b2f3 | 125 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 126 | if (c <= ' ') { |
Sergunb | 0:9dcf85d9b2f3 | 127 | // Throw away whitepace and control characters |
Sergunb | 0:9dcf85d9b2f3 | 128 | } else if (c == '/') { |
Sergunb | 0:9dcf85d9b2f3 | 129 | // Block delete NOT SUPPORTED. Ignore character. |
Sergunb | 0:9dcf85d9b2f3 | 130 | // NOTE: If supported, would simply need to check the system if block delete is enabled. |
Sergunb | 0:9dcf85d9b2f3 | 131 | } else if (c == '(') { |
Sergunb | 0:9dcf85d9b2f3 | 132 | // Enable comments flag and ignore all characters until ')' or EOL. |
Sergunb | 0:9dcf85d9b2f3 | 133 | // NOTE: This doesn't follow the NIST definition exactly, but is good enough for now. |
Sergunb | 0:9dcf85d9b2f3 | 134 | // In the future, we could simply remove the items within the comments, but retain the |
Sergunb | 0:9dcf85d9b2f3 | 135 | // comment control characters, so that the g-code parser can error-check it. |
Sergunb | 0:9dcf85d9b2f3 | 136 | line_flags |= LINE_FLAG_COMMENT_PARENTHESES; |
Sergunb | 0:9dcf85d9b2f3 | 137 | } else if (c == ';') { |
Sergunb | 0:9dcf85d9b2f3 | 138 | // NOTE: ';' comment to EOL is a LinuxCNC definition. Not NIST. |
Sergunb | 0:9dcf85d9b2f3 | 139 | line_flags |= LINE_FLAG_COMMENT_SEMICOLON; |
Sergunb | 0:9dcf85d9b2f3 | 140 | // TODO: Install '%' feature |
Sergunb | 0:9dcf85d9b2f3 | 141 | // } else if (c == '%') { |
Sergunb | 0:9dcf85d9b2f3 | 142 | // Program start-end percent sign NOT SUPPORTED. |
Sergunb | 0:9dcf85d9b2f3 | 143 | // NOTE: This maybe installed to tell Grbl when a program is running vs manual input, |
Sergunb | 0:9dcf85d9b2f3 | 144 | // where, during a program, the system auto-cycle start will continue to execute |
Sergunb | 0:9dcf85d9b2f3 | 145 | // everything until the next '%' sign. This will help fix resuming issues with certain |
Sergunb | 0:9dcf85d9b2f3 | 146 | // functions that empty the planner buffer to execute its task on-time. |
Sergunb | 0:9dcf85d9b2f3 | 147 | } else if (char_counter >= (LINE_BUFFER_SIZE-1)) { |
Sergunb | 0:9dcf85d9b2f3 | 148 | // Detect line buffer overflow and set flag. |
Sergunb | 0:9dcf85d9b2f3 | 149 | line_flags |= LINE_FLAG_OVERFLOW; |
Sergunb | 0:9dcf85d9b2f3 | 150 | } else if (c >= 'a' && c <= 'z') { // Upcase lowercase |
Sergunb | 0:9dcf85d9b2f3 | 151 | line[char_counter++] = c-'a'+'A'; |
Sergunb | 0:9dcf85d9b2f3 | 152 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 153 | line[char_counter++] = c; |
Sergunb | 0:9dcf85d9b2f3 | 154 | } |
Sergunb | 0:9dcf85d9b2f3 | 155 | } |
Sergunb | 0:9dcf85d9b2f3 | 156 | |
Sergunb | 0:9dcf85d9b2f3 | 157 | } |
Sergunb | 0:9dcf85d9b2f3 | 158 | } |
Sergunb | 0:9dcf85d9b2f3 | 159 | |
Sergunb | 0:9dcf85d9b2f3 | 160 | // If there are no more characters in the serial read buffer to be processed and executed, |
Sergunb | 0:9dcf85d9b2f3 | 161 | // this indicates that g-code streaming has either filled the planner buffer or has |
Sergunb | 0:9dcf85d9b2f3 | 162 | // completed. In either case, auto-cycle start, if enabled, any queued moves. |
Sergunb | 0:9dcf85d9b2f3 | 163 | protocol_auto_cycle_start(); |
Sergunb | 0:9dcf85d9b2f3 | 164 | |
Sergunb | 0:9dcf85d9b2f3 | 165 | protocol_execute_realtime(); // Runtime command check point. |
Sergunb | 0:9dcf85d9b2f3 | 166 | if (sys.abort) { return; } // Bail to main() program loop to reset system. |
Sergunb | 0:9dcf85d9b2f3 | 167 | } |
Sergunb | 0:9dcf85d9b2f3 | 168 | |
Sergunb | 0:9dcf85d9b2f3 | 169 | return; /* Never reached */ |
Sergunb | 0:9dcf85d9b2f3 | 170 | } |
Sergunb | 0:9dcf85d9b2f3 | 171 | |
Sergunb | 0:9dcf85d9b2f3 | 172 | |
Sergunb | 0:9dcf85d9b2f3 | 173 | // Block until all buffered steps are executed or in a cycle state. Works with feed hold |
Sergunb | 0:9dcf85d9b2f3 | 174 | // during a synchronize call, if it should happen. Also, waits for clean cycle end. |
Sergunb | 0:9dcf85d9b2f3 | 175 | void protocol_buffer_synchronize() |
Sergunb | 0:9dcf85d9b2f3 | 176 | { |
Sergunb | 0:9dcf85d9b2f3 | 177 | // If system is queued, ensure cycle resumes if the auto start flag is present. |
Sergunb | 0:9dcf85d9b2f3 | 178 | protocol_auto_cycle_start(); |
Sergunb | 0:9dcf85d9b2f3 | 179 | do { |
Sergunb | 0:9dcf85d9b2f3 | 180 | protocol_execute_realtime(); // Check and execute run-time commands |
Sergunb | 0:9dcf85d9b2f3 | 181 | if (sys.abort) { return; } // Check for system abort |
Sergunb | 0:9dcf85d9b2f3 | 182 | } while (plan_get_current_block() || (sys.state == STATE_CYCLE)); |
Sergunb | 0:9dcf85d9b2f3 | 183 | } |
Sergunb | 0:9dcf85d9b2f3 | 184 | |
Sergunb | 0:9dcf85d9b2f3 | 185 | |
Sergunb | 0:9dcf85d9b2f3 | 186 | // Auto-cycle start triggers when there is a motion ready to execute and if the main program is not |
Sergunb | 0:9dcf85d9b2f3 | 187 | // actively parsing commands. |
Sergunb | 0:9dcf85d9b2f3 | 188 | // NOTE: This function is called from the main loop, buffer sync, and mc_line() only and executes |
Sergunb | 0:9dcf85d9b2f3 | 189 | // when one of these conditions exist respectively: There are no more blocks sent (i.e. streaming |
Sergunb | 0:9dcf85d9b2f3 | 190 | // is finished, single commands), a command that needs to wait for the motions in the buffer to |
Sergunb | 0:9dcf85d9b2f3 | 191 | // execute calls a buffer sync, or the planner buffer is full and ready to go. |
Sergunb | 0:9dcf85d9b2f3 | 192 | void protocol_auto_cycle_start() |
Sergunb | 0:9dcf85d9b2f3 | 193 | { |
Sergunb | 0:9dcf85d9b2f3 | 194 | if (plan_get_current_block() != NULL) { // Check if there are any blocks in the buffer. |
Sergunb | 0:9dcf85d9b2f3 | 195 | system_set_exec_state_flag(EXEC_CYCLE_START); // If so, execute them! |
Sergunb | 0:9dcf85d9b2f3 | 196 | } |
Sergunb | 0:9dcf85d9b2f3 | 197 | } |
Sergunb | 0:9dcf85d9b2f3 | 198 | |
Sergunb | 0:9dcf85d9b2f3 | 199 | |
Sergunb | 0:9dcf85d9b2f3 | 200 | // This function is the general interface to Grbl's real-time command execution system. It is called |
Sergunb | 0:9dcf85d9b2f3 | 201 | // from various check points in the main program, primarily where there may be a while loop waiting |
Sergunb | 0:9dcf85d9b2f3 | 202 | // for a buffer to clear space or any point where the execution time from the last check point may |
Sergunb | 0:9dcf85d9b2f3 | 203 | // be more than a fraction of a second. This is a way to execute realtime commands asynchronously |
Sergunb | 0:9dcf85d9b2f3 | 204 | // (aka multitasking) with grbl's g-code parsing and planning functions. This function also serves |
Sergunb | 0:9dcf85d9b2f3 | 205 | // as an interface for the interrupts to set the system realtime flags, where only the main program |
Sergunb | 0:9dcf85d9b2f3 | 206 | // handles them, removing the need to define more computationally-expensive volatile variables. This |
Sergunb | 0:9dcf85d9b2f3 | 207 | // also provides a controlled way to execute certain tasks without having two or more instances of |
Sergunb | 0:9dcf85d9b2f3 | 208 | // the same task, such as the planner recalculating the buffer upon a feedhold or overrides. |
Sergunb | 0:9dcf85d9b2f3 | 209 | // NOTE: The sys_rt_exec_state variable flags are set by any process, step or serial interrupts, pinouts, |
Sergunb | 0:9dcf85d9b2f3 | 210 | // limit switches, or the main program. |
Sergunb | 0:9dcf85d9b2f3 | 211 | void protocol_execute_realtime() |
Sergunb | 0:9dcf85d9b2f3 | 212 | { |
Sergunb | 0:9dcf85d9b2f3 | 213 | protocol_exec_rt_system(); |
Sergunb | 0:9dcf85d9b2f3 | 214 | if (sys.suspend) { protocol_exec_rt_suspend(); } |
Sergunb | 0:9dcf85d9b2f3 | 215 | } |
Sergunb | 0:9dcf85d9b2f3 | 216 | |
Sergunb | 0:9dcf85d9b2f3 | 217 | |
Sergunb | 0:9dcf85d9b2f3 | 218 | // Executes run-time commands, when required. This function primarily operates as Grbl's state |
Sergunb | 0:9dcf85d9b2f3 | 219 | // machine and controls the various real-time features Grbl has to offer. |
Sergunb | 0:9dcf85d9b2f3 | 220 | // NOTE: Do not alter this unless you know exactly what you are doing! |
Sergunb | 0:9dcf85d9b2f3 | 221 | void protocol_exec_rt_system() |
Sergunb | 0:9dcf85d9b2f3 | 222 | { |
Sergunb | 0:9dcf85d9b2f3 | 223 | uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times. |
Sergunb | 0:9dcf85d9b2f3 | 224 | rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm. |
Sergunb | 0:9dcf85d9b2f3 | 225 | if (rt_exec) { // Enter only if any bit flag is true |
Sergunb | 0:9dcf85d9b2f3 | 226 | // System alarm. Everything has shutdown by something that has gone severely wrong. Report |
Sergunb | 0:9dcf85d9b2f3 | 227 | // the source of the error to the user. If critical, Grbl disables by entering an infinite |
Sergunb | 0:9dcf85d9b2f3 | 228 | // loop until system reset/abort. |
Sergunb | 0:9dcf85d9b2f3 | 229 | sys.state = STATE_ALARM; // Set system alarm state |
Sergunb | 0:9dcf85d9b2f3 | 230 | report_alarm_message(rt_exec); |
Sergunb | 0:9dcf85d9b2f3 | 231 | // Halt everything upon a critical event flag. Currently hard and soft limits flag this. |
Sergunb | 0:9dcf85d9b2f3 | 232 | if ((rt_exec == EXEC_ALARM_HARD_LIMIT) || (rt_exec == EXEC_ALARM_SOFT_LIMIT)) { |
Sergunb | 0:9dcf85d9b2f3 | 233 | report_feedback_message(MESSAGE_CRITICAL_EVENT); |
Sergunb | 0:9dcf85d9b2f3 | 234 | system_clear_exec_state_flag(EXEC_RESET); // Disable any existing reset |
Sergunb | 0:9dcf85d9b2f3 | 235 | do { |
Sergunb | 0:9dcf85d9b2f3 | 236 | // Block everything, except reset and status reports, until user issues reset or power |
Sergunb | 0:9dcf85d9b2f3 | 237 | // cycles. Hard limits typically occur while unattended or not paying attention. Gives |
Sergunb | 0:9dcf85d9b2f3 | 238 | // the user and a GUI time to do what is needed before resetting, like killing the |
Sergunb | 0:9dcf85d9b2f3 | 239 | // incoming stream. The same could be said about soft limits. While the position is not |
Sergunb | 0:9dcf85d9b2f3 | 240 | // lost, continued streaming could cause a serious crash if by chance it gets executed. |
Sergunb | 0:9dcf85d9b2f3 | 241 | } while (bit_isfalse(sys_rt_exec_state,EXEC_RESET)); |
Sergunb | 0:9dcf85d9b2f3 | 242 | } |
Sergunb | 0:9dcf85d9b2f3 | 243 | system_clear_exec_alarm(); // Clear alarm |
Sergunb | 0:9dcf85d9b2f3 | 244 | } |
Sergunb | 0:9dcf85d9b2f3 | 245 | |
Sergunb | 0:9dcf85d9b2f3 | 246 | rt_exec = sys_rt_exec_state; // Copy volatile sys_rt_exec_state. |
Sergunb | 0:9dcf85d9b2f3 | 247 | if (rt_exec) { |
Sergunb | 0:9dcf85d9b2f3 | 248 | |
Sergunb | 0:9dcf85d9b2f3 | 249 | // Execute system abort. |
Sergunb | 0:9dcf85d9b2f3 | 250 | if (rt_exec & EXEC_RESET) { |
Sergunb | 0:9dcf85d9b2f3 | 251 | sys.abort = true; // Only place this is set true. |
Sergunb | 0:9dcf85d9b2f3 | 252 | return; // Nothing else to do but exit. |
Sergunb | 0:9dcf85d9b2f3 | 253 | } |
Sergunb | 0:9dcf85d9b2f3 | 254 | |
Sergunb | 0:9dcf85d9b2f3 | 255 | // Execute and serial print status |
Sergunb | 0:9dcf85d9b2f3 | 256 | if (rt_exec & EXEC_STATUS_REPORT) { |
Sergunb | 0:9dcf85d9b2f3 | 257 | report_realtime_status(); |
Sergunb | 0:9dcf85d9b2f3 | 258 | system_clear_exec_state_flag(EXEC_STATUS_REPORT); |
Sergunb | 0:9dcf85d9b2f3 | 259 | } |
Sergunb | 0:9dcf85d9b2f3 | 260 | |
Sergunb | 0:9dcf85d9b2f3 | 261 | // NOTE: Once hold is initiated, the system immediately enters a suspend state to block all |
Sergunb | 0:9dcf85d9b2f3 | 262 | // main program processes until either reset or resumed. This ensures a hold completes safely. |
Sergunb | 0:9dcf85d9b2f3 | 263 | if (rt_exec & (EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR | EXEC_SLEEP)) { |
Sergunb | 0:9dcf85d9b2f3 | 264 | |
Sergunb | 0:9dcf85d9b2f3 | 265 | // State check for allowable states for hold methods. |
Sergunb | 0:9dcf85d9b2f3 | 266 | if (!(sys.state & (STATE_ALARM | STATE_CHECK_MODE))) { |
Sergunb | 0:9dcf85d9b2f3 | 267 | |
Sergunb | 0:9dcf85d9b2f3 | 268 | // If in CYCLE or JOG states, immediately initiate a motion HOLD. |
Sergunb | 0:9dcf85d9b2f3 | 269 | if (sys.state & (STATE_CYCLE | STATE_JOG)) { |
Sergunb | 0:9dcf85d9b2f3 | 270 | if (!(sys.suspend & (SUSPEND_MOTION_CANCEL | SUSPEND_JOG_CANCEL))) { // Block, if already holding. |
Sergunb | 0:9dcf85d9b2f3 | 271 | st_update_plan_block_parameters(); // Notify stepper module to recompute for hold deceleration. |
Sergunb | 0:9dcf85d9b2f3 | 272 | sys.step_control = STEP_CONTROL_EXECUTE_HOLD; // Initiate suspend state with active flag. |
Sergunb | 0:9dcf85d9b2f3 | 273 | if (sys.state == STATE_JOG) { // Jog cancelled upon any hold event, except for sleeping. |
Sergunb | 0:9dcf85d9b2f3 | 274 | if (!(rt_exec & EXEC_SLEEP)) { sys.suspend |= SUSPEND_JOG_CANCEL; } |
Sergunb | 0:9dcf85d9b2f3 | 275 | } |
Sergunb | 0:9dcf85d9b2f3 | 276 | } |
Sergunb | 0:9dcf85d9b2f3 | 277 | } |
Sergunb | 0:9dcf85d9b2f3 | 278 | // If IDLE, Grbl is not in motion. Simply indicate suspend state and hold is complete. |
Sergunb | 0:9dcf85d9b2f3 | 279 | if (sys.state == STATE_IDLE) { sys.suspend = SUSPEND_HOLD_COMPLETE; } |
Sergunb | 0:9dcf85d9b2f3 | 280 | |
Sergunb | 0:9dcf85d9b2f3 | 281 | // Execute and flag a motion cancel with deceleration and return to idle. Used primarily by probing cycle |
Sergunb | 0:9dcf85d9b2f3 | 282 | // to halt and cancel the remainder of the motion. |
Sergunb | 0:9dcf85d9b2f3 | 283 | if (rt_exec & EXEC_MOTION_CANCEL) { |
Sergunb | 0:9dcf85d9b2f3 | 284 | // MOTION_CANCEL only occurs during a CYCLE, but a HOLD and SAFETY_DOOR may been initiated beforehand |
Sergunb | 0:9dcf85d9b2f3 | 285 | // to hold the CYCLE. Motion cancel is valid for a single planner block motion only, while jog cancel |
Sergunb | 0:9dcf85d9b2f3 | 286 | // will handle and clear multiple planner block motions. |
Sergunb | 0:9dcf85d9b2f3 | 287 | if (!(sys.state & STATE_JOG)) { sys.suspend |= SUSPEND_MOTION_CANCEL; } // NOTE: State is STATE_CYCLE. |
Sergunb | 0:9dcf85d9b2f3 | 288 | } |
Sergunb | 0:9dcf85d9b2f3 | 289 | |
Sergunb | 0:9dcf85d9b2f3 | 290 | // Execute a feed hold with deceleration, if required. Then, suspend system. |
Sergunb | 0:9dcf85d9b2f3 | 291 | if (rt_exec & EXEC_FEED_HOLD) { |
Sergunb | 0:9dcf85d9b2f3 | 292 | // Block SAFETY_DOOR, JOG, and SLEEP states from changing to HOLD state. |
Sergunb | 0:9dcf85d9b2f3 | 293 | if (!(sys.state & (STATE_SAFETY_DOOR | STATE_JOG | STATE_SLEEP))) { sys.state = STATE_HOLD; } |
Sergunb | 0:9dcf85d9b2f3 | 294 | } |
Sergunb | 0:9dcf85d9b2f3 | 295 | |
Sergunb | 0:9dcf85d9b2f3 | 296 | // Execute a safety door stop with a feed hold and disable spindle/coolant. |
Sergunb | 0:9dcf85d9b2f3 | 297 | // NOTE: Safety door differs from feed holds by stopping everything no matter state, disables powered |
Sergunb | 0:9dcf85d9b2f3 | 298 | // devices (spindle/coolant), and blocks resuming until switch is re-engaged. |
Sergunb | 0:9dcf85d9b2f3 | 299 | if (rt_exec & EXEC_SAFETY_DOOR) { |
Sergunb | 0:9dcf85d9b2f3 | 300 | report_feedback_message(MESSAGE_SAFETY_DOOR_AJAR); |
Sergunb | 0:9dcf85d9b2f3 | 301 | // If jogging, block safety door methods until jog cancel is complete. Just flag that it happened. |
Sergunb | 0:9dcf85d9b2f3 | 302 | if (!(sys.suspend & SUSPEND_JOG_CANCEL)) { |
Sergunb | 0:9dcf85d9b2f3 | 303 | // Check if the safety re-opened during a restore parking motion only. Ignore if |
Sergunb | 0:9dcf85d9b2f3 | 304 | // already retracting, parked or in sleep state. |
Sergunb | 0:9dcf85d9b2f3 | 305 | if (sys.state == STATE_SAFETY_DOOR) { |
Sergunb | 0:9dcf85d9b2f3 | 306 | if (sys.suspend & SUSPEND_INITIATE_RESTORE) { // Actively restoring |
Sergunb | 0:9dcf85d9b2f3 | 307 | #ifdef PARKING_ENABLE |
Sergunb | 0:9dcf85d9b2f3 | 308 | // Set hold and reset appropriate control flags to restart parking sequence. |
Sergunb | 0:9dcf85d9b2f3 | 309 | if (sys.step_control & STEP_CONTROL_EXECUTE_SYS_MOTION) { |
Sergunb | 0:9dcf85d9b2f3 | 310 | st_update_plan_block_parameters(); // Notify stepper module to recompute for hold deceleration. |
Sergunb | 0:9dcf85d9b2f3 | 311 | sys.step_control = (STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION); |
Sergunb | 0:9dcf85d9b2f3 | 312 | sys.suspend &= ~(SUSPEND_HOLD_COMPLETE); |
Sergunb | 0:9dcf85d9b2f3 | 313 | } // else NO_MOTION is active. |
Sergunb | 0:9dcf85d9b2f3 | 314 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 315 | sys.suspend &= ~(SUSPEND_RETRACT_COMPLETE | SUSPEND_INITIATE_RESTORE | SUSPEND_RESTORE_COMPLETE); |
Sergunb | 0:9dcf85d9b2f3 | 316 | sys.suspend |= SUSPEND_RESTART_RETRACT; |
Sergunb | 0:9dcf85d9b2f3 | 317 | } |
Sergunb | 0:9dcf85d9b2f3 | 318 | } |
Sergunb | 0:9dcf85d9b2f3 | 319 | if (sys.state != STATE_SLEEP) { sys.state = STATE_SAFETY_DOOR; } |
Sergunb | 0:9dcf85d9b2f3 | 320 | } |
Sergunb | 0:9dcf85d9b2f3 | 321 | // NOTE: This flag doesn't change when the door closes, unlike sys.state. Ensures any parking motions |
Sergunb | 0:9dcf85d9b2f3 | 322 | // are executed if the door switch closes and the state returns to HOLD. |
Sergunb | 0:9dcf85d9b2f3 | 323 | sys.suspend |= SUSPEND_SAFETY_DOOR_AJAR; |
Sergunb | 0:9dcf85d9b2f3 | 324 | } |
Sergunb | 0:9dcf85d9b2f3 | 325 | |
Sergunb | 0:9dcf85d9b2f3 | 326 | } |
Sergunb | 0:9dcf85d9b2f3 | 327 | |
Sergunb | 0:9dcf85d9b2f3 | 328 | if (rt_exec & EXEC_SLEEP) { |
Sergunb | 0:9dcf85d9b2f3 | 329 | if (sys.state == STATE_ALARM) { sys.suspend |= (SUSPEND_RETRACT_COMPLETE|SUSPEND_HOLD_COMPLETE); } |
Sergunb | 0:9dcf85d9b2f3 | 330 | sys.state = STATE_SLEEP; |
Sergunb | 0:9dcf85d9b2f3 | 331 | } |
Sergunb | 0:9dcf85d9b2f3 | 332 | |
Sergunb | 0:9dcf85d9b2f3 | 333 | system_clear_exec_state_flag((EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR | EXEC_SLEEP)); |
Sergunb | 0:9dcf85d9b2f3 | 334 | } |
Sergunb | 0:9dcf85d9b2f3 | 335 | |
Sergunb | 0:9dcf85d9b2f3 | 336 | // Execute a cycle start by starting the stepper interrupt to begin executing the blocks in queue. |
Sergunb | 0:9dcf85d9b2f3 | 337 | if (rt_exec & EXEC_CYCLE_START) { |
Sergunb | 0:9dcf85d9b2f3 | 338 | // Block if called at same time as the hold commands: feed hold, motion cancel, and safety door. |
Sergunb | 0:9dcf85d9b2f3 | 339 | // Ensures auto-cycle-start doesn't resume a hold without an explicit user-input. |
Sergunb | 0:9dcf85d9b2f3 | 340 | if (!(rt_exec & (EXEC_FEED_HOLD | EXEC_MOTION_CANCEL | EXEC_SAFETY_DOOR))) { |
Sergunb | 0:9dcf85d9b2f3 | 341 | // Resume door state when parking motion has retracted and door has been closed. |
Sergunb | 0:9dcf85d9b2f3 | 342 | if ((sys.state == STATE_SAFETY_DOOR) && !(sys.suspend & SUSPEND_SAFETY_DOOR_AJAR)) { |
Sergunb | 0:9dcf85d9b2f3 | 343 | if (sys.suspend & SUSPEND_RESTORE_COMPLETE) { |
Sergunb | 0:9dcf85d9b2f3 | 344 | sys.state = STATE_IDLE; // Set to IDLE to immediately resume the cycle. |
Sergunb | 0:9dcf85d9b2f3 | 345 | } else if (sys.suspend & SUSPEND_RETRACT_COMPLETE) { |
Sergunb | 0:9dcf85d9b2f3 | 346 | // Flag to re-energize powered components and restore original position, if disabled by SAFETY_DOOR. |
Sergunb | 0:9dcf85d9b2f3 | 347 | // NOTE: For a safety door to resume, the switch must be closed, as indicated by HOLD state, and |
Sergunb | 0:9dcf85d9b2f3 | 348 | // the retraction execution is complete, which implies the initial feed hold is not active. To |
Sergunb | 0:9dcf85d9b2f3 | 349 | // restore normal operation, the restore procedures must be initiated by the following flag. Once, |
Sergunb | 0:9dcf85d9b2f3 | 350 | // they are complete, it will call CYCLE_START automatically to resume and exit the suspend. |
Sergunb | 0:9dcf85d9b2f3 | 351 | sys.suspend |= SUSPEND_INITIATE_RESTORE; |
Sergunb | 0:9dcf85d9b2f3 | 352 | } |
Sergunb | 0:9dcf85d9b2f3 | 353 | } |
Sergunb | 0:9dcf85d9b2f3 | 354 | // Cycle start only when IDLE or when a hold is complete and ready to resume. |
Sergunb | 0:9dcf85d9b2f3 | 355 | if ((sys.state == STATE_IDLE) || ((sys.state & STATE_HOLD) && (sys.suspend & SUSPEND_HOLD_COMPLETE))) { |
Sergunb | 0:9dcf85d9b2f3 | 356 | if (sys.state == STATE_HOLD && sys.spindle_stop_ovr) { |
Sergunb | 0:9dcf85d9b2f3 | 357 | sys.spindle_stop_ovr |= SPINDLE_STOP_OVR_RESTORE_CYCLE; // Set to restore in suspend routine and cycle start after. |
Sergunb | 0:9dcf85d9b2f3 | 358 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 359 | // Start cycle only if queued motions exist in planner buffer and the motion is not canceled. |
Sergunb | 0:9dcf85d9b2f3 | 360 | sys.step_control = STEP_CONTROL_NORMAL_OP; // Restore step control to normal operation |
Sergunb | 0:9dcf85d9b2f3 | 361 | if (plan_get_current_block() && bit_isfalse(sys.suspend,SUSPEND_MOTION_CANCEL)) { |
Sergunb | 0:9dcf85d9b2f3 | 362 | sys.suspend = SUSPEND_DISABLE; // Break suspend state. |
Sergunb | 0:9dcf85d9b2f3 | 363 | sys.state = STATE_CYCLE; |
Sergunb | 0:9dcf85d9b2f3 | 364 | st_prep_buffer(); // Initialize step segment buffer before beginning cycle. |
Sergunb | 0:9dcf85d9b2f3 | 365 | st_wake_up(); |
Sergunb | 0:9dcf85d9b2f3 | 366 | } else { // Otherwise, do nothing. Set and resume IDLE state. |
Sergunb | 0:9dcf85d9b2f3 | 367 | sys.suspend = SUSPEND_DISABLE; // Break suspend state. |
Sergunb | 0:9dcf85d9b2f3 | 368 | sys.state = STATE_IDLE; |
Sergunb | 0:9dcf85d9b2f3 | 369 | } |
Sergunb | 0:9dcf85d9b2f3 | 370 | } |
Sergunb | 0:9dcf85d9b2f3 | 371 | } |
Sergunb | 0:9dcf85d9b2f3 | 372 | } |
Sergunb | 0:9dcf85d9b2f3 | 373 | system_clear_exec_state_flag(EXEC_CYCLE_START); |
Sergunb | 0:9dcf85d9b2f3 | 374 | } |
Sergunb | 0:9dcf85d9b2f3 | 375 | |
Sergunb | 0:9dcf85d9b2f3 | 376 | if (rt_exec & EXEC_CYCLE_STOP) { |
Sergunb | 0:9dcf85d9b2f3 | 377 | // Reinitializes the cycle plan and stepper system after a feed hold for a resume. Called by |
Sergunb | 0:9dcf85d9b2f3 | 378 | // realtime command execution in the main program, ensuring that the planner re-plans safely. |
Sergunb | 0:9dcf85d9b2f3 | 379 | // NOTE: Bresenham algorithm variables are still maintained through both the planner and stepper |
Sergunb | 0:9dcf85d9b2f3 | 380 | // cycle reinitializations. The stepper path should continue exactly as if nothing has happened. |
Sergunb | 0:9dcf85d9b2f3 | 381 | // NOTE: EXEC_CYCLE_STOP is set by the stepper subsystem when a cycle or feed hold completes. |
Sergunb | 0:9dcf85d9b2f3 | 382 | if ((sys.state & (STATE_HOLD|STATE_SAFETY_DOOR|STATE_SLEEP)) && !(sys.soft_limit) && !(sys.suspend & SUSPEND_JOG_CANCEL)) { |
Sergunb | 0:9dcf85d9b2f3 | 383 | // Hold complete. Set to indicate ready to resume. Remain in HOLD or DOOR states until user |
Sergunb | 0:9dcf85d9b2f3 | 384 | // has issued a resume command or reset. |
Sergunb | 0:9dcf85d9b2f3 | 385 | plan_cycle_reinitialize(); |
Sergunb | 0:9dcf85d9b2f3 | 386 | if (sys.step_control & STEP_CONTROL_EXECUTE_HOLD) { sys.suspend |= SUSPEND_HOLD_COMPLETE; } |
Sergunb | 0:9dcf85d9b2f3 | 387 | bit_false(sys.step_control,(STEP_CONTROL_EXECUTE_HOLD | STEP_CONTROL_EXECUTE_SYS_MOTION)); |
Sergunb | 0:9dcf85d9b2f3 | 388 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 389 | // Motion complete. Includes CYCLE/JOG/HOMING states and jog cancel/motion cancel/soft limit events. |
Sergunb | 0:9dcf85d9b2f3 | 390 | // NOTE: Motion and jog cancel both immediately return to idle after the hold completes. |
Sergunb | 0:9dcf85d9b2f3 | 391 | if (sys.suspend & SUSPEND_JOG_CANCEL) { // For jog cancel, flush buffers and sync positions. |
Sergunb | 0:9dcf85d9b2f3 | 392 | sys.step_control = STEP_CONTROL_NORMAL_OP; |
Sergunb | 0:9dcf85d9b2f3 | 393 | plan_reset(); |
Sergunb | 0:9dcf85d9b2f3 | 394 | st_reset(); |
Sergunb | 0:9dcf85d9b2f3 | 395 | gc_sync_position(); |
Sergunb | 0:9dcf85d9b2f3 | 396 | plan_sync_position(); |
Sergunb | 0:9dcf85d9b2f3 | 397 | } |
Sergunb | 0:9dcf85d9b2f3 | 398 | if (sys.suspend & SUSPEND_SAFETY_DOOR_AJAR) { // Only occurs when safety door opens during jog. |
Sergunb | 0:9dcf85d9b2f3 | 399 | sys.suspend &= ~(SUSPEND_JOG_CANCEL); |
Sergunb | 0:9dcf85d9b2f3 | 400 | sys.suspend |= SUSPEND_HOLD_COMPLETE; |
Sergunb | 0:9dcf85d9b2f3 | 401 | sys.state = STATE_SAFETY_DOOR; |
Sergunb | 0:9dcf85d9b2f3 | 402 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 403 | sys.suspend = SUSPEND_DISABLE; |
Sergunb | 0:9dcf85d9b2f3 | 404 | sys.state = STATE_IDLE; |
Sergunb | 0:9dcf85d9b2f3 | 405 | } |
Sergunb | 0:9dcf85d9b2f3 | 406 | } |
Sergunb | 0:9dcf85d9b2f3 | 407 | system_clear_exec_state_flag(EXEC_CYCLE_STOP); |
Sergunb | 0:9dcf85d9b2f3 | 408 | } |
Sergunb | 0:9dcf85d9b2f3 | 409 | } |
Sergunb | 0:9dcf85d9b2f3 | 410 | |
Sergunb | 0:9dcf85d9b2f3 | 411 | // Execute overrides. |
Sergunb | 0:9dcf85d9b2f3 | 412 | rt_exec = sys_rt_exec_motion_override; // Copy volatile sys_rt_exec_motion_override |
Sergunb | 0:9dcf85d9b2f3 | 413 | if (rt_exec) { |
Sergunb | 0:9dcf85d9b2f3 | 414 | system_clear_exec_motion_overrides(); // Clear all motion override flags. |
Sergunb | 0:9dcf85d9b2f3 | 415 | |
Sergunb | 0:9dcf85d9b2f3 | 416 | uint8_t new_f_override = sys.f_override; |
Sergunb | 0:9dcf85d9b2f3 | 417 | if (rt_exec & EXEC_FEED_OVR_RESET) { new_f_override = DEFAULT_FEED_OVERRIDE; } |
Sergunb | 0:9dcf85d9b2f3 | 418 | if (rt_exec & EXEC_FEED_OVR_COARSE_PLUS) { new_f_override += FEED_OVERRIDE_COARSE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 419 | if (rt_exec & EXEC_FEED_OVR_COARSE_MINUS) { new_f_override -= FEED_OVERRIDE_COARSE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 420 | if (rt_exec & EXEC_FEED_OVR_FINE_PLUS) { new_f_override += FEED_OVERRIDE_FINE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 421 | if (rt_exec & EXEC_FEED_OVR_FINE_MINUS) { new_f_override -= FEED_OVERRIDE_FINE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 422 | new_f_override = min(new_f_override,MAX_FEED_RATE_OVERRIDE); |
Sergunb | 0:9dcf85d9b2f3 | 423 | new_f_override = max(new_f_override,MIN_FEED_RATE_OVERRIDE); |
Sergunb | 0:9dcf85d9b2f3 | 424 | |
Sergunb | 0:9dcf85d9b2f3 | 425 | uint8_t new_r_override = sys.r_override; |
Sergunb | 0:9dcf85d9b2f3 | 426 | if (rt_exec & EXEC_RAPID_OVR_RESET) { new_r_override = DEFAULT_RAPID_OVERRIDE; } |
Sergunb | 0:9dcf85d9b2f3 | 427 | if (rt_exec & EXEC_RAPID_OVR_MEDIUM) { new_r_override = RAPID_OVERRIDE_MEDIUM; } |
Sergunb | 0:9dcf85d9b2f3 | 428 | if (rt_exec & EXEC_RAPID_OVR_LOW) { new_r_override = RAPID_OVERRIDE_LOW; } |
Sergunb | 0:9dcf85d9b2f3 | 429 | |
Sergunb | 0:9dcf85d9b2f3 | 430 | if ((new_f_override != sys.f_override) || (new_r_override != sys.r_override)) { |
Sergunb | 0:9dcf85d9b2f3 | 431 | sys.f_override = new_f_override; |
Sergunb | 0:9dcf85d9b2f3 | 432 | sys.r_override = new_r_override; |
Sergunb | 0:9dcf85d9b2f3 | 433 | sys.report_ovr_counter = 0; // Set to report change immediately |
Sergunb | 0:9dcf85d9b2f3 | 434 | plan_update_velocity_profile_parameters(); |
Sergunb | 0:9dcf85d9b2f3 | 435 | plan_cycle_reinitialize(); |
Sergunb | 0:9dcf85d9b2f3 | 436 | } |
Sergunb | 0:9dcf85d9b2f3 | 437 | } |
Sergunb | 0:9dcf85d9b2f3 | 438 | |
Sergunb | 0:9dcf85d9b2f3 | 439 | rt_exec = sys_rt_exec_accessory_override; |
Sergunb | 0:9dcf85d9b2f3 | 440 | if (rt_exec) { |
Sergunb | 0:9dcf85d9b2f3 | 441 | system_clear_exec_accessory_overrides(); // Clear all accessory override flags. |
Sergunb | 0:9dcf85d9b2f3 | 442 | |
Sergunb | 0:9dcf85d9b2f3 | 443 | // NOTE: Unlike motion overrides, spindle overrides do not require a planner reinitialization. |
Sergunb | 0:9dcf85d9b2f3 | 444 | uint8_t last_s_override = sys.spindle_speed_ovr; |
Sergunb | 0:9dcf85d9b2f3 | 445 | if (rt_exec & EXEC_SPINDLE_OVR_RESET) { last_s_override = DEFAULT_SPINDLE_SPEED_OVERRIDE; } |
Sergunb | 0:9dcf85d9b2f3 | 446 | if (rt_exec & EXEC_SPINDLE_OVR_COARSE_PLUS) { last_s_override += SPINDLE_OVERRIDE_COARSE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 447 | if (rt_exec & EXEC_SPINDLE_OVR_COARSE_MINUS) { last_s_override -= SPINDLE_OVERRIDE_COARSE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 448 | if (rt_exec & EXEC_SPINDLE_OVR_FINE_PLUS) { last_s_override += SPINDLE_OVERRIDE_FINE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 449 | if (rt_exec & EXEC_SPINDLE_OVR_FINE_MINUS) { last_s_override -= SPINDLE_OVERRIDE_FINE_INCREMENT; } |
Sergunb | 0:9dcf85d9b2f3 | 450 | last_s_override = min(last_s_override,MAX_SPINDLE_SPEED_OVERRIDE); |
Sergunb | 0:9dcf85d9b2f3 | 451 | last_s_override = max(last_s_override,MIN_SPINDLE_SPEED_OVERRIDE); |
Sergunb | 0:9dcf85d9b2f3 | 452 | |
Sergunb | 0:9dcf85d9b2f3 | 453 | if (last_s_override != sys.spindle_speed_ovr) { |
Sergunb | 0:9dcf85d9b2f3 | 454 | bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM); |
Sergunb | 0:9dcf85d9b2f3 | 455 | sys.spindle_speed_ovr = last_s_override; |
Sergunb | 0:9dcf85d9b2f3 | 456 | sys.report_ovr_counter = 0; // Set to report change immediately |
Sergunb | 0:9dcf85d9b2f3 | 457 | } |
Sergunb | 0:9dcf85d9b2f3 | 458 | |
Sergunb | 0:9dcf85d9b2f3 | 459 | if (rt_exec & EXEC_SPINDLE_OVR_STOP) { |
Sergunb | 0:9dcf85d9b2f3 | 460 | // Spindle stop override allowed only while in HOLD state. |
Sergunb | 0:9dcf85d9b2f3 | 461 | // NOTE: Report counters are set in spindle_set_state() when spindle stop is executed. |
Sergunb | 0:9dcf85d9b2f3 | 462 | if (sys.state == STATE_HOLD) { |
Sergunb | 0:9dcf85d9b2f3 | 463 | if (!(sys.spindle_stop_ovr)) { sys.spindle_stop_ovr = SPINDLE_STOP_OVR_INITIATE; } |
Sergunb | 0:9dcf85d9b2f3 | 464 | else if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_ENABLED) { sys.spindle_stop_ovr |= SPINDLE_STOP_OVR_RESTORE; } |
Sergunb | 0:9dcf85d9b2f3 | 465 | } |
Sergunb | 0:9dcf85d9b2f3 | 466 | } |
Sergunb | 0:9dcf85d9b2f3 | 467 | |
Sergunb | 0:9dcf85d9b2f3 | 468 | // NOTE: Since coolant state always performs a planner sync whenever it changes, the current |
Sergunb | 0:9dcf85d9b2f3 | 469 | // run state can be determined by checking the parser state. |
Sergunb | 0:9dcf85d9b2f3 | 470 | if (rt_exec & (EXEC_COOLANT_FLOOD_OVR_TOGGLE | EXEC_COOLANT_MIST_OVR_TOGGLE)) { |
Sergunb | 0:9dcf85d9b2f3 | 471 | if ((sys.state == STATE_IDLE) || (sys.state & (STATE_CYCLE | STATE_HOLD))) { |
Sergunb | 0:9dcf85d9b2f3 | 472 | uint8_t coolant_state = gc_state.modal.coolant; |
Sergunb | 0:9dcf85d9b2f3 | 473 | #ifdef ENABLE_M7 |
Sergunb | 0:9dcf85d9b2f3 | 474 | if (rt_exec & EXEC_COOLANT_MIST_OVR_TOGGLE) { |
Sergunb | 0:9dcf85d9b2f3 | 475 | if (coolant_state & COOLANT_MIST_ENABLE) { bit_false(coolant_state,COOLANT_MIST_ENABLE); } |
Sergunb | 0:9dcf85d9b2f3 | 476 | else { coolant_state |= COOLANT_MIST_ENABLE; } |
Sergunb | 0:9dcf85d9b2f3 | 477 | } |
Sergunb | 0:9dcf85d9b2f3 | 478 | if (rt_exec & EXEC_COOLANT_FLOOD_OVR_TOGGLE) { |
Sergunb | 0:9dcf85d9b2f3 | 479 | if (coolant_state & COOLANT_FLOOD_ENABLE) { bit_false(coolant_state,COOLANT_FLOOD_ENABLE); } |
Sergunb | 0:9dcf85d9b2f3 | 480 | else { coolant_state |= COOLANT_FLOOD_ENABLE; } |
Sergunb | 0:9dcf85d9b2f3 | 481 | } |
Sergunb | 0:9dcf85d9b2f3 | 482 | #else |
Sergunb | 0:9dcf85d9b2f3 | 483 | if (coolant_state & COOLANT_FLOOD_ENABLE) { bit_false(coolant_state,COOLANT_FLOOD_ENABLE); } |
Sergunb | 0:9dcf85d9b2f3 | 484 | else { coolant_state |= COOLANT_FLOOD_ENABLE; } |
Sergunb | 0:9dcf85d9b2f3 | 485 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 486 | coolant_set_state(coolant_state); // Report counter set in coolant_set_state(). |
Sergunb | 0:9dcf85d9b2f3 | 487 | gc_state.modal.coolant = coolant_state; |
Sergunb | 0:9dcf85d9b2f3 | 488 | } |
Sergunb | 0:9dcf85d9b2f3 | 489 | } |
Sergunb | 0:9dcf85d9b2f3 | 490 | } |
Sergunb | 0:9dcf85d9b2f3 | 491 | |
Sergunb | 0:9dcf85d9b2f3 | 492 | #ifdef DEBUG |
Sergunb | 0:9dcf85d9b2f3 | 493 | if (sys_rt_exec_debug) { |
Sergunb | 0:9dcf85d9b2f3 | 494 | report_realtime_debug(); |
Sergunb | 0:9dcf85d9b2f3 | 495 | sys_rt_exec_debug = 0; |
Sergunb | 0:9dcf85d9b2f3 | 496 | } |
Sergunb | 0:9dcf85d9b2f3 | 497 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 498 | |
Sergunb | 0:9dcf85d9b2f3 | 499 | // Reload step segment buffer |
Sergunb | 0:9dcf85d9b2f3 | 500 | if (sys.state & (STATE_CYCLE | STATE_HOLD | STATE_SAFETY_DOOR | STATE_HOMING | STATE_SLEEP| STATE_JOG)) { |
Sergunb | 0:9dcf85d9b2f3 | 501 | st_prep_buffer(); |
Sergunb | 0:9dcf85d9b2f3 | 502 | } |
Sergunb | 0:9dcf85d9b2f3 | 503 | |
Sergunb | 0:9dcf85d9b2f3 | 504 | } |
Sergunb | 0:9dcf85d9b2f3 | 505 | |
Sergunb | 0:9dcf85d9b2f3 | 506 | |
Sergunb | 0:9dcf85d9b2f3 | 507 | // Handles Grbl system suspend procedures, such as feed hold, safety door, and parking motion. |
Sergunb | 0:9dcf85d9b2f3 | 508 | // The system will enter this loop, create local variables for suspend tasks, and return to |
Sergunb | 0:9dcf85d9b2f3 | 509 | // whatever function that invoked the suspend, such that Grbl resumes normal operation. |
Sergunb | 0:9dcf85d9b2f3 | 510 | // This function is written in a way to promote custom parking motions. Simply use this as a |
Sergunb | 0:9dcf85d9b2f3 | 511 | // template |
Sergunb | 0:9dcf85d9b2f3 | 512 | static void protocol_exec_rt_suspend() |
Sergunb | 0:9dcf85d9b2f3 | 513 | { |
Sergunb | 0:9dcf85d9b2f3 | 514 | #ifdef PARKING_ENABLE |
Sergunb | 0:9dcf85d9b2f3 | 515 | // Declare and initialize parking local variables |
Sergunb | 0:9dcf85d9b2f3 | 516 | float restore_target[N_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 517 | float parking_target[N_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 518 | float retract_waypoint = PARKING_PULLOUT_INCREMENT; |
Sergunb | 0:9dcf85d9b2f3 | 519 | plan_line_data_t plan_data; |
Sergunb | 0:9dcf85d9b2f3 | 520 | plan_line_data_t *pl_data = &plan_data; |
Sergunb | 0:9dcf85d9b2f3 | 521 | memset(pl_data,0,sizeof(plan_line_data_t)); |
Sergunb | 0:9dcf85d9b2f3 | 522 | pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE); |
Sergunb | 0:9dcf85d9b2f3 | 523 | #ifdef USE_LINE_NUMBERS |
Sergunb | 0:9dcf85d9b2f3 | 524 | pl_data->line_number = PARKING_MOTION_LINE_NUMBER; |
Sergunb | 0:9dcf85d9b2f3 | 525 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 526 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 527 | |
Sergunb | 0:9dcf85d9b2f3 | 528 | plan_block_t *block = plan_get_current_block(); |
Sergunb | 0:9dcf85d9b2f3 | 529 | uint8_t restore_condition; |
Sergunb | 0:9dcf85d9b2f3 | 530 | #ifdef VARIABLE_SPINDLE |
Sergunb | 0:9dcf85d9b2f3 | 531 | float restore_spindle_speed; |
Sergunb | 0:9dcf85d9b2f3 | 532 | if (block == NULL) { |
Sergunb | 0:9dcf85d9b2f3 | 533 | restore_condition = (gc_state.modal.spindle | gc_state.modal.coolant); |
Sergunb | 0:9dcf85d9b2f3 | 534 | restore_spindle_speed = gc_state.spindle_speed; |
Sergunb | 0:9dcf85d9b2f3 | 535 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 536 | restore_condition = block->condition; |
Sergunb | 0:9dcf85d9b2f3 | 537 | restore_spindle_speed = block->spindle_speed; |
Sergunb | 0:9dcf85d9b2f3 | 538 | } |
Sergunb | 0:9dcf85d9b2f3 | 539 | #ifdef DISABLE_LASER_DURING_HOLD |
Sergunb | 0:9dcf85d9b2f3 | 540 | if (bit_istrue(settings.flags, BITFLAG_LASER_MODE)) { |
Sergunb | 0:9dcf85d9b2f3 | 541 | system_set_exec_accessory_override_flag(EXEC_SPINDLE_OVR_STOP); |
Sergunb | 0:9dcf85d9b2f3 | 542 | } |
Sergunb | 0:9dcf85d9b2f3 | 543 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 544 | #else |
Sergunb | 0:9dcf85d9b2f3 | 545 | if (block == NULL) { restore_condition = (gc_state.modal.spindle | gc_state.modal.coolant); } |
Sergunb | 0:9dcf85d9b2f3 | 546 | else { restore_condition = block->condition; } |
Sergunb | 0:9dcf85d9b2f3 | 547 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 548 | |
Sergunb | 0:9dcf85d9b2f3 | 549 | while (sys.suspend) { |
Sergunb | 0:9dcf85d9b2f3 | 550 | |
Sergunb | 0:9dcf85d9b2f3 | 551 | if (sys.abort) { return; } |
Sergunb | 0:9dcf85d9b2f3 | 552 | |
Sergunb | 0:9dcf85d9b2f3 | 553 | // Block until initial hold is complete and the machine has stopped motion. |
Sergunb | 0:9dcf85d9b2f3 | 554 | if (sys.suspend & SUSPEND_HOLD_COMPLETE) { |
Sergunb | 0:9dcf85d9b2f3 | 555 | |
Sergunb | 0:9dcf85d9b2f3 | 556 | // Parking manager. Handles de/re-energizing, switch state checks, and parking motions for |
Sergunb | 0:9dcf85d9b2f3 | 557 | // the safety door and sleep states. |
Sergunb | 0:9dcf85d9b2f3 | 558 | if (sys.state & (STATE_SAFETY_DOOR | STATE_SLEEP)) { |
Sergunb | 0:9dcf85d9b2f3 | 559 | |
Sergunb | 0:9dcf85d9b2f3 | 560 | // Handles retraction motions and de-energizing. |
Sergunb | 0:9dcf85d9b2f3 | 561 | if (bit_isfalse(sys.suspend,SUSPEND_RETRACT_COMPLETE)) { |
Sergunb | 0:9dcf85d9b2f3 | 562 | |
Sergunb | 0:9dcf85d9b2f3 | 563 | // Ensure any prior spindle stop override is disabled at start of safety door routine. |
Sergunb | 0:9dcf85d9b2f3 | 564 | sys.spindle_stop_ovr = SPINDLE_STOP_OVR_DISABLED; |
Sergunb | 0:9dcf85d9b2f3 | 565 | |
Sergunb | 0:9dcf85d9b2f3 | 566 | #ifndef PARKING_ENABLE |
Sergunb | 0:9dcf85d9b2f3 | 567 | |
Sergunb | 0:9dcf85d9b2f3 | 568 | spindle_set_state(SPINDLE_DISABLE,0.0f); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 569 | coolant_set_state(COOLANT_DISABLE); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 570 | |
Sergunb | 0:9dcf85d9b2f3 | 571 | #else |
Sergunb | 0:9dcf85d9b2f3 | 572 | |
Sergunb | 0:9dcf85d9b2f3 | 573 | // Get current position and store restore location and spindle retract waypoint. |
Sergunb | 0:9dcf85d9b2f3 | 574 | system_convert_array_steps_to_mpos(parking_target,sys_position); |
Sergunb | 0:9dcf85d9b2f3 | 575 | if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) { |
Sergunb | 0:9dcf85d9b2f3 | 576 | memcpy(restore_target,parking_target,sizeof(parking_target)); |
Sergunb | 0:9dcf85d9b2f3 | 577 | retract_waypoint += restore_target[PARKING_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 578 | retract_waypoint = min(retract_waypoint,PARKING_TARGET); |
Sergunb | 0:9dcf85d9b2f3 | 579 | } |
Sergunb | 0:9dcf85d9b2f3 | 580 | |
Sergunb | 0:9dcf85d9b2f3 | 581 | // Execute slow pull-out parking retract motion. Parking requires homing enabled, the |
Sergunb | 0:9dcf85d9b2f3 | 582 | // current location not exceeding the parking target location, and laser mode disabled. |
Sergunb | 0:9dcf85d9b2f3 | 583 | // NOTE: State is will remain DOOR, until the de-energizing and retract is complete. |
Sergunb | 0:9dcf85d9b2f3 | 584 | #ifdef ENABLE_PARKING_OVERRIDE_CONTROL |
Sergunb | 0:9dcf85d9b2f3 | 585 | if ((bit_istrue(settings.flags, BITFLAG_HOMING_ENABLE)) && |
Sergunb | 0:9dcf85d9b2f3 | 586 | (parking_target[PARKING_AXIS] < PARKING_TARGET) && |
Sergunb | 0:9dcf85d9b2f3 | 587 | bit_isfalse(settings.flags, BITFLAG_LASER_MODE) && |
Sergunb | 0:9dcf85d9b2f3 | 588 | (sys.override_ctrl == OVERRIDE_PARKING_MOTION)) { |
Sergunb | 0:9dcf85d9b2f3 | 589 | #else |
Sergunb | 0:9dcf85d9b2f3 | 590 | if ((bit_istrue(settings.flags, BITFLAG_HOMING_ENABLE)) && |
Sergunb | 0:9dcf85d9b2f3 | 591 | (parking_target[PARKING_AXIS] < PARKING_TARGET) && |
Sergunb | 0:9dcf85d9b2f3 | 592 | bit_isfalse(settings.flags, BITFLAG_LASER_MODE)) { |
Sergunb | 0:9dcf85d9b2f3 | 593 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 594 | // Retract spindle by pullout distance. Ensure retraction motion moves away from |
Sergunb | 0:9dcf85d9b2f3 | 595 | // the workpiece and waypoint motion doesn't exceed the parking target location. |
Sergunb | 0:9dcf85d9b2f3 | 596 | if (parking_target[PARKING_AXIS] < retract_waypoint) { |
Sergunb | 0:9dcf85d9b2f3 | 597 | parking_target[PARKING_AXIS] = retract_waypoint; |
Sergunb | 0:9dcf85d9b2f3 | 598 | pl_data->feed_rate = PARKING_PULLOUT_RATE; |
Sergunb | 0:9dcf85d9b2f3 | 599 | pl_data->condition |= (restore_condition & PL_COND_ACCESSORY_MASK); // Retain accessory state |
Sergunb | 0:9dcf85d9b2f3 | 600 | pl_data->spindle_speed = restore_spindle_speed; |
Sergunb | 0:9dcf85d9b2f3 | 601 | mc_parking_motion(parking_target, pl_data); |
Sergunb | 0:9dcf85d9b2f3 | 602 | } |
Sergunb | 0:9dcf85d9b2f3 | 603 | |
Sergunb | 0:9dcf85d9b2f3 | 604 | // NOTE: Clear accessory state after retract and after an aborted restore motion. |
Sergunb | 0:9dcf85d9b2f3 | 605 | pl_data->condition = (PL_COND_FLAG_SYSTEM_MOTION|PL_COND_FLAG_NO_FEED_OVERRIDE); |
Sergunb | 0:9dcf85d9b2f3 | 606 | pl_data->spindle_speed = 0.0f; |
Sergunb | 0:9dcf85d9b2f3 | 607 | spindle_set_state(SPINDLE_DISABLE,0.0f); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 608 | coolant_set_state(COOLANT_DISABLE); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 609 | |
Sergunb | 0:9dcf85d9b2f3 | 610 | // Execute fast parking retract motion to parking target location. |
Sergunb | 0:9dcf85d9b2f3 | 611 | if (parking_target[PARKING_AXIS] < PARKING_TARGET) { |
Sergunb | 0:9dcf85d9b2f3 | 612 | parking_target[PARKING_AXIS] = PARKING_TARGET; |
Sergunb | 0:9dcf85d9b2f3 | 613 | pl_data->feed_rate = PARKING_RATE; |
Sergunb | 0:9dcf85d9b2f3 | 614 | mc_parking_motion(parking_target, pl_data); |
Sergunb | 0:9dcf85d9b2f3 | 615 | } |
Sergunb | 0:9dcf85d9b2f3 | 616 | |
Sergunb | 0:9dcf85d9b2f3 | 617 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 618 | |
Sergunb | 0:9dcf85d9b2f3 | 619 | // Parking motion not possible. Just disable the spindle and coolant. |
Sergunb | 0:9dcf85d9b2f3 | 620 | // NOTE: Laser mode does not start a parking motion to ensure the laser stops immediately. |
Sergunb | 0:9dcf85d9b2f3 | 621 | spindle_set_state(SPINDLE_DISABLE,0.0f); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 622 | coolant_set_state(COOLANT_DISABLE); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 623 | |
Sergunb | 0:9dcf85d9b2f3 | 624 | } |
Sergunb | 0:9dcf85d9b2f3 | 625 | |
Sergunb | 0:9dcf85d9b2f3 | 626 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 627 | |
Sergunb | 0:9dcf85d9b2f3 | 628 | sys.suspend &= ~(SUSPEND_RESTART_RETRACT); |
Sergunb | 0:9dcf85d9b2f3 | 629 | sys.suspend |= SUSPEND_RETRACT_COMPLETE; |
Sergunb | 0:9dcf85d9b2f3 | 630 | |
Sergunb | 0:9dcf85d9b2f3 | 631 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 632 | |
Sergunb | 0:9dcf85d9b2f3 | 633 | |
Sergunb | 0:9dcf85d9b2f3 | 634 | if (sys.state == STATE_SLEEP) { |
Sergunb | 0:9dcf85d9b2f3 | 635 | report_feedback_message(MESSAGE_SLEEP_MODE); |
Sergunb | 0:9dcf85d9b2f3 | 636 | // Spindle and coolant should already be stopped, but do it again just to be sure. |
Sergunb | 0:9dcf85d9b2f3 | 637 | spindle_set_state(SPINDLE_DISABLE,0.0f); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 638 | coolant_set_state(COOLANT_DISABLE); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 639 | st_go_idle(); // Disable steppers |
Sergunb | 0:9dcf85d9b2f3 | 640 | while (!(sys.abort)) { protocol_exec_rt_system(); } // Do nothing until reset. |
Sergunb | 0:9dcf85d9b2f3 | 641 | return; // Abort received. Return to re-initialize. |
Sergunb | 0:9dcf85d9b2f3 | 642 | } |
Sergunb | 0:9dcf85d9b2f3 | 643 | |
Sergunb | 0:9dcf85d9b2f3 | 644 | // Allows resuming from parking/safety door. Actively checks if safety door is closed and ready to resume. |
Sergunb | 0:9dcf85d9b2f3 | 645 | if (sys.state == STATE_SAFETY_DOOR) { |
Sergunb | 0:9dcf85d9b2f3 | 646 | if (!(system_check_safety_door_ajar())) { |
Sergunb | 0:9dcf85d9b2f3 | 647 | sys.suspend &= ~(SUSPEND_SAFETY_DOOR_AJAR); // Reset door ajar flag to denote ready to resume. |
Sergunb | 0:9dcf85d9b2f3 | 648 | } |
Sergunb | 0:9dcf85d9b2f3 | 649 | } |
Sergunb | 0:9dcf85d9b2f3 | 650 | |
Sergunb | 0:9dcf85d9b2f3 | 651 | // Handles parking restore and safety door resume. |
Sergunb | 0:9dcf85d9b2f3 | 652 | if (sys.suspend & SUSPEND_INITIATE_RESTORE) { |
Sergunb | 0:9dcf85d9b2f3 | 653 | |
Sergunb | 0:9dcf85d9b2f3 | 654 | #ifdef PARKING_ENABLE |
Sergunb | 0:9dcf85d9b2f3 | 655 | // Execute fast restore motion to the pull-out position. Parking requires homing enabled. |
Sergunb | 0:9dcf85d9b2f3 | 656 | // NOTE: State is will remain DOOR, until the de-energizing and retract is complete. |
Sergunb | 0:9dcf85d9b2f3 | 657 | #ifdef ENABLE_PARKING_OVERRIDE_CONTROL |
Sergunb | 0:9dcf85d9b2f3 | 658 | if (((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) && |
Sergunb | 0:9dcf85d9b2f3 | 659 | (sys.override_ctrl == OVERRIDE_PARKING_MOTION)) { |
Sergunb | 0:9dcf85d9b2f3 | 660 | #else |
Sergunb | 0:9dcf85d9b2f3 | 661 | if ((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) { |
Sergunb | 0:9dcf85d9b2f3 | 662 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 663 | // Check to ensure the motion doesn't move below pull-out position. |
Sergunb | 0:9dcf85d9b2f3 | 664 | if (parking_target[PARKING_AXIS] <= PARKING_TARGET) { |
Sergunb | 0:9dcf85d9b2f3 | 665 | parking_target[PARKING_AXIS] = retract_waypoint; |
Sergunb | 0:9dcf85d9b2f3 | 666 | pl_data->feed_rate = PARKING_RATE; |
Sergunb | 0:9dcf85d9b2f3 | 667 | mc_parking_motion(parking_target, pl_data); |
Sergunb | 0:9dcf85d9b2f3 | 668 | } |
Sergunb | 0:9dcf85d9b2f3 | 669 | } |
Sergunb | 0:9dcf85d9b2f3 | 670 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 671 | |
Sergunb | 0:9dcf85d9b2f3 | 672 | // Delayed Tasks: Restart spindle and coolant, delay to power-up, then resume cycle. |
Sergunb | 0:9dcf85d9b2f3 | 673 | if (gc_state.modal.spindle != SPINDLE_DISABLE) { |
Sergunb | 0:9dcf85d9b2f3 | 674 | // Block if safety door re-opened during prior restore actions. |
Sergunb | 0:9dcf85d9b2f3 | 675 | if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) { |
Sergunb | 0:9dcf85d9b2f3 | 676 | if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) { |
Sergunb | 0:9dcf85d9b2f3 | 677 | // When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts. |
Sergunb | 0:9dcf85d9b2f3 | 678 | bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM); |
Sergunb | 0:9dcf85d9b2f3 | 679 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 680 | spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed); |
Sergunb | 0:9dcf85d9b2f3 | 681 | delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND); |
Sergunb | 0:9dcf85d9b2f3 | 682 | } |
Sergunb | 0:9dcf85d9b2f3 | 683 | } |
Sergunb | 0:9dcf85d9b2f3 | 684 | } |
Sergunb | 0:9dcf85d9b2f3 | 685 | if (gc_state.modal.coolant != COOLANT_DISABLE) { |
Sergunb | 0:9dcf85d9b2f3 | 686 | // Block if safety door re-opened during prior restore actions. |
Sergunb | 0:9dcf85d9b2f3 | 687 | if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) { |
Sergunb | 0:9dcf85d9b2f3 | 688 | // NOTE: Laser mode will honor this delay. An exhaust system is often controlled by this pin. |
Sergunb | 0:9dcf85d9b2f3 | 689 | coolant_set_state((restore_condition & (PL_COND_FLAG_COOLANT_FLOOD | PL_COND_FLAG_COOLANT_FLOOD))); |
Sergunb | 0:9dcf85d9b2f3 | 690 | delay_sec(SAFETY_DOOR_COOLANT_DELAY, DELAY_MODE_SYS_SUSPEND); |
Sergunb | 0:9dcf85d9b2f3 | 691 | } |
Sergunb | 0:9dcf85d9b2f3 | 692 | } |
Sergunb | 0:9dcf85d9b2f3 | 693 | |
Sergunb | 0:9dcf85d9b2f3 | 694 | #ifdef PARKING_ENABLE |
Sergunb | 0:9dcf85d9b2f3 | 695 | // Execute slow plunge motion from pull-out position to resume position. |
Sergunb | 0:9dcf85d9b2f3 | 696 | #ifdef ENABLE_PARKING_OVERRIDE_CONTROL |
Sergunb | 0:9dcf85d9b2f3 | 697 | if (((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) && |
Sergunb | 0:9dcf85d9b2f3 | 698 | (sys.override_ctrl == OVERRIDE_PARKING_MOTION)) { |
Sergunb | 0:9dcf85d9b2f3 | 699 | #else |
Sergunb | 0:9dcf85d9b2f3 | 700 | if ((settings.flags & (BITFLAG_HOMING_ENABLE | BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) { |
Sergunb | 0:9dcf85d9b2f3 | 701 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 702 | // Block if safety door re-opened during prior restore actions. |
Sergunb | 0:9dcf85d9b2f3 | 703 | if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) { |
Sergunb | 0:9dcf85d9b2f3 | 704 | // Regardless if the retract parking motion was a valid/safe motion or not, the |
Sergunb | 0:9dcf85d9b2f3 | 705 | // restore parking motion should logically be valid, either by returning to the |
Sergunb | 0:9dcf85d9b2f3 | 706 | // original position through valid machine space or by not moving at all. |
Sergunb | 0:9dcf85d9b2f3 | 707 | pl_data->feed_rate = PARKING_PULLOUT_RATE; |
Sergunb | 0:9dcf85d9b2f3 | 708 | pl_data->condition |= (restore_condition & PL_COND_ACCESSORY_MASK); // Restore accessory state |
Sergunb | 0:9dcf85d9b2f3 | 709 | pl_data->spindle_speed = restore_spindle_speed; |
Sergunb | 0:9dcf85d9b2f3 | 710 | mc_parking_motion(restore_target, pl_data); |
Sergunb | 0:9dcf85d9b2f3 | 711 | } |
Sergunb | 0:9dcf85d9b2f3 | 712 | } |
Sergunb | 0:9dcf85d9b2f3 | 713 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 714 | |
Sergunb | 0:9dcf85d9b2f3 | 715 | if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) { |
Sergunb | 0:9dcf85d9b2f3 | 716 | sys.suspend |= SUSPEND_RESTORE_COMPLETE; |
Sergunb | 0:9dcf85d9b2f3 | 717 | system_set_exec_state_flag(EXEC_CYCLE_START); // Set to resume program. |
Sergunb | 0:9dcf85d9b2f3 | 718 | } |
Sergunb | 0:9dcf85d9b2f3 | 719 | } |
Sergunb | 0:9dcf85d9b2f3 | 720 | |
Sergunb | 0:9dcf85d9b2f3 | 721 | } |
Sergunb | 0:9dcf85d9b2f3 | 722 | |
Sergunb | 0:9dcf85d9b2f3 | 723 | |
Sergunb | 0:9dcf85d9b2f3 | 724 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 725 | |
Sergunb | 0:9dcf85d9b2f3 | 726 | // Feed hold manager. Controls spindle stop override states. |
Sergunb | 0:9dcf85d9b2f3 | 727 | // NOTE: Hold ensured as completed by condition check at the beginning of suspend routine. |
Sergunb | 0:9dcf85d9b2f3 | 728 | if (sys.spindle_stop_ovr) { |
Sergunb | 0:9dcf85d9b2f3 | 729 | // Handles beginning of spindle stop |
Sergunb | 0:9dcf85d9b2f3 | 730 | if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_INITIATE) { |
Sergunb | 0:9dcf85d9b2f3 | 731 | if (gc_state.modal.spindle != SPINDLE_DISABLE) { |
Sergunb | 0:9dcf85d9b2f3 | 732 | spindle_set_state(SPINDLE_DISABLE,0.0f); // De-energize |
Sergunb | 0:9dcf85d9b2f3 | 733 | sys.spindle_stop_ovr = SPINDLE_STOP_OVR_ENABLED; // Set stop override state to enabled, if de-energized. |
Sergunb | 0:9dcf85d9b2f3 | 734 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 735 | sys.spindle_stop_ovr = SPINDLE_STOP_OVR_DISABLED; // Clear stop override state |
Sergunb | 0:9dcf85d9b2f3 | 736 | } |
Sergunb | 0:9dcf85d9b2f3 | 737 | // Handles restoring of spindle state |
Sergunb | 0:9dcf85d9b2f3 | 738 | } else if (sys.spindle_stop_ovr & (SPINDLE_STOP_OVR_RESTORE | SPINDLE_STOP_OVR_RESTORE_CYCLE)) { |
Sergunb | 0:9dcf85d9b2f3 | 739 | if (gc_state.modal.spindle != SPINDLE_DISABLE) { |
Sergunb | 0:9dcf85d9b2f3 | 740 | report_feedback_message(MESSAGE_SPINDLE_RESTORE); |
Sergunb | 0:9dcf85d9b2f3 | 741 | if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) { |
Sergunb | 0:9dcf85d9b2f3 | 742 | // When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts. |
Sergunb | 0:9dcf85d9b2f3 | 743 | bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM); |
Sergunb | 0:9dcf85d9b2f3 | 744 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 745 | spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed); |
Sergunb | 0:9dcf85d9b2f3 | 746 | } |
Sergunb | 0:9dcf85d9b2f3 | 747 | } |
Sergunb | 0:9dcf85d9b2f3 | 748 | if (sys.spindle_stop_ovr & SPINDLE_STOP_OVR_RESTORE_CYCLE) { |
Sergunb | 0:9dcf85d9b2f3 | 749 | system_set_exec_state_flag(EXEC_CYCLE_START); // Set to resume program. |
Sergunb | 0:9dcf85d9b2f3 | 750 | } |
Sergunb | 0:9dcf85d9b2f3 | 751 | sys.spindle_stop_ovr = SPINDLE_STOP_OVR_DISABLED; // Clear stop override state |
Sergunb | 0:9dcf85d9b2f3 | 752 | } |
Sergunb | 0:9dcf85d9b2f3 | 753 | } else { |
Sergunb | 0:9dcf85d9b2f3 | 754 | // Handles spindle state during hold. NOTE: Spindle speed overrides may be altered during hold state. |
Sergunb | 0:9dcf85d9b2f3 | 755 | // NOTE: STEP_CONTROL_UPDATE_SPINDLE_PWM is automatically reset upon resume in step generator. |
Sergunb | 0:9dcf85d9b2f3 | 756 | if (bit_istrue(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM)) { |
Sergunb | 0:9dcf85d9b2f3 | 757 | spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed); |
Sergunb | 0:9dcf85d9b2f3 | 758 | bit_false(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM); |
Sergunb | 0:9dcf85d9b2f3 | 759 | } |
Sergunb | 0:9dcf85d9b2f3 | 760 | } |
Sergunb | 0:9dcf85d9b2f3 | 761 | |
Sergunb | 0:9dcf85d9b2f3 | 762 | } |
Sergunb | 0:9dcf85d9b2f3 | 763 | } |
Sergunb | 0:9dcf85d9b2f3 | 764 | |
Sergunb | 0:9dcf85d9b2f3 | 765 | protocol_exec_rt_system(); |
Sergunb | 0:9dcf85d9b2f3 | 766 | |
Sergunb | 0:9dcf85d9b2f3 | 767 | } |
Sergunb | 0:9dcf85d9b2f3 | 768 | } |