gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
gcode.h
Go to the documentation of this file.
1 /*
2  gcode.h - rs274/ngc parser.
3  Part of Grbl
4 
5  Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
6  Copyright (c) 2009-2011 Simen Svale Skogsrud
7 
8  Grbl is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Grbl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Grbl. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef gcode_h
23 #define gcode_h
24 
26 // type of command that is called in the block. A modal group is a group of g-code commands that are
27 // mutually exclusive, or cannot exist on the same line, because they each toggle a state or execute
28 // a unique motion. These are defined in the NIST RS274-NGC v3 g-code standard, available online,
29 // and are similar/identical to other g-code interpreters by manufacturers (Haas,Fanuc,Mazak,etc).
30 //
32 #define MODAL_GROUP_G0 0
33 #define MODAL_GROUP_G1 1
34 #define MODAL_GROUP_G2 2
35 #define MODAL_GROUP_G3 3
36 #define MODAL_GROUP_G4 4
37 #define MODAL_GROUP_G5 5
38 #define MODAL_GROUP_G6 6
39 #define MODAL_GROUP_G7 7
40 #define MODAL_GROUP_G8 8
41 #define MODAL_GROUP_G12 9
42 #define MODAL_GROUP_G13 10
43 
44 #define MODAL_GROUP_M4 11
45 #define MODAL_GROUP_M7 12
46 #define MODAL_GROUP_M8 13
47 // #define OTHER_INPUT_S 15
49 // #define OTHER_INPUT_T 16
51 // internally by the parser to know which command to execute.
52 //
54 // compile a litte smaller. Necessary due to being completely out of flash on the 328p. Although not
55 // ideal, just be careful with values that state 'do not alter' and check both report.c and gcode.c
56 // to see how they are used, if you need to alter them.
58 #define NON_MODAL_NO_ACTION 0
59 #define NON_MODAL_DWELL 4
60 #define NON_MODAL_SET_COORDINATE_DATA 10
61 #define NON_MODAL_GO_HOME_0 28
62 #define NON_MODAL_SET_HOME_0 38
63 #define NON_MODAL_GO_HOME_1 30
64 #define NON_MODAL_SET_HOME_1 40
65 #define NON_MODAL_ABSOLUTE_OVERRIDE 53
66 #define NON_MODAL_SET_COORDINATE_OFFSET 92
67 #define NON_MODAL_RESET_COORDINATE_OFFSET 102 //G92.1 (Do not alter value)
68 #define MOTION_MODE_SEEK 0
70 #define MOTION_MODE_LINEAR 1
71 #define MOTION_MODE_CW_ARC 2
72 #define MOTION_MODE_CCW_ARC 3
73 #define MOTION_MODE_PROBE_TOWARD 140
74 #define MOTION_MODE_PROBE_TOWARD_NO_ERROR 141
75 #define MOTION_MODE_PROBE_AWAY 142
76 #define MOTION_MODE_PROBE_AWAY_NO_ERROR 143
77 #define MOTION_MODE_NONE 80
78 #define PLANE_SELECT_XY 0
80 #define PLANE_SELECT_ZX 1
81 #define PLANE_SELECT_YZ 2
82 #define DISTANCE_MODE_ABSOLUTE 0
84 #define DISTANCE_MODE_INCREMENTAL 1
85 #define DISTANCE_ARC_MODE_INCREMENTAL 0
87 #define PROGRAM_FLOW_RUNNING 0
89 #define PROGRAM_FLOW_PAUSED 3
90 #define PROGRAM_FLOW_OPTIONAL_STOP 1
91 #define PROGRAM_FLOW_COMPLETED_M2 2
93 #define PROGRAM_FLOW_COMPLETED_M30 30
94 #define FEED_RATE_MODE_UNITS_PER_MIN 0
96 #define FEED_RATE_MODE_INVERSE_TIME 1
97 #define UNITS_MODE_MM 0
99 #define UNITS_MODE_INCHES 1
100 #define CUTTER_COMP_DISABLE 0
102 #define CONTROL_MODE_EXACT_PATH 0
104 #define SPINDLE_DISABLE 0
106 #define SPINDLE_ENABLE_CW PL_COND_FLAG_SPINDLE_CW
107 #define SPINDLE_ENABLE_CCW PL_COND_FLAG_SPINDLE_CCW
109 #define COOLANT_DISABLE 0
112 #define COOLANT_FLOOD_ENABLE PL_COND_FLAG_COOLANT_FLOOD
113 #define COOLANT_MIST_ENABLE PL_COND_FLAG_COOLANT_MIST
115 #define TOOL_LENGTH_OFFSET_CANCEL 0
118 #define TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC 1
119 // N/A: Stores coordinate system value (54-59) to change to.
121 #define WORD_F 0
123 #define WORD_I 1
124 #define WORD_J 2
125 #define WORD_K 3
126 #define WORD_L 4
127 #define WORD_N 5
128 #define WORD_P 6
129 #define WORD_R 7
130 #define WORD_S 8
131 #define WORD_T 9
132 #define WORD_X 10
133 #define WORD_Y 11
134 #define WORD_Z 12
135 #define GC_UPDATE_POS_TARGET 0
137 #define GC_UPDATE_POS_SYSTEM 1
138 #define GC_UPDATE_POS_NONE 2
139 #define GC_PROBE_FOUND GC_UPDATE_POS_SYSTEM
141 #define GC_PROBE_ABORT GC_UPDATE_POS_NONE
142 #define GC_PROBE_FAIL_INIT GC_UPDATE_POS_NONE
143 #define GC_PROBE_FAIL_END GC_UPDATE_POS_TARGET
144 #ifdef SET_CHECK_MODE_PROBE_TO_START
145  #define GC_PROBE_CHECK_MODE GC_UPDATE_POS_NONE
146 #else
147  #define GC_PROBE_CHECK_MODE GC_UPDATE_POS_TARGET
148 #endif
149 #define GC_PARSER_NONE 0
151 #define GC_PARSER_JOG_MOTION bit(0)
152 #define GC_PARSER_CHECK_MANTISSA bit(1)
153 #define GC_PARSER_ARC_IS_CLOCKWISE bit(2)
154 #define GC_PARSER_PROBE_IS_AWAY bit(3)
155 #define GC_PARSER_PROBE_IS_NO_ERROR bit(4)
156 #define GC_PARSER_LASER_FORCE_SYNC bit(5)
157 #define GC_PARSER_LASER_DISABLE bit(6)
158 #define GC_PARSER_LASER_ISMOTION bit(7)
159 
162 typedef struct {
163  uint8_t motion;
164  uint8_t feed_rate;
165  uint8_t units;
166  uint8_t distance;
167 // uint8_t distance_arc; //!< {G91.1}
169  uint8_t plane_select;
170 // uint8_t cutter_comp; //!< {G40}
172  uint8_t tool_length;
173  uint8_t coord_select;
174 // uint8_t control; //!< {G61}
176  uint8_t program_flow;
177  uint8_t coolant;
178  uint8_t spindle;
179 } gc_modal_t;
180 
181 typedef struct {
182  float f;
183  float ijk[3];
184  uint8_t l;
185  int32_t n;
186  float p;
187 // float q; //!< G82 peck drilling
188  float r;
189  float s;
190  uint8_t t;
191  float xyz[3];
192 } gc_values_t;
193 
194 
195 typedef struct {
197 
199  float feed_rate;
200  uint8_t tool;
201  int32_t line_number;
202 
203  float position[N_AXIS];
204 
205  float coord_system[N_AXIS];
206 // position in mm. Loaded from EEPROM when called.
207  float coord_offset[N_AXIS];
208 // machine zero in mm. Non-persistent. Cleared upon reset and boot.
211 extern parser_state_t gc_state;
212 
213 
214 typedef struct {
219 
221 void gc_init();
223 uint8_t gc_execute_line(char *line);
225 void gc_sync_position();
226 
227 #endif
float r
Arc radius.
Definition: gcode.h:188
#define N_AXIS
Axis array index values. Must start with 0 and be continuous.
Definition: nuts_bolts.h:30
uint8_t plane_select
NOTE: Don't track. Only default supported.
Definition: gcode.h:169
uint8_t non_modal_command
Definition: gcode.h:215
void gc_sync_position()
Set g-code parser position. Input in steps.
Definition: gcode.c:53
float tool_length_offset
Tracks tool length offset value when enabled.
Definition: gcode.h:209
gc_modal_t modal
Definition: gcode.h:196
void gc_init()
Initialize the parser.
Definition: gcode.c:41
float feed_rate
Millimeters/min.
Definition: gcode.h:199
uint8_t t
Tool selection.
Definition: gcode.h:190
int32_t n
Line number.
Definition: gcode.h:185
uint8_t distance
{G90,G91}
Definition: gcode.h:166
parser_state_t gc_state
Declare gc extern struct.
Definition: gcode.c:35
gc_values_t values
Definition: gcode.h:217
NOTE: When this struct is zeroed, the above defines set the defaults for the system.
Definition: gcode.h:162
uint8_t l
G10 or canned cycles parameters.
Definition: gcode.h:184
uint8_t feed_rate
{G93,G94}
Definition: gcode.h:164
gc_modal_t modal
Definition: gcode.h:216
uint8_t coord_select
{G54,G55,G56,G57,G58,G59}
Definition: gcode.h:173
int32_t line_number
Last line number sent.
Definition: gcode.h:201
uint8_t coolant
{M7,M8,M9}
Definition: gcode.h:177
uint8_t gc_execute_line(char *line)
Execute one block of rs275/ngc/g-code.
Definition: gcode.c:63
float s
Spindle speed.
Definition: gcode.h:189
uint8_t tool_length
NOTE: Don't track. Only default supported.
Definition: gcode.h:172
uint8_t spindle
{M3,M4,M5}
Definition: gcode.h:178
float f
Feed.
Definition: gcode.h:182
float spindle_speed
RPM.
Definition: gcode.h:198
uint8_t program_flow
NOTE: Don't track. Only default supported.
Definition: gcode.h:176
uint8_t units
{G20,G21}
Definition: gcode.h:165
uint8_t tool
Tracks tool number. NOT USED.
Definition: gcode.h:200
uint8_t motion
{G0,G1,G2,G3,G38.2,G80}
Definition: gcode.h:163
float p
G10 or dwell parameters.
Definition: gcode.h:186