00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #include <stdio.h>
00091 #include <stdlib.h>
00092 #include <math.h>
00093 #include <string.h>
00094 #include <ctype.h>
00095 #include "canon.hh"
00096 #include "rs274ngc.hh"
00097
00098
00099 static char ident[] = "$Id: rs274ngc.cc,v 1.4 2000/10/27 20:34:44 terrylr Exp $";
00100
00101
00102
00103 #ifdef STAND_ALONE_INTERP
00104
00105 #define DEBUG_EMC
00106 setup _interpreter_settings;
00107
00108 #else
00109
00110 #define DEBUG_EMC
00111 setup _interpreter_settings;
00112
00113 #endif
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 int read_real_value(char * line, int * counter,
00124 double * double_ptr, double * parameters);
00125 int read_real_expression(char * line, int * counter,
00126 double * hold2, double * parameters);
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 static int gees[] SET_TO {
00175 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00176 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00177 4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00178 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00179 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00180 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00181 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00182 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00183 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00184 2,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00185 6,-1,-1,-1,-1,-1,-1,-1,-1,-1, 6,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00186 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00187 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00188 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00189 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00190 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00191 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00192 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00193 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00194 -1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00195 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 7,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00196 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00197 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00198 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00199 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00200 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00201 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 4,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00202 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00203 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00204 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,12,12,12,-1,-1,-1,-1,-1,-1,
00205 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00206 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00207 13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00208 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00209 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00210 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00211 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00212 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00213 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00214 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00215 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00216 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00217 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00218 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00219 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00220 3,-1,-1,-1,-1,-1,-1,-1,-1,-1, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00221 0,-1, 0,-1,-1,-1,-1,-1,-1,-1, 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00222 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00223 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00224 10,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1};
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 static int ems[] SET_TO {
00242 4, 4, 4, 7, 7, 7, 6, 8, 8, 8,
00243 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00244 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00245 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00246 -1, -1, -1, -1, -1, -1, -1, -1, 9, 9,
00247 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00248 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00249 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00250 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00251 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 char * interp_errors[] SET_TO {
00263 "Unspecified error",
00264 "All axes missing with G92",
00265 "Arc radius too small to reach end point",
00266 "Argument to acos out of range",
00267 "Argument to asin out of range",
00268 "Attempt to divide by zero",
00269 "Bad character used",
00270 "Bad format unsigned integer",
00271 "Bad number format",
00272 "Bad tool radius value with cutter radius comp",
00273
00274
00275 "Cannot change axis offsets with cutter radius comp",
00276
00277 "Cannot change units with cutter radius comp",
00278
00279 "Cannot create backup file",
00280 "Cannot do G1 with zero feed rate",
00281 "Cannot do zero repeats of cycle",
00282 "Cannot have concave corner with cutter radius comp",
00283
00284 "Cannot make arc with zero feed rate",
00285 "Cannot open backup file",
00286 "Cannot open file",
00287 "Cannot open variable file",
00288 "Cannot probe in inverse time feed mode",
00289 "Cannot probe with cutter radius compensation on",
00290
00291 "Cannot probe with zero feed rate",
00292 "Cannot put an M code for stopping with G38.2",
00293 "Cannot raise negative number to non-integer power",
00294
00295 "Cannot turn cutter radius comp on out of XY-plane",
00296
00297 "Cannot turn cutter radius comp on when already on",
00298
00299 "Cannot use G0 with cutter radius comp",
00300 "Cannot use G53 in incremental distance mode",
00301 "Cannot use G53 with cutter radius comp",
00302 "Cannot use XZ plane with cutter radius comp",
00303
00304 "Cannot use YZ plane with cutter radius comp",
00305
00306 "Cannot use a G code for motion with G10",
00307 "Cannot use a G motion with G92",
00308 "Cannot use axis commands with G4",
00309 "Cannot use axis commands with G80",
00310 "Cannot use inverse time feed with cutter radius comp",
00311
00312 "Cannot use two G codes from group 0",
00313 "Command too long",
00314 "Concave corner with cutter radius comp",
00315 "Coordinate setting given with G80",
00316 "Current point same as end point of arc",
00317
00318 "Cutter gouging with cutter radius comp",
00319
00320 "D word missing with cutter radius comp on",
00321
00322 "D word on line with no cutter comp on (G41 or G42) command",
00323
00324 "Dwell time missing with G4",
00325 "Equal sign missing in parameter setting",
00326
00327 "F word missing with inverse time G1 move",
00328 "F word missing with inverse time arc move",
00329 "File ended with no stopping command given",
00330 "G code out of range",
00331 "H word on line with no tool length comp (G43) command",
00332
00333 "I word given for arc in YZ-plane",
00334 "I word missing with G87",
00335 "I word on line with no G code (G2, G3, G87) that uses it",
00336
00337 "J word given for arc in XZ-plane",
00338 "J word missing with G87",
00339 "J word on line with no G code (G2, G3, G87) that uses it",
00340
00341 "K word given for arc in XY-plane",
00342 "K word missing with G87",
00343 "K word on line with no G code (G2, G3, G87) that uses it",
00344
00345 "L word on line with no canned cycle or G10 to use it",
00346
00347 "Left bracket missing after slash with atan operator",
00348
00349 "Left bracket missing after unary operation name",
00350 "Line number greater than 99999",
00351 "Line with G10 does not have L2",
00352 "M code greater than 99",
00353 "Mixed radius-ijk format for arc",
00354 "Multiple D words on one line",
00355 "Multiple F words on one line",
00356 "Multiple I words on one line",
00357 "Multiple J words on one line",
00358 "Multiple K words on one line",
00359 "Multiple L words on one line",
00360 "Multiple P words on one line",
00361 "Multiple Q words on one line",
00362 "Multiple R words on one line",
00363 "Multiple S word spindle speed settings on one line",
00364
00365 "Multiple T words (tool ids) on one line",
00366 "Multiple X words on one line",
00367 "Multiple Y words on one line",
00368 "Multiple Z words on one line",
00369 "Multiple tool length offsets on one line",
00370 "Must use G0 or G1 with G53",
00371 "Negative D code used",
00372 "Negative F word found",
00373 "Negative G code used",
00374 "Negative L word used",
00375 "Negative M code used",
00376 "Negative P value used",
00377 "Negative Q value used",
00378 "Negative argument to sqrt",
00379 "Negative spindle speed found",
00380 "Negative tool id used",
00381 "Negative tool length offset used",
00382 "Nested comment found",
00383 "No characters found in reading real value",
00384 "No digits found where real number should be",
00385 "Non-integer value for integer",
00386 "Null missing after newline",
00387 "Offset index missing",
00388 "P value not an integer with G10 L2",
00389 "P value out of range with G10 L2",
00390 "P word (dwell time) missing with G82",
00391 "P word (dwell time) missing with G86",
00392 "P word (dwell time) missing with G88",
00393 "P word (dwell time) missing with G89",
00394 "P word on line with no G code (G4 G10 G82 G86 G88 G89) that uses it",
00395
00396 "Parameter number out of range",
00397
00398
00399 "Q word (depth increment) missing with G83",
00400 "Q word on line with no G83 cycle that uses it",
00401
00402 "Queue is not empty after probing",
00403
00404 "R clearance plane unspecified in canned cycle",
00405 "R value less than Z value in canned cycle",
00406 "R word on line with no G code (arc or cycle) that uses it",
00407
00408 "R, I, J, and K words all missing for arc",
00409 "Radius to end of arc differs from radius to start of arc",
00410
00411 "Radius too small to reach end point",
00412 "Selected tool slot number too large",
00413 "Slash missing",
00414 "Spindle not turning clockwise in G84 canned cycle",
00415
00416 "Spindle not turning in G86 canned cycle",
00417 "Spindle not turning in G87 canned cycle",
00418 "Spindle not turning in G88 canned cycle",
00419 "Too many G codes on line",
00420 "Too many M codes on line",
00421 "Tool index out of bounds",
00422 "Tool radius not less than arc radius with cutter radius comp",
00423
00424 "Two G codes used from same modal group",
00425 "Two M codes used from same modal group",
00426 "Unable to open file",
00427 "Unclosed comment found",
00428 "Unclosed expression",
00429 "Unknown G code used",
00430 "Unknown M code used",
00431 "Unknown operation name starting with A",
00432 "Unknown operation name starting with M",
00433 "Unknown operation name starting with O",
00434 "Unknown operation name starting with X",
00435 "Unknown operation",
00436 "Unknown word starting with A",
00437 "Unknown word starting with C",
00438 "Unknown word starting with E",
00439 "Unknown word starting with F",
00440 "Unknown word starting with L",
00441 "Unknown word starting with R",
00442 "Unknown word starting with S",
00443 "Unknown word starting with T",
00444 "Unknown word where unary operation could be",
00445
00446 "X and Y words missing for arc in XY-plane",
00447 "X and Z words missing for arc in XZ-plane",
00448 "X, Y, and Z words all missing with G0 or G1",
00449 "X, Y, and Z words all missing with G38.2",
00450 "Y and Z words missing for arc in YZ-plane",
00451 "Z value unspecified in canned cycle",
00452 "Zero or negative argument to ln",
00453
00454
00455 "", "", "", "",
00456 "", "", "", "", "", "", "", "", "", "",
00457 "", "", "", "", "", "", "", "", "", "",
00458 "", "", "", "", "", "", "", "", "", "",
00459 "", "", "", "", "", "", "", "", "", "",
00460
00461 "Bad setting of g_mode in check_g_codes",
00462 "Code is not G0 or G1 in convert_straight",
00463 "Code is not G0 to G3 or G80 to G89 in convert_motion",
00464 "Code is not G10, G92, or G92.2 in convert_modal_0",
00465 "Code is not G17, G18, or G19 in convert_set_plane",
00466 "Code is not G2 or G3 in arc_data_comp",
00467 "Code is not G2 or G3 in arc_data_ijk",
00468 "Code is not G20 or G21 in convert_length_units",
00469 "Code is not G40, G41, or G42 in convert_cutter_compensation",
00470 "Code is not G43 or G49 in convert_tool_length_offset",
00471 "Code is not G54 to G59.3 in convert_coordinate_system",
00472 "Code is not G61 or G64 in convert_control_mode",
00473 "Code is not G90 or G91 in convert_distance_mode",
00474 "Code is not G92 or G92.2 in convert_axis_offsets",
00475 "Code is not G93 or G94 in convert_feed_mode",
00476 "Code is not G98 or G99 in convert_retract_mode",
00477 "Code is not M0, M1, M2, M30 or M60 in convert_stop",
00478 "Convert_cycle should not have been called",
00479 "Distance mode is neither absolute nor incremental in convert_cycle",
00480 "Plane is not XY, YZ, or XZ in convert_arc",
00481 "Read_comment should not have been called",
00482 "Read_d should not have been called",
00483 "Read_f should not have been called",
00484 "Read_g should not have been called",
00485 "Read_i should not have been called",
00486 "Read_j should not have been called",
00487 "Read_k should not have been called",
00488 "Read_l should not have been called",
00489 "Read_line_number should not have been called",
00490 "Read_m should not have been called",
00491 "Read_p should not have been called",
00492 "Read_parameter should not have been called",
00493 "Read_parameter_setting should not have been called",
00494 "Read_q should not have been called",
00495 "Read_r should not have been called",
00496 "Read_real_expression should not have been called",
00497 "Read_spindle_speed should not have been called",
00498 "Read_tool should not have been called",
00499 "Read_tool_length_offset should not have been called",
00500 "Read_x should not have been called",
00501 "Read_y should not have been called",
00502 "Read_z should not have been called",
00503 "Side fails to be right or left in convert_straight_comp1",
00504 "Side fails to be right or left in convert_straight_comp2",
00505 "Sscanf failure in read_integer_unsigned",
00506 "Sscanf failure in read_real_number",
00507 "Unknown operation in execute_binary1",
00508 "Unknown operation in execute_binary2",
00509 "Unknown operation in execute_unary",
00510
00511 ""};
00512
00513
00514
00515
00516 #ifdef STAND_ALONE_INTERP
00517
00518 int _textline SET_TO 0;
00519 char _interpreter_filename[INTERP_TEXT_SIZE];
00520 char _interpreter_linetext[INTERP_TEXT_SIZE];
00521 char _interpreter_blocktext[INTERP_TEXT_SIZE];
00522 block _interpreter_block SET_TO {0};
00523 FILE *_interpreter_fp SET_TO NULL;
00524 int _interpreter_status SET_TO 0;
00525
00526 #else
00527
00528 static int _textline SET_TO 0;
00529 static char _interpreter_filename[INTERP_TEXT_SIZE];
00530 static char _interpreter_linetext[INTERP_TEXT_SIZE];
00531 static char _interpreter_blocktext[INTERP_TEXT_SIZE];
00532 static block _interpreter_block SET_TO {0};
00533 static FILE *_interpreter_fp SET_TO NULL;
00534 static int _interpreter_status SET_TO 0;
00535
00536 #endif
00537
00538 static int _interpreter_length SET_TO 0;
00539 static int _interpreter_active_g_codes[RS274NGC_ACTIVE_G_CODES];
00540 static int _interpreter_active_m_codes[RS274NGC_ACTIVE_M_CODES];
00541 static double _interpreter_active_settings[RS274NGC_ACTIVE_SETTINGS];
00542
00543
00544 char RS274NGC_PARAMETER_FILE[INTERP_TEXT_SIZE] =
00545 DEFAULT_RS274NGC_PARAMETER_FILE;
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574 int utility_error_number(
00575 char * message,
00576 char * error_array[],
00577 int index)
00578 {
00579 for (;error_array[index][0] ISNT 0; index++)
00580 {
00581 if (strcmp(message, error_array[index]) IS 0)
00582 return index;
00583 }
00584 return 0;
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607 int execute_binary1(
00608 double * left,
00609 int operation,
00610 double * right)
00611 {
00612 static char name[] SET_TO "execute_binary1";
00613 switch (operation)
00614 {
00615 case DIVIDED_BY:
00616 if (*right IS 0.0)
00617 ERROR_MACRO(_interpreter_linetext, name, "Attempt to divide by zero");
00618 else
00619 {
00620 *left SET_TO (*left / *right);
00621 return RS274NGC_OK;
00622 }
00623 case MODULO:
00624 *left SET_TO fmod(*left, *right);
00625 if (*left < 0.0)
00626 {
00627 *left SET_TO (*left + fabs(*right));
00628 }
00629 return RS274NGC_OK;
00630 case POWER:
00631 if ((*left < 0.0) AND (floor(*right) ISNT *right))
00632 ERROR_MACRO(_interpreter_linetext, name, "Cannot raise negative number to non-integer power");
00633 *left SET_TO pow(*left, *right);
00634 return RS274NGC_OK;
00635 case TIMES:
00636 *left SET_TO (*left * *right);
00637 return RS274NGC_OK;
00638 default:
00639 BUG_MACRO(name, "Unknown operation in execute_binary1");
00640 }
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666 int execute_binary2(
00667 double * left,
00668 int operation,
00669 double * right)
00670 {
00671 static char name[] SET_TO "execute_binary2";
00672 switch (operation)
00673 {
00674 case AND2:
00675 *left SET_TO ((*left IS 0.0) OR (*right IS 0.0)) ? 0.0 : 1.0;
00676 return RS274NGC_OK;
00677 case EXCLUSIVE_OR:
00678 *left SET_TO (((*left IS 0.0) AND (*right ISNT 0.0)) OR
00679 ((*left ISNT 0.0) AND (*right IS 0.0))) ? 1.0 : 0.0;
00680 return RS274NGC_OK;
00681 case MINUS:
00682 *left SET_TO (*left - *right);
00683 return RS274NGC_OK;
00684 case NON_EXCLUSIVE_OR:
00685 *left SET_TO ((*left ISNT 0.0) OR (*right ISNT 0.0)) ? 1.0 : 0.0;
00686 return RS274NGC_OK;
00687 case PLUS:
00688 *left SET_TO (*left + *right);
00689 return RS274NGC_OK;
00690 default:
00691 BUG_MACRO(name, "Unknown operation in execute_binary2");
00692 }
00693 }
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720 int execute_unary (
00721 double * double_ptr,
00722 int operation)
00723 {
00724 static char name[] SET_TO "execute_unary";
00725 switch (operation)
00726 {
00727 case ABS:
00728 if (*double_ptr < 0.0)
00729 *double_ptr SET_TO (-1.0 * *double_ptr);
00730 return RS274NGC_OK;
00731 case ACOS:
00732 if ((*double_ptr < -1.0) OR (*double_ptr > 1.0))
00733 ERROR_MACRO(_interpreter_linetext, name, "Argument to acos out of range");
00734 else
00735 {
00736 *double_ptr SET_TO acos(*double_ptr);
00737 *double_ptr SET_TO ((*double_ptr * 180.0)/ PI);
00738 return RS274NGC_OK;
00739 }
00740 case ASIN:
00741 if ((*double_ptr < -1.0) OR (*double_ptr > 1.0))
00742 ERROR_MACRO(_interpreter_linetext, name, "Argument to asin out of range");
00743 else
00744 {
00745 *double_ptr SET_TO asin(*double_ptr);
00746 *double_ptr SET_TO ((*double_ptr * 180.0)/ PI);
00747 return RS274NGC_OK;
00748 }
00749 case COS:
00750 *double_ptr SET_TO cos((*double_ptr * PI)/180.0);
00751 return RS274NGC_OK;
00752 case EXP:
00753 *double_ptr SET_TO exp(*double_ptr);
00754 return RS274NGC_OK;
00755 case FIX:
00756 *double_ptr SET_TO floor(*double_ptr);
00757 return RS274NGC_OK;
00758 case FUP:
00759 *double_ptr SET_TO ceil(*double_ptr);
00760 return RS274NGC_OK;
00761 case LN:
00762 if (*double_ptr <= 0.0)
00763 ERROR_MACRO(_interpreter_linetext, name, "Zero or negative argument to ln");
00764 else
00765 {
00766 *double_ptr SET_TO log(*double_ptr);
00767 return RS274NGC_OK;
00768 }
00769 case ROUND:
00770 *double_ptr SET_TO (double)
00771 ((int) (*double_ptr + ((*double_ptr < 0.0) ? -0.5 : 0.5)));
00772 return RS274NGC_OK;
00773 case SIN:
00774 *double_ptr SET_TO sin((*double_ptr * PI)/180.0);
00775 return RS274NGC_OK;
00776 case SQRT:
00777 if (*double_ptr < 0.0)
00778 ERROR_MACRO(_interpreter_linetext, name, "Negative argument to sqrt");
00779 else
00780 {
00781 *double_ptr SET_TO sqrt(*double_ptr);
00782 return RS274NGC_OK;
00783 }
00784 case TAN:
00785 *double_ptr SET_TO tan((*double_ptr * PI)/180.0);
00786 return RS274NGC_OK;
00787 default:
00788 BUG_MACRO(name, "Unknown operation in execute_unary");
00789 }
00790 }
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826 int read_atan(
00827 char * line,
00828 int * counter,
00829 double * double_ptr,
00830 double * parameters)
00831 {
00832 static char name[] SET_TO "read_atan";
00833 double argument2;
00834
00835 if (line [*counter] ISNT '/')
00836 ERROR_MACRO(_interpreter_linetext, name, "Slash missing");
00837
00838 *counter SET_TO (*counter + 1);
00839
00840 if(line[*counter] ISNT '[')
00841 ERROR_MACRO(_interpreter_linetext, name, "Left bracket missing after slash with atan operator");
00842
00843 if (read_real_expression (line, counter, &argument2, parameters)
00844 IS RS274NGC_ERROR)
00845 ERROR_MACRO_PASS(name);
00846
00847 *double_ptr SET_TO atan2(*double_ptr, argument2);
00848 *double_ptr SET_TO ((*double_ptr * 180.0)/PI);
00849 return RS274NGC_OK;
00850 }
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884 int read_integer_value(
00885 char * line,
00886 int * counter,
00887 int * integer_ptr,
00888 double * parameters)
00889 {
00890 static char name[] SET_TO "read_integer_value";
00891 double float_value;
00892
00893 if (read_real_value(line, counter, &float_value, parameters)
00894 IS RS274NGC_ERROR)
00895 ERROR_MACRO_PASS(name);
00896 *integer_ptr SET_TO (int)floor(float_value);
00897 if ((float_value - *integer_ptr) > 0.9999)
00898 {
00899 *integer_ptr SET_TO (int)ceil(float_value);
00900 }
00901 else if ((float_value - *integer_ptr) > 0.0001)
00902 ERROR_MACRO(_interpreter_linetext, name, "Non-integer value for integer");
00903 return RS274NGC_OK;
00904 }
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922 int read_operation(
00923 char * line,
00924 int * counter,
00925 int * operation)
00926 {
00927 static char name[] SET_TO "read_operation";
00928 char c;
00929
00930 c SET_TO line[*counter];
00931 *counter SET_TO (*counter + 1);
00932 switch(c)
00933 {
00934 case '+':
00935 *operation SET_TO PLUS;
00936 return RS274NGC_OK;
00937 case '-':
00938 *operation SET_TO MINUS;
00939 return RS274NGC_OK;
00940 case '/':
00941 *operation SET_TO DIVIDED_BY;
00942 return RS274NGC_OK;
00943 case '*':
00944 if(strncmp((line + *counter), "*", 1) IS 0)
00945 {
00946 *operation SET_TO POWER;
00947 *counter SET_TO (*counter + 1);
00948 return RS274NGC_OK;
00949 }
00950 else
00951 {
00952 *operation SET_TO TIMES;
00953 return RS274NGC_OK;
00954 }
00955 case ']':
00956 *operation SET_TO RIGHT_BRACKET;
00957 return RS274NGC_OK;
00958 case 'a':
00959 if(strncmp((line + *counter), "nd", 2) IS 0)
00960 {
00961 *operation SET_TO AND2;
00962 *counter SET_TO (*counter + 2);
00963 return RS274NGC_OK;
00964 }
00965 else
00966 ERROR_MACRO(_interpreter_linetext, name, "Unknown operation name starting with A");
00967 case 'm':
00968 if(strncmp((line + *counter), "od", 2) IS 0)
00969 {
00970 *operation SET_TO MODULO;
00971 *counter SET_TO (*counter + 2);
00972 return RS274NGC_OK;
00973 }
00974 else
00975 ERROR_MACRO(_interpreter_linetext, name, "Unknown operation name starting with M");
00976 case 'o':
00977 if(strncmp((line + *counter), "r", 1) IS 0)
00978 {
00979 *operation SET_TO NON_EXCLUSIVE_OR;
00980 *counter SET_TO (*counter + 1);
00981 return RS274NGC_OK;
00982 }
00983 else
00984 ERROR_MACRO(_interpreter_linetext, name, "Unknown operation name starting with O");
00985 case 'x':
00986 if(strncmp((line + *counter), "or", 2) IS 0)
00987 {
00988 *operation SET_TO EXCLUSIVE_OR;
00989 *counter SET_TO (*counter + 2);
00990 return RS274NGC_OK;
00991 }
00992 else
00993 ERROR_MACRO(_interpreter_linetext, name, "Unknown operation name starting with X");
00994 case 0:
00995 ERROR_MACRO(_interpreter_linetext, name, "Unclosed expression");
00996 default:
00997 ERROR_MACRO(_interpreter_linetext, name, "Unknown operation");
00998 }
00999 }
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023 int read_operation_unary(
01024 char * line,
01025 int * counter,
01026 int * operation)
01027 {
01028 static char name[] SET_TO "read_operation_unary";
01029 char c;
01030
01031 c SET_TO line[*counter];
01032 *counter SET_TO (*counter + 1);
01033 switch (c)
01034 {
01035 case 'a':
01036 if(strncmp((line + *counter), "bs", 2) IS 0)
01037 {
01038 *operation SET_TO ABS;
01039 *counter SET_TO (*counter + 2);
01040 return RS274NGC_OK;
01041 }
01042 else if(strncmp((line + *counter), "cos", 3) IS 0)
01043 {
01044 *operation SET_TO ACOS;
01045 *counter SET_TO (*counter + 3);
01046 return RS274NGC_OK;
01047 }
01048 else if(strncmp((line + *counter), "sin", 3) IS 0)
01049 {
01050 *operation SET_TO ASIN;
01051 *counter SET_TO (*counter + 3);
01052 return RS274NGC_OK;
01053 }
01054 else if(strncmp((line + *counter), "tan", 3) IS 0)
01055 {
01056 *operation SET_TO ATAN;
01057 *counter SET_TO (*counter + 3);
01058 return RS274NGC_OK;
01059 }
01060 else
01061 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with A");
01062 case 'c':
01063 if(strncmp((line + *counter), "os", 2) IS 0)
01064 {
01065 *operation SET_TO COS;
01066 *counter SET_TO (*counter + 2);
01067 return RS274NGC_OK;
01068 }
01069 else
01070 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with C");
01071 case 'e':
01072 if(strncmp((line + *counter), "xp", 2) IS 0)
01073 {
01074 *operation SET_TO EXP;
01075 *counter SET_TO (*counter + 2);
01076 return RS274NGC_OK;
01077 }
01078 else
01079 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with E");
01080 case 'f':
01081 if(strncmp((line + *counter), "ix", 2) IS 0)
01082 {
01083 *operation SET_TO FIX;
01084 *counter SET_TO (*counter + 2);
01085 return RS274NGC_OK;
01086 }
01087 else if(strncmp((line + *counter), "up", 2) IS 0)
01088 {
01089 *operation SET_TO FUP;
01090 *counter SET_TO (*counter + 2);
01091 return RS274NGC_OK;
01092 }
01093 else
01094 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with F");
01095 case 'l':
01096 if(strncmp((line + *counter), "n", 1) IS 0)
01097 {
01098 *operation SET_TO LN;
01099 *counter SET_TO (*counter + 1);
01100 return RS274NGC_OK;
01101 }
01102 else
01103 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with L");
01104 case 'r':
01105 if(strncmp((line + *counter), "ound", 4) IS 0)
01106 {
01107 *operation SET_TO ROUND;
01108 *counter SET_TO (*counter + 4);
01109 return RS274NGC_OK;
01110 }
01111 else
01112 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with R");
01113 case 's':
01114 if(strncmp((line + *counter), "in", 2) IS 0)
01115 {
01116 *operation SET_TO SIN;
01117 *counter SET_TO (*counter + 2);
01118 return RS274NGC_OK;
01119 }
01120 else if(strncmp((line + *counter), "qrt", 3) IS 0)
01121 {
01122 *operation SET_TO SQRT;
01123 *counter SET_TO (*counter + 3);
01124 return RS274NGC_OK;
01125 }
01126 else
01127 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with S");
01128 case 't':
01129 if(strncmp((line + *counter), "an", 2) IS 0)
01130 {
01131 *operation SET_TO TAN;
01132 *counter SET_TO (*counter + 2);
01133 return RS274NGC_OK;
01134 }
01135 else
01136 ERROR_MACRO(_interpreter_linetext, name, "Unknown word starting with T");
01137 default:
01138 ERROR_MACRO(_interpreter_linetext, name, "Unknown word where unary operation could be");
01139 }
01140 }
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160 double utility_find_turn(
01161 double x1,
01162 double y1,
01163 double center_x,
01164 double center_y,
01165 int turn,
01166 double x2,
01167 double y2)
01168 {
01169 double alpha;
01170 double beta;
01171 double theta;
01172
01173 if (turn IS 0)
01174 return 0.0;
01175 alpha SET_TO atan2((y1 - center_y), (x1 - center_x));
01176 beta SET_TO atan2((y2 - center_y), (x2 - center_x));
01177 if (turn > 0)
01178 {
01179 if (beta <= alpha)
01180 beta SET_TO (beta + TWO_PI);
01181 theta SET_TO ((beta - alpha) + ((turn - 1) * TWO_PI));
01182 }
01183 else
01184 {
01185 if (alpha <= beta)
01186 alpha SET_TO (alpha + TWO_PI);
01187 theta SET_TO ((beta - alpha) + ((turn + 1) * TWO_PI));
01188 }
01189 return (theta);
01190 }
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218 int arc_data_comp_ijk(
01219 int move,
01220 int side,
01221 double tool_radius,
01222 double current_x,
01223 double current_y,
01224 double end_x,
01225 double end_y,
01226 double i_number,
01227 double j_number,
01228 double * center_x,
01229 double * center_y,
01230 int * turn,
01231 double tolerance)
01232 {
01233 static char name[] SET_TO "arc_data_comp_ijk";
01234 double arc_radius;
01235 double radius2;
01236 *center_x SET_TO (current_x + i_number);
01237 *center_y SET_TO (current_y + j_number);
01238 arc_radius SET_TO hypot((*center_x - current_x), (*center_y - current_y));
01239 radius2 SET_TO hypot((*center_x - end_x), (*center_y - end_y));
01240 radius2 SET_TO
01241 (((side IS LEFT ) AND (move IS 30)) OR
01242 ((side IS RIGHT) AND (move IS 20))) ?
01243 (radius2 - tool_radius): (radius2 + tool_radius);
01244 if (fabs(arc_radius - radius2) > tolerance)
01245 ERROR_MACRO(_interpreter_linetext, name,
01246 "Radius to end of arc differs from radius to start of arc");
01247
01248 if (move IS G_2)
01249 *turn SET_TO -1;
01250 else if (move IS G_3)
01251 *turn SET_TO 1;
01252 else
01253 BUG_MACRO(name, "Code is not G2 or G3 in arc_data_comp");
01254 return RS274NGC_OK;
01255 }
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298 int arc_data_comp_r(
01299 int move,
01300 int side,
01301 double tool_radius,
01302 double current_x,
01303 double current_y,
01304 double end_x,
01305 double end_y,
01306 double big_radius,
01307 double * center_x,
01308 double * center_y,
01309 int * turn)
01310 {
01311 static char name[] SET_TO "arc_data_comp_r";
01312 double abs_radius;
01313 double radius2;
01314 double distance;
01315 double mid_length;
01316 double offset;
01317 double alpha;
01318 double theta;
01319 double mid_x;
01320 double mid_y;
01321
01322 if ((end_x IS current_x) AND (end_y IS current_y))
01323 ERROR_MACRO(_interpreter_linetext, name, "Current point same as end point of arc");
01324 abs_radius SET_TO fabs(big_radius);
01325 if ((abs_radius < tool_radius) AND (((side IS LEFT ) AND (move IS G_3)) OR
01326 ((side IS RIGHT) AND (move IS G_2))))
01327 ERROR_MACRO(_interpreter_linetext, name,
01328 "Tool radius not less than arc radius with cutter radius comp");
01329
01330 distance SET_TO hypot((end_x - current_x), (end_y - current_y));
01331 alpha SET_TO atan2 ((end_y - current_y), (end_x - current_x));
01332 theta SET_TO (((move IS G_3) AND (big_radius > 0)) OR
01333 ((move IS G_2) AND (big_radius < 0))) ?
01334 (alpha + PI2) : (alpha - PI2);
01335 radius2 SET_TO (((side IS LEFT ) AND (move IS G_3)) OR
01336 ((side IS RIGHT) AND (move IS G_2))) ?
01337 (abs_radius - tool_radius) : (abs_radius + tool_radius);
01338 if (distance > (radius2 + abs_radius))
01339 ERROR_MACRO(_interpreter_linetext, name, "Radius too small to reach end point");
01340 mid_length SET_TO (((radius2 * radius2) + (distance * distance) -
01341 (abs_radius * abs_radius)) / (2.0 * distance));
01342 mid_x SET_TO (current_x + (mid_length * cos(alpha)));
01343 mid_y SET_TO (current_y + (mid_length * sin(alpha)));
01344 offset SET_TO sqrt((radius2 * radius2) - (mid_length * mid_length));
01345 *center_x SET_TO mid_x + (offset * cos(theta));
01346 *center_y SET_TO mid_y + (offset * sin(theta));
01347 *turn SET_TO (move IS G_2) ? -1 : 1;
01348
01349 return RS274NGC_OK;
01350 }
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380 int arc_data_ijk(
01381 int move,
01382 double current_x,
01383 double current_y,
01384 double end_x,
01385 double end_y,
01386 double i_number,
01387 double j_number,
01388 double * center_x,
01389 double * center_y,
01390 int * turn,
01391 double tolerance)
01392 {
01393 static char name[] SET_TO "arc_data_ijk";
01394 double radius;
01395 double radius2;
01396 *center_x SET_TO (current_x + i_number);
01397 *center_y SET_TO (current_y + j_number);
01398 radius SET_TO hypot((*center_x - current_x), (*center_y - current_y));
01399 radius2 SET_TO hypot((*center_x - end_x), (*center_y - end_y));
01400 if (fabs(radius - radius2) > tolerance)
01401 ERROR_MACRO(_interpreter_linetext, name,
01402 "Radius to end of arc differs from radius to start of arc");
01403 if (move IS G_2)
01404 *turn SET_TO -1;
01405 else if (move IS G_3)
01406 *turn SET_TO 1;
01407 else
01408 BUG_MACRO(name, "Code is not G2 or G3 in arc_data_ijk");
01409 return RS274NGC_OK;
01410 }
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447 int arc_data_r(
01448 int move,
01449 double current_x,
01450 double current_y,
01451 double end_x,
01452 double end_y,
01453 double radius,
01454 double * center_x,
01455 double * center_y,
01456 int * turn)
01457 {
01458 static char name[] SET_TO "arc_data_r";
01459 double abs_radius;
01460 double half_length;
01461 double turn2;
01462 double offset;
01463 double theta;
01464 double mid_x;
01465 double mid_y;
01466
01467 if ((end_x IS current_x) AND (end_y IS current_y))
01468 ERROR_MACRO(_interpreter_linetext, name, "Current point same as end point of arc");
01469 abs_radius SET_TO fabs(radius);
01470 mid_x SET_TO (end_x + current_x)/2.0;
01471 mid_y SET_TO (end_y + current_y)/2.0;
01472 half_length SET_TO hypot((mid_x - end_x), (mid_y - end_y));
01473 if ((half_length/abs_radius) > (1+TINY))
01474 ERROR_MACRO(_interpreter_linetext, name, "Arc radius too small to reach end point");
01475 else if ((half_length/abs_radius) > (1-TINY))
01476 half_length SET_TO abs_radius;
01477
01478 if (((move IS G_2) AND (radius > 0)) OR
01479 ((move IS G_3) AND (radius < 0)))
01480 theta SET_TO atan2((end_y - current_y), (end_x - current_x)) - PI2;
01481 else
01482 theta SET_TO atan2((end_y - current_y), (end_x - current_x)) + PI2;
01483
01484 turn2 SET_TO asin (half_length/abs_radius);
01485 offset SET_TO abs_radius * cos(turn2);
01486 *center_x SET_TO mid_x + (offset * cos(theta));
01487 *center_y SET_TO mid_y + (offset * sin(theta));
01488 *turn SET_TO (move IS G_2) ? -1 : 1;
01489
01490 return RS274NGC_OK;
01491 }
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523 int read_parameter(
01524 char * line,
01525 int * counter,
01526 double * double_ptr,
01527 double * parameters)
01528 {
01529 static char name[] SET_TO "read_parameter";
01530 int index;
01531
01532 if (line[*counter] ISNT '#')
01533 BUG_MACRO(name, "Read_parameter should not have been called");
01534 *counter SET_TO (*counter + 1);
01535 if (read_integer_value(line, counter, &index, parameters) IS RS274NGC_ERROR)
01536 ERROR_MACRO_PASS(name);
01537 else if ((index < 1) OR (index >= RS274NGC_MAX_PARAMETERS))
01538 ERROR_MACRO(_interpreter_linetext, name, "Parameter number out of range");
01539 else
01540 {
01541 *double_ptr SET_TO parameters[index];
01542 return RS274NGC_OK;
01543 }
01544 }
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853 int read_real_expression(
01854 char * line,
01855 int * counter,
01856 double * hold2,
01857 double * parameters)
01858 {
01859 static char name[] SET_TO "read_real_expression";
01860 double value;
01861 double hold1;
01862 int waiting_operation;
01863 int last_operation;
01864 int next_operation;
01865
01866 if (line[*counter] ISNT '[')
01867 BUG_MACRO(name, "Read_real_expression should not have been called");
01868 *counter SET_TO (*counter + 1);
01869 waiting_operation SET_TO PLUS;
01870 *hold2 SET_TO 0.0;
01871 last_operation SET_TO PLUS;
01872
01873 for (;;)
01874 {
01875 if (read_real_value(line, counter, &value, parameters) ISNT RS274NGC_OK)
01876 ERROR_MACRO_PASS(name);
01877 if (read_operation(line, counter, &next_operation) ISNT RS274NGC_OK)
01878 ERROR_MACRO_PASS(name);
01879 if (next_operation IS RIGHT_BRACKET)
01880 {
01881 if (last_operation < AND2)
01882 {
01883 if (execute_binary1(&hold1,last_operation, &value)
01884 ISNT RS274NGC_OK)
01885 ERROR_MACRO_PASS(name);
01886 if (execute_binary2(hold2, waiting_operation, &hold1)
01887 ISNT RS274NGC_OK)
01888 ERROR_MACRO_PASS(name);
01889 }
01890 else if (execute_binary2(hold2, waiting_operation, &value)
01891 ISNT RS274NGC_OK)
01892 ERROR_MACRO_PASS(name);
01893 else {}
01894 return RS274NGC_OK;
01895 }
01896 else if (next_operation < AND2)
01897 {
01898 if (last_operation >= AND2)
01899 {
01900 hold1 SET_TO value;
01901 }
01902 else if (execute_binary1(&hold1, last_operation, &value)
01903 ISNT RS274NGC_OK)
01904 ERROR_MACRO_PASS(name);
01905 }
01906 else
01907 {
01908 if (last_operation < AND2)
01909 {
01910 if (execute_binary1(&hold1, last_operation, &value)
01911 ISNT RS274NGC_OK)
01912 ERROR_MACRO_PASS(name);
01913 if (execute_binary2(hold2, waiting_operation, &hold1)
01914 ISNT RS274NGC_OK)
01915 ERROR_MACRO_PASS(name);
01916 }
01917 else
01918 {
01919 if (execute_binary2(hold2, waiting_operation, &value)
01920 ISNT RS274NGC_OK)
01921 ERROR_MACRO_PASS(name);
01922 }
01923 waiting_operation SET_TO next_operation;
01924 }
01925 last_operation SET_TO next_operation;
01926 }
01927 }
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965 int read_real_number(
01966 char * line,
01967 int * counter,
01968 double * double_ptr)
01969 {
01970 static char name[] SET_TO "read_real_number";
01971 int n;
01972 char c;
01973 int flag_point;
01974 int flag_digit;
01975
01976 n SET_TO *counter;
01977 flag_point SET_TO OFF;
01978 flag_digit SET_TO OFF;
01979
01980
01981 c SET_TO line[n];
01982 if (c IS '+')
01983 {
01984 *counter SET_TO (*counter + 1);
01985 n++;
01986 }
01987 else if (c IS '-')
01988 {
01989 n++;
01990 }
01991 else if ((c ISNT '.') AND ((c < 48) OR (c > 57)))
01992 ERROR_MACRO(_interpreter_linetext, name, "Bad number format");
01993
01994
01995 for (; (c SET_TO line[n]) ISNT (char) NULL; n++)
01996 {
01997 if (( 47 < c) AND ( c < 58))
01998 {
01999 flag_digit SET_TO ON;
02000 }
02001 else if (c IS '.')
02002 {
02003 if (flag_point IS OFF)
02004 {
02005 flag_point SET_TO ON;
02006 }
02007 else
02008 break;
02009 }
02010 else
02011 break;
02012 }
02013
02014 if (flag_digit IS OFF)
02015 ERROR_MACRO(_interpreter_linetext, name, "No digits found where real number should be");
02016
02017 line[n] SET_TO (char) NULL;
02018 if (sscanf(line + *counter, "%lf", double_ptr) IS 0)
02019 {
02020 line[n] SET_TO c;
02021 BUG_MACRO(name, "Sscanf failure in read_real_number");
02022 }
02023 else
02024 {
02025 line[n] SET_TO c;
02026 *counter SET_TO n;
02027 return RS274NGC_OK;
02028 }
02029 }
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057 int read_unary(
02058 char * line,
02059 int * counter,
02060 double * double_ptr,
02061 double * parameters)
02062 {
02063 static char name[] SET_TO "read_unary";
02064 int operation;
02065
02066 if (read_operation_unary (line, counter, &operation) IS RS274NGC_ERROR)
02067 ERROR_MACRO_PASS(name);
02068 if (line[*counter] ISNT '[')
02069 ERROR_MACRO(_interpreter_linetext, name, "Left bracket missing after unary operation name");
02070 if (read_real_expression (line, counter, double_ptr, parameters)
02071 IS RS274NGC_ERROR)
02072 ERROR_MACRO_PASS(name);
02073
02074 if (operation IS ATAN)
02075 return read_atan(line, counter, double_ptr, parameters);
02076 else
02077 return execute_unary (double_ptr, operation);
02078 }
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111 double utility_find_arc_length(
02112 double x1,
02113 double y1,
02114 double z1,
02115 double center_x,
02116 double center_y,
02117 int turn,
02118 double x2,
02119 double y2,
02120 double z2)
02121 {
02122 double radius;
02123 double theta;
02124
02125 if (turn IS 0)
02126 return 0.0;
02127 radius SET_TO hypot((center_x - x1), (center_y - y1));
02128 theta SET_TO utility_find_turn(x1, y1, center_x, center_y, turn, x2, y2);
02129 if (z2 IS z1)
02130 return (radius * fabs(theta));
02131 else
02132 return hypot((radius * theta), (z2 - z1));
02133 }
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158 double utility_find_straight_length(
02159 double x2,
02160 double y2,
02161 double z2,
02162 double x1,
02163 double y1,
02164 double z1)
02165 {
02166 return sqrt(pow((x2 - x1),2) + pow((y2 - y1),2) + pow((z2 - z1),2));
02167 }
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198 int convert_arc_comp1(
02199 int move,
02200 block_pointer block,
02201 setup_pointer settings,
02202 double end_x,
02203 double end_y,
02204 double end_z)
02205 {
02206 static char name[] SET_TO "convert_arc_comp1";
02207 double center_x;
02208 double center_y;
02209 int turn;
02210 double gamma;
02211 double tolerance;
02212 double tool_radius;
02213 int side;
02214 int status;
02215
02216 side SET_TO settings->cutter_radius_compensation;
02217 tool_radius SET_TO
02218 (settings->tool_table[settings->tool_table_index].diameter)/2.0;
02219 if (tool_radius <= 0.0)
02220 ERROR_MACRO(_interpreter_linetext, name, "Bad tool radius value with cutter radius comp");
02221 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
02222 TOLERANCE_INCH : TOLERANCE_MM;
02223
02224 if (block->r_flag)
02225 {
02226 status SET_TO
02227 arc_data_comp_r(move, side, tool_radius, settings->current_x,
02228 settings->current_y, end_x, end_y, block->r_number,
02229 ¢er_x, ¢er_y, &turn);
02230 }
02231 else
02232 {
02233 status SET_TO
02234 arc_data_comp_ijk(move, side, tool_radius, settings->current_x,
02235 settings->current_y, end_x, end_y,
02236 block->i_number, block->j_number,
02237 ¢er_x, ¢er_y, &turn, tolerance);
02238 }
02239
02240 if (status IS RS274NGC_ERROR)
02241 ERROR_MACRO_PASS(name);
02242
02243 gamma SET_TO
02244 (((side IS LEFT) AND (move IS G_3)) OR
02245 ((side IS RIGHT) AND (move IS G_2))) ?
02246 atan2 ((center_y - end_y), (center_x - end_x)) :
02247 atan2 ((end_y - center_y), (end_x - center_x));
02248
02249 settings->program_x SET_TO end_x;
02250 settings->program_y SET_TO end_y;
02251 end_x SET_TO (end_x + (tool_radius * cos(gamma)));
02252 end_y SET_TO (end_y + (tool_radius * sin(gamma)));
02253 ARC_FEED(end_x, end_y, center_x, center_y, turn, end_z);
02254 settings->current_x SET_TO end_x;
02255 settings->current_y SET_TO end_y;
02256 settings->current_z SET_TO end_z;
02257
02258 return RS274NGC_OK;
02259 }
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292 int convert_arc_comp2(
02293 int move,
02294 block_pointer block,
02295 setup_pointer settings,
02296 double end_x,
02297 double end_y,
02298 double end_z)
02299 {
02300 static char name[] SET_TO "convert_arc_comp2";
02301 double center_x;
02302 double center_y;
02303 double start_x;
02304 double start_y;
02305 int turn;
02306 double theta;
02307 double delta;
02308 double alpha;
02309 double beta;
02310 double gamma;
02311 double arc_radius;
02312 double tool_radius;
02313
02314 double small SET_TO TOLERANCE_CONCAVE_CORNER;
02315 int side;
02316 int status;
02317 double tolerance;
02318
02319
02320
02321 start_x SET_TO settings->program_x;
02322 start_y SET_TO settings->program_y;
02323 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
02324 TOLERANCE_INCH : TOLERANCE_MM;
02325
02326 if (block->r_flag)
02327 {
02328 status SET_TO arc_data_r(move, start_x, start_y, end_x, end_y,
02329 block->r_number, ¢er_x, ¢er_y, &turn);
02330 }
02331 else
02332 {
02333 status SET_TO
02334 arc_data_ijk(move, start_x, start_y, end_x, end_y,
02335 block->i_number, block->j_number,
02336 ¢er_x, ¢er_y, &turn, tolerance);
02337 }
02338
02339 if (status IS RS274NGC_ERROR)
02340 ERROR_MACRO_PASS(name);
02341
02342
02343 side SET_TO settings->cutter_radius_compensation;
02344 tool_radius SET_TO
02345 (settings->tool_table[settings->tool_table_index].diameter)/2.0;
02346 if (tool_radius <= 0.0)
02347 ERROR_MACRO(_interpreter_linetext, name, "Bad tool radius value with cutter radius comp");
02348 arc_radius SET_TO hypot((center_x - end_x), (center_y - end_y));
02349 theta SET_TO
02350 atan2(settings->current_y - start_y, settings->current_x - start_x);
02351 theta SET_TO (side IS LEFT) ? (theta - PI2) : (theta + PI2);
02352 delta SET_TO atan2(center_y - start_y, center_x - start_x);
02353 alpha SET_TO (move IS G_3) ? (delta - PI2) : (delta + PI2);
02354 beta SET_TO (side IS LEFT) ? (theta - alpha) : (alpha - theta);
02355 beta SET_TO (beta > (1.5 * PI)) ? (beta - TWO_PI) :
02356 (beta < -PI2) ? (beta + TWO_PI) : beta;
02357
02358 if (((side IS LEFT) AND (move IS G_3)) OR
02359 ((side IS RIGHT) AND (move IS G_2)))
02360 {
02361 gamma SET_TO atan2 ((center_y - end_y), (center_x - end_x));
02362 if (arc_radius <= tool_radius)
02363 ERROR_MACRO(_interpreter_linetext, name,
02364 "Tool radius not less than arc radius with cutter radius comp");
02365 }
02366 else
02367 {
02368 gamma SET_TO atan2 ((end_y - center_y), (end_x - center_x));
02369 delta SET_TO (delta + PI);
02370 }
02371
02372 settings->program_x SET_TO end_x;
02373 settings->program_y SET_TO end_y;
02374
02375
02376
02377 if ((beta < -small) OR (beta > (PI + small)))
02378 ERROR_MACRO(_interpreter_linetext, name, "Concave corner with cutter radius comp");
02379 else if (beta > small)
02380 ARC_FEED((start_x + (tool_radius * cos(delta))),
02381 (start_y + (tool_radius * sin(delta))),
02382 start_x, start_y, (side IS LEFT) ? -1 : 1,
02383 settings->current_z);
02384
02385 end_x SET_TO (end_x + (tool_radius * cos(gamma)));
02386 end_y SET_TO (end_y + (tool_radius * sin(gamma)));
02387
02388
02389 ARC_FEED(end_x, end_y, center_x, center_y, turn, end_z);
02390
02391 settings->current_x SET_TO end_x;
02392 settings->current_y SET_TO end_y;
02393 settings->current_z SET_TO end_z;
02394
02395 return RS274NGC_OK;
02396 }
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418 int convert_arc_xy(
02419 int move,
02420 block_pointer block,
02421 setup_pointer settings,
02422 double end_x,
02423 double end_y,
02424 double end_z)
02425 {
02426 static char name[] SET_TO "convert_arc_xy";
02427 double center_x;
02428 double center_y;
02429 double length;
02430 double rate;
02431 int turn;
02432 int status;
02433 double tolerance;
02434
02435 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
02436 TOLERANCE_INCH : TOLERANCE_MM;
02437
02438 if (block->r_flag)
02439 {
02440 status SET_TO
02441 arc_data_r(move, settings->current_x, settings->current_y, end_x,
02442 end_y, block->r_number, ¢er_x, ¢er_y, &turn);
02443 }
02444 else
02445 {
02446 status SET_TO
02447 arc_data_ijk(move, settings->current_x, settings->current_y,
02448 end_x, end_y, block->i_number, block->j_number,
02449 ¢er_x, ¢er_y, &turn, tolerance);
02450 }
02451
02452 if (status IS RS274NGC_ERROR)
02453 ERROR_MACRO_PASS(name);
02454
02455 if (settings->feed_mode IS INVERSE_TIME)
02456 {
02457 length SET_TO utility_find_arc_length
02458 (settings->current_x, settings->current_y, settings->current_z,
02459 center_x, center_y, turn, end_x, end_y, end_z);
02460 rate SET_TO MAX(0.1, (length * block->f_number));
02461 SET_FEED_RATE (rate);
02462 settings->feed_rate SET_TO rate;
02463 }
02464
02465 ARC_FEED(end_x, end_y, center_x, center_y, turn, end_z);
02466 settings->current_x SET_TO end_x;
02467 settings->current_y SET_TO end_y;
02468 settings->current_z SET_TO end_z;
02469 return RS274NGC_OK;
02470 }
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492 int convert_arc_yz(
02493 int move,
02494 block_pointer block,
02495 setup_pointer settings,
02496 double end_y,
02497 double end_z,
02498 double end_x)
02499 {
02500 static char name[] SET_TO "convert_arc_yz";
02501 double center_y;
02502 double center_z;
02503 double length;
02504 double rate;
02505 int turn;
02506 int status;
02507 double tolerance;
02508
02509 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
02510 TOLERANCE_INCH : TOLERANCE_MM;
02511
02512 if (block->r_flag)
02513 {
02514 status SET_TO
02515 arc_data_r(move, settings->current_y, settings->current_z, end_y,
02516 end_z, block->r_number, ¢er_y, ¢er_z, &turn);
02517 }
02518 else
02519 {
02520 status SET_TO
02521 arc_data_ijk(move, settings->current_y, settings->current_z,
02522 end_y, end_z, block->j_number, block->k_number,
02523 ¢er_y, ¢er_z, &turn, tolerance);
02524 }
02525
02526 if (status IS RS274NGC_ERROR)
02527 ERROR_MACRO_PASS(name);
02528
02529 if (settings->feed_mode IS INVERSE_TIME)
02530 {
02531 length SET_TO utility_find_arc_length
02532 (settings->current_y, settings->current_z, settings->current_x,
02533 center_y, center_z, turn, end_y, end_z, end_x);
02534 rate SET_TO MAX(0.1, (length * block->f_number));
02535 SET_FEED_RATE (rate);
02536 settings->feed_rate SET_TO rate;
02537 }
02538
02539 ARC_FEED(end_y, end_z, center_y, center_z, turn, end_x);
02540 settings->current_y SET_TO end_y;
02541 settings->current_z SET_TO end_z;
02542 settings->current_x SET_TO end_x;
02543
02544 return RS274NGC_OK;
02545 }
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567 int convert_arc_zx(
02568 int move,
02569 block_pointer block,
02570 setup_pointer settings,
02571 double end_z,
02572 double end_x,
02573 double end_y)
02574 {
02575 static char name[] SET_TO "convert_arc_zx";
02576 double center_z;
02577 double center_x;
02578 double length;
02579 double rate;
02580 int turn;
02581 int status;
02582 double tolerance;
02583
02584 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
02585 TOLERANCE_INCH : TOLERANCE_MM;
02586
02587 if (block->r_flag)
02588 {
02589 status SET_TO
02590 arc_data_r(move, settings->current_z, settings->current_x, end_z,
02591 end_x, block->r_number, ¢er_z, ¢er_x, &turn);
02592 }
02593 else
02594 {
02595 status SET_TO
02596 arc_data_ijk(move, settings->current_z, settings->current_x,
02597 end_z, end_x, block->k_number, block->i_number,
02598 ¢er_z, ¢er_x, &turn, tolerance);
02599 }
02600
02601 if (status IS RS274NGC_ERROR)
02602 ERROR_MACRO_PASS(name);
02603
02604 if (settings->feed_mode IS INVERSE_TIME)
02605 {
02606 length SET_TO utility_find_arc_length
02607 (settings->current_z, settings->current_x, settings->current_y,
02608 center_z, center_x, turn, end_z, end_x, end_y);
02609 rate SET_TO MAX(0.1, (length * block->f_number));
02610 SET_FEED_RATE (rate);
02611 settings->feed_rate SET_TO rate;
02612 }
02613
02614 ARC_FEED(end_z, end_x, center_z, center_x, turn, end_y);
02615 settings->current_z SET_TO end_z;
02616 settings->current_x SET_TO end_x;
02617 settings->current_y SET_TO end_y;
02618
02619 return RS274NGC_OK;
02620 }
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643 int convert_cycle_g81(
02644 double x,
02645 double y,
02646 double clear_z,
02647 double bottom_z)
02648 {
02649 static char name[] SET_TO "convert_cycle_g81";
02650
02651 STRAIGHT_FEED(x, y, bottom_z);
02652 STRAIGHT_TRAVERSE(x, y, clear_z);
02653
02654 return RS274NGC_OK;
02655 }
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677 int convert_cycle_g82(
02678 double x,
02679 double y,
02680 double clear_z,
02681 double bottom_z,
02682 double dwell)
02683 {
02684 static char name[] SET_TO "convert_cycle_g82";
02685
02686 STRAIGHT_FEED(x, y, bottom_z);
02687 DWELL(dwell);
02688 STRAIGHT_TRAVERSE(x, y, clear_z);
02689
02690 return RS274NGC_OK;
02691 }
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721 #define G83_RAPID_DELTA 0.010
02722
02723 int convert_cycle_g83(
02724 double x,
02725 double y,
02726 double r,
02727 double clear_z,
02728 double bottom_z,
02729 double delta)
02730 {
02731 static char name[] SET_TO "convert_cycle_g83";
02732 double current_depth;
02733 double rapid_delta;
02734
02735 rapid_delta SET_TO G83_RAPID_DELTA;
02736 if (_interpreter_settings.length_units IS CANON_UNITS_MM)
02737 rapid_delta *= 25.4;
02738
02739 for (current_depth SET_TO (r - delta);
02740 current_depth > bottom_z;
02741 current_depth SET_TO (current_depth - delta))
02742 {
02743 STRAIGHT_FEED(x, y, current_depth);
02744 DWELL(0.25);
02745 STRAIGHT_TRAVERSE(x, y, clear_z);
02746 STRAIGHT_TRAVERSE(x, y, current_depth + rapid_delta);
02747 }
02748 STRAIGHT_FEED(x, y, bottom_z);
02749 DWELL(0.25);
02750 STRAIGHT_TRAVERSE(x, y, clear_z);
02751
02752 return RS274NGC_OK;
02753 }
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784 int convert_cycle_g84(
02785 double x,
02786 double y,
02787 double clear_z,
02788 double bottom_z,
02789 CANON_DIRECTION direction,
02790 CANON_SPEED_FEED_MODE mode)
02791 {
02792 static char name[] SET_TO "convert_cycle_g84";
02793
02794 if (direction ISNT CANON_CLOCKWISE)
02795 ERROR_MACRO(_interpreter_linetext, name, "Spindle not turning clockwise in G84 canned cycle");
02796 START_SPEED_FEED_SYNCH();
02797 STRAIGHT_FEED(x, y, bottom_z);
02798 STOP_SPINDLE_TURNING();
02799 START_SPINDLE_COUNTERCLOCKWISE();
02800 STRAIGHT_FEED(x, y, clear_z);
02801 if (mode ISNT CANON_SYNCHED)
02802 STOP_SPEED_FEED_SYNCH();
02803 STOP_SPINDLE_TURNING();
02804 START_SPINDLE_CLOCKWISE();
02805
02806 return RS274NGC_OK;
02807 }
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824
02825
02826
02827
02828 int convert_cycle_g85(
02829 double x,
02830 double y,
02831 double clear_z,
02832 double bottom_z)
02833 {
02834 static char name[] SET_TO "convert_cycle_g85";
02835
02836 STRAIGHT_FEED(x, y, bottom_z);
02837 STRAIGHT_FEED(x, y, clear_z);
02838
02839 return RS274NGC_OK;
02840 }
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864
02865
02866
02867 int convert_cycle_g86(
02868 double x,
02869 double y,
02870 double clear_z,
02871 double bottom_z,
02872 double dwell,
02873 CANON_DIRECTION direction)
02874 {
02875 static char name[] SET_TO "convert_cycle_g86";
02876
02877 if ((direction ISNT CANON_CLOCKWISE) AND
02878 (direction ISNT CANON_COUNTERCLOCKWISE))
02879 ERROR_MACRO(_interpreter_linetext, name, "Spindle not turning in G86 canned cycle");
02880
02881 STRAIGHT_FEED(x, y, bottom_z);
02882 DWELL(dwell);
02883 STOP_SPINDLE_TURNING();
02884 STRAIGHT_TRAVERSE(x, y, clear_z);
02885 if (direction IS CANON_CLOCKWISE)
02886 START_SPINDLE_CLOCKWISE();
02887 else
02888 START_SPINDLE_COUNTERCLOCKWISE();
02889
02890 return RS274NGC_OK;
02891 }
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942 int convert_cycle_g87(
02943 double x,
02944 double offset_x,
02945 double y,
02946 double offset_y,
02947 double r,
02948 double clear_z,
02949 double middle_z,
02950 double bottom_z,
02951 CANON_DIRECTION direction)
02952 {
02953 static char name[] SET_TO "convert_cycle_g87";
02954
02955 if ((direction ISNT CANON_CLOCKWISE) AND
02956 (direction ISNT CANON_COUNTERCLOCKWISE))
02957 ERROR_MACRO(_interpreter_linetext, name, "Spindle not turning in G87 canned cycle");
02958
02959 STRAIGHT_TRAVERSE(offset_x, offset_y, r);
02960 STOP_SPINDLE_TURNING();
02961 ORIENT_SPINDLE(0.0, direction);
02962 STRAIGHT_TRAVERSE(offset_x, offset_y, bottom_z);
02963 STRAIGHT_TRAVERSE(x, y, bottom_z);
02964 if (direction IS CANON_CLOCKWISE)
02965 START_SPINDLE_CLOCKWISE();
02966 else
02967 START_SPINDLE_COUNTERCLOCKWISE();
02968 STRAIGHT_FEED(x, y, middle_z);
02969 STRAIGHT_FEED(x, y, bottom_z);
02970 STOP_SPINDLE_TURNING();
02971 ORIENT_SPINDLE(0.0, direction);
02972 STRAIGHT_TRAVERSE(offset_x, offset_y, bottom_z);
02973 STRAIGHT_TRAVERSE(offset_x, offset_y, clear_z);
02974 STRAIGHT_TRAVERSE(x, y, clear_z);
02975 if (direction IS CANON_CLOCKWISE)
02976 START_SPINDLE_CLOCKWISE();
02977 else
02978 START_SPINDLE_COUNTERCLOCKWISE();
02979
02980 return RS274NGC_OK;
02981 }
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008 int convert_cycle_g88(
03009 double x,
03010 double y,
03011 double bottom_z,
03012 double dwell,
03013 CANON_DIRECTION direction)
03014 {
03015 static char name[] SET_TO "convert_cycle_g88";
03016
03017 if ((direction ISNT CANON_CLOCKWISE) AND
03018 (direction ISNT CANON_COUNTERCLOCKWISE))
03019 ERROR_MACRO(_interpreter_linetext, name, "Spindle not turning in G88 canned cycle");
03020
03021 STRAIGHT_FEED(x, y, bottom_z);
03022 DWELL(dwell);
03023 STOP_SPINDLE_TURNING();
03024 PROGRAM_STOP();
03025 if (direction IS CANON_CLOCKWISE)
03026 START_SPINDLE_CLOCKWISE();
03027 else
03028 START_SPINDLE_COUNTERCLOCKWISE();
03029
03030 return RS274NGC_OK;
03031 }
03032
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051 int convert_cycle_g89(
03052 double x,
03053 double y,
03054 double clear_z,
03055 double bottom_z,
03056 double dwell)
03057 {
03058 static char name[] SET_TO "convert_cycle_g89";
03059
03060 STRAIGHT_FEED(x, y, bottom_z);
03061 DWELL(dwell);
03062 STRAIGHT_FEED(x, y, clear_z);
03063
03064 return RS274NGC_OK;
03065 }
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083
03084
03085
03086
03087
03088
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099 int convert_straight_comp1(
03100 setup_pointer settings,
03101 double px,
03102 double py,
03103 double end_z)
03104 {
03105 static char name[] SET_TO "convert_straight_comp1";
03106 double radius;
03107 double cx, cy;
03108 double distance;
03109 double theta;
03110 double alpha;
03111 int side;
03112
03113 side SET_TO settings->cutter_radius_compensation;
03114 cx SET_TO settings->current_x;
03115 cy SET_TO settings->current_y;
03116
03117 radius SET_TO
03118 (settings->tool_table[settings->tool_table_index].diameter)/2.0;
03119 if (radius <= 0.0)
03120 ERROR_MACRO(_interpreter_linetext, name, "Bad tool radius value with cutter radius comp");
03121 distance SET_TO hypot((px - cx), (py -cy));
03122
03123 if ((side ISNT LEFT) AND (side ISNT RIGHT))
03124 BUG_MACRO(name,
03125 "Side fails to be right or left in convert_straight_comp1");
03126 else if (distance <= radius)
03127 ERROR_MACRO(_interpreter_linetext, name, "Cutter gouging with cutter radius comp");
03128
03129 theta SET_TO acos(radius/distance);
03130 alpha SET_TO (side IS LEFT) ? (atan2((cy - py), (cx - px)) - theta) :
03131 (atan2((cy - py), (cx - px)) + theta);
03132 cx SET_TO (px + (radius * cos(alpha)));
03133 cy SET_TO (py + (radius * sin(alpha)));
03134 STRAIGHT_FEED (cx, cy, end_z);
03135 settings->current_x SET_TO cx;
03136 settings->current_y SET_TO cy;
03137 settings->program_x SET_TO px;
03138 settings->program_y SET_TO py;
03139 return RS274NGC_OK;
03140 }
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160
03161
03162
03163
03164
03165
03166
03167
03168
03169
03170
03171
03172
03173
03174
03175
03176
03177
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193 int convert_straight_comp2(
03194 setup_pointer settings,
03195 double program_end_x,
03196 double program_end_y,
03197 double end_z)
03198 {
03199 static char name[] SET_TO "convert_straight_comp2";
03200 double radius;
03201 double cx, cy;
03202 double dx, dy;
03203 double start_x, start_y;
03204 double theta;
03205 double alpha;
03206 double beta;
03207 double gamma;
03208
03209 double small SET_TO TOLERANCE_CONCAVE_CORNER;
03210 int side;
03211
03212 side SET_TO settings->cutter_radius_compensation;
03213 start_x SET_TO settings->program_x;
03214 start_y SET_TO settings->program_y;
03215 if ((start_x IS program_end_x) AND (start_y IS program_end_y))
03216 {
03217 STRAIGHT_FEED(settings->current_x, settings->current_y, end_z);
03218 return RS274NGC_OK;
03219 }
03220 radius SET_TO
03221 (settings->tool_table[settings->tool_table_index].diameter)/2.0;
03222 if (radius <= 0.0)
03223 ERROR_MACRO(_interpreter_linetext, name, "Bad tool radius value with cutter radius comp");
03224 theta SET_TO atan2(settings->current_y - start_y,
03225 settings->current_x - start_x);
03226 alpha SET_TO
03227 atan2(program_end_y - start_y, program_end_x - start_x);
03228
03229 if (side IS LEFT)
03230 {
03231 if (theta < alpha)
03232 theta SET_TO (theta + TWO_PI);
03233 beta SET_TO ((theta - alpha) - PI2);
03234 gamma SET_TO PI2;
03235 }
03236 else if (side IS RIGHT)
03237 {
03238 if (alpha < theta)
03239 alpha SET_TO (alpha + TWO_PI);
03240 beta SET_TO ((alpha - theta) - PI2);
03241 gamma SET_TO -PI2;
03242 }
03243 else
03244 BUG_MACRO(name,
03245 "Side fails to be right or left in convert_straight_comp2");
03246 cx SET_TO (program_end_x + (radius * cos(alpha + gamma)));
03247 cy SET_TO (program_end_y + (radius * sin(alpha + gamma)));
03248 dx SET_TO (start_x + (radius * cos(alpha + gamma)));
03249 dy SET_TO (start_y + (radius * sin(alpha + gamma)));
03250
03251 if ((beta < -small) OR (beta > (PI + small)))
03252 ERROR_MACRO(_interpreter_linetext, name, "Cannot have concave corner with cutter radius comp");
03253 else if (beta > small)
03254 {
03255 ARC_FEED(dx, dy, start_x, start_y, (side IS LEFT) ? -1 : 1, end_z);
03256 STRAIGHT_FEED (cx, cy, end_z);
03257 }
03258 else STRAIGHT_FEED (cx, cy, end_z);
03259
03260 settings->current_x SET_TO cx;
03261 settings->current_y SET_TO cy;
03262 settings->program_x SET_TO program_end_x;
03263 settings->program_y SET_TO program_end_y;
03264 return RS274NGC_OK;
03265 }
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290
03291 int read_integer_unsigned(
03292 char * line,
03293 int * counter,
03294 int * integer_ptr)
03295 {
03296 static char name[] SET_TO "read_integer_unsigned";
03297 int n;
03298 char c;
03299
03300 for (n SET_TO *counter; ; n++)
03301 {
03302 c SET_TO line[n];
03303 if ((c < 48) OR (c > 57))
03304 break;
03305 }
03306 if (n IS *counter)
03307 ERROR_MACRO(_interpreter_linetext, name, "Bad format unsigned integer");
03308 if (sscanf(line + *counter, "%d", integer_ptr) IS 0)
03309 BUG_MACRO(name, "Sscanf failure in read_integer_unsigned");
03310 else
03311 {
03312 *counter SET_TO n;
03313 return RS274NGC_OK;
03314 }
03315 }
03316
03317
03318
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350
03351
03352
03353
03354
03355
03356
03357 int read_real_value(
03358 char * line,
03359 int * counter,
03360 double * double_ptr,
03361 double * parameters)
03362 {
03363 static char name[] SET_TO "read_real_value";
03364 char c;
03365
03366 c SET_TO line[*counter];
03367 if (c IS 0)
03368 ERROR_MACRO(_interpreter_linetext, name, "No characters found in reading real value");
03369 else if (c IS '[')
03370 return read_real_expression (line, counter, double_ptr, parameters);
03371 else if (c IS '#')
03372 return read_parameter(line, counter, double_ptr, parameters);
03373 else if ((c >= 'a') AND (c <= 'z'))
03374 return read_unary(line, counter, double_ptr, parameters);
03375 else
03376 return read_real_number(line, counter, double_ptr);
03377 }
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396 int utility_find_ends(
03397 block_pointer block,
03398 setup_pointer settings,
03399 double * px,
03400 double * py,
03401 double * pz)
03402 {
03403 int mode;
03404 int middle;
03405 int comp;
03406
03407 mode SET_TO settings->distance_mode;
03408 middle SET_TO (settings->program_x ISNT UNKNOWN);
03409 comp SET_TO (settings->cutter_radius_compensation ISNT OFF);
03410
03411 if (block->g_modes[4] IS G_53)
03412 {
03413 #ifdef DEBUG_EMC
03414 COMMENT("interpreter: offsets temporarily suspended");
03415 #endif
03416 *px SET_TO (block->x_flag IS ON) ? (block->x_number -
03417 (settings->origin_offset_x + settings->axis_offset_x)) :
03418 settings->current_x;
03419 *py SET_TO (block->y_flag IS ON) ? (block->y_number -
03420 (settings->origin_offset_y + settings->axis_offset_y)) :
03421 settings->current_y;
03422 *pz SET_TO (block->z_flag IS ON) ? (block->z_number -
03423 (settings->tool_length_offset + settings->origin_offset_z
03424 + settings->axis_offset_z)) : settings->current_z;
03425 }
03426 else if (mode IS MODE_ABSOLUTE)
03427 {
03428 *px SET_TO (block->x_flag IS ON) ? block->x_number :
03429 (comp AND middle) ? settings->program_x :
03430 settings->current_x ;
03431
03432 *py SET_TO (block->y_flag IS ON) ? block->y_number :
03433 (comp AND middle) ? settings->program_y :
03434 settings->current_y ;
03435
03436 *pz SET_TO (block->z_flag IS ON) ? block->z_number :
03437 settings->current_z ;
03438 }
03439 else
03440 {
03441 *px SET_TO (block->x_flag IS ON)
03442 ? ((comp AND middle) ? (block->x_number + settings->program_x)
03443 : (block->x_number + settings->current_x))
03444 : ((comp AND middle) ? settings->program_x
03445 : settings->current_x);
03446
03447 *py SET_TO (block->y_flag IS ON)
03448 ? ((comp AND middle) ? (block->y_number + settings->program_y)
03449 : (block->y_number + settings->current_y))
03450 : ((comp AND middle) ? settings->program_y
03451 : settings->current_y);
03452
03453 *pz SET_TO (block->z_flag IS ON)
03454 ? (settings->current_z + block->z_number)
03455 : settings->current_z;
03456 }
03457
03458 return RS274NGC_OK;
03459 }
03460
03461
03462
03463
03464
03465
03466
03467
03468
03469
03470
03471
03472
03473
03474
03475
03476
03477
03478
03479
03480
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507
03508 int convert_arc(
03509 int move,
03510 block_pointer block,
03511 setup_pointer settings)
03512 {
03513 static char name[] SET_TO "convert_arc";
03514 int status;
03515 DISTANCE_MODE mode;
03516 int first;
03517 int ijk_flag;
03518 double end_x;
03519 double end_y;
03520 double end_z;
03521
03522 mode SET_TO settings->distance_mode;
03523 ijk_flag SET_TO
03524 ((block->i_flag OR block->j_flag) OR block->k_flag) ? ON : OFF;
03525 first SET_TO (settings->program_x IS UNKNOWN);
03526
03527 if ((block->r_flag ISNT ON) AND (ijk_flag ISNT ON))
03528 ERROR_MACRO(_interpreter_linetext, name, "R, I, J, and K words all missing for arc");
03529 else if ((block->r_flag IS ON) AND (ijk_flag IS ON))
03530 ERROR_MACRO(_interpreter_linetext, name, "Mixed radius-ijk format for arc");
03531 else if (settings->feed_rate IS 0.0)
03532 ERROR_MACRO(_interpreter_linetext, name, "Cannot make arc with zero feed rate");
03533 else if (ijk_flag)
03534 {
03535 if (settings->plane IS CANON_PLANE_XY)
03536 {
03537 if (block->k_flag)
03538 ERROR_MACRO(_interpreter_linetext, name, "K word given for arc in XY-plane");
03539 else if (block->i_flag IS OFF)
03540 block->i_number SET_TO 0.0;
03541 else if (block->j_flag IS OFF)
03542 block->j_number SET_TO 0.0;
03543 }
03544 else if (settings->plane IS CANON_PLANE_YZ)
03545 {
03546 if (block->i_flag)
03547 ERROR_MACRO(_interpreter_linetext, name, "I word given for arc in YZ-plane");
03548 else if (block->j_flag IS OFF)
03549 block->j_number SET_TO 0.0;
03550 else if (block->k_flag IS OFF)
03551 block->k_number SET_TO 0.0;
03552 }
03553 else if (settings->plane IS CANON_PLANE_XZ)
03554 {
03555 if (block->j_flag)
03556 ERROR_MACRO(_interpreter_linetext, name, "J word given for arc in XZ-plane");
03557 else if (block->i_flag IS OFF)
03558 block->i_number SET_TO 0.0;
03559 else if (block->k_flag IS OFF)
03560 block->k_number SET_TO 0.0;
03561 }
03562 else
03563 BUG_MACRO(name, "Plane is not XY, YZ, or XZ in convert_arc");
03564 }
03565 else;
03566
03567 if (settings->plane IS CANON_PLANE_XY)
03568 {
03569 if ((block->x_flag IS OFF) AND (block->y_flag IS OFF))
03570 ERROR_MACRO(_interpreter_linetext, name, "X and Y words missing for arc in XY-plane");
03571 }
03572 else if (settings->plane IS CANON_PLANE_YZ)
03573 {
03574 if ((block->y_flag IS OFF) AND (block->z_flag IS OFF))
03575 ERROR_MACRO(_interpreter_linetext, name, "Y and Z words missing for arc in YZ-plane");
03576 }
03577 else if (settings->plane IS CANON_PLANE_XZ)
03578 {
03579 if ((block->x_flag IS OFF) AND (block->z_flag IS OFF))
03580 ERROR_MACRO(_interpreter_linetext, name, "X and Z words missing for arc in XZ-plane");
03581 }
03582
03583 utility_find_ends(block, settings, &end_x, &end_y, &end_z);
03584
03585 settings->motion_mode SET_TO move;
03586
03587 if (settings->plane IS CANON_PLANE_XY)
03588 {
03589 if (settings->cutter_radius_compensation IS OFF)
03590 status SET_TO convert_arc_xy(move, block, settings, end_x, end_y,
03591 end_z);
03592 else if (settings->feed_mode IS INVERSE_TIME)
03593 ERROR_MACRO(_interpreter_linetext, name,
03594 "Cannot use inverse time feed with cutter radius comp");
03595 else if (first)
03596 status SET_TO convert_arc_comp1
03597 (move, block, settings, end_x, end_y, end_z);
03598 else
03599 status SET_TO convert_arc_comp2
03600 (move, block, settings, end_x, end_y, end_z);
03601 }
03602 else if (settings->plane IS CANON_PLANE_XZ)
03603 status SET_TO convert_arc_zx (move, block, settings, end_z, end_x, end_y);
03604 else if (settings->plane IS CANON_PLANE_YZ)
03605 status SET_TO convert_arc_yz (move, block, settings, end_y, end_z, end_x);
03606 else
03607 BUG_MACRO(name, "Plane is not XY, YZ, or XZ in convert_arc");
03608
03609 if (status ISNT RS274NGC_OK)
03610 ERROR_MACRO_PASS(name);
03611 else
03612 return RS274NGC_OK;
03613 }
03614
03615
03616
03617
03618
03619
03620
03621
03622
03623
03624
03625
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650
03651
03652
03653
03654
03655
03656
03657
03658
03659
03660
03661
03662
03663 int convert_axis_offsets(
03664 int g_code,
03665 block_pointer block,
03666 setup_pointer settings)
03667 {
03668 static char name[] SET_TO "convert_axis_offsets";
03669
03670 if (settings->cutter_radius_compensation ISNT OFF)
03671 ERROR_MACRO(_interpreter_linetext, name, "Cannot change axis offsets with cutter radius comp");
03672 else if (g_code IS G_92)
03673 {
03674 if (block->x_flag IS ON)
03675 {
03676 settings->axis_offset_x SET_TO
03677 (settings->current_x + settings->axis_offset_x - block->x_number);
03678 settings->current_x SET_TO block->x_number;
03679 }
03680
03681 if (block->y_flag IS ON)
03682 {
03683 settings->axis_offset_y SET_TO
03684 (settings->current_y + settings->axis_offset_y - block->y_number);
03685 settings->current_y SET_TO block->y_number;
03686 }
03687
03688 if (block->z_flag IS ON)
03689 {
03690 settings->axis_offset_z SET_TO
03691 (settings->current_z + settings->axis_offset_z - block->z_number);
03692 settings->current_z SET_TO block->z_number;
03693 }
03694
03695 SET_ORIGIN_OFFSETS(settings->origin_offset_x + settings->axis_offset_x,
03696 settings->origin_offset_y + settings->axis_offset_y,
03697 settings->origin_offset_z + settings->axis_offset_z);
03698
03699 settings->parameters[5211] SET_TO settings->axis_offset_x;
03700 settings->parameters[5212] SET_TO settings->axis_offset_y;
03701 settings->parameters[5213] SET_TO settings->axis_offset_z;
03702 }
03703 else if (g_code IS G_92_2)
03704 {
03705 settings->current_x SET_TO
03706 settings->current_x + settings->axis_offset_x;
03707 settings->current_y SET_TO
03708 settings->current_y + settings->axis_offset_y;
03709 settings->current_z SET_TO
03710 settings->current_z + settings->axis_offset_z;
03711 SET_ORIGIN_OFFSETS(settings->origin_offset_x,
03712 settings->origin_offset_y,
03713 settings->origin_offset_z);
03714 settings->axis_offset_x SET_TO 0.0;
03715 settings->axis_offset_y SET_TO 0.0;
03716 settings->axis_offset_z SET_TO 0.0;
03717
03718 settings->parameters[5211] SET_TO 0.0;
03719 settings->parameters[5212] SET_TO 0.0;
03720 settings->parameters[5213] SET_TO 0.0;
03721 }
03722 else
03723 BUG_MACRO(name, "Code is not G92 or G92.2 in convert_axis_offsets");
03724
03725 return RS274NGC_OK;
03726 }
03727
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737
03738
03739
03740
03741
03742
03743
03744
03745 int convert_cutter_compensation_off(
03746 setup_pointer settings)
03747 {
03748 #ifdef DEBUG_EMC
03749 COMMENT("interpreter: cutter radius compensation off");
03750 #endif
03751 settings->cutter_radius_compensation SET_TO OFF;
03752 settings->program_x SET_TO UNKNOWN;
03753 return RS274NGC_OK;
03754 }
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775
03776
03777
03778
03779
03780
03781
03782
03783
03784
03785 int convert_cutter_compensation_on(
03786 int side,
03787 block_pointer block,
03788 setup_pointer settings)
03789 {
03790 static char name[] SET_TO "convert_cutter_compensation_on";
03791
03792 if (settings->plane ISNT CANON_PLANE_XY)
03793 ERROR_MACRO(_interpreter_linetext, name, "Cannot turn cutter radius comp on out of XY-plane");
03794 if (block->d_number IS -1)
03795 ERROR_MACRO(_interpreter_linetext, name, "D word missing with cutter radius comp on");
03796 if (settings->cutter_radius_compensation ISNT OFF)
03797 ERROR_MACRO(_interpreter_linetext, name, "Cannot turn cutter radius comp on when already on");
03798
03799 #ifdef DEBUG_EMC
03800 if (side IS RIGHT)
03801 COMMENT("interpreter: cutter radius compensation on right");
03802 else
03803 COMMENT("interpreter: cutter radius compensation on left");
03804 #endif
03805
03806
03807 settings->tool_table_index SET_TO block->d_number;
03808 settings->cutter_radius_compensation SET_TO side;
03809 return RS274NGC_OK;
03810 }
03811
03812
03813
03814
03815
03816
03817
03818
03819
03820
03821
03822
03823
03824
03825
03826
03827
03828
03829
03830
03831
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845
03846
03847
03848
03849
03850
03851
03852
03853
03854
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864
03865
03866
03867
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877
03878
03879
03880
03881
03882
03883
03884
03885
03886
03887
03888
03889
03890
03891
03892
03893
03894
03895 #define CYCLE_MACRO(call) \
03896 for (repeat SET_TO block->l_number; \
03897 repeat > 0; \
03898 repeat--) \
03899 { \
03900 x SET_TO (x + x_increment); \
03901 y SET_TO (y + y_increment); \
03902 STRAIGHT_TRAVERSE(x, y, old_z); \
03903 if (old_z ISNT r) \
03904 STRAIGHT_TRAVERSE(x, y, r); \
03905 if (call IS RS274NGC_ERROR) \
03906 ERROR_MACRO_PASS(name); \
03907 old_z SET_TO clear_z; \
03908 }
03909
03910 int convert_cycle(
03911 int motion,
03912 block_pointer block,
03913 setup_pointer settings)
03914 {
03915 static char name[] SET_TO "convert_cycle";
03916 double x_increment;
03917 double y_increment;
03918 double i;
03919 double j;
03920 double k;
03921 double x;
03922 double y;
03923 double clear_z;
03924 double old_z;
03925 double z;
03926 double r;
03927 int repeat;
03928 CANON_MOTION_MODE save_mode;
03929
03930 if (settings->motion_mode ISNT motion)
03931 {
03932 if (block->r_flag IS OFF)
03933 ERROR_MACRO(_interpreter_linetext, name, "R clearance plane unspecified in canned cycle");
03934 if (block->z_flag IS OFF)
03935 ERROR_MACRO(_interpreter_linetext, name, "Z value unspecified in canned cycle");
03936 }
03937
03938 block->r_number SET_TO
03939 block->r_flag IS ON ? block->r_number : settings->cycle_r;
03940 block->z_number SET_TO
03941 block->z_flag IS ON ? block->z_number : settings->cycle_z;
03942 old_z SET_TO settings->current_z;
03943
03944 if (settings->distance_mode IS MODE_ABSOLUTE)
03945 {
03946 x_increment SET_TO 0.0;
03947 y_increment SET_TO 0.0;
03948 r SET_TO block->r_number;
03949 z SET_TO block->z_number;
03950 x SET_TO block->x_flag IS ON ? block->x_number : settings->current_x;
03951 y SET_TO block->y_flag IS ON ? block->y_number : settings->current_y;
03952 }
03953 else if (settings->distance_mode IS MODE_INCREMENTAL)
03954 {
03955 x_increment SET_TO block->x_number;
03956 y_increment SET_TO block->y_number;
03957 r SET_TO (block->r_number + old_z);
03958 z SET_TO (r + block->z_number);
03959 x SET_TO settings->current_x;
03960 y SET_TO settings->current_y;
03961 }
03962 else
03963 BUG_MACRO(name,
03964 "Distance mode is neither absolute nor incremental in convert_cycle");
03965
03966 if (r < z)
03967 ERROR_MACRO(_interpreter_linetext, name, "R value less than Z value in canned cycle");
03968
03969 if (block->l_number IS -1)
03970 block->l_number SET_TO 1;
03971 else if (block->l_number IS 0)
03972 ERROR_MACRO(_interpreter_linetext, name, "Cannot do zero repeats of cycle");
03973
03974 if (old_z < r)
03975 {
03976 STRAIGHT_TRAVERSE(settings->current_x, settings->current_y, r);
03977 old_z SET_TO r;
03978 }
03979 clear_z SET_TO (settings->retract_mode IS R_PLANE) ? r : old_z;
03980
03981 save_mode = GET_MOTION_CONTROL_MODE();
03982 if (save_mode ISNT CANON_EXACT_PATH)
03983 SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH);
03984
03985 switch(motion)
03986 {
03987 case G_81:
03988 CYCLE_MACRO(convert_cycle_g81(x, y, clear_z, z))
03989 break;
03990 case G_82:
03991 if ((settings->motion_mode ISNT G_82) AND (block->p_number IS -1.0))
03992 ERROR_MACRO(_interpreter_linetext, name, "P word (dwell time) missing with G82");
03993 block->p_number SET_TO
03994 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
03995 CYCLE_MACRO(convert_cycle_g82 (x, y, clear_z, z, block->p_number))
03996 settings->cycle_p SET_TO block->p_number;
03997 break;
03998 case G_83:
03999 if ((settings->motion_mode ISNT G_83) AND (block->q_number IS -1.0))
04000 ERROR_MACRO(_interpreter_linetext, name, "Q word (depth increment) missing with G83");
04001 block->q_number SET_TO
04002 block->q_number IS -1.0 ? settings->cycle_q : block->q_number;
04003 CYCLE_MACRO(convert_cycle_g83 (x, y, r, clear_z, z, block->q_number))
04004 settings->cycle_q SET_TO block->q_number;
04005 break;
04006 case G_84:
04007 CYCLE_MACRO(convert_cycle_g84 (x, y, clear_z, z,
04008 settings->spindle_turning, settings->speed_feed_mode))
04009 break;
04010 case G_85:
04011 CYCLE_MACRO(convert_cycle_g85 (x, y, clear_z, z))
04012 break;
04013 case G_86:
04014 if ((settings->motion_mode ISNT G_86) AND (block->p_number IS -1.0))
04015 ERROR_MACRO(_interpreter_linetext, name, "P word (dwell time) missing with G86");
04016 block->p_number SET_TO
04017 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04018 CYCLE_MACRO(convert_cycle_g86 (x, y, clear_z, z, block->p_number,
04019 settings->spindle_turning))
04020 settings->cycle_p SET_TO block->p_number;
04021 break;
04022 case G_87:
04023 if (settings->motion_mode ISNT G_87)
04024 {
04025 if (block->i_flag IS OFF)
04026 ERROR_MACRO(_interpreter_linetext, name, "I word missing with G87");
04027 if (block->j_flag IS OFF)
04028 ERROR_MACRO(_interpreter_linetext, name, "J word missing with G87");
04029 if (block->k_flag IS OFF)
04030 ERROR_MACRO(_interpreter_linetext, name, "K word missing with G87");
04031 }
04032 i SET_TO block->i_flag IS ON ? block->i_number : settings->cycle_i;
04033 j SET_TO block->j_flag IS ON ? block->j_number : settings->cycle_j;
04034 k SET_TO block->k_flag IS ON ? block->k_number : settings->cycle_k;
04035 settings->cycle_i SET_TO i;
04036 settings->cycle_j SET_TO j;
04037 settings->cycle_k SET_TO k;
04038 if (settings->distance_mode IS MODE_INCREMENTAL)
04039 {
04040 k SET_TO (z + k);
04041 }
04042 CYCLE_MACRO(convert_cycle_g87 (x, (x + i), y, (y + j), r, clear_z, k,
04043 z, settings->spindle_turning))
04044 break;
04045 case G_88:
04046 if ((settings->motion_mode ISNT G_88) AND (block->p_number IS -1.0))
04047 ERROR_MACRO(_interpreter_linetext, name, "P word (dwell time) missing with G88");
04048 block->p_number SET_TO
04049 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04050 CYCLE_MACRO(convert_cycle_g88 (x, y, z, block->p_number,
04051 settings->spindle_turning))
04052 settings->cycle_p SET_TO block->p_number;
04053 break;
04054 case G_89:
04055 if ((settings->motion_mode ISNT G_89) AND (block->p_number IS -1.0))
04056 ERROR_MACRO(_interpreter_linetext, name, "P word (dwell time) missing with G89");
04057 block->p_number SET_TO
04058 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04059 CYCLE_MACRO(convert_cycle_g89 (x, y, clear_z, z, block->p_number))
04060 settings->cycle_p SET_TO block->p_number;
04061 break;
04062 default:
04063 BUG_MACRO(name, "Convert_cycle should not have been called");
04064 }
04065 settings->current_x SET_TO x;
04066 settings->current_y SET_TO y;
04067 settings->current_z SET_TO clear_z;
04068 settings->cycle_l SET_TO block->l_number;
04069 settings->cycle_r SET_TO block->r_number;
04070 settings->cycle_z SET_TO block->z_number;
04071 settings->motion_mode SET_TO motion;
04072
04073 if (save_mode ISNT CANON_EXACT_PATH)
04074 SET_MOTION_CONTROL_MODE(save_mode);
04075
04076 return RS274NGC_OK;
04077 }
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091
04092
04093
04094
04095
04096
04097
04098
04099
04100
04101
04102
04103
04104
04105
04106
04107
04108
04109
04110
04111 int convert_probe(
04112 block_pointer block,
04113 setup_pointer settings)
04114 {
04115 static char name[] SET_TO "convert_probe";
04116 double end_x;
04117 double end_y;
04118 double end_z;
04119
04120 if (((block->x_flag IS OFF) AND (block->y_flag IS OFF)) AND
04121 (block->z_flag IS OFF))
04122 ERROR_MACRO(_interpreter_linetext, name, "X, Y, and Z words all missing with G38.2");
04123 utility_find_ends(block, settings, &end_x, &end_y, &end_z);
04124 TURN_PROBE_ON();
04125 STRAIGHT_PROBE (end_x, end_y, end_z);
04126 TURN_PROBE_OFF();
04127 settings->motion_mode SET_TO G_38_2;
04128 settings->probe_flag SET_TO ON;
04129 #ifdef STAND_ALONE_INTERP
04130 settings->current_x SET_TO ((0.9 * end_x) + (0.1 * settings->current_x));
04131 settings->current_y SET_TO ((0.9 * end_y) + (0.1 * settings->current_y));
04132 settings->current_z SET_TO ((0.9 * end_z) + (0.1 * settings->current_z));
04133 #endif
04134 return RS274NGC_OK;
04135 }
04136
04137
04138
04139
04140
04141
04142
04143
04144
04145
04146
04147
04148
04149
04150
04151
04152
04153
04154
04155
04156
04157
04158
04159
04160
04161
04162
04163 int convert_setup(
04164 block_pointer block,
04165 setup_pointer settings)
04166 {
04167 static char name[] SET_TO "convert_setup";
04168 double x;
04169 double y;
04170 double z;
04171 double * parameters;
04172 int p_int;
04173
04174 parameters SET_TO settings->parameters;
04175 p_int SET_TO (int)(block->p_number + 0.0001);
04176
04177 if (block->x_flag IS ON)
04178 {
04179 x SET_TO block->x_number;
04180 parameters[5201 + (p_int * 20)] SET_TO x;
04181 }
04182 else
04183 x SET_TO parameters[5201 + (p_int * 20)];
04184
04185 if (block->y_flag IS ON)
04186 {
04187 y SET_TO block->y_number;
04188 parameters[5202 + (p_int * 20)] SET_TO y;
04189 }
04190 else
04191 y SET_TO parameters[5202 + (p_int * 20)];
04192
04193 if (block->z_flag IS ON)
04194 {
04195 z SET_TO block->z_number;
04196 parameters[5203 + (p_int * 20)] SET_TO z;
04197 }
04198 else
04199 z SET_TO parameters[5203 + (p_int * 20)];
04200
04201
04202
04203 if (p_int IS settings->origin_ngc)
04204 {
04205 settings->current_x SET_TO
04206 (settings->current_x + settings->origin_offset_x);
04207 settings->current_y SET_TO
04208 (settings->current_y + settings->origin_offset_y);
04209 settings->current_z SET_TO
04210 (settings->current_z + settings->origin_offset_z);
04211
04212 settings->origin_offset_x SET_TO x;
04213 settings->origin_offset_y SET_TO y;
04214 settings->origin_offset_z SET_TO z;
04215
04216 SET_ORIGIN_OFFSETS(x + settings->axis_offset_x,
04217 y + settings->axis_offset_y,
04218 z + settings->axis_offset_z);
04219 settings->current_x SET_TO (settings->current_x - x);
04220 settings->current_y SET_TO (settings->current_y - y);
04221 settings->current_z SET_TO (settings->current_z - z);
04222 }
04223 #ifdef DEBUG_EMC
04224 else
04225 COMMENT("interpreter: setting coordinate system origin");
04226 #endif
04227 return RS274NGC_OK;
04228 }
04229
04230
04231
04232
04233
04234
04235
04236
04237
04238
04239
04240
04241
04242
04243
04244
04245
04246
04247
04248
04249
04250
04251
04252
04253
04254
04255
04256
04257
04258
04259
04260
04261
04262
04263
04264 int convert_straight(
04265 int move,
04266 block_pointer block,
04267 setup_pointer settings)
04268 {
04269 static char name[] SET_TO "convert_straight";
04270 double end_x = 0.0;
04271 double end_y = 0.0;
04272 double end_z = 0.0;
04273 double length;
04274 double rate;
04275
04276 if (((block->x_flag IS OFF) AND (block->y_flag IS OFF)) AND
04277 (block->z_flag IS OFF))
04278 ERROR_MACRO(_interpreter_linetext, name, "X, Y, and Z words all missing with G0 or G1");
04279
04280 settings->motion_mode SET_TO move;
04281 utility_find_ends(block, settings, &end_x, &end_y, &end_z);
04282
04283 if (move IS G_0)
04284 {
04285 if (settings->cutter_radius_compensation ISNT OFF)
04286 ERROR_MACRO(_interpreter_linetext, name, "Cannot use G0 with cutter radius comp");
04287 STRAIGHT_TRAVERSE(end_x, end_y, end_z);
04288 settings->current_x SET_TO end_x;
04289 settings->current_y SET_TO end_y;
04290 }
04291 else if (move IS G_1)
04292 {
04293 if (settings->cutter_radius_compensation ISNT OFF)
04294 {
04295 if (settings->feed_mode IS INVERSE_TIME)
04296 ERROR_MACRO(_interpreter_linetext, name,
04297 "Cannot use inverse time feed with cutter radius comp");
04298 else if (block->g_modes[4] IS G_53)
04299 ERROR_MACRO(_interpreter_linetext, name, "Cannot use G53 with cutter radius comp");
04300 else if (settings->feed_rate IS 0.0)
04301 ERROR_MACRO(_interpreter_linetext, name, "Cannot do G1 with zero feed rate");
04302 else if (settings->program_x IS UNKNOWN)
04303 {
04304 if (convert_straight_comp1(settings, end_x, end_y, end_z)
04305 IS RS274NGC_ERROR)
04306 ERROR_MACRO_PASS(name);
04307 }
04308 else
04309 {
04310 if (convert_straight_comp2(settings, end_x, end_y, end_z)
04311 IS RS274NGC_ERROR)
04312 ERROR_MACRO_PASS(name);
04313 }
04314 }
04315 else
04316 {
04317 if (settings->feed_mode IS INVERSE_TIME)
04318 {
04319 if (block->f_number IS -1.0)
04320 ERROR_MACRO(_interpreter_linetext, name,
04321 "F word missing with inverse time G1 move");
04322 else
04323 {
04324 length SET_TO utility_find_straight_length
04325 (end_x, end_y, end_z,
04326 settings->current_x, settings->current_y,
04327 settings->current_z);
04328 rate SET_TO MAX(0.1, (length * block->f_number));
04329 SET_FEED_RATE (rate);
04330 settings->feed_rate SET_TO rate;
04331 }
04332 }
04333 else if (settings->feed_rate IS 0.0)
04334 ERROR_MACRO(_interpreter_linetext, name, "Cannot do G1 with zero feed rate");
04335 STRAIGHT_FEED(end_x, end_y, end_z);
04336 settings->current_x SET_TO end_x;
04337 settings->current_y SET_TO end_y;
04338 }
04339 }
04340 else
04341 BUG_MACRO(name, "Code is not G0 or G1 in convert_straight");
04342
04343 settings->current_z SET_TO end_z;
04344 return RS274NGC_OK;
04345 }
04346
04347
04348
04349
04350
04351
04352
04353
04354
04355
04356
04357
04358
04359
04360
04361
04362
04363
04364
04365
04366
04367
04368
04369
04370
04371
04372
04373
04374
04375
04376
04377
04378
04379 int read_comment(
04380 char * line,
04381 int * counter,
04382 block_pointer block,
04383 double * parameters)
04384 {
04385 static char name[] SET_TO "read_comment";
04386 int n;
04387
04388 if (line[*counter] ISNT '(')
04389 BUG_MACRO(name, "Read_comment should not have been called");
04390
04391 (*counter)++;
04392 for (n SET_TO 0; line[*counter] ISNT ')' ; (*counter)++, n++)
04393 {
04394 block->comment[n] SET_TO line[*counter];
04395 }
04396 block->comment[n] SET_TO 0;
04397 (*counter)++;
04398 return RS274NGC_OK;
04399 }
04400
04401
04402
04403
04404
04405
04406
04407
04408
04409
04410
04411
04412
04413
04414
04415
04416
04417
04418
04419
04420
04421
04422
04423
04424
04425
04426
04427
04428
04429 int read_d(
04430 char * line,
04431 int * counter,
04432 block_pointer block,
04433 double * parameters)
04434 {
04435 static char name[] SET_TO "read_d";
04436 int value;
04437
04438 if (line[*counter] ISNT 'd')
04439 BUG_MACRO(name, "Read_d should not have been called");
04440
04441 *counter SET_TO (*counter + 1);
04442
04443 if (block->d_number > -1)
04444 ERROR_MACRO(_interpreter_linetext, name, "Multiple D words on one line");
04445 else if (read_integer_value(line, counter, &value, parameters)
04446 IS RS274NGC_ERROR)
04447 ERROR_MACRO_PASS(name);
04448 else if (value < 0)
04449 ERROR_MACRO(_interpreter_linetext, name, "Negative D code used");
04450 else
04451 {
04452 block->d_number SET_TO value;
04453 return RS274NGC_OK;
04454 }
04455 }
04456
04457
04458
04459
04460
04461
04462
04463
04464
04465
04466
04467
04468
04469
04470
04471
04472
04473
04474
04475
04476
04477
04478
04479
04480
04481
04482
04483
04484
04485
04486
04487 int read_f(
04488 char * line,
04489 int * counter,
04490 block_pointer block,
04491 double * parameters)
04492 {
04493 static char name[] SET_TO "read_f";
04494 double value;
04495
04496 if (line[*counter] ISNT 'f')
04497 BUG_MACRO(name, "Read_f should not have been called");
04498
04499 *counter SET_TO (*counter + 1);
04500
04501 if (block->f_number > -1.0)
04502 ERROR_MACRO(_interpreter_linetext, name, "Multiple F words on one line");
04503 else if (read_real_value(line, counter, &value, parameters)
04504 IS RS274NGC_ERROR)
04505 ERROR_MACRO_PASS(name);
04506 else if (value < 0.0)
04507 ERROR_MACRO(_interpreter_linetext, name, "Negative F word found");
04508 else
04509 {
04510 block->f_number SET_TO value;
04511 return RS274NGC_OK;
04512 }
04513 }
04514
04515
04516
04517
04518
04519
04520
04521
04522
04523
04524
04525
04526
04527
04528
04529
04530
04531
04532
04533
04534
04535
04536
04537
04538
04539
04540
04541
04542
04543
04544
04545
04546
04547
04548
04549
04550
04551
04552
04553
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563 int read_g(
04564 char * line,
04565 int * counter,
04566 block_pointer block,
04567 double * parameters)
04568 {
04569 static char name[] SET_TO "read_g";
04570 double value_read;
04571 int value;
04572 int mode;
04573
04574 if (line[*counter] ISNT 'g')
04575 BUG_MACRO(name, "Read_g should not have been called");
04576
04577 *counter SET_TO (*counter + 1);
04578 if (read_real_value(line, counter, &value_read, parameters)
04579 IS RS274NGC_ERROR)
04580 ERROR_MACRO_PASS(name);
04581 value_read SET_TO (10.0 * value_read);
04582 value SET_TO (int)floor(value_read);
04583
04584 if ((value_read - value) > 0.999)
04585 value SET_TO (int)ceil(value_read);
04586 else if ((value_read - value) > 0.001)
04587 ERROR_MACRO(_interpreter_linetext, name,"G code out of range");
04588
04589 if (value > 999)
04590 ERROR_MACRO(_interpreter_linetext, name, "G code out of range");
04591 else if (value < 0)
04592 ERROR_MACRO(_interpreter_linetext, name, "Negative G code used");
04593
04594 mode SET_TO gees[value];
04595
04596 if (mode IS -1)
04597 ERROR_MACRO(_interpreter_linetext, name, "Unknown G code used");
04598 else if (block->g_modes[mode] ISNT -1)
04599 ERROR_MACRO(_interpreter_linetext, name, "Two G codes used from same modal group");
04600 else
04601 {
04602 block->g_modes[mode] SET_TO value;
04603 block->g_count++;
04604 return RS274NGC_OK;
04605 }
04606 }
04607
04608
04609
04610
04611
04612
04613
04614
04615
04616
04617
04618
04619
04620
04621
04622
04623
04624
04625
04626
04627
04628
04629
04630
04631
04632
04633
04634
04635
04636
04637
04638
04639 int read_i(
04640 char * line,
04641 int * counter,
04642 block_pointer block,
04643 double * parameters)
04644 {
04645 static char name[] SET_TO "read_i";
04646 double value;
04647
04648 if (line[*counter] ISNT 'i')
04649 BUG_MACRO(name, "Read_i should not have been called");
04650
04651 *counter SET_TO (*counter + 1);
04652
04653 if (block->i_flag ISNT OFF)
04654 ERROR_MACRO(_interpreter_linetext, name, "Multiple I words on one line");
04655 else if (read_real_value(line, counter, &value, parameters)
04656 IS RS274NGC_ERROR)
04657 ERROR_MACRO_PASS(name);
04658 else
04659 {
04660 block->i_flag SET_TO ON;
04661 block->i_number SET_TO value;
04662 return RS274NGC_OK;
04663 }
04664 }
04665
04666
04667
04668
04669
04670
04671
04672
04673
04674
04675
04676
04677
04678
04679
04680
04681
04682
04683
04684
04685
04686
04687
04688
04689
04690
04691
04692
04693
04694
04695
04696
04697 int read_j(
04698 char * line,
04699 int * counter,
04700 block_pointer block,
04701 double * parameters)
04702 {
04703 static char name[] SET_TO "read_j";
04704 double value;
04705
04706 if (line[*counter] ISNT 'j')
04707 BUG_MACRO(name, "Read_j should not have been called");
04708
04709 *counter SET_TO (*counter + 1);
04710
04711 if (block->j_flag ISNT OFF)
04712 ERROR_MACRO(_interpreter_linetext, name, "Multiple J words on one line");
04713 else if (read_real_value(line, counter, &value, parameters)
04714 IS RS274NGC_ERROR)
04715 ERROR_MACRO_PASS(name);
04716 else
04717 {
04718 block->j_flag SET_TO ON;
04719 block->j_number SET_TO value;
04720 return RS274NGC_OK;
04721 }
04722 }
04723
04724
04725
04726
04727
04728
04729
04730
04731
04732
04733
04734
04735
04736
04737
04738
04739
04740
04741
04742
04743
04744
04745
04746
04747
04748
04749
04750
04751
04752
04753
04754
04755 int read_k(
04756 char * line,
04757 int * counter,
04758 block_pointer block,
04759 double * parameters)
04760 {
04761 static char name[] SET_TO "read_k";
04762 double value;
04763
04764 if (line[*counter] ISNT 'k')
04765 BUG_MACRO(name, "Read_k should not have been called");
04766
04767 *counter SET_TO (*counter + 1);
04768
04769 if (block->k_flag ISNT OFF)
04770 ERROR_MACRO(_interpreter_linetext, name, "Multiple K words on one line");
04771 else if (read_real_value(line, counter, &value, parameters)
04772 IS RS274NGC_ERROR)
04773 ERROR_MACRO_PASS(name);
04774 else
04775 {
04776 block->k_flag SET_TO ON;
04777 block->k_number SET_TO value;
04778 return RS274NGC_OK;
04779 }
04780 }
04781
04782
04783
04784
04785
04786
04787
04788
04789
04790
04791
04792
04793
04794
04795
04796
04797
04798
04799
04800
04801
04802
04803
04804
04805
04806
04807
04808
04809
04810
04811 int read_l(
04812 char * line,
04813 int * counter,
04814 block_pointer block,
04815 double * parameters)
04816 {
04817 static char name[] SET_TO "read_l";
04818 int value;
04819
04820 if (line[*counter] ISNT 'l')
04821 BUG_MACRO(name, "Read_l should not have been called");
04822
04823 *counter SET_TO (*counter + 1);
04824
04825 if (block->l_number > -1)
04826 ERROR_MACRO(_interpreter_linetext, name, "Multiple L words on one line");
04827 else if (read_integer_value(line, counter, &value, parameters)
04828 IS RS274NGC_ERROR)
04829 ERROR_MACRO_PASS(name);
04830 else if (value < 0)
04831 ERROR_MACRO(_interpreter_linetext, name, "Negative L word used");
04832 else
04833 {
04834 block->l_number SET_TO value;
04835 return RS274NGC_OK;
04836 }
04837 }
04838
04839
04840
04841
04842
04843
04844
04845
04846
04847
04848
04849
04850
04851
04852
04853
04854
04855
04856
04857
04858
04859
04860
04861
04862
04863
04864
04865
04866
04867
04868
04869
04870
04871 int read_m(
04872 char * line,
04873 int * counter,
04874 block_pointer block,
04875 double * parameters)
04876 {
04877 static char name[] SET_TO "read_m";
04878 int value;
04879 int mode;
04880
04881 if (line[*counter] ISNT 'm')
04882 BUG_MACRO(name, "Read_m should not have been called");
04883
04884 *counter SET_TO (*counter + 1);
04885
04886 if (read_integer_value(line, counter, &value, parameters) IS RS274NGC_ERROR)
04887 ERROR_MACRO_PASS(name);
04888 else if (value < 0)
04889 ERROR_MACRO(_interpreter_linetext, name, "Negative M code used");
04890 else if (value > 99)
04891 ERROR_MACRO(_interpreter_linetext, name, "M code greater than 99");
04892
04893 mode SET_TO ems[value];
04894
04895 if (mode IS -1)
04896 ERROR_MACRO(_interpreter_linetext, name, "Unknown M code used");
04897 else if (block->m_modes[mode] ISNT -1)
04898 ERROR_MACRO(_interpreter_linetext, name, "Two M codes used from same modal group");
04899 else
04900 {
04901 block->m_modes[mode] SET_TO value;
04902 block->m_count++;
04903 return RS274NGC_OK;
04904 }
04905 }
04906
04907
04908
04909
04910
04911
04912
04913
04914
04915
04916
04917
04918
04919
04920
04921
04922
04923
04924
04925
04926
04927
04928
04929
04930
04931
04932
04933
04934
04935
04936
04937
04938 int read_p(
04939 char * line,
04940 int * counter,
04941 block_pointer block,
04942 double * parameters)
04943 {
04944 static char name[] SET_TO "read_p";
04945 double value;
04946
04947 if (line[*counter] ISNT 'p')
04948 BUG_MACRO(name, "Read_p should not have been called");
04949
04950 *counter SET_TO (*counter + 1);
04951 if (block->p_number > -1.0)
04952 ERROR_MACRO(_interpreter_linetext, name, "Multiple P words on one line");
04953 else if (read_real_value(line, counter, &value, parameters)
04954 IS RS274NGC_ERROR)
04955 ERROR_MACRO_PASS(name);
04956 else if (value < 0.0)
04957 ERROR_MACRO(_interpreter_linetext, name, "Negative P value used");
04958 else
04959 {
04960 block->p_number SET_TO value;
04961 return RS274NGC_OK;
04962 }
04963 }
04964
04965
04966
04967
04968
04969
04970
04971
04972
04973
04974
04975
04976
04977
04978
04979
04980
04981
04982
04983
04984
04985
04986
04987
04988
04989
04990
04991
04992
04993
04994
04995
04996
04997
04998
04999
05000
05001
05002
05003
05004
05005
05006
05007
05008
05009
05010
05011
05012
05013
05014
05015 int read_parameter_setting(
05016 char * line,
05017 int * counter,
05018 block_pointer block,
05019 double * parameters)
05020 {
05021 static char name[] SET_TO "read_parameter_setting";
05022 int index;
05023 double value;
05024
05025 if (line[*counter] ISNT '#')
05026 BUG_MACRO(name, "Read_parameter_setting should not have been called");
05027 *counter SET_TO (*counter + 1);
05028 if (read_integer_value(line, counter, &index, parameters) IS RS274NGC_ERROR)
05029 ERROR_MACRO_PASS(name);
05030 else if ((index < 1) OR (index >= RS274NGC_MAX_PARAMETERS))
05031 ERROR_MACRO(_interpreter_linetext, name, "Parameter number out of range");
05032 else if (line[*counter] ISNT '=')
05033 ERROR_MACRO(_interpreter_linetext, name, "Equal sign missing in parameter setting");
05034 *counter SET_TO (*counter + 1);
05035 if (read_real_value(line, counter, &value, parameters) IS RS274NGC_ERROR)
05036 ERROR_MACRO_PASS(name);
05037 else
05038 {
05039 parameters[index] SET_TO value;
05040 return RS274NGC_OK;
05041 }
05042 }
05043
05044
05045
05046
05047
05048
05049
05050
05051
05052
05053
05054
05055
05056
05057
05058
05059
05060
05061
05062
05063
05064
05065
05066
05067
05068
05069
05070
05071
05072 int read_q(
05073 char * line,
05074 int * counter,
05075 block_pointer block,
05076 double * parameters)
05077 {
05078 static char name[] SET_TO "read_q";
05079 double value;
05080
05081 if (line[*counter] ISNT 'q')
05082 BUG_MACRO(name, "Read_q should not have been called");
05083
05084 *counter SET_TO (*counter + 1);
05085 if (block->q_number > -1.0)
05086 ERROR_MACRO(_interpreter_linetext, name, "Multiple Q words on one line");
05087 else if (read_real_value(line, counter, &value, parameters)
05088 IS RS274NGC_ERROR)
05089 ERROR_MACRO_PASS(name);
05090 else if (value < 0.0)
05091 ERROR_MACRO(_interpreter_linetext, name, "Negative Q value used");
05092 else
05093 {
05094 block->q_number SET_TO value;
05095 return RS274NGC_OK;
05096 }
05097 }
05098
05099
05100
05101
05102
05103
05104
05105
05106
05107
05108
05109
05110
05111
05112
05113
05114
05115
05116
05117
05118
05119
05120
05121
05122
05123
05124
05125
05126
05127
05128
05129
05130 int read_r(
05131 char * line,
05132 int * counter,
05133 block_pointer block,
05134 double * parameters)
05135 {
05136 static char name[] SET_TO "read_r";
05137 double value;
05138
05139 if (line[*counter] ISNT 'r')
05140 BUG_MACRO(name, "Read_r should not have been called");
05141
05142 *counter SET_TO (*counter + 1);
05143
05144 if (block->r_flag ISNT OFF)
05145 ERROR_MACRO(_interpreter_linetext, name, "Multiple R words on one line");
05146 else if (read_real_value(line, counter, &value, parameters)
05147 IS RS274NGC_ERROR)
05148 ERROR_MACRO_PASS(name);
05149 else
05150 {
05151 block->r_flag SET_TO ON;
05152 block->r_number SET_TO value;
05153 return RS274NGC_OK;
05154 }
05155 }
05156
05157
05158
05159
05160
05161
05162
05163
05164
05165
05166
05167
05168
05169
05170
05171
05172
05173
05174
05175
05176
05177
05178
05179
05180
05181
05182
05183
05184
05185
05186 int read_spindle_speed(
05187 char * line,
05188 int * counter,
05189 block_pointer block,
05190 double * parameters)
05191 {
05192 static char name[] SET_TO "read_spindle_speed";
05193 double speed;
05194
05195 if (line[*counter] ISNT 's')
05196 BUG_MACRO(name, "Read_spindle_speed should not have been called");
05197
05198 *counter SET_TO (*counter + 1);
05199
05200 if (block->s_number > -1.0)
05201 ERROR_MACRO(_interpreter_linetext, name, "Multiple S word spindle speed settings on one line");
05202 else if (read_real_value(line, counter, &speed, parameters)
05203 IS RS274NGC_ERROR)
05204 ERROR_MACRO_PASS(name);
05205 else if (speed < 0.0)
05206 ERROR_MACRO(_interpreter_linetext, name, "Negative spindle speed found");
05207 else
05208 {
05209 block->s_number SET_TO speed;
05210 return RS274NGC_OK;
05211 }
05212 }
05213
05214
05215
05216
05217
05218
05219
05220
05221
05222
05223
05224
05225
05226
05227
05228
05229
05230
05231
05232
05233
05234
05235
05236
05237
05238
05239 int read_tool(
05240 char * line,
05241 int * counter,
05242 block_pointer block,
05243 double * parameters)
05244 {
05245 static char name[] SET_TO "read_tool";
05246 int value;
05247
05248 if (line[*counter] ISNT 't')
05249 BUG_MACRO(name, "Read_tool should not have been called");
05250
05251 *counter SET_TO (*counter + 1);
05252 if (block->t_number > -1)
05253 ERROR_MACRO(_interpreter_linetext, name, "Multiple T words (tool ids) on one line");
05254 if (read_integer_value(line, counter, &value, parameters) IS RS274NGC_ERROR)
05255 ERROR_MACRO_PASS(name);
05256 else if (value < 0)
05257 ERROR_MACRO(_interpreter_linetext, name, "Negative tool id used");
05258 else
05259 {
05260 block->t_number SET_TO value;
05261 return RS274NGC_OK;
05262 }
05263 }
05264
05265
05266
05267
05268
05269
05270
05271
05272
05273
05274
05275
05276
05277
05278
05279
05280
05281
05282
05283
05284
05285
05286
05287
05288
05289
05290
05291
05292 int read_tool_length_offset(
05293 char * line,
05294 int * counter,
05295 block_pointer block,
05296 double * parameters)
05297 {
05298 static char name[] SET_TO "read_tool_length_offset";
05299 int value;
05300
05301 if (line[*counter] ISNT 'h')
05302 BUG_MACRO(name, "Read_tool_length_offset should not have been called");
05303
05304 *counter SET_TO (*counter + 1);
05305 if (block->h_number > -1)
05306 ERROR_MACRO(_interpreter_linetext, name, "Multiple tool length offsets on one line");
05307 if (read_integer_value(line, counter, &value, parameters) IS RS274NGC_ERROR)
05308 ERROR_MACRO_PASS(name);
05309 else if (value < 0)
05310 ERROR_MACRO(_interpreter_linetext, name, "Negative tool length offset used");
05311 else
05312 {
05313 block->h_number SET_TO value;
05314 return RS274NGC_OK;
05315 }
05316 }
05317
05318
05319
05320
05321
05322
05323
05324
05325
05326
05327
05328
05329
05330
05331
05332
05333
05334
05335
05336
05337
05338
05339
05340
05341
05342
05343
05344
05345
05346
05347
05348
05349 int read_x(
05350 char * line,
05351 int * counter,
05352 block_pointer block,
05353 double * parameters)
05354 {
05355 static char name[] SET_TO "read_x";
05356 double value;
05357
05358 if (line[*counter] ISNT 'x')
05359 BUG_MACRO(name, "Read_x should not have been called");
05360
05361 *counter SET_TO (*counter + 1);
05362
05363 if (block->x_flag ISNT OFF)
05364 ERROR_MACRO(_interpreter_linetext, name, "Multiple X words on one line");
05365 else if (read_real_value(line, counter, &value, parameters)
05366 IS RS274NGC_ERROR)
05367 ERROR_MACRO_PASS(name);
05368 else
05369 {
05370 block->x_flag SET_TO ON;
05371 block->x_number SET_TO value;
05372 return RS274NGC_OK;
05373 }
05374 }
05375
05376
05377
05378
05379
05380
05381
05382
05383
05384
05385
05386
05387
05388
05389
05390
05391
05392
05393
05394
05395
05396
05397
05398
05399
05400
05401
05402
05403
05404
05405
05406
05407 int read_y(
05408 char * line,
05409 int * counter,
05410 block_pointer block,
05411 double * parameters)
05412 {
05413 static char name[] SET_TO "read_y";
05414 double value;
05415
05416 if (line[*counter] ISNT 'y')
05417 BUG_MACRO(name, "Read_y should not have been called");
05418
05419 *counter SET_TO (*counter + 1);
05420
05421 if (block->y_flag ISNT OFF)
05422 ERROR_MACRO(_interpreter_linetext, name, "Multiple Y words on one line");
05423 else if (read_real_value(line, counter, &value, parameters)
05424 IS RS274NGC_ERROR)
05425 ERROR_MACRO_PASS(name);
05426 else
05427 {
05428 block->y_flag SET_TO ON;
05429 block->y_number SET_TO value;
05430 return RS274NGC_OK;
05431 }
05432 }
05433
05434
05435
05436
05437
05438
05439
05440
05441
05442
05443
05444
05445
05446
05447
05448
05449
05450
05451
05452
05453
05454
05455
05456
05457
05458
05459
05460
05461
05462
05463
05464
05465 int read_z(
05466 char * line,
05467 int * counter,
05468 block_pointer block,
05469 double * parameters)
05470 {
05471 static char name[] SET_TO "read_z";
05472 double value;
05473
05474 if (line[*counter] ISNT 'z')
05475 BUG_MACRO(name, "Read_z should not have been called");
05476
05477 *counter SET_TO (*counter + 1);
05478
05479 if (block->z_flag ISNT OFF)
05480 ERROR_MACRO(_interpreter_linetext, name, "Multiple Z words on one line");
05481 else if (read_real_value(line, counter, &value, parameters)
05482 IS RS274NGC_ERROR)
05483 ERROR_MACRO_PASS(name);
05484 else
05485 {
05486 block->z_flag SET_TO ON;
05487 block->z_number SET_TO value;
05488 return RS274NGC_OK;
05489 }
05490 }
05491
05492
05493
05494
05495
05496
05497
05498
05499
05500
05501
05502
05503
05504
05505
05506
05507
05508
05509
05510
05511
05512
05513
05514
05515
05516
05517
05518
05519
05520
05521
05522
05523
05524
05525
05526
05527
05528
05529
05530
05531
05532
05533
05534
05535
05536
05537
05538
05539
05540
05541 int check_g_codes(
05542 block_pointer block,
05543 setup_pointer settings)
05544 {
05545 static char name[] SET_TO "check_g_codes";
05546 ON_OFF axis_flag;
05547 int explicit_motion;
05548 int mode0;
05549 int p_int;
05550
05551 axis_flag SET_TO
05552 ((block->x_flag) OR (block->y_flag) OR (block->z_flag)) ? ON : OFF;
05553 explicit_motion SET_TO block->g_modes[1];
05554 mode0 SET_TO block->g_modes[0];
05555
05556 if(block->g_count > MAX_GEES)
05557 ERROR_MACRO(_interpreter_linetext, name, "Too many G codes on line");
05558
05559 if (mode0 IS -1)
05560 {
05561 if (block->g_modes[4] IS -1)
05562 {
05563 if ((block->motion_to_be IS G_80) AND (axis_flag IS ON))
05564 ERROR_MACRO(_interpreter_linetext, name, "Cannot use axis commands with G80");
05565 }
05566 else if (block->g_modes[4] IS G_4)
05567 {
05568 if (((block->motion_to_be IS -1) OR
05569 (block->motion_to_be IS G_80)) AND
05570 (axis_flag IS ON))
05571 ERROR_MACRO(_interpreter_linetext, name, "Cannot use axis commands with G4");
05572 if(block->p_number IS -1.0)
05573 ERROR_MACRO(_interpreter_linetext, name, "Dwell time missing with G4");
05574 }
05575 else if (block->g_modes[4] IS G_53)
05576 {
05577 if ((block->motion_to_be ISNT G_0) AND
05578 (block->motion_to_be ISNT G_1))
05579 ERROR_MACRO(_interpreter_linetext, name, "Must use G0 or G1 with G53");
05580 if((block->g_modes[3] IS G_91) OR
05581 ((block->g_modes[3] ISNT G_90) AND
05582 (settings->distance_mode IS MODE_INCREMENTAL)))
05583 ERROR_MACRO(_interpreter_linetext, name, "Cannot use G53 in incremental distance mode");
05584 }
05585 else
05586 BUG_MACRO(name, "Bad setting of g_mode in check_g_codes");
05587 }
05588 else if (block->g_modes[4] ISNT -1)
05589 ERROR_MACRO(_interpreter_linetext, name, "Cannot use two G codes from group 0");
05590 else if (mode0 IS G_10)
05591 {
05592 p_int SET_TO (int)(block->p_number + 0.0001);
05593 if ((explicit_motion ISNT -1) AND (explicit_motion ISNT G_80))
05594 ERROR_MACRO(_interpreter_linetext, name, "Cannot use a G code for motion with G10");
05595 if (block->l_number ISNT 2)
05596 ERROR_MACRO(_interpreter_linetext, name, "Line with G10 does not have L2");
05597 if (((block->p_number + 0.0001) - p_int) > 0.0002)
05598 ERROR_MACRO(_interpreter_linetext, name, "P value not an integer with G10 L2");
05599 if ((p_int < 1) OR (p_int > 9))
05600 ERROR_MACRO(_interpreter_linetext, name, "P value out of range with G10 L2");
05601 }
05602 else if (mode0 IS G_92)
05603 {
05604 if ((explicit_motion ISNT -1) AND (explicit_motion ISNT G_80))
05605 ERROR_MACRO(_interpreter_linetext, name, "Cannot use a G motion with G92");
05606 if (axis_flag IS OFF)
05607 ERROR_MACRO(_interpreter_linetext, name, "All axes missing with G92");
05608 }
05609 else if (mode0 IS G_92_2)
05610 {}
05611 else
05612 BUG_MACRO(name, "Bad setting of g_mode in check_g_codes");
05613
05614 return RS274NGC_OK;
05615 }
05616
05617
05618
05619
05620
05621
05622
05623
05624
05625
05626
05627
05628
05629
05630
05631
05632
05633
05634
05635
05636
05637 int check_m_codes(
05638 block_pointer block,
05639 setup_pointer settings)
05640 {
05641 static char name[] SET_TO "check_m_codes";
05642
05643 if(block->m_count > MAX_EMS)
05644 ERROR_MACRO(_interpreter_linetext, name, "Too many M codes on line");
05645
05646 return RS274NGC_OK;
05647 }
05648
05649
05650
05651
05652
05653
05654
05655
05656
05657
05658
05659
05660
05661
05662
05663
05664
05665
05666
05667
05668
05669
05670
05671
05672
05673
05674
05675
05676
05677
05678 int check_other_codes(
05679 block_pointer block,
05680 setup_pointer settings)
05681 {
05682 static char name[] SET_TO "check_other_codes";
05683 int motion;
05684
05685 motion SET_TO block->motion_to_be;
05686 if (block->d_number ISNT -1)
05687 {
05688 if ((block->g_modes[7] ISNT G_41) AND (block->g_modes[7] ISNT G_42))
05689 ERROR_MACRO(_interpreter_linetext, name,
05690 "D word on line with no cutter comp on (G41 or G42) command");
05691 }
05692 if (block->h_number ISNT -1)
05693 {
05694 if (block->g_modes[8] ISNT G_43)
05695 ERROR_MACRO(_interpreter_linetext, name,
05696 "H word on line with no tool length comp (G43) command");
05697 }
05698
05699 if (block->i_flag IS ON)
05700 {
05701 if (((motion ISNT G_2) AND (motion ISNT G_3)) AND (motion ISNT G_87))
05702 ERROR_MACRO(_interpreter_linetext, name,
05703 "I word on line with no G code (G2, G3, G87) that uses it");
05704 }
05705
05706
05707 if (block->j_flag IS ON)
05708 {
05709 if (((motion ISNT G_2) AND (motion ISNT G_3)) AND (motion ISNT G_87))
05710 ERROR_MACRO(_interpreter_linetext, name,
05711 "J word on line with no G code (G2, G3, G87) that uses it");
05712 }
05713
05714 if (block->k_flag IS ON)
05715 {
05716 if (((motion ISNT G_2) AND (motion ISNT G_3)) AND (motion ISNT G_87))
05717 ERROR_MACRO(_interpreter_linetext, name,
05718 "K word on line with no G code (G2, G3, G87) that uses it");
05719 }
05720
05721 if (block->l_number ISNT -1)
05722 {
05723 if (((motion < G_81) OR (motion > G_89)) AND
05724 (block->g_modes[0] ISNT G_10))
05725 ERROR_MACRO(_interpreter_linetext, name,
05726 "L word on line with no canned cycle or G10 to use it");
05727 }
05728
05729 if (block->p_number ISNT -1.0)
05730 {
05731 if (((block->g_modes[0] ISNT G_10) AND
05732 (block->g_modes[4] ISNT G_4)) AND
05733 (((motion ISNT G_82) AND (motion ISNT G_86)) AND
05734 ((motion ISNT G_88) AND (motion ISNT G_89))))
05735 ERROR_MACRO(_interpreter_linetext, name,
05736 "P word on line with no G code (G4 G10 G82 G86 G88 G89) that uses it");
05737 }
05738
05739 if (block->q_number ISNT -1.0)
05740 {
05741 if (motion ISNT G_83)
05742 ERROR_MACRO(_interpreter_linetext, name, "Q word on line with no G83 cycle that uses it");
05743 }
05744
05745 if (block->r_flag IS ON)
05746 {
05747 if (((motion ISNT G_2) AND (motion ISNT G_3)) AND
05748 ((motion < G_81) OR (motion > G_89)))
05749 ERROR_MACRO(_interpreter_linetext, name,
05750 "R word on line with no G code (arc or cycle) that uses it");
05751 }
05752
05753 return RS274NGC_OK;
05754 }
05755
05756
05757
05758
05759
05760
05761
05762
05763
05764
05765
05766
05767
05768
05769
05770
05771
05772
05773
05774
05775
05776
05777
05778
05779
05780
05781
05782
05783
05784
05785 int convert_control_mode(
05786 int g_code,
05787 block_pointer block,
05788 setup_pointer settings)
05789 {
05790 static char name[] SET_TO "convert_control_mode";
05791 if (g_code IS G_61)
05792 {
05793 SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH);
05794 settings->control_mode SET_TO CANON_EXACT_PATH;
05795 }
05796 else if (g_code IS G_64)
05797 {
05798 SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS);
05799 settings->control_mode SET_TO CANON_CONTINUOUS;
05800 }
05801 else
05802 BUG_MACRO(name, "Code is not G61 or G64 in convert_control_mode");
05803 return RS274NGC_OK;
05804 }
05805
05806
05807
05808
05809
05810
05811
05812
05813
05814
05815
05816
05817
05818
05819
05820
05821
05822
05823
05824
05825
05826
05827
05828
05829
05830
05831
05832
05833
05834
05835
05836
05837
05838
05839
05840
05841
05842
05843
05844
05845
05846
05847
05848
05849
05850
05851
05852
05853
05854
05855
05856
05857
05858
05859
05860
05861
05862
05863
05864
05865
05866
05867
05868
05869
05870
05871
05872
05873
05874
05875
05876
05877 int convert_coordinate_system(
05878 int g_code,
05879 block_pointer block,
05880 setup_pointer settings)
05881 {
05882 static char name[] SET_TO "convert_coordinate_system";
05883 int origin;
05884 double x;
05885 double y;
05886 double z;
05887 double * parameters;
05888
05889 parameters SET_TO settings->parameters;
05890 switch(g_code)
05891 {
05892 case 540:
05893 origin SET_TO 1;
05894 break;
05895 case 550:
05896 origin SET_TO 2;
05897 break;
05898 case 560:
05899 origin SET_TO 3;
05900 break;
05901 case 570:
05902 origin SET_TO 4;
05903 break;
05904 case 580:
05905 origin SET_TO 5;
05906 break;
05907 case 590:
05908 origin SET_TO 6;
05909 break;
05910 case 591:
05911 origin SET_TO 7;
05912 break;
05913 case 592:
05914 origin SET_TO 8;
05915 break;
05916 case 593:
05917 origin SET_TO 9;
05918 break;
05919 default:
05920 BUG_MACRO(name, "Code is not G54 to G59.3 in convert_coordinate_system");
05921 }
05922
05923 if (origin IS settings->origin_ngc)
05924 {
05925 #ifdef DEBUG_EMC
05926 COMMENT("interpreter: continuing to use same coordinate system");
05927 #endif
05928 return RS274NGC_OK;
05929 }
05930
05931
05932
05933 settings->current_x SET_TO
05934 (settings->current_x + settings->origin_offset_x);
05935 settings->current_y SET_TO
05936 (settings->current_y + settings->origin_offset_y);
05937 settings->current_z SET_TO
05938 (settings->current_z + settings->origin_offset_z);
05939
05940 x SET_TO parameters[5201 + (origin * 20)];
05941 y SET_TO parameters[5202 + (origin * 20)];
05942 z SET_TO parameters[5203 + (origin * 20)];
05943
05944 settings->origin_offset_x SET_TO x;
05945 settings->origin_offset_y SET_TO y;
05946 settings->origin_offset_z SET_TO z;
05947
05948 settings->current_x SET_TO (settings->current_x - x);
05949 settings->current_y SET_TO (settings->current_y - y);
05950 settings->current_z SET_TO (settings->current_z - z);
05951 settings->origin_ngc SET_TO origin;
05952
05953 SET_ORIGIN_OFFSETS(x + settings->axis_offset_x,
05954 y + settings->axis_offset_y,
05955 z + settings->axis_offset_z);
05956
05957 return RS274NGC_OK;
05958 }
05959
05960
05961
05962
05963
05964
05965
05966
05967
05968
05969
05970
05971
05972
05973
05974
05975
05976
05977
05978
05979
05980
05981
05982
05983 int convert_cutter_compensation(
05984 int g_code,
05985 block_pointer block,
05986 setup_pointer settings)
05987 {
05988 static char name[] SET_TO "convert_cutter_compensation";
05989 if (g_code IS G_40)
05990 {
05991 if (convert_cutter_compensation_off(settings) IS RS274NGC_ERROR)
05992 ERROR_MACRO_PASS(name);
05993 }
05994 else if (g_code IS G_41)
05995 {
05996 if (convert_cutter_compensation_on(LEFT, block, settings)
05997 IS RS274NGC_ERROR)
05998 ERROR_MACRO_PASS(name);
05999 }
06000 else if (g_code IS G_42)
06001 {
06002 if (convert_cutter_compensation_on(RIGHT, block, settings)
06003 IS RS274NGC_ERROR)
06004 ERROR_MACRO_PASS(name);
06005 }
06006 else
06007 BUG_MACRO(name,
06008 "Code is not G40, G41, or G42 in convert_cutter_compensation");
06009
06010 return RS274NGC_OK;
06011 }
06012
06013
06014
06015
06016
06017
06018
06019
06020
06021
06022
06023
06024
06025
06026
06027
06028
06029
06030
06031
06032 int convert_distance_mode(
06033 int g_code,
06034 block_pointer block,
06035 setup_pointer settings)
06036 {
06037 static char name[] SET_TO "convert_distance_mode";
06038 if (g_code IS G_90)
06039 {
06040 if (settings->distance_mode ISNT MODE_ABSOLUTE)
06041 {
06042 #ifdef DEBUG_EMC
06043 COMMENT("interpreter: distance mode changed to absolute");
06044 #endif
06045 settings->distance_mode SET_TO MODE_ABSOLUTE;
06046 }
06047 }
06048 else if (g_code IS G_91)
06049 {
06050 if (settings->distance_mode ISNT MODE_INCREMENTAL)
06051 {
06052 #ifdef DEBUG_EMC
06053 COMMENT("interpreter: distance mode changed to incremental");
06054 #endif
06055 settings->distance_mode SET_TO MODE_INCREMENTAL;
06056 }
06057 }
06058 else
06059 BUG_MACRO(name, "Code is not G90 or G91 in convert_distance_mode");
06060 return RS274NGC_OK;
06061 }
06062
06063
06064
06065
06066
06067
06068
06069
06070
06071
06072
06073
06074
06075
06076 int convert_dwell(
06077 double time)
06078 {
06079 DWELL(time);
06080 return RS274NGC_OK;
06081 }
06082
06083
06084
06085
06086
06087
06088
06089
06090
06091
06092
06093
06094
06095
06096
06097
06098
06099
06100
06101
06102
06103
06104
06105
06106
06107
06108
06109
06110
06111
06112
06113
06114
06115
06116
06117
06118
06119
06120
06121
06122
06123
06124 int convert_length_units(
06125 int g_code,
06126 setup_pointer settings)
06127 {
06128 static char name[] SET_TO "convert_length_units";
06129 if (settings->cutter_radius_compensation ISNT OFF)
06130 ERROR_MACRO(_interpreter_linetext, name, "Cannot change units with cutter radius comp");
06131 else if (g_code IS G_20)
06132 {
06133 USE_LENGTH_UNITS(CANON_UNITS_INCHES);
06134 if (settings->length_units ISNT CANON_UNITS_INCHES)
06135 {
06136 settings->length_units SET_TO CANON_UNITS_INCHES;
06137 settings->current_x SET_TO (settings->current_x * INCH_PER_MM);
06138 settings->current_y SET_TO (settings->current_y * INCH_PER_MM);
06139 settings->current_z SET_TO (settings->current_z * INCH_PER_MM);
06140 settings->axis_offset_x SET_TO
06141 (settings->axis_offset_x * INCH_PER_MM);
06142 settings->axis_offset_y SET_TO
06143 (settings->axis_offset_y * INCH_PER_MM);
06144 settings->axis_offset_z SET_TO
06145 (settings->axis_offset_z * INCH_PER_MM);
06146 settings->origin_offset_x SET_TO
06147 (settings->origin_offset_x * INCH_PER_MM);
06148 settings->origin_offset_y SET_TO
06149 (settings->origin_offset_y * INCH_PER_MM);
06150 settings->origin_offset_z SET_TO
06151 (settings->origin_offset_z * INCH_PER_MM);
06152 }
06153 }
06154 else if (g_code IS G_21)
06155 {
06156 USE_LENGTH_UNITS(CANON_UNITS_MM);
06157 if (settings->length_units ISNT CANON_UNITS_MM)
06158 {
06159 settings->length_units SET_TO CANON_UNITS_MM;
06160 settings->current_x SET_TO (settings->current_x * MM_PER_INCH);
06161 settings->current_y SET_TO (settings->current_y * MM_PER_INCH);
06162 settings->current_z SET_TO (settings->current_z * MM_PER_INCH);
06163 settings->axis_offset_x SET_TO
06164 (settings->axis_offset_x * MM_PER_INCH);
06165 settings->axis_offset_y SET_TO
06166 (settings->axis_offset_y * MM_PER_INCH);
06167 settings->axis_offset_z SET_TO
06168 (settings->axis_offset_z * MM_PER_INCH);
06169 settings->origin_offset_x SET_TO
06170 (settings->origin_offset_x * MM_PER_INCH);
06171 settings->origin_offset_y SET_TO
06172 (settings->origin_offset_y * MM_PER_INCH);
06173 settings->origin_offset_z SET_TO
06174 (settings->origin_offset_z * MM_PER_INCH);
06175 }
06176 }
06177 else
06178 BUG_MACRO(name, "Code is not G20 or G21 in convert_length_units");
06179 return RS274NGC_OK;
06180 }
06181
06182
06183
06184
06185
06186
06187
06188
06189
06190
06191
06192
06193
06194
06195
06196
06197
06198
06199
06200
06201 int convert_modal_0(
06202 int code,
06203 block_pointer block,
06204 setup_pointer settings)
06205 {
06206 static char name[] SET_TO "convert_modal_0";
06207
06208 if (code IS G_10)
06209 {
06210 if (convert_setup(block, settings) IS RS274NGC_ERROR)
06211 ERROR_MACRO_PASS(name);
06212 }
06213 else if ((code IS G_92) OR (code IS G_92_2))
06214 {
06215 if (convert_axis_offsets(code, block, settings) IS RS274NGC_ERROR)
06216 ERROR_MACRO_PASS(name);
06217 }
06218 else
06219 BUG_MACRO(name, "Code is not G10, G92, or G92.2 in convert_modal_0");
06220 return RS274NGC_OK;
06221 }
06222
06223
06224
06225
06226
06227
06228
06229
06230
06231
06232
06233
06234
06235
06236
06237
06238
06239
06240
06241
06242
06243
06244
06245
06246
06247
06248
06249
06250
06251
06252 int convert_motion(
06253 int motion,
06254 block_pointer block,
06255 setup_pointer settings)
06256 {
06257 static char name[] SET_TO "convert_motion";
06258
06259 if ((motion IS G_0) OR (motion IS G_1))
06260 {
06261 if (convert_straight (motion, block, settings) IS RS274NGC_ERROR)
06262 ERROR_MACRO_PASS(name);
06263 }
06264 else if ((motion IS G_3) OR (motion IS G_2))
06265 {
06266 if ((settings->feed_mode IS INVERSE_TIME) AND
06267 (block->f_number IS -1.0))
06268 ERROR_MACRO(_interpreter_linetext, name, "F word missing with inverse time arc move");
06269 if (convert_arc (motion, block, settings) IS RS274NGC_ERROR)
06270 ERROR_MACRO_PASS(name);
06271 }
06272 else if (motion IS G_38_2)
06273 {
06274 if (settings->feed_mode IS INVERSE_TIME)
06275 ERROR_MACRO(_interpreter_linetext, name, "Cannot probe in inverse time feed mode");
06276 if (settings->cutter_radius_compensation ISNT OFF)
06277 ERROR_MACRO(_interpreter_linetext, name, "Cannot probe with cutter radius compensation on");
06278 if (settings->feed_rate IS 0.0)
06279 ERROR_MACRO(_interpreter_linetext, name, "Cannot probe with zero feed rate");
06280 if (convert_probe (block, settings) IS RS274NGC_ERROR)
06281 ERROR_MACRO_PASS(name);
06282 }
06283 else if (motion IS G_80)
06284 {
06285 if((block->x_flag) OR (block->y_flag) OR (block->z_flag))
06286 ERROR_MACRO(_interpreter_linetext, name, "Coordinate setting given with G80");
06287 else
06288 {
06289 #ifdef DEBUG_EMC
06290 COMMENT("interpreter: motion mode set to none");
06291 #endif
06292 settings->motion_mode SET_TO G_80;
06293 }
06294 }
06295 else if ((motion > G_80) AND (motion < G_90))
06296 {
06297 if (convert_cycle(motion, block, settings) IS RS274NGC_ERROR)
06298 ERROR_MACRO_PASS(name);
06299 }
06300 else
06301 BUG_MACRO(name, "Code is not G0 to G3 or G80 to G89 in convert_motion");
06302
06303 return RS274NGC_OK;
06304 }
06305
06306
06307
06308
06309
06310
06311
06312
06313
06314
06315
06316
06317
06318
06319
06320
06321
06322
06323
06324
06325
06326
06327 int convert_retract_mode(
06328 int g_code,
06329 block_pointer block,
06330 setup_pointer settings)
06331 {
06332 static char name[] SET_TO "convert_retract_mode";
06333 if (g_code IS G_98)
06334 {
06335 #ifdef DEBUG_EMC
06336 COMMENT("interpreter: retract mode set to old_z");
06337 #endif
06338 settings->retract_mode SET_TO OLD_Z;
06339 }
06340 else if (g_code IS G_99)
06341 {
06342 #ifdef DEBUG_EMC
06343 COMMENT("interpreter: retract mode set to r_plane");
06344 #endif
06345 settings->retract_mode SET_TO R_PLANE;
06346 }
06347 else
06348 BUG_MACRO(name, "Code is not G98 or G99 in convert_retract_mode");
06349 return RS274NGC_OK;
06350 }
06351
06352
06353
06354
06355
06356
06357
06358
06359
06360
06361
06362
06363
06364
06365
06366
06367
06368
06369 int convert_set_plane(
06370 int g_code,
06371 block_pointer block,
06372 setup_pointer settings)
06373 {
06374 static char name[] SET_TO "convert_set_plane";
06375 if (g_code IS G_17)
06376 {
06377 SELECT_PLANE(CANON_PLANE_XY);
06378 settings->plane SET_TO CANON_PLANE_XY;
06379 }
06380 else if (g_code IS G_18)
06381 {
06382 if (settings->cutter_radius_compensation ISNT OFF)
06383 ERROR_MACRO(_interpreter_linetext, name, "Cannot use XZ plane with cutter radius comp");
06384 SELECT_PLANE(CANON_PLANE_XZ);
06385 settings->plane SET_TO CANON_PLANE_XZ;
06386 }
06387 else if (g_code IS G_19)
06388 {
06389 if (settings->cutter_radius_compensation ISNT OFF)
06390 ERROR_MACRO(_interpreter_linetext, name, "Cannot use YZ plane with cutter radius comp");
06391 SELECT_PLANE(CANON_PLANE_YZ);
06392 settings->plane SET_TO CANON_PLANE_YZ;
06393 }
06394 else
06395 BUG_MACRO(name, "Code is not G17, G18, or G19 in convert_set_plane");
06396 return RS274NGC_OK;
06397 }
06398
06399
06400
06401
06402
06403
06404
06405
06406
06407
06408
06409
06410
06411
06412
06413
06414
06415
06416
06417
06418
06419
06420
06421
06422
06423
06424
06425
06426
06427
06428
06429
06430
06431
06432
06433
06434
06435
06436
06437
06438
06439
06440
06441
06442
06443
06444
06445
06446
06447
06448
06449
06450
06451
06452
06453
06454
06455
06456
06457
06458 int convert_tool_change(
06459 block_pointer block,
06460 setup_pointer settings)
06461 {
06462 static char name[] SET_TO "convert_tool_change";
06463
06464 CHANGE_TOOL(settings->selected_tool_slot);
06465 settings->current_slot SET_TO settings->selected_tool_slot;
06466 settings->spindle_turning SET_TO CANON_STOPPED;
06467
06468 return RS274NGC_OK;
06469 }
06470
06471
06472
06473
06474
06475
06476
06477
06478
06479
06480
06481
06482
06483
06484
06485
06486
06487
06488
06489
06490
06491
06492
06493
06494
06495
06496
06497
06498
06499
06500
06501
06502
06503 int convert_tool_length_offset(
06504 int g_code,
06505 block_pointer block,
06506 setup_pointer settings)
06507 {
06508 static char name[] SET_TO "convert_tool_length_offset";
06509 int index;
06510 double offset;
06511
06512 if (g_code IS G_49)
06513 {
06514 USE_TOOL_LENGTH_OFFSET(0.0);
06515 settings->current_z SET_TO (settings->current_z +
06516 settings->tool_length_offset);
06517 settings->tool_length_offset SET_TO 0.0;
06518 settings->length_offset_index SET_TO 0;
06519 }
06520 else if (g_code IS G_43)
06521 {
06522 index SET_TO block->h_number;
06523 if (index IS -1)
06524 ERROR_MACRO(_interpreter_linetext, name, "Offset index missing");
06525 else if (index > GET_EXTERNAL_TOOL_MAX())
06526 ERROR_MACRO(_interpreter_linetext, name, "Tool index out of bounds");
06527 else
06528 {
06529 offset SET_TO settings->tool_table[index].length;
06530 USE_TOOL_LENGTH_OFFSET(offset);
06531 settings->current_z SET_TO
06532 (settings->current_z + settings->tool_length_offset - offset);
06533 settings->tool_length_offset SET_TO offset;
06534 settings->length_offset_index SET_TO index;
06535 }
06536 }
06537 else
06538 BUG_MACRO(name, "Code is not G43 or G49 in convert_tool_length_offset");
06539 return RS274NGC_OK;
06540 }
06541
06542
06543
06544
06545
06546
06547
06548
06549
06550
06551
06552
06553
06554
06555
06556
06557
06558
06559
06560
06561
06562
06563
06564
06565
06566
06567
06568
06569 int read_line_number(
06570 char * line,
06571 int * counter,
06572 block_pointer block)
06573 {
06574 static char name[] SET_TO "read_line_number";
06575 int value;
06576
06577 if (line[*counter] ISNT 'n')
06578 BUG_MACRO(name, "Read_line_number should not have been called");
06579
06580 *counter SET_TO (*counter + 1);
06581 if (read_integer_unsigned(line, counter, &value) IS RS274NGC_ERROR)
06582 ERROR_MACRO_PASS(name);
06583 else if (value > 99999)
06584 ERROR_MACRO(_interpreter_linetext, name, "Line number greater than 99999");
06585 else
06586 {
06587 block->line_number SET_TO value;
06588 return RS274NGC_OK;
06589 }
06590 }
06591
06592
06593
06594
06595
06596
06597
06598
06599
06600
06601
06602
06603
06604
06605
06606
06607
06608
06609
06610
06611
06612
06613
06614
06615
06616
06617
06618
06619
06620
06621
06622
06623
06624
06625
06626
06627
06628
06629
06630
06631
06632 typedef int (*_function_pointer) (char *, int *, block_pointer, double *);
06633
06634 int read_one_item(
06635 char * line,
06636 int * counter,
06637 block_pointer block,
06638 double * parameters)
06639 {
06640 static char name[] SET_TO "read_one_item";
06641 _function_pointer function_pointer;
06642
06643 switch (line[*counter])
06644 {
06645 case 'd':
06646 function_pointer SET_TO read_d;
06647 break;
06648 case 'f':
06649 function_pointer SET_TO read_f;
06650 break;
06651 case 'g':
06652 function_pointer SET_TO read_g;
06653 break;
06654 case 'h':
06655 function_pointer SET_TO read_tool_length_offset;
06656 break;
06657 case 'i':
06658 function_pointer SET_TO read_i;
06659 break;
06660 case 'j':
06661 function_pointer SET_TO read_j;
06662 break;
06663 case 'k':
06664 function_pointer SET_TO read_k;
06665 break;
06666 case 'l':
06667 function_pointer SET_TO read_l;
06668 break;
06669 case 'm':
06670 function_pointer SET_TO read_m;
06671 break;
06672 case 'p':
06673 function_pointer SET_TO read_p;
06674 break;
06675 case 'q':
06676 function_pointer SET_TO read_q;
06677 break;
06678 case 'r':
06679 function_pointer SET_TO read_r;
06680 break;
06681 case 's':
06682 function_pointer SET_TO read_spindle_speed;
06683 break;
06684 case 't':
06685 function_pointer SET_TO read_tool;
06686 break;
06687 case 'x':
06688 function_pointer SET_TO read_x;
06689 break;
06690 case 'y':
06691 function_pointer SET_TO read_y;
06692 break;
06693 case 'z':
06694 function_pointer SET_TO read_z;
06695 break;
06696 case '(':
06697 function_pointer SET_TO read_comment;
06698 break;
06699 case '#':
06700 function_pointer SET_TO read_parameter_setting;
06701 break;
06702 default:
06703 ERROR_MACRO(_interpreter_linetext, name, "Bad character used");
06704 }
06705 if (function_pointer (line, counter, block, parameters) IS RS274NGC_ERROR)
06706 ERROR_MACRO_PASS(name);
06707 return RS274NGC_OK;
06708 }
06709
06710
06711
06712
06713
06714
06715
06716
06717
06718
06719
06720
06721
06722
06723
06724
06725
06726
06727
06728
06729
06730
06731
06732
06733
06734
06735
06736
06737
06738
06739
06740
06741
06742 int check_items(
06743 block_pointer block,
06744 setup_pointer settings)
06745 {
06746 static char name[] SET_TO "check_items";
06747 if (check_g_codes(block, settings) ISNT RS274NGC_OK)
06748 ERROR_MACRO_PASS(name);
06749 if (check_m_codes(block, settings) ISNT RS274NGC_OK)
06750 ERROR_MACRO_PASS(name);
06751 if (check_other_codes(block, settings) ISNT RS274NGC_OK)
06752 ERROR_MACRO_PASS(name);
06753 if ((block->m_modes[4] ISNT -1) AND (block->g_modes[1] IS G_38_2))
06754 ERROR_MACRO(_interpreter_linetext, name, "Cannot put an M code for stopping with G38.2");
06755 return RS274NGC_OK;
06756 }
06757
06758
06759
06760
06761
06762
06763
06764
06765
06766
06767
06768
06769
06770
06771
06772
06773
06774
06775
06776
06777
06778
06779
06780
06781
06782
06783
06784
06785
06786
06787
06788
06789
06790
06791
06792
06793
06794
06795
06796
06797
06798
06799
06800 int close_and_downcase(
06801 char * line)
06802 {
06803 static char name[] SET_TO "close_and_downcase";
06804 int m;
06805 int n;
06806 int comment;
06807 char item;
06808 comment SET_TO 0;
06809 for (n SET_TO 0, m SET_TO 0; (item SET_TO line[m]) ISNT (char) NULL; m++)
06810 {
06811 if (comment)
06812 {
06813 line[n++] SET_TO item;
06814 if (item IS ')')
06815 {
06816 comment SET_TO 0;
06817 }
06818 else if (item IS '(')
06819 ERROR_MACRO(_interpreter_linetext, name, "Nested comment found");
06820 }
06821 else if ((item IS ' ') OR (item IS '\t') OR (item IS '\r'));
06822
06823 else if (item IS '\n')
06824 {
06825 if (line[m+1] ISNT 0)
06826 ERROR_MACRO(_interpreter_linetext, name, "Null missing after newline");
06827 }
06828 else if ((64 < item) AND (item < 91))
06829 {
06830 line[n++] SET_TO (32 + item);
06831 }
06832 else if (item IS '(')
06833 {
06834 comment SET_TO 1;
06835 line[n++] SET_TO item;
06836 }
06837 else
06838 {
06839 line[n++] SET_TO item;
06840 }
06841 }
06842 if (m IS (INTERP_TEXT_SIZE - 1))
06843 ERROR_MACRO(_interpreter_linetext, name, "Command too long");
06844 else if (comment)
06845 ERROR_MACRO(_interpreter_linetext, name, "Unclosed comment found");
06846 line[n] SET_TO 0;
06847 return RS274NGC_OK;
06848 }
06849
06850
06851
06852
06853
06854
06855
06856
06857
06858
06859
06860
06861
06862
06863
06864
06865
06866
06867
06868
06869
06870
06871
06872
06873 int convert_comment(
06874 char * comment)
06875 {
06876 int m;
06877 int item;
06878
06879 for (m SET_TO 0; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
06880 if ((item ISNT 'M') AND (item ISNT 'm'))
06881 {
06882 COMMENT(comment);
06883 return RS274NGC_OK;
06884 }
06885 for (m++; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
06886 if ((item ISNT 'S') AND (item ISNT 's'))
06887 {
06888 COMMENT(comment);
06889 return RS274NGC_OK;
06890 }
06891 for (m++; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
06892 if ((item ISNT 'G') AND (item ISNT 'g'))
06893 {
06894 COMMENT(comment);
06895 return RS274NGC_OK;
06896 }
06897 for (m++; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
06898 if (item ISNT ',')
06899 {
06900 COMMENT(comment);
06901 return RS274NGC_OK;
06902 }
06903 MESSAGE(comment + m + 1);
06904 return RS274NGC_OK;
06905 }
06906
06907
06908
06909
06910
06911
06912
06913
06914
06915
06916
06917
06918
06919
06920
06921
06922
06923
06924
06925
06926
06927
06928 int convert_feed_mode(
06929 int g_code,
06930 block_pointer block,
06931 setup_pointer settings)
06932 {
06933 static char name[] SET_TO "convert_feed_mode";
06934 if (g_code IS G_93)
06935 {
06936 #ifdef DEBUG_EMC
06937 COMMENT("interpreter: feed mode set to inverse time");
06938 #endif
06939 settings->feed_mode SET_TO INVERSE_TIME;
06940 }
06941 else if (g_code IS G_94)
06942 {
06943 #ifdef DEBUG_EMC
06944 COMMENT("interpreter: feed mode set to units per minute");
06945 #endif
06946 settings->feed_mode SET_TO UNITS_PER_MINUTE;
06947 }
06948 else
06949 BUG_MACRO(name, "Code is not G93 or G94 in convert_feed_mode");
06950 return RS274NGC_OK;
06951 }
06952
06953
06954
06955
06956
06957
06958
06959
06960
06961
06962
06963
06964
06965
06966
06967
06968 int convert_feed_rate(
06969 block_pointer block,
06970 setup_pointer settings)
06971 {
06972 SET_FEED_RATE(block->f_number);
06973 settings->feed_rate SET_TO block->f_number;
06974 return RS274NGC_OK;
06975 }
06976
06977
06978
06979
06980
06981
06982
06983
06984
06985
06986
06987
06988
06989
06990
06991
06992
06993
06994
06995
06996
06997
06998
06999
07000
07001
07002
07003
07004
07005
07006
07007
07008
07009
07010
07011
07012
07013
07014
07015
07016
07017
07018
07019
07020
07021
07022
07023
07024
07025
07026
07027
07028
07029
07030
07031
07032
07033
07034
07035
07036
07037
07038
07039 int convert_g(
07040 block_pointer block,
07041 setup_pointer settings)
07042 {
07043 static char name[] SET_TO "convert_g";
07044
07045 if (block->g_modes[4] IS G_4)
07046 {
07047 if (convert_dwell(block->p_number) IS RS274NGC_ERROR)
07048 ERROR_MACRO_PASS(name);
07049 }
07050
07051 if (block->g_modes[2] ISNT -1)
07052 {
07053 if (convert_set_plane(block->g_modes[2], block, settings)
07054 IS RS274NGC_ERROR)
07055 ERROR_MACRO_PASS(name);
07056 }
07057
07058 if (block->g_modes[6] ISNT -1)
07059 {
07060 if (convert_length_units(block->g_modes[6], settings) IS RS274NGC_ERROR)
07061 ERROR_MACRO_PASS(name);
07062 }
07063
07064 if (block->g_modes[7] ISNT -1)
07065 {
07066 if (convert_cutter_compensation(block->g_modes[7], block, settings)
07067 IS RS274NGC_ERROR)
07068 ERROR_MACRO_PASS(name);
07069 }
07070
07071 if (block->g_modes[8] ISNT -1)
07072 {
07073 if (convert_tool_length_offset(block->g_modes[8], block, settings)
07074 IS RS274NGC_ERROR)
07075 ERROR_MACRO_PASS(name);
07076 }
07077
07078 if (block->g_modes[12] ISNT -1)
07079 {
07080 if (convert_coordinate_system (block->g_modes[12], block, settings)
07081 IS RS274NGC_ERROR)
07082 ERROR_MACRO_PASS(name);
07083 }
07084
07085 if (block->g_modes[13] ISNT -1)
07086 {
07087 if (convert_control_mode (block->g_modes[13], block, settings)
07088 IS RS274NGC_ERROR)
07089 ERROR_MACRO_PASS(name);
07090 }
07091
07092 if (block->g_modes[3] ISNT -1)
07093 {
07094 if (convert_distance_mode(block->g_modes[3], block, settings)
07095 IS RS274NGC_ERROR)
07096 ERROR_MACRO_PASS(name);
07097 }
07098
07099 if (block->g_modes[10] ISNT -1)
07100 {
07101 if (convert_retract_mode(block->g_modes[10], block, settings)
07102 IS RS274NGC_ERROR)
07103 ERROR_MACRO_PASS(name);
07104 }
07105
07106 if (block->g_modes[0] ISNT -1)
07107 {
07108 if (convert_modal_0(block->g_modes[0], block, settings)
07109 IS RS274NGC_ERROR)
07110 ERROR_MACRO_PASS(name);
07111 }
07112
07113 if (block->motion_to_be ISNT -1)
07114 {
07115 if (convert_motion(block->motion_to_be, block, settings)
07116 IS RS274NGC_ERROR)
07117 ERROR_MACRO_PASS(name);
07118 }
07119 return RS274NGC_OK;
07120 }
07121
07122
07123
07124
07125
07126
07127
07128
07129
07130
07131
07132
07133
07134
07135
07136
07137
07138
07139
07140
07141
07142
07143
07144
07145
07146
07147
07148
07149 int convert_m(
07150 block_pointer block,
07151 setup_pointer settings)
07152 {
07153 static char name[] SET_TO "convert_m";
07154 if (block->m_modes[6] ISNT -1)
07155 if (convert_tool_change(block, settings) IS RS274NGC_ERROR)
07156 ERROR_MACRO_PASS(name);
07157
07158 if (block->m_modes[7] IS 3)
07159 {
07160 START_SPINDLE_CLOCKWISE();
07161 settings->spindle_turning SET_TO CANON_CLOCKWISE;
07162 }
07163 else if (block->m_modes[7] IS 4)
07164 {
07165 START_SPINDLE_COUNTERCLOCKWISE();
07166 settings->spindle_turning SET_TO CANON_COUNTERCLOCKWISE;
07167 }
07168 else if (block->m_modes[7] IS 5)
07169 {
07170 STOP_SPINDLE_TURNING();
07171 settings->spindle_turning SET_TO CANON_STOPPED;
07172 }
07173
07174 if (block->m_modes[8] IS 7)
07175 {
07176 MIST_ON();
07177 settings->mist SET_TO ON;
07178 }
07179 else if (block->m_modes[8] IS 8)
07180 {
07181 FLOOD_ON();
07182 settings->flood SET_TO ON;
07183 }
07184 else if (block->m_modes[8] IS 9)
07185 {
07186 MIST_OFF();
07187 settings->mist SET_TO OFF;
07188 FLOOD_OFF();
07189 settings->flood SET_TO OFF;
07190 }
07191
07192 if (block->m_modes[9] IS 48)
07193 {
07194 ENABLE_FEED_OVERRIDE();
07195 ENABLE_SPEED_OVERRIDE();
07196 settings->feed_override SET_TO ON;
07197 settings->speed_override SET_TO ON;
07198 }
07199 else if (block->m_modes[9] IS 49)
07200 {
07201 DISABLE_FEED_OVERRIDE();
07202 DISABLE_SPEED_OVERRIDE();
07203 settings->feed_override SET_TO OFF;
07204 settings->speed_override SET_TO OFF;
07205 }
07206 return RS274NGC_OK;
07207 }
07208
07209
07210
07211
07212
07213
07214
07215
07216
07217
07218
07219
07220
07221
07222
07223
07224 int convert_speed(
07225 block_pointer block,
07226 setup_pointer settings)
07227 {
07228 SET_SPINDLE_SPEED(block->s_number);
07229 settings->speed SET_TO block->s_number;
07230 return RS274NGC_OK;
07231 }
07232
07233
07234
07235
07236
07237
07238
07239
07240
07241
07242
07243
07244
07245
07246
07247
07248
07249
07250
07251
07252
07253
07254
07255
07256
07257
07258
07259
07260
07261
07262
07263
07264
07265
07266
07267
07268
07269
07270
07271
07272
07273
07274
07275
07276
07277
07278
07279
07280
07281
07282
07283
07284
07285
07286
07287
07288
07289
07290
07291
07292
07293
07294
07295
07296
07297 int convert_stop(
07298 block_pointer block,
07299 setup_pointer settings)
07300 {
07301 static char name[] SET_TO "convert_stop";
07302
07303 if (block->m_modes[4] IS 0)
07304 {
07305 PROGRAM_STOP();
07306 }
07307 else if (block->m_modes[4] IS 60)
07308 {
07309 PALLET_SHUTTLE();
07310 PROGRAM_STOP();
07311 }
07312 else if (block->m_modes[4] IS 1)
07313 {
07314 OPTIONAL_PROGRAM_STOP();
07315 }
07316 else if ((block->m_modes[4] IS 2) OR (block->m_modes[4] IS 30))
07317 {
07318
07319 settings->current_x SET_TO settings->current_x
07320 + settings->origin_offset_x;
07321 settings->current_y SET_TO settings->current_y
07322 + settings->origin_offset_y;
07323 settings->current_z SET_TO settings->current_z
07324 + settings->origin_offset_z;
07325 settings->origin_offset_x SET_TO settings->parameters[5221];
07326 settings->origin_offset_y SET_TO settings->parameters[5222];
07327 settings->origin_offset_z SET_TO settings->parameters[5223];
07328 settings->current_x SET_TO settings->current_x -
07329 settings->origin_offset_x;
07330 settings->current_y SET_TO settings->current_y -
07331 settings->origin_offset_y;
07332 settings->current_z SET_TO settings->current_z -
07333 settings->origin_offset_z;
07334 SET_ORIGIN_OFFSETS(settings->origin_offset_x + settings->axis_offset_x,
07335 settings->origin_offset_y + settings->axis_offset_y,
07336 settings->origin_offset_z + settings->axis_offset_z);
07337
07338 if (settings->plane ISNT CANON_PLANE_XY)
07339 {
07340 SELECT_PLANE(CANON_PLANE_XY);
07341 settings->plane SET_TO CANON_PLANE_XY;
07342 }
07343
07344 settings->distance_mode SET_TO MODE_ABSOLUTE;
07345
07346 settings->feed_mode SET_TO UNITS_PER_MINUTE;
07347
07348 if (settings->feed_override ISNT ON)
07349 {
07350 ENABLE_FEED_OVERRIDE();
07351 settings->feed_override SET_TO ON;
07352 }
07353 if (settings->speed_override ISNT ON)
07354 {
07355 ENABLE_SPEED_OVERRIDE();
07356 settings->speed_override SET_TO ON;
07357 }
07358
07359 settings->cutter_radius_compensation SET_TO OFF;
07360 settings->program_x SET_TO UNKNOWN;
07361
07362 STOP_SPINDLE_TURNING();
07363 settings->spindle_turning SET_TO CANON_STOPPED;
07364
07365 settings->motion_mode SET_TO G_1;
07366
07367 if (settings->mist IS ON)
07368 {
07369 MIST_OFF();
07370 settings->mist SET_TO OFF;
07371 }
07372 if (settings->flood IS ON)
07373 {
07374 FLOOD_OFF();
07375 settings->flood SET_TO OFF;
07376 }
07377
07378 if (block->m_modes[4] IS 30)
07379 PALLET_SHUTTLE();
07380 PROGRAM_END();
07381 return RS274NGC_EXIT;
07382 }
07383 else
07384 BUG_MACRO(name, "Code is not M0, M1, M2, M30 or M60 in convert_stop");
07385 return RS274NGC_OK;
07386 }
07387
07388
07389
07390
07391
07392
07393
07394
07395
07396
07397
07398
07399
07400
07401
07402
07403
07404
07405
07406 int convert_tool_select(
07407 block_pointer block,
07408 setup_pointer settings)
07409 {
07410 static char name[] SET_TO "convert_tool_select";
07411
07412 if (block->t_number > GET_EXTERNAL_TOOL_MAX())
07413 ERROR_MACRO(_interpreter_linetext, name, "Selected tool slot number too large");
07414
07415 SELECT_TOOL(block->t_number);
07416 settings->selected_tool_slot SET_TO block->t_number;
07417 return RS274NGC_OK;
07418 }
07419
07420
07421
07422
07423
07424
07425
07426
07427
07428
07429
07430
07431
07432
07433
07434
07435
07436
07437
07438
07439
07440
07441
07442
07443
07444
07445
07446
07447
07448
07449
07450
07451
07452
07453
07454
07455
07456
07457
07458 int init_block(
07459 block_pointer block)
07460 {
07461 int n;
07462 block->comment[0] SET_TO 0;
07463 block->d_number SET_TO -1;
07464 block->f_number SET_TO -1.0;
07465 block->g_count SET_TO 0;
07466 for (n SET_TO 0; n < 14; n++)
07467 {
07468 block->g_modes[n] SET_TO -1;
07469 }
07470 block->h_number SET_TO -1;
07471 block->i_flag SET_TO OFF;
07472 block->j_flag SET_TO OFF;
07473 block->k_flag SET_TO OFF;
07474 block->l_number SET_TO -1;
07475 block->line_number SET_TO -1;
07476 block->motion_to_be SET_TO -1;
07477 block->m_count SET_TO 0;
07478 for (n SET_TO 0; n < 10; n++)
07479 {
07480 block->m_modes[n] SET_TO -1;
07481 }
07482 block->p_number SET_TO -1.0;
07483 block->q_number SET_TO -1.0;
07484 block->r_flag SET_TO OFF;
07485 block->s_number SET_TO -1.0;
07486 block->t_number SET_TO -1;
07487 block->x_flag SET_TO OFF;
07488 block->y_flag SET_TO OFF;
07489 block->z_flag SET_TO OFF;
07490
07491 return RS274NGC_OK;
07492 }
07493
07494
07495
07496
07497
07498
07499
07500
07501
07502
07503
07504
07505
07506
07507
07508
07509
07510
07511 int read_items(
07512 block_pointer block,
07513 char * line,
07514 double * parameters)
07515 {
07516 static char name[] SET_TO "read_items";
07517 int counter;
07518 int length;
07519
07520 length SET_TO strlen(line);
07521 counter SET_TO 0;
07522
07523 if (line[counter] IS '/')
07524 counter++;
07525 if (line[counter] IS 'n')
07526 {
07527 if (read_line_number(line, &counter, block) IS RS274NGC_ERROR)
07528 ERROR_MACRO_PASS(name);
07529 }
07530 for ( ; counter < length; )
07531 {
07532 if (read_one_item (line, &counter, block, parameters) IS RS274NGC_ERROR)
07533 ERROR_MACRO_PASS(name);
07534 }
07535 return RS274NGC_OK;
07536 }
07537
07538
07539
07540
07541
07542
07543
07544
07545
07546
07547
07548
07549
07550
07551
07552
07553
07554
07555
07556
07557 int utility_enhance_block(
07558 block_pointer block,
07559 setup_pointer settings)
07560 {
07561 static char name[] SET_TO "utility_enhance_block";
07562 if (block->g_modes[1] ISNT -1)
07563 block->motion_to_be SET_TO block->g_modes[1];
07564 else if ((((block->x_flag IS ON) OR (block->y_flag IS ON)) OR
07565 (block->z_flag IS ON)) AND
07566 (block->g_modes[0] IS -1))
07567 block->motion_to_be SET_TO settings->motion_mode;
07568 return RS274NGC_OK;
07569 }
07570
07571
07572
07573
07574
07575
07576
07577
07578
07579
07580
07581
07582
07583
07584
07585
07586
07587
07588
07589
07590
07591
07592
07593
07594
07595
07596 int write_g_codes(
07597 block_pointer block,
07598 setup_pointer settings,
07599 int line_number,
07600 int * gez)
07601 {
07602 gez[0] SET_TO line_number;
07603 gez[1] SET_TO settings->motion_mode;
07604 gez[2] SET_TO
07605 (block IS NULL) ? -1 :
07606 (block->g_modes[0] ISNT -1) ? block->g_modes[0] :
07607 block->g_modes[4] ;
07608 gez[3] SET_TO
07609 (settings->plane IS CANON_PLANE_XY) ? G_17 :
07610 (settings->plane IS CANON_PLANE_XZ) ? G_18 : G_19;
07611 gez[4] SET_TO
07612 (settings->cutter_radius_compensation IS RIGHT) ? G_42 :
07613 (settings->cutter_radius_compensation IS LEFT) ? G_41 : G_40;
07614 gez[5] SET_TO
07615 (settings->length_units IS CANON_UNITS_INCHES) ? G_20 : G_21;
07616 gez[6] SET_TO
07617 (settings->distance_mode IS MODE_ABSOLUTE) ? G_90 : G_91;
07618 gez[7] SET_TO
07619 (settings->feed_mode IS INVERSE_TIME) ? G_93 : G_94;
07620 gez[8] SET_TO
07621 (settings->origin_ngc < 7) ? (530 + (10 * settings->origin_ngc)) :
07622 (584 + settings->origin_ngc);
07623 gez[9] SET_TO
07624 (settings->tool_length_offset IS 0.0) ? G_49 : G_43;
07625 gez[10] SET_TO
07626 (settings->retract_mode IS OLD_Z) ? G_98 : G_99;
07627 gez[11] SET_TO
07628 (settings->control_mode IS CANON_CONTINUOUS) ? G_64 : G_61;
07629
07630 return RS274NGC_OK;
07631 }
07632
07633
07634
07635
07636
07637
07638
07639
07640
07641
07642
07643
07644
07645
07646
07647
07648
07649
07650
07651 int write_m_codes(
07652 block_pointer block,
07653 setup_pointer settings,
07654 int line_number,
07655 int * ems)
07656 {
07657 ems[0] SET_TO line_number;
07658 ems[1] SET_TO
07659 (block IS NULL) ? -1 : block->m_modes[4];
07660 ems[2] SET_TO
07661 (settings->spindle_turning IS CANON_STOPPED) ? 5 :
07662 (settings->spindle_turning IS CANON_CLOCKWISE) ? 3 : 4;
07663 ems[3] SET_TO
07664 (block IS NULL) ? -1 : block->m_modes[6];
07665 ems[4] SET_TO
07666 (settings->mist IS ON) ? 7 :
07667 (settings->flood IS ON) ? -1 : 9;
07668 ems[5] SET_TO
07669 (settings->flood IS ON) ? 8 : -1;
07670 ems[6] SET_TO
07671 (settings->feed_override IS ON) ? 48 : 49;
07672
07673 return RS274NGC_OK;
07674 }
07675
07676
07677
07678
07679
07680
07681
07682
07683
07684
07685
07686
07687
07688
07689
07690 int write_settings(
07691 block_pointer block,
07692 setup_pointer settings,
07693 int line_number,
07694 double * vals)
07695 {
07696 vals[0] SET_TO line_number;
07697 vals[1] SET_TO settings->feed_rate;
07698 vals[2] SET_TO settings->speed;
07699
07700 return RS274NGC_OK;
07701 }
07702
07703
07704
07705
07706
07707
07708
07709
07710
07711
07712
07713
07714
07715
07716
07717
07718
07719
07720
07721
07722
07723
07724
07725
07726
07727
07728
07729
07730
07731
07732
07733
07734
07735
07736
07737
07738
07739
07740
07741
07742
07743 int execute_block(
07744 block_pointer block,
07745 setup_pointer settings,
07746 int line_number)
07747 {
07748 static char name[] SET_TO "execute_block";
07749 if (block->comment[0] ISNT 0)
07750 {
07751 if (convert_comment(block->comment) IS RS274NGC_ERROR)
07752 ERROR_MACRO_PASS(name);
07753 }
07754 if (block->g_modes[5] ISNT -1)
07755 {
07756 if (convert_feed_mode(block->g_modes[5], block, settings)
07757 IS RS274NGC_ERROR)
07758 ERROR_MACRO_PASS(name);
07759 }
07760 if (block->f_number > -1.0)
07761 {
07762 if (settings->feed_mode IS INVERSE_TIME);
07763 else if (convert_feed_rate(block, settings) IS RS274NGC_ERROR)
07764 ERROR_MACRO_PASS(name);
07765 }
07766 if (block->s_number > -1.0)
07767 {
07768 if (convert_speed(block, settings) IS RS274NGC_ERROR)
07769 ERROR_MACRO_PASS(name);
07770 }
07771 if (block->t_number ISNT -1)
07772 {
07773 if (convert_tool_select(block, settings) IS RS274NGC_ERROR)
07774 ERROR_MACRO_PASS(name);
07775 }
07776 if (convert_m(block, settings) IS RS274NGC_ERROR)
07777 ERROR_MACRO_PASS(name);
07778 if (convert_g(block, settings) IS RS274NGC_ERROR)
07779 ERROR_MACRO_PASS(name);
07780 if (block->m_modes[4] ISNT -1)
07781 {
07782 if (convert_stop(block, settings) IS RS274NGC_EXIT)
07783 return RS274NGC_EXIT;
07784 }
07785 if (settings->probe_flag IS ON)
07786 return RS274NGC_EXECUTE_FINISH;
07787 else
07788 return RS274NGC_OK;
07789 }
07790
07791
07792
07793
07794
07795
07796
07797
07798
07799
07800
07801
07802
07803
07804
07805
07806
07807
07808
07809
07810 int read_line(
07811 char * line,
07812 block_pointer block,
07813 setup_pointer settings)
07814 {
07815 static char name[] SET_TO "read_line";
07816 if (init_block (block) IS RS274NGC_ERROR)
07817 ERROR_MACRO_PASS(name);
07818 if (read_items(block, line, settings->parameters) IS RS274NGC_ERROR)
07819 ERROR_MACRO_PASS(name);
07820 if (utility_enhance_block(block, settings) IS RS274NGC_ERROR)
07821 ERROR_MACRO_PASS(name);
07822 if (check_items (block, settings) IS RS274NGC_ERROR)
07823 ERROR_MACRO_PASS(name);
07824 return RS274NGC_OK;
07825 }
07826
07827
07828
07829
07830
07831
07832
07833
07834
07835
07836
07837
07838
07839
07840
07841
07842
07843
07844
07845
07846
07847
07848
07849
07850
07851
07852
07853
07854
07855
07856
07857
07858
07859
07860
07861
07862
07863
07864
07865
07866
07867
07868
07869
07870
07871
07872
07873
07874
07875
07876
07877
07878
07879 int read_text(
07880 const char * command,
07881 FILE * inport,
07882 char * raw_line,
07883 char * line,
07884 int * length,
07885 ON_OFF block_delete)
07886 {
07887 static char name[] SET_TO "read_text";
07888 char * returned_value;
07889 int len;
07890
07891 if (command IS NULL)
07892 {
07893 returned_value SET_TO fgets(raw_line, INTERP_TEXT_SIZE, inport);
07894
07895 len = strlen(raw_line) - 1;
07896 while (len >= 0)
07897 {
07898 if (isspace(raw_line[len]))
07899 {
07900 raw_line[len] = 0;
07901 len--;
07902 }
07903 else
07904 {
07905 break;
07906 }
07907 }
07908 if (returned_value IS NULL)
07909 return RS274NGC_ENDFILE;
07910 else
07911 strcpy(line, raw_line);
07912 }
07913 else
07914 {
07915 strcpy(raw_line, command);
07916 strcpy(line, command);
07917 }
07918
07919 if (close_and_downcase(line) IS RS274NGC_ERROR)
07920 ERROR_MACRO_PASS(name);
07921
07922 if (((line[0] IS '/') AND ((block_delete IS ON) OR (line[1] IS 0))) OR
07923 (line[0] IS 0))
07924 *length SET_TO 0;
07925 else
07926 *length SET_TO strlen(line);
07927
07928 return RS274NGC_OK;
07929 }
07930
07931
07932
07933
07934
07935
07936
07937
07938
07939
07940
07941
07942
07943
07944
07945
07946 int set_probe_data(
07947 setup_pointer settings)
07948 {
07949 static char name[] SET_TO "set_probe_data";
07950 CANON_POSITION position;
07951 CANON_POSITION probe_position;
07952
07953 position SET_TO GET_EXTERNAL_POSITION();
07954 settings->current_x SET_TO position.x;
07955 settings->current_y SET_TO position.y;
07956 settings->current_z SET_TO position.z;
07957 probe_position SET_TO GET_EXTERNAL_PROBE_POSITION();
07958 settings->parameters[5061] SET_TO probe_position.x;
07959 settings->parameters[5062] SET_TO probe_position.y;
07960 settings->parameters[5063] SET_TO probe_position.z;
07961 settings->parameters[5067] SET_TO GET_EXTERNAL_PROBE_VALUE();
07962 return RS274NGC_OK;
07963 }
07964
07965
07966
07967
07968
07969
07970
07971
07972
07973
07974
07975
07976
07977
07978
07979
07980
07981
07982
07983
07984
07985
07986
07987
07988
07989
07990
07991
07992
07993
07994
07995
07996
07997
07998
07999
08000
08001 int rs274ngc_reset()
08002 {
08003 _textline SET_TO 0;
08004 _interpreter_filename[0] SET_TO 0;
08005 _interpreter_linetext[0] SET_TO 0;
08006 _interpreter_blocktext[0] SET_TO 0;
08007 _interpreter_fp SET_TO NULL;
08008 _interpreter_status SET_TO 0;
08009 _interpreter_length SET_TO 0;
08010
08011 return 0;
08012 }
08013
08014
08015
08016
08017
08018
08019
08020
08021
08022
08023
08024
08025
08026
08027
08028
08029 const char * rs274ngc_command()
08030 {
08031 return _interpreter_linetext;
08032 }
08033
08034
08035
08036
08037
08038
08039
08040
08041
08042
08043
08044
08045
08046
08047
08048
08049 const char * rs274ngc_file()
08050 {
08051 return _interpreter_filename;
08052 }
08053
08054
08055
08056
08057
08058
08059
08060
08061
08062
08063
08064
08065
08066
08067
08068
08069
08070
08071
08072
08073
08074
08075 int rs274ngc_line()
08076 {
08077 return _textline;
08078 }
08079
08080
08081
08082
08083
08084
08085
08086
08087
08088
08089
08090
08091
08092
08093
08094
08095
08096 int rs274ngc_close()
08097 {
08098 if (_interpreter_fp ISNT NULL)
08099 {
08100 fclose(_interpreter_fp);
08101 _interpreter_fp SET_TO NULL;
08102 }
08103
08104 _interpreter_filename[0] SET_TO 0;
08105
08106 rs274ngc_reset();
08107
08108 return RS274NGC_OK;
08109 }
08110
08111
08112
08113
08114
08115
08116
08117
08118
08119
08120
08121
08122
08123
08124
08125
08126
08127
08128
08129
08130
08131
08132
08133
08134
08135
08136
08137
08138
08139
08140
08141
08142
08143
08144
08145
08146
08147
08148
08149
08150 int rs274ngc_execute(
08151 const char * command)
08152 {
08153 static char name[] SET_TO "rs274ngc_execute";
08154
08155 if (_interpreter_settings.probe_flag IS ON)
08156 {
08157 if (IS_EXTERNAL_QUEUE_EMPTY() IS 0)
08158 {
08159
08160 ERR_MACRO(_interpreter_linetext, name, "Queue is not empty after probing");
08161 }
08162 set_probe_data(&_interpreter_settings);
08163 _interpreter_settings.probe_flag SET_TO OFF;
08164 }
08165
08166 if (command ISNT NULL)
08167 {
08168 if(strlen(command) > (INTERP_TEXT_SIZE -1))
08169 ERR_MACRO(_interpreter_linetext, name, "Command too long");
08170 else if (read_text (command, NULL, _interpreter_linetext,
08171 _interpreter_blocktext, &_interpreter_length,
08172 _interpreter_settings.block_delete) ISNT RS274NGC_OK)
08173 ERR_MACRO_PASS(name);
08174 else if (_interpreter_length IS 0)
08175 return RS274NGC_OK;
08176 else if (read_line(_interpreter_blocktext, &_interpreter_block,
08177 &_interpreter_settings) IS RS274NGC_ERROR)
08178 ERR_MACRO_PASS(name);
08179 _textline++;
08180 }
08181
08182 if (_interpreter_length IS 0)
08183 {
08184 write_g_codes((block *) NULL, &_interpreter_settings, _textline,
08185 &_interpreter_active_g_codes[0]);
08186 write_m_codes((block *) NULL, &_interpreter_settings, _textline,
08187 &_interpreter_active_m_codes[0]);
08188 write_settings((block *) NULL, &_interpreter_settings, _textline,
08189 &_interpreter_active_settings[0]);
08190
08191 return RS274NGC_OK;
08192 }
08193
08194 _interpreter_status SET_TO
08195 execute_block (&_interpreter_block, &_interpreter_settings, _textline);
08196
08197
08198 write_g_codes(&_interpreter_block, &_interpreter_settings, _textline,
08199 &_interpreter_active_g_codes[0]);
08200 write_m_codes(&_interpreter_block, &_interpreter_settings, _textline,
08201 &_interpreter_active_m_codes[0]);
08202 write_settings(&_interpreter_block, &_interpreter_settings, _textline,
08203 &_interpreter_active_settings[0]);
08204
08205 if (_interpreter_status IS RS274NGC_EXIT)
08206 {
08207 if (_interpreter_fp ISNT NULL)
08208 {
08209 fclose(_interpreter_fp);
08210 _interpreter_fp SET_TO NULL;
08211 _textline SET_TO 0;
08212 _interpreter_linetext[0] SET_TO 0;
08213 }
08214 return RS274NGC_EXIT;
08215 }
08216 else if (_interpreter_status IS RS274NGC_ERROR)
08217 ERR_MACRO_PASS(name);
08218 else if (_interpreter_status IS RS274NGC_EXECUTE_FINISH)
08219 return RS274NGC_EXECUTE_FINISH;
08220 else
08221 return RS274NGC_OK;
08222 }
08223
08224
08225
08226
08227
08228
08229
08230
08231
08232
08233
08234
08235
08236
08237
08238
08239
08240 int rs274ngc_exit()
08241 {
08242 rs274ngc_save_parameters(RS274NGC_PARAMETER_FILE,
08243 _interpreter_settings.parameters);
08244
08245 rs274ngc_reset();
08246
08247 return RS274NGC_OK;
08248 }
08249
08250
08251
08252
08253
08254
08255
08256
08257
08258
08259
08260
08261
08262
08263
08264
08265
08266
08267 int rs274ngc_synch()
08268 {
08269 CANON_POSITION current_point;
08270
08271 _interpreter_settings.current_slot SET_TO GET_EXTERNAL_TOOL();
08272
08273 rs274ngc_load_tool_table();
08274
08275 _interpreter_settings.control_mode SET_TO GET_MOTION_CONTROL_MODE();
08276 current_point SET_TO GET_EXTERNAL_POSITION();
08277 _interpreter_settings.current_x SET_TO current_point.x;
08278 _interpreter_settings.current_y SET_TO current_point.y;
08279 _interpreter_settings.current_z SET_TO current_point.z;
08280
08281 _interpreter_settings.feed_rate SET_TO GET_EXTERNAL_FEED_RATE();
08282
08283 _interpreter_settings.flood SET_TO (GET_EXTERNAL_FLOOD() ISNT 0) ? ON : OFF;
08284
08285 _interpreter_settings.mist SET_TO (GET_EXTERNAL_MIST() ISNT 0) ? ON : OFF;
08286
08287 _interpreter_settings.selected_tool_slot SET_TO GET_EXTERNAL_POCKET();
08288
08289 _interpreter_settings.speed SET_TO GET_EXTERNAL_SPEED();
08290
08291 _interpreter_settings.spindle_turning SET_TO GET_EXTERNAL_SPINDLE();
08292
08293 _interpreter_settings.traverse_rate SET_TO GET_EXTERNAL_TRAVERSE_RATE();
08294
08295 return RS274NGC_OK;
08296 }
08297
08298
08299
08300
08301
08302
08303
08304
08305
08306
08307
08308
08309
08310
08311
08312
08313
08314
08315
08316
08317
08318
08319
08320
08321
08322
08323
08324
08325
08326
08327
08328
08329
08330
08331
08332 int rs274ngc_init()
08333 {
08334 CANON_VECTOR axis_offset;
08335 CANON_VECTOR origin_point;
08336 int k;
08337
08338 rs274ngc_reset();
08339
08340 INIT_CANON();
08341
08342 _interpreter_settings.length_units SET_TO CANON_UNITS_INCHES;
08343 USE_LENGTH_UNITS(_interpreter_settings.length_units);
08344
08345 for (k SET_TO 5161; k < 5387; k++)
08346 {
08347 _interpreter_settings.parameters[k] SET_TO 0.0;
08348 }
08349 rs274ngc_restore_parameters(
08350 #ifdef STAND_ALONE_INTERP
08351 DEFAULT_RS274NGC_PARAMETER_FILE,
08352 #else
08353 RS274NGC_PARAMETER_FILE,
08354 #endif
08355 _interpreter_settings.parameters);
08356
08357
08358 axis_offset.x SET_TO _interpreter_settings.parameters[5211];
08359 axis_offset.y SET_TO _interpreter_settings.parameters[5212];
08360 axis_offset.z SET_TO _interpreter_settings.parameters[5213];
08361
08362
08363 origin_point.x SET_TO _interpreter_settings.parameters[5221];
08364 origin_point.y SET_TO _interpreter_settings.parameters[5222];
08365 origin_point.z SET_TO _interpreter_settings.parameters[5223];
08366
08367
08368 SET_ORIGIN_OFFSETS(origin_point.x + axis_offset.x,
08369 origin_point.y + axis_offset.y,
08370 origin_point.z + axis_offset.z);
08371
08372 SET_FEED_REFERENCE(CANON_XYZ);
08373
08374 _textline SET_TO 0;
08375 _interpreter_settings.axis_offset_x SET_TO 0.0;
08376 _interpreter_settings.axis_offset_y SET_TO 0.0;
08377 _interpreter_settings.axis_offset_z SET_TO 0.0;
08378 _interpreter_settings.block_delete SET_TO OFF;
08379
08380
08381 _interpreter_settings.current_x SET_TO 0.0;
08382 _interpreter_settings.current_y SET_TO 0.0;
08383 _interpreter_settings.current_z SET_TO 0.0;
08384 _interpreter_settings.cutter_radius_compensation SET_TO OFF;
08385
08386 _interpreter_settings.distance_mode SET_TO MODE_ABSOLUTE;
08387 _interpreter_settings.feed_mode SET_TO UNITS_PER_MINUTE;
08388 _interpreter_settings.feed_override SET_TO ON;
08389
08390
08391 _interpreter_settings.length_offset_index SET_TO 1;
08392
08393
08394 _interpreter_settings.motion_mode SET_TO G_1;
08395 _interpreter_settings.origin_ngc SET_TO 1;
08396 _interpreter_settings.axis_offset_x SET_TO axis_offset.x;
08397 _interpreter_settings.axis_offset_y SET_TO axis_offset.y;
08398 _interpreter_settings.axis_offset_z SET_TO axis_offset.z;
08399 _interpreter_settings.origin_offset_x SET_TO origin_point.x;
08400 _interpreter_settings.origin_offset_y SET_TO origin_point.y;
08401 _interpreter_settings.origin_offset_z SET_TO origin_point.z;
08402
08403 _interpreter_settings.plane SET_TO CANON_PLANE_XY;
08404 SELECT_PLANE(_interpreter_settings.plane);
08405 _interpreter_settings.probe_flag SET_TO OFF;
08406 _interpreter_settings.program_x SET_TO UNKNOWN;
08407 _interpreter_settings.program_y SET_TO UNKNOWN;
08408 _interpreter_settings.retract_mode SET_TO R_PLANE;
08409
08410
08411 _interpreter_settings.speed_feed_mode SET_TO CANON_INDEPENDENT;
08412 _interpreter_settings.speed_override SET_TO ON;
08413 _interpreter_settings.tool_length_offset SET_TO 0.0;
08414
08415 _interpreter_settings.tool_table_index SET_TO 1;
08416
08417
08418 write_g_codes((block_pointer)NULL, &_interpreter_settings,
08419 _textline, &_interpreter_active_g_codes[0]);
08420 write_m_codes((block_pointer)NULL, &_interpreter_settings,
08421 _textline, &_interpreter_active_m_codes[0]);
08422 write_settings((block_pointer)NULL, &_interpreter_settings,
08423 _textline, &_interpreter_active_settings[0]);
08424
08425
08426 rs274ngc_synch();
08427
08428 return RS274NGC_OK;
08429 }
08430
08431
08432
08433
08434
08435
08436
08437
08438
08439
08440
08441
08442
08443
08444
08445
08446
08447
08448
08449
08450
08451
08452
08453
08454
08455
08456
08457 int rs274ngc_open(
08458 const char *filename)
08459 {
08460 static char name[] SET_TO "rs274ngc_open";
08461
08462 _interpreter_fp SET_TO fopen(filename, "r");
08463 if (_interpreter_fp IS NULL)
08464 ERR_MACRO(_interpreter_linetext, name, "Unable to open file");
08465
08466 _textline SET_TO 0;
08467
08468 strcpy(_interpreter_filename, filename);
08469
08470 return RS274NGC_OK;
08471 }
08472
08473
08474
08475
08476
08477
08478
08479
08480
08481
08482
08483
08484
08485
08486
08487
08488
08489
08490
08491
08492
08493
08494
08495
08496
08497
08498
08499
08500
08501
08502
08503
08504
08505
08506
08507
08508
08509
08510
08511
08512
08513
08514
08515
08516
08517
08518 int rs274ngc_read()
08519 {
08520 static char name[] SET_TO "rs274ngc_read";
08521 int status;
08522
08523 if (_interpreter_settings.probe_flag IS ON)
08524 {
08525 if (IS_EXTERNAL_QUEUE_EMPTY() IS 0)
08526 {
08527
08528 ERR_MACRO(_interpreter_linetext, name, "Queue is not empty after probing");
08529 }
08530 set_probe_data(&_interpreter_settings);
08531 _interpreter_settings.probe_flag SET_TO OFF;
08532 }
08533
08534 if (_interpreter_fp IS NULL)
08535 {
08536 if (_interpreter_status IS RS274NGC_EXIT)
08537 {
08538
08539 return RS274NGC_EXIT;
08540 }
08541 else
08542 {
08543
08544 ERR_MACRO_PASS(name);
08545 }
08546 }
08547
08548
08549 _textline++;
08550 status SET_TO read_text (NULL, _interpreter_fp, _interpreter_linetext,
08551 _interpreter_blocktext, &_interpreter_length,
08552 _interpreter_settings.block_delete);
08553 if ((status IS RS274NGC_ENDFILE) AND (_interpreter_block.m_modes[4] IS 1))
08554 return RS274NGC_ENDFILE;
08555 else if (status IS RS274NGC_ENDFILE)
08556 {
08557 fclose(_interpreter_fp);
08558 _interpreter_fp SET_TO NULL;
08559
08560 ERR_MACRO(_interpreter_linetext, name, "File ended with no stopping command given");
08561 }
08562 else if (status IS RS274NGC_ERROR)
08563 {
08564
08565 ERR_MACRO_PASS(name);
08566 }
08567 if (_interpreter_length IS 0)
08568 return RS274NGC_OK;
08569
08570
08571 else if (read_line(_interpreter_blocktext, &_interpreter_block,
08572 &_interpreter_settings) IS RS274NGC_ERROR)
08573 {
08574
08575 ERR_MACRO_PASS(name);
08576 }
08577 else
08578 return RS274NGC_OK;
08579 }
08580
08581
08582
08583
08584
08585
08586
08587
08588
08589
08590
08591
08592
08593
08594
08595
08596
08597
08598
08599 int rs274ngc_load_tool_table()
08600 {
08601 int t;
08602
08603 for (t SET_TO 0; t <= CANON_TOOL_MAX; t++)
08604 {
08605 _interpreter_settings.tool_table[t] SET_TO GET_EXTERNAL_TOOL_TABLE(t);
08606 }
08607
08608 return 0;
08609 }
08610
08611
08612
08613
08614
08615
08616
08617
08618
08619
08620
08621
08622
08623
08624
08625
08626
08627
08628
08629
08630
08631
08632
08633 int rs274ngc_restore_parameters(const char *filename, double parameters[])
08634 {
08635 static char name[] SET_TO "rs274ngc_restore_parameters";
08636 FILE *infp = NULL;
08637 char line[256];
08638 int variable;
08639 double value;
08640
08641
08642 if (NULL == (infp = fopen(filename, "r")))
08643 {
08644 ERR_MACRO(_interpreter_linetext, name, "Cannot open file");
08645 return -1;
08646 }
08647
08648 while (!feof(infp))
08649 {
08650 if (NULL == fgets(line, 256, infp))
08651 {
08652 break;
08653 }
08654
08655
08656 if (2 == sscanf(line, "%d %lf", &variable, &value))
08657 {
08658
08659 if (variable <= 0 || variable >= RS274NGC_MAX_PARAMETERS)
08660 {
08661 ERR_MACRO(_interpreter_linetext, name, "Parameter number out of range");
08662 }
08663 else
08664 {
08665 parameters[variable] = value;
08666 }
08667 }
08668 }
08669
08670 fclose(infp);
08671
08672 return 0;
08673 }
08674
08675
08676
08677
08678
08679
08680
08681
08682
08683
08684
08685
08686
08687
08688
08689
08690
08691
08692
08693
08694
08695
08696
08697 int rs274ngc_save_parameters(const char *filename, const double parameters[])
08698 {
08699 static char name[] SET_TO "rs274ngc_save_parameters";
08700 FILE *infp = NULL;
08701 FILE *outfp = NULL;
08702 char line[256];
08703 int variable;
08704 double value;
08705
08706
08707 strcpy(line, filename);
08708 strcat(line, RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX);
08709 if (0 != rename(filename, line))
08710 {
08711 ERR_MACRO(_interpreter_linetext, name, "Cannot create backup file");
08712 return -1;
08713 }
08714
08715
08716 if (NULL == (infp = fopen(line, "r")))
08717 {
08718 ERR_MACRO(_interpreter_linetext, name, "Cannot open backup file");
08719 return -1;
08720 }
08721
08722
08723 if (NULL == (outfp = fopen(filename, "w")))
08724 {
08725 ERR_MACRO(_interpreter_linetext, name, "Cannot open variable file");
08726 return -1;
08727 }
08728
08729 while (!feof(infp))
08730 {
08731 if (NULL == fgets(line, 256, infp))
08732 {
08733 break;
08734 }
08735
08736
08737 if (2 == sscanf(line, "%d %f", &variable, &value))
08738 {
08739
08740 if (variable <= 0 || variable >= RS274NGC_MAX_PARAMETERS)
08741 {
08742 ERR_MACRO(_interpreter_linetext, name, "Parameter number out of range");
08743 }
08744 else
08745 {
08746 sprintf(line, "%d\t%f\n", variable, parameters[variable]);
08747 }
08748 }
08749
08750
08751 fputs(line, outfp);
08752 }
08753
08754 fclose(infp);
08755 fclose(outfp);
08756
08757 return 0;
08758 }
08759
08760
08761
08762
08763
08764
08765
08766
08767
08768
08769
08770
08771
08772
08773
08774
08775
08776
08777
08778
08779
08780 #ifdef STAND_ALONE_INTERP
08781
08782 int rs274ngc_ini_load(const char *filename)
08783 {
08784 return RS274NGC_OK;
08785 }
08786
08787 #else
08788
08789 #include "inifile.h"
08790
08791 int rs274ngc_ini_load(const char *filename)
08792 {
08793 INIFILE inifile;
08794 const char *inistring;
08795
08796
08797 if (-1 == inifile.open(filename))
08798 {
08799 return -1;
08800 }
08801
08802 if (NULL != (inistring = inifile.find("PARAMETER_FILE", "RS274NGC")))
08803 {
08804
08805 strcpy(RS274NGC_PARAMETER_FILE, inistring);
08806 }
08807 else
08808 {
08809
08810 }
08811
08812
08813 inifile.close();
08814
08815 return RS274NGC_OK;
08816 }
08817
08818 #endif
08819
08820
08821
08822
08823
08824
08825
08826
08827
08828
08829
08830
08831
08832 int rs274ngc_active_g_codes(int *codes)
08833 {
08834 int t;
08835
08836 for (t = 0; t < RS274NGC_ACTIVE_G_CODES; t++)
08837 {
08838 codes[t] = _interpreter_active_g_codes[t];
08839 }
08840
08841 return RS274NGC_OK;
08842 }
08843
08844
08845
08846
08847
08848
08849
08850
08851
08852
08853
08854
08855
08856 int rs274ngc_active_m_codes(int *codes)
08857 {
08858 int t;
08859
08860 for (t = 0; t < RS274NGC_ACTIVE_M_CODES; t++)
08861 {
08862 codes[t] = _interpreter_active_m_codes[t];
08863 }
08864
08865 return RS274NGC_OK;
08866 }
08867
08868
08869
08870
08871
08872
08873
08874
08875
08876
08877
08878
08879
08880 int rs274ngc_active_settings(double *settings)
08881 {
08882 int t;
08883
08884 for (t = 0; t < RS274NGC_ACTIVE_SETTINGS; t++)
08885 {
08886 settings[t] = _interpreter_active_settings[t];
08887 }
08888
08889 return RS274NGC_OK;
08890 }
08891
08892