interp_array.cc
1 /******************************************************************** 2 * Description: interp_array.cc 3 * 4 * This file just allocates space for the static arrays used by the 5 * interpreter. 6 * 7 * Author: 8 * License: GPL Version 2 9 * System: Linux 10 * 11 * Copyright (c) 2004 All rights reserved. 12 ********************************************************************/ 13 #include <unistd.h> 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <math.h> 17 #include <string.h> 18 #include <ctype.h> 19 #include <sys/types.h> 20 #include <sys/stat.h> 21 #include "rs274ngc.hh" 22 #include "rs274ngc_return.hh" 23 #include "rs274ngc_interp.hh" 24 #include "interp_parameter_def.hh" 25 26 using namespace interp_param_global; 27 28 /* Interpreter global arrays for g_codes and m_codes. The nth entry 29 in each array is the modal group number corresponding to the nth 30 code. Entries which are -1 represent illegal codes. Remember g_codes 31 in this interpreter are multiplied by 10. 32 33 The modal g groups and group numbers defined in [NCMS, pages 71 - 73] 34 (see also [Fanuc, pages 43 - 45]) are used here, except the canned 35 cycles (g80 - g89), which comprise modal g group 9 in [Fanuc], are 36 treated here as being in the same modal group (group 1) with the 37 straight moves and arcs (g0, g1, g2,g3). [Fanuc, page 45] says only 38 one g_code from any one group may appear on a line, and we are 39 following that rule. The straight_probe move, g38.2, is in group 1; it 40 is not defined in [NCMS]. 41 42 Some g_codes are non-modal (g4, g10, g28, g30, g53, g92, g92.1, g92.2, 43 and g92.3 here - many more in [NCMS]). [Fanuc] and [NCMS] put all 44 these in the same group 0, so we do also. Logically, there are two 45 subgroups, those which require coordinate values (g10, g28, g30, and 46 g92) and those which do not (g4, g53, g92.1, g92.2, and g92.3). 47 The subgroups are identified by itemization when necessary. 48 49 Those in group 0 which require coordinate values may not be on the 50 same line as those in group 1 (except g80) because they would be 51 competing for the coordinate values. Others in group 0 may be used on 52 the same line as those in group 1. 53 54 A total of 52 G-codes are implemented. 55 56 The groups are: 57 group 0 = {g4,g10,g28,g30,g52,g53,g92,g92.1,g92.2,g92.3} - NON-MODAL 58 dwell, setup, return to ref1, return to ref2, 59 local coordinate system, motion in machine coordinates, 60 set and unset axis offsets 61 group 1 = {g0,g1,g2,g3,g33,g33.1,g38.2,g38.3,g38.4,g38.5, 62 g70,g71,g71.1,g71.2,g72,g72.1,g72.2, 63 g73,g76,g80, 64 g81,g82,g83,g84,g85,g86,g87,g88,g89} - motion 65 group 2 = {g17,g17.1,g18,g18.1,g19,g19.1} - plane selection 66 group 3 = {g90,g91} - distance mode 67 group 4 = {g90.1,g91.1} - arc IJK distance mode 68 group 5 = {g93,g94,g95} - feed rate mode 69 group 6 = {g20,g21} - units 70 group 7 = {g40,g41,g42} - cutter diameter compensation 71 group 8 = {g43,g49} - tool length offset 72 group 10 = {g98,g99} - return mode in canned cycles 73 group 12 = {g54,g55,g56,g57,g58,g59,g59.1,g59.2,g59.3} - coordinate system 74 group 13 = {g61,g61.1,g64} - control mode (path following) 75 group 14 = {g96,g97} - spindle speed mode 76 group 15 = {G07,G08} - lathe diameter mode 77 */ 78 // This stops indent from reformatting the following code. 79 // *INDENT-OFF* 80 const int Interp::_gees[] = { 81 /* 0 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 82 /* 20 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 83 /* 40 */ //0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 84 /* 40 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 0,-1,-1,-1,-1,-1,-1, 85 /* 60 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, 86 /* 80 */ 15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 87 /* 100 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 88 /* 120 */ -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Modal groups and modal group numbers for M codes are not described in 136 [Fanuc]. We have used the groups from [NCMS] and added M60, as an 137 extension of the language for pallet shuttle and stop. This version has 138 no codes related to axis clamping. 139 140 The groups are: 141 group 4 = {m0,m1,m2,m30,m60, 142 m99} - stopping 143 group 5 = {m62,m63,m64,m65, - turn I/O point on/off 144 m66} - wait for Input 145 group 6 = {m6,m61} - tool change 146 group 7 = {m3,m4,m5,m19} - spindle turning, orient 147 group 8 = {m7,m8,m9} - coolant 148 group 9 = {m48,m49, - feed and speed override switch bypass 149 m50, - feed override switch bypass P1 to turn on, P0 to turn off 150 m51, - spindle speed override switch bypass P1 to turn on, P0 to turn off 151 m52, - adaptive feed override switch bypass P1 to turn on, P0 to turn off 152 m53} - feedstop override switch bypass P1 to turn on, P0 to turn off 153 group 10 = {m100..m199} - user-defined 154 */ 155 156 const int Interp::_ems[] = { 157 4, 4, 4, 7, 7, 7, 6, 8, 8, 8, // 9 158 -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, // 19 159 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 29 160 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 39 161 -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, // 49 162 9, 9, 9, 9, -1, -1, -1, -1, -1, -1, // 59 163 4, 6, 5, 5, 5, 5, 5, 5, 5, -1, // 69 164 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, // 79 165 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 89 166 -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, // 99 167 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //109 168 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //119 169 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //129 170 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //139 171 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //149 172 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //159 173 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //169 174 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //179 175 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, //189 176 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};//199 177 178 /* 179 180 This is an array of the index numbers of system parameters that must 181 be included in a file used with the Interp::restore_parameters 182 function. The array is used by that function and by the 183 Interp::save_parameters function. 184 185 */ 186 187 const int Interp::_required_parameters[] = { 188 5161, 5162, 5163, /* G28 home */ 189 5164, 5165, 5166, /* A, B, & C */ 190 5167, 5168, 5169, /* U, V, & W */ 191 5181, 5182, 5183, /* G30 home */ 192 5184, 5185, 5186, /* A, B, & C */ 193 5187, 5188, 5189, /* U, V, & W */ 194 5210, /* G92 is currently applied */ 195 5211, 5212, 5213, /* G92 offsets */ 196 5214, 5215, 5216, /* A, B, & C */ 197 5217, 5218, 5219, /* U, V, & W */ 198 5220, /* selected coordinate */ 199 5221, 5222, 5223, /* coordinate system 1 */ 200 5224, 5225, 5226, /* A, B, & C */ 201 5227, 5228, 5229, /* U, V, & W */ 202 5230, 203 5241, 5242, 5243, /* coordinate system 2 */ 204 5244, 5245, 5246, /* A, B, & C */ 205 5247, 5248, 5249, /* U, V, & W */ 206 5250, 207 5261, 5262, 5263, /* coordinate system 3 */ 208 5264, 5265, 5266, /* A, B, & C */ 209 5267, 5268, 5269, /* U, V, & W */ 210 5270, 211 5281, 5282, 5283, /* coordinate system 4 */ 212 5284, 5285, 5286, /* A, B, & C */ 213 5287, 5288, 5289, /* U, V, & W */ 214 5290, 215 5301, 5302, 5303, /* coordinate system 5 */ 216 5304, 5305, 5306, /* A, B, & C */ 217 5307, 5308, 5309, /* U, V, & W */ 218 5310, 219 5321, 5322, 5323, /* coordinate system 6 */ 220 5324, 5325, 5326, /* A, B, & C */ 221 5327, 5328, 5329, /* U, V, & W */ 222 5330, 223 5341, 5342, 5343, /* coordinate system 7 */ 224 5344, 5345, 5346, /* A, B, & C */ 225 5347, 5348, 5349, /* U, V, & W */ 226 5350, 227 5361, 5362, 5363, /* coordinate system 8 */ 228 5364, 5365, 5366, /* A, B, & C */ 229 5367, 5368, 5369, /* U, V, & W */ 230 5370, 231 5381, 5382, 5383, /* coordinate system 9 */ 232 5384, 5385, 5386, /* A, B, & C */ 233 5387, 5388, 5389, /* U, V, & W */ 234 5390, 235 RS274NGC_MAX_PARAMETERS 236 }; 237 238 const int Interp::_readonly_parameters[] = { 239 5400, // tool toolno 240 5401, // tool x offset 241 5402, // tool y offset 242 5403, // tool z offset 243 5404, // tool a offset 244 5405, // tool b offset 245 5406, // tool c offset 246 5407, // tool u offset 247 5408, // tool v offset 248 5409, // tool w offset 249 5410, // tool diameter 250 5411, // tool frontangle 251 5412, // tool backangle 252 5413, // tool orientation 253 5420, 5421, 5422, 5423, 5424, 5425, 5426, 5427, 5428, // current X Y ... W 254 }; 255 const int Interp::_n_readonly_parameters = sizeof(_readonly_parameters)/sizeof(int); 256 257 /* _readers is an array of pointers to functions that read. 258 It is used by read_one_item. 259 260 Each read function is placed in the array according to the ASCII character it 261 corresponds to. Whilst a switch statement could have been used in read_one_item, 262 using an array of function pointers allows a new read_foo to be added quickly 263 in this one table. 264 265 At some point, it may be advantageous to add a read_$ or read_n for perhaps 266 macro or jump labels.. 267 */ 268 const read_function_pointer Interp::default_readers[256] = { 269 /* 00 */ 270 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 271 /* 10 */ 272 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 273 /* 20 */ 274 0, 0, 0, 275 &Interp::read_parameter_setting, // reads # or ASCII 0x23 276 &Interp::read_dollar, // reads $ or ASCII 0x24 277 0, 0, 0, 278 &Interp::read_comment, // reads ( or ASCII 0x28 279 0, 0, 0, 0, 0, 0, 0, 280 /* 30 */ 281 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 282 &Interp::read_semicolon, 283 0, 0, 0, 0, 284 /* 40 */ 285 &Interp::read_atsign, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 286 /* 50 */ 287 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &Interp::read_carat, 0, 288 /* 60 */ 289 0, 290 &Interp::read_a, // reads a or ASCII 0x61 291 &Interp::read_b, // reads b or ASCII 0x62 292 &Interp::read_c, // reads c or ASCII 0x63 293 &Interp::read_d, // reads d or ASCII 0x64 294 &Interp::read_e, // reads d or ASCII 0x65 295 &Interp::read_f, // reads f or ASCII 0x66 296 &Interp::read_g, // reads g or ASCII 0x67 297 &Interp::read_h, // reads h or ASCII 0x68 298 &Interp::read_i, // reads i or ASCII 0x69 299 &Interp::read_j, // reads j or ASCII 0x6A 300 &Interp::read_k, // reads k or ASCII 0x6B 301 &Interp::read_l, // reads l or ASCII 0x6C 302 &Interp::read_m, // reads m or ASCII 0x6D 303 0, 0, 304 &Interp::read_p, // reads p or ASCII 0x70 305 &Interp::read_q, // reads q or ASCII 0x71 306 &Interp::read_r, // reads r or ASCII 0x72 307 &Interp::read_s, // reads s or ASCII 0x73 308 &Interp::read_t, // reads t or ASCII 0x74 309 &Interp::read_u, 310 &Interp::read_v, 311 &Interp::read_w, 312 &Interp::read_x, // reads x or ASCII 0x78 313 &Interp::read_y, // reads y or ASCII 0x79 314 &Interp::read_z}; // reads z or ASCII 0x7A 315 // *INDENT-ON* 316 // And now indent can continue. 317 /****************************************************************************/ 318 319 /* There are four global variables*. The first three are _gees, _ems, 320 and _readers. */ 321 322 /* The notion of "global variables" is a misnomer - These last four should only 323 be accessable by the interpreter and not exported to the rest of emc */ 324 325