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
00091
00092
00093
00094
00095
00096
00097
00098 #include <stdio.h>
00099 #include <stdlib.h>
00100 #include <math.h>
00101 #include <string.h>
00102 #include <ctype.h>
00103 #include "rs274ngc.hh"
00104 #include "rs274ngc_return.hh"
00105 #include "rs274ngc_errors.cc"
00106
00107 #define DEBUG_EMC
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 #define ERM(error_code) if (1) { \
00127 _setup.stack_index SET_TO 0; \
00128 strcpy(_setup.stack[_setup.stack_index++], name); \
00129 _setup.stack[_setup.stack_index][0] SET_TO 0; \
00130 return error_code; \
00131 } else
00132
00133 #define ERP(error_code) if (_setup.stack_index < 49) { \
00134 strcpy(_setup.stack[_setup.stack_index++], name); \
00135 _setup.stack[_setup.stack_index][0] SET_TO 0; \
00136 return error_code; \
00137 } else return error_code
00138
00139 #define CHK(bad, error_code) if (bad) { \
00140 _setup.stack_index SET_TO 0; \
00141 strcpy(_setup.stack[_setup.stack_index++], name); \
00142 _setup.stack[_setup.stack_index][0] SET_TO 0; \
00143 return error_code; \
00144 } else
00145
00146 #define CHP(try_this) \
00147 if ((status SET_TO (try_this)) ISNT RS274NGC_OK) { \
00148 if (_setup.stack_index < 49) \
00149 {strcpy(_setup.stack[_setup.stack_index++], name); \
00150 _setup.stack[_setup.stack_index][0] SET_TO 0; \
00151 return status;} \
00152 else {return status;} \
00153 } else
00154
00155
00156
00157
00158
00159
00160
00161 static int arc_data_comp_ijk(int move, int side, double tool_radius,
00162 double current_x, double current_y, double end_x, double end_y,
00163 double i_number, double j_number, double * center_x, double * center_y,
00164 int * turn, double tolerance);
00165 static int arc_data_comp_r(int move, int side, double tool_radius,
00166 double current_x, double current_y, double end_x, double end_y,
00167 double big_radius, double * center_x, double * center_y, int * turn);
00168 static int arc_data_ijk(int move, double current_x, double current_y,
00169 double end_x, double end_y, double i_number, double j_number,
00170 double * center_x, double * center_y, int * turn, double tolerance);
00171 static int arc_data_r(int move, double current_x, double current_y,
00172 double end_x, double end_y, double radius, double * center_x,
00173 double * center_y, int * turn);
00174 static int check_g_codes(block_pointer block, setup_pointer settings);
00175 static int check_items(block_pointer block, setup_pointer settings);
00176 static int check_m_codes(block_pointer block);
00177 static int check_other_codes(block_pointer block);
00178 static int close_and_downcase(char * line);
00179 static int convert_arc(int move, block_pointer block, setup_pointer settings);
00180 static int convert_arc2(int move, block_pointer block,
00181 setup_pointer settings, double * current1, double * current2,
00182 double * current3, double end1, double end2,
00183 double end3
00184 #ifdef AA
00185 , double AA_end
00186 #endif
00187
00188 #ifdef BB
00189 , double BB_end
00190 #endif
00191
00192 #ifdef CC
00193 , double CC_end
00194 #endif
00195 , double offset1,
00196 double offset2);
00197 static int convert_arc_comp1(int move, block_pointer block,
00198 setup_pointer settings, double end_x, double end_y,
00199 double end_z
00200 #ifdef AA
00201 , double AA_end
00202 #endif
00203
00204 #ifdef BB
00205 , double BB_end
00206 #endif
00207
00208 #ifdef CC
00209 , double CC_end
00210 #endif
00211 );
00212 static int convert_arc_comp2(int move, block_pointer block,
00213 setup_pointer settings, double end_x, double end_y,
00214 double end_z
00215 #ifdef AA
00216 , double AA_end
00217 #endif
00218
00219 #ifdef BB
00220 , double BB_end
00221 #endif
00222
00223 #ifdef CC
00224 , double CC_end
00225 #endif
00226 );
00227 static int convert_axis_offsets(int g_code, block_pointer block,
00228 setup_pointer settings);
00229 static int convert_comment(char * comment);
00230 static int convert_control_mode(int g_code, setup_pointer settings);
00231 static int convert_coordinate_system(int g_code, setup_pointer settings);
00232 static int convert_cutter_compensation(int g_code, block_pointer block,
00233 setup_pointer settings);
00234 static int convert_cutter_compensation_off(setup_pointer settings);
00235 static int convert_cutter_compensation_on(int side, block_pointer block,
00236 setup_pointer settings);
00237 static int convert_cycle(int motion, block_pointer block,
00238 setup_pointer settings);
00239 static int convert_cycle_g81(CANON_PLANE plane, double x, double y,
00240 double clear_z, double bottom_z);
00241 static int convert_cycle_g82(CANON_PLANE plane, double x, double y,
00242 double clear_z, double bottom_z, double dwell);
00243 static int convert_cycle_g83(CANON_PLANE plane, double x, double y,
00244 double r, double clear_z, double bottom_z, double delta);
00245 static int convert_cycle_g84(CANON_PLANE plane, double x, double y,
00246 double clear_z, double bottom_z, CANON_DIRECTION direction,
00247 CANON_SPEED_FEED_MODE mode);
00248 static int convert_cycle_g85(CANON_PLANE plane, double x, double y,
00249 double clear_z, double bottom_z);
00250 static int convert_cycle_g86(CANON_PLANE plane, double x, double y,
00251 double clear_z, double bottom_z, double dwell, CANON_DIRECTION direction);
00252 static int convert_cycle_g87(CANON_PLANE plane, double x, double offset_x,
00253 double y, double offset_y, double r, double clear_z, double middle_z,
00254 double bottom_z, CANON_DIRECTION direction);
00255 static int convert_cycle_g88(CANON_PLANE plane, double x, double y,
00256 double bottom_z, double dwell, CANON_DIRECTION direction);
00257 static int convert_cycle_g89(CANON_PLANE plane, double x, double y,
00258 double clear_z, double bottom_z, double dwell);
00259 static int convert_cycle_xy(int motion, block_pointer block,
00260 setup_pointer settings);
00261 static int convert_cycle_yz(int motion, block_pointer block,
00262 setup_pointer settings);
00263 static int convert_cycle_zx(int motion, block_pointer block,
00264 setup_pointer settings);
00265 static int convert_distance_mode(int g_code, setup_pointer settings);
00266 static int convert_dwell(double time);
00267 static int convert_feed_mode(int g_code, setup_pointer settings);
00268 static int convert_feed_rate(block_pointer block, setup_pointer settings);
00269 static int convert_g(block_pointer block, setup_pointer settings);
00270 static int convert_home(int move, block_pointer block, setup_pointer settings);
00271 static int convert_length_units(int g_code, setup_pointer settings);
00272 static int convert_m(block_pointer block, setup_pointer settings);
00273 static int convert_modal_0(int code, block_pointer block,
00274 setup_pointer settings);
00275 static int convert_motion(int motion, block_pointer block,
00276 setup_pointer settings);
00277 static int convert_probe(block_pointer block, setup_pointer settings);
00278 static int convert_retract_mode(int g_code, setup_pointer settings);
00279 static int convert_setup(block_pointer block, setup_pointer settings);
00280 static int convert_set_plane(int g_code, setup_pointer settings);
00281 static int convert_speed(block_pointer block, setup_pointer settings);
00282 static int convert_stop(block_pointer block, setup_pointer settings);
00283 static int convert_straight(int move, block_pointer block,
00284 setup_pointer settings);
00285 static int convert_straight_comp1(int move, block_pointer block,
00286 setup_pointer settings, double px, double py,
00287 double end_z
00288 #ifdef AA
00289 , double AA_end
00290 #endif
00291
00292 #ifdef BB
00293 , double BB_end
00294 #endif
00295
00296 #ifdef CC
00297 , double CC_end
00298 #endif
00299 );
00300 static int convert_straight_comp2(int move, block_pointer block,
00301 setup_pointer settings, double px, double py,
00302 double end_z
00303 #ifdef AA
00304 , double AA_end
00305 #endif
00306
00307 #ifdef BB
00308 , double BB_end
00309 #endif
00310
00311 #ifdef CC
00312 , double CC_end
00313 #endif
00314 );
00315 static int convert_tool_change(setup_pointer settings);
00316 static int convert_tool_length_offset(int g_code, block_pointer block,
00317 setup_pointer settings);
00318 static int convert_tool_select(block_pointer block, setup_pointer settings);
00319 static int cycle_feed(CANON_PLANE plane, double end1,
00320 double end2, double end3);
00321 static int cycle_traverse(CANON_PLANE plane, double end1, double end2,
00322 double end3);
00323 static int enhance_block(block_pointer block, setup_pointer settings);
00324 static int execute_binary(double * left, int operation, double * right);
00325 static int execute_binary1(double * left, int operation, double * right);
00326 static int execute_binary2(double * left, int operation, double * right);
00327 static int execute_block(block_pointer block, setup_pointer settings);
00328 static int execute_unary(double * double_ptr, int operation);
00329 static double find_arc_length(double x1, double y1, double z1,
00330 double center_x, double center_y, int turn, double x2, double y2, double z2);
00331 static int find_ends(block_pointer block, setup_pointer settings, double * px,
00332 double * py, double * pz
00333 #ifdef AA
00334 , double * AA_p
00335 #endif
00336
00337 #ifdef BB
00338 , double * BB_p
00339 #endif
00340
00341 #ifdef CC
00342 , double * CC_p
00343 #endif
00344 );
00345 static int find_relative(double x1, double y1,
00346 double z1
00347 #ifdef AA
00348 , double AA_1
00349 #endif
00350
00351 #ifdef BB
00352 , double BB_1
00353 #endif
00354
00355 #ifdef CC
00356 , double CC_1
00357 #endif
00358 , double * x2, double * y2,
00359 double * z2
00360 #ifdef AA
00361 , double * AA_2
00362 #endif
00363
00364 #ifdef BB
00365 , double * BB_2
00366 #endif
00367
00368 #ifdef CC
00369 , double * CC_2
00370 #endif
00371 ,
00372 setup_pointer settings);
00373 static double find_straight_length(double x2, double y2,
00374 double z2
00375 #ifdef AA
00376 , double AA_2
00377 #endif
00378
00379 #ifdef BB
00380 , double BB_2
00381 #endif
00382
00383 #ifdef CC
00384 , double CC_2
00385 #endif
00386 , double x1, double y1,
00387 double z1
00388 #ifdef AA
00389 , double AA_1
00390 #endif
00391
00392 #ifdef BB
00393 , double BB_1
00394 #endif
00395
00396 #ifdef CC
00397 , double CC_1
00398 #endif
00399 );
00400 static double find_turn(double x1, double y1, double center_x, double center_y,
00401 int turn, double x2, double y2);
00402 static int init_block(block_pointer block);
00403 static int inverse_time_rate_arc(double x1, double y1, double z1,
00404 double cx, double cy, int turn, double x2, double y2, double z2,
00405 block_pointer block, setup_pointer settings);
00406 static int inverse_time_rate_arc2(double start_x, double start_y, int turn1,
00407 double mid_x, double mid_y, double cx, double cy, int turn2, double end_x,
00408 double end_y, double end_z, block_pointer block, setup_pointer settings);
00409 static int inverse_time_rate_as(double start_x, double start_y, int turn,
00410 double mid_x, double mid_y, double end_x, double end_y,
00411 double end_z
00412 #ifdef AA
00413 , double AA_end
00414 #endif
00415
00416 #ifdef BB
00417 , double BB_end
00418 #endif
00419
00420 #ifdef CC
00421 , double CC_end
00422 #endif
00423 ,
00424 block_pointer block, setup_pointer settings);
00425 static int inverse_time_rate_straight(double end_x, double end_y,
00426 double end_z
00427 #ifdef AA
00428 , double AA_end
00429 #endif
00430
00431 #ifdef BB
00432 , double BB_end
00433 #endif
00434
00435 #ifdef CC
00436 , double CC_end
00437 #endif
00438 ,
00439 block_pointer block, setup_pointer settings);
00440 static int parse_line(char * line, block_pointer block,setup_pointer settings);
00441 static int precedence(int an_operator);
00442 static int read_a(char * line, int * counter, block_pointer block,
00443 double * parameters);
00444 static int read_atan(char * line, int * counter, double * double_ptr,
00445 double * parameters);
00446 static int read_b(char * line, int * counter, block_pointer block,
00447 double * parameters);
00448 static int read_c(char * line, int * counter, block_pointer block,
00449 double * parameters);
00450 static int read_comment(char * line, int * counter, block_pointer block,
00451 double * parameters);
00452 static int read_d(char * line, int * counter, block_pointer block,
00453 double * parameters);
00454 static int read_f(char * line, int * counter, block_pointer block,
00455 double * parameters);
00456 static int read_g(char * line, int * counter, block_pointer block,
00457 double * parameters);
00458 static int read_h(char * line, int * counter, block_pointer block,
00459 double * parameters);
00460 static int read_i(char * line, int * counter, block_pointer block,
00461 double * parameters);
00462 static int read_integer_unsigned(char * line, int * counter,
00463 int * integer_ptr);
00464 static int read_integer_value(char * line, int * counter, int * integer_ptr,
00465 double * parameters);
00466 static int read_items(block_pointer block, char * line, double * parameters);
00467 static int read_j(char * line, int * counter, block_pointer block,
00468 double * parameters);
00469 static int read_k(char * line, int * counter, block_pointer block,
00470 double * parameters);
00471 static int read_l(char * line, int * counter, block_pointer block,
00472 double * parameters);
00473 static int read_line_number(char * line, int * counter, block_pointer block);
00474 static int read_m(char * line, int * counter, block_pointer block,
00475 double * parameters);
00476 static int read_one_item(char * line, int * counter, block_pointer block,
00477 double * parameters);
00478 static int read_operation(char * line, int * counter, int * operation);
00479 static int read_operation_unary(char * line, int * counter, int * operation);
00480 static int read_p(char * line, int * counter, block_pointer block,
00481 double * parameters);
00482 static int read_parameter(char * line, int * counter, double * double_ptr,
00483 double * parameters);
00484 static int read_parameter_setting(char * line, int * counter,
00485 block_pointer block, double * parameters);
00486 static int read_q(char * line, int * counter, block_pointer block,
00487 double * parameters);
00488 static int read_r(char * line, int * counter, block_pointer block,
00489 double * parameters);
00490 static int read_real_expression(char * line, int * counter,
00491 double * hold2, double * parameters);
00492 static int read_real_number(char * line, int * counter, double * double_ptr);
00493 static int read_real_value(char * line, int * counter, double * double_ptr,
00494 double * parameters);
00495 static int read_s(char * line, int * counter, block_pointer block,
00496 double * parameters);
00497 static int read_t(char * line, int * counter, block_pointer block,
00498 double * parameters);
00499 static int read_text(const char * command, FILE * inport, char * raw_line,
00500 char * line, int * length);
00501 static int read_unary(char * line, int * counter, double * double_ptr,
00502 double * parameters);
00503 static int read_x(char * line, int * counter, block_pointer block,
00504 double * parameters);
00505 static int read_y(char * line, int * counter, block_pointer block,
00506 double * parameters);
00507 static int read_z(char * line, int * counter, block_pointer block,
00508 double * parameters);
00509 static int set_probe_data(setup_pointer settings);
00510 static int write_g_codes(block_pointer block, setup_pointer settings);
00511 static int write_m_codes(block_pointer block, setup_pointer settings);
00512 static int write_settings(setup_pointer settings);
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 static const int _gees[] SET_TO {
00560 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00561 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00562 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00563 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00564 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00565 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00566 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00567 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00568 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00569 2,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00570 6,-1,-1,-1,-1,-1,-1,-1,-1,-1, 6,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00571 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00572 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00573 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00574 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00575 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00576 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00577 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00578 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00579 -1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00580 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 7,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00581 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00582 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00583 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00584 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00585 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00586 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00587 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00588 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00589 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,12,12,12,-1,-1,-1,-1,-1,-1,
00590 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,13,13,-1,-1,-1,-1,-1,-1,-1,-1,
00591 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00592 13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00593 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00594 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00595 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00596 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00597 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00598 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00599 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00600 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00601 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00602 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00603 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00604 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00605 3,-1,-1,-1,-1,-1,-1,-1,-1,-1, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00606 0, 0, 0, 0,-1,-1,-1,-1,-1,-1, 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00607 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00608 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00609 10,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1};
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 static const int _ems[] SET_TO {
00628 4, 4, 4, 7, 7, 7, 6, 8, 8, 8,
00629 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00630 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00631 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00632 -1, -1, -1, -1, -1, -1, -1, -1, 9, 9,
00633 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00634 4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00635 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00636 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00637 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648 static const int _required_parameters[] SET_TO {
00649 5161, 5162, 5163,
00650 #ifdef AA
00651 5164,
00652 #endif
00653 #ifdef BB
00654 5165,
00655 #endif
00656 #ifdef CC
00657 5166,
00658 #endif
00659 5181, 5182, 5183,
00660 #ifdef AA
00661 5184,
00662 #endif
00663 #ifdef BB
00664 5185,
00665 #endif
00666 #ifdef CC
00667 5186,
00668 #endif
00669 5211, 5212, 5213,
00670 #ifdef AA
00671 5214,
00672 #endif
00673 #ifdef BB
00674 5215,
00675 #endif
00676 #ifdef CC
00677 5216,
00678 #endif
00679 5220,
00680 5221, 5222, 5223,
00681 #ifdef AA
00682 5224,
00683 #endif
00684 #ifdef BB
00685 5225,
00686 #endif
00687 #ifdef CC
00688 5226,
00689 #endif
00690 5241, 5242, 5243,
00691 #ifdef AA
00692 5244,
00693 #endif
00694 #ifdef BB
00695 5245,
00696 #endif
00697 #ifdef CC
00698 5246,
00699 #endif
00700 5261, 5262, 5263,
00701 #ifdef AA
00702 5264,
00703 #endif
00704 #ifdef BB
00705 5265,
00706 #endif
00707 #ifdef CC
00708 5266,
00709 #endif
00710 5281, 5282, 5283,
00711 #ifdef AA
00712 5284,
00713 #endif
00714 #ifdef BB
00715 5285,
00716 #endif
00717 #ifdef CC
00718 5286,
00719 #endif
00720 5301, 5302, 5303,
00721 #ifdef AA
00722 5304,
00723 #endif
00724 #ifdef BB
00725 5305,
00726 #endif
00727 #ifdef CC
00728 5306,
00729 #endif
00730 5321, 5322, 5323,
00731 #ifdef AA
00732 5324,
00733 #endif
00734 #ifdef BB
00735 5325,
00736 #endif
00737 #ifdef CC
00738 5326,
00739 #endif
00740 5341, 5342, 5343,
00741 #ifdef AA
00742 5344,
00743 #endif
00744 #ifdef BB
00745 5345,
00746 #endif
00747 #ifdef CC
00748 5346,
00749 #endif
00750 5361, 5362, 5363,
00751 #ifdef AA
00752 5364,
00753 #endif
00754 #ifdef BB
00755 5365,
00756 #endif
00757 #ifdef CC
00758 5366,
00759 #endif
00760 5381, 5382, 5383,
00761 #ifdef AA
00762 5384,
00763 #endif
00764 #ifdef BB
00765 5385,
00766 #endif
00767 #ifdef CC
00768 5386,
00769 #endif
00770 RS274NGC_MAX_PARAMETERS
00771 };
00772
00773
00774
00775
00776
00777
00778
00779
00780 static const read_function_pointer _readers[] SET_TO {
00781 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00782 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00783 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00784 0, 0, 0, 0, 0, read_parameter_setting,0, 0, 0, 0,
00785 read_comment, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00786 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00787 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00788 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00789 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00790 0, 0, 0, 0, 0, 0, 0, read_a, read_b, read_c,
00791 read_d, 0, read_f, read_g, read_h, read_i, read_j, read_k, read_l, read_m,
00792 0, 0, read_p, read_q, read_r, read_s, read_t, 0 , 0, 0,
00793 read_x, read_y, read_z};
00794
00795
00796
00797
00798
00799
00800 static setup _setup;
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
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 static int arc_data_comp_ijk(
00842 int move,
00843 int side,
00844 double tool_radius,
00845 double current_x,
00846 double current_y,
00847 double end_x,
00848 double end_y,
00849 double i_number,
00850 double j_number,
00851 double * center_x,
00852 double * center_y,
00853 int * turn,
00854 double tolerance)
00855 {
00856 static char name[] SET_TO "arc_data_comp_ijk";
00857 double arc_radius;
00858 double radius2;
00859
00860 *center_x SET_TO (current_x + i_number);
00861 *center_y SET_TO (current_y + j_number);
00862 arc_radius SET_TO hypot(i_number, j_number);
00863 radius2 SET_TO hypot((*center_x - end_x), (*center_y - end_y));
00864 radius2 SET_TO
00865 (((side IS LEFT ) AND (move IS 30)) OR
00866 ((side IS RIGHT) AND (move IS 20))) ?
00867 (radius2 - tool_radius): (radius2 + tool_radius);
00868 CHK((fabs(arc_radius - radius2) > tolerance),
00869 NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START);
00870
00871 if (move IS G_2)
00872 *turn SET_TO -1;
00873 else if (move IS G_3)
00874 *turn SET_TO 1;
00875 else
00876 ERM(NCE_BUG_CODE_NOT_G2_OR_G3);
00877 return RS274NGC_OK;
00878 }
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937 static int arc_data_comp_r(
00938 int move,
00939 int side,
00940 double tool_radius,
00941 double current_x,
00942 double current_y,
00943 double end_x,
00944 double end_y,
00945 double big_radius,
00946 double * center_x,
00947 double * center_y,
00948 int * turn)
00949 {
00950 static char name[] SET_TO "arc_data_comp_r";
00951 double abs_radius;
00952 double alpha;
00953 double distance;
00954 double mid_length;
00955 double offset;
00956 double radius2;
00957 double mid_x;
00958 double mid_y;
00959 double theta;
00960
00961 abs_radius SET_TO fabs(big_radius);
00962 CHK(((abs_radius <= tool_radius) AND (((side IS LEFT ) AND (move IS G_3)) OR
00963 ((side IS RIGHT) AND (move IS G_2)))),
00964 NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP);
00965
00966 distance SET_TO hypot((end_x - current_x), (end_y - current_y));
00967 alpha SET_TO atan2 ((end_y - current_y), (end_x - current_x));
00968 theta SET_TO (((move IS G_3) AND (big_radius > 0)) OR
00969 ((move IS G_2) AND (big_radius < 0))) ?
00970 (alpha + PI2) : (alpha - PI2);
00971 radius2 SET_TO (((side IS LEFT ) AND (move IS G_3)) OR
00972 ((side IS RIGHT) AND (move IS G_2))) ?
00973 (abs_radius - tool_radius) : (abs_radius + tool_radius);
00974 CHK((distance > (radius2 + abs_radius)),
00975 NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT);
00976 mid_length SET_TO (((radius2 * radius2) + (distance * distance) -
00977 (abs_radius * abs_radius)) / (2.0 * distance));
00978 mid_x SET_TO (current_x + (mid_length * cos(alpha)));
00979 mid_y SET_TO (current_y + (mid_length * sin(alpha)));
00980 CHK(((radius2 * radius2) <= (mid_length * mid_length)),
00981 NCE_BUG_IN_TOOL_RADIUS_COMP);
00982 offset SET_TO sqrt((radius2 * radius2) - (mid_length * mid_length));
00983 *center_x SET_TO mid_x + (offset * cos(theta));
00984 *center_y SET_TO mid_y + (offset * sin(theta));
00985 *turn SET_TO (move IS G_2) ? -1 : 1;
00986
00987 return RS274NGC_OK;
00988 }
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019 static int arc_data_ijk(
01020 int move,
01021 double current_x,
01022 double current_y,
01023 double end_x,
01024 double end_y,
01025 double i_number,
01026 double j_number,
01027 double * center_x,
01028 double * center_y,
01029 int * turn,
01030 double tolerance)
01031 {
01032 static char name[] SET_TO "arc_data_ijk";
01033 double radius;
01034 double radius2;
01035 *center_x SET_TO (current_x + i_number);
01036 *center_y SET_TO (current_y + j_number);
01037 radius SET_TO hypot((*center_x - current_x), (*center_y - current_y));
01038 radius2 SET_TO hypot((*center_x - end_x), (*center_y - end_y));
01039 CHK(((radius IS 0.0) OR (radius2 IS 0.0)), NCE_ZERO_RADIUS_ARC);
01040 CHK((fabs(radius - radius2) > tolerance),
01041 NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START);
01042 if (move IS G_2)
01043 *turn SET_TO -1;
01044 else if (move IS G_3)
01045 *turn SET_TO 1;
01046 else
01047 ERM(NCE_BUG_CODE_NOT_G2_OR_G3);
01048 return RS274NGC_OK;
01049 }
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087 static int arc_data_r(
01088 int move,
01089 double current_x,
01090 double current_y,
01091 double end_x,
01092 double end_y,
01093 double radius,
01094 double * center_x,
01095 double * center_y,
01096 int * turn)
01097 {
01098 static char name[] SET_TO "arc_data_r";
01099 double abs_radius;
01100 double half_length;
01101 double mid_x;
01102 double mid_y;
01103 double offset;
01104 double theta;
01105 double turn2;
01106
01107 CHK(((end_x IS current_x) AND (end_y IS current_y)),
01108 NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC);
01109 abs_radius SET_TO fabs(radius);
01110 mid_x SET_TO (end_x + current_x)/2.0;
01111 mid_y SET_TO (end_y + current_y)/2.0;
01112 half_length SET_TO hypot((mid_x - end_x), (mid_y - end_y));
01113 CHK(((half_length/abs_radius) > (1+TINY)),
01114 NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT);
01115 if ((half_length/abs_radius) > (1-TINY))
01116 half_length SET_TO abs_radius;
01117
01118 if (((move IS G_2) AND (radius > 0)) OR
01119 ((move IS G_3) AND (radius < 0)))
01120 theta SET_TO atan2((end_y - current_y), (end_x - current_x)) - PI2;
01121 else
01122 theta SET_TO atan2((end_y - current_y), (end_x - current_x)) + PI2;
01123
01124 turn2 SET_TO asin (half_length/abs_radius);
01125 offset SET_TO abs_radius * cos(turn2);
01126 *center_x SET_TO mid_x + (offset * cos(theta));
01127 *center_y SET_TO mid_y + (offset * sin(theta));
01128 *turn SET_TO (move IS G_2) ? -1 : 1;
01129
01130 return RS274NGC_OK;
01131 }
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184 static int check_g_codes(
01185 block_pointer block,
01186 setup_pointer settings)
01187 {
01188 static char name[] SET_TO "check_g_codes";
01189 int mode0;
01190 int p_int;
01191
01192 mode0 SET_TO block->g_modes[0];
01193
01194 if (mode0 IS -1)
01195 {}
01196 else if (mode0 IS G_4)
01197 {
01198 CHK((block->p_number IS -1.0), NCE_DWELL_TIME_MISSING_WITH_G4);
01199 }
01200 else if (mode0 IS G_10)
01201 {
01202 p_int SET_TO (int)(block->p_number + 0.0001);
01203 CHK((block->l_number ISNT 2), NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2);
01204 CHK((((block->p_number + 0.0001) - p_int) > 0.0002),
01205 NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2);
01206 CHK(((p_int < 1) OR (p_int > 9)), NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2);
01207 }
01208 else if (mode0 IS G_28)
01209 {}
01210 else if (mode0 IS G_30)
01211 {}
01212 else if (mode0 IS G_53)
01213 {
01214 CHK(((block->motion_to_be ISNT G_0) AND (block->motion_to_be ISNT G_1)),
01215 NCE_MUST_USE_G0_OR_G1_WITH_G53);
01216 CHK(((block->g_modes[3] IS G_91) OR
01217 ((block->g_modes[3] ISNT G_90) AND
01218 (settings->distance_mode IS MODE_INCREMENTAL))),
01219 NCE_CANNOT_USE_G53_INCREMENTAL);
01220 }
01221 else if (mode0 IS G_92)
01222 {}
01223 else if ((mode0 IS G_92_1) OR (mode0 IS G_92_2) OR (mode0 IS G_92_3))
01224 {}
01225 else
01226 ERM(NCE_BUG_BAD_G_CODE_MODAL_GROUP_0);
01227 return RS274NGC_OK;
01228 }
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259 static int check_items(
01260 block_pointer block,
01261 setup_pointer settings)
01262 {
01263 static char name[] SET_TO "check_items";
01264 int status;
01265
01266 CHP(check_g_codes(block, settings));
01267 CHP(check_m_codes(block));
01268 CHP(check_other_codes(block));
01269 return RS274NGC_OK;
01270 }
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292 static int check_m_codes(
01293 block_pointer block)
01294 {
01295 static char name[] SET_TO "check_m_codes";
01296
01297 CHK((block->m_count > MAX_EMS), NCE_TOO_MANY_M_CODES_ON_LINE);
01298 return RS274NGC_OK;
01299 }
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345 static int check_other_codes(
01346 block_pointer block)
01347 {
01348 static char name[] SET_TO "check_other_codes";
01349 int motion;
01350
01351 motion SET_TO block->motion_to_be;
01352 #ifdef AA
01353 if (block->a_flag ISNT OFF)
01354 {
01355 CHK(((block->g_modes[1] > G_80) AND (block->g_modes[1] < G_90)),
01356 NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE);
01357 }
01358 #endif
01359 #ifdef BB
01360 if (block->b_flag ISNT OFF)
01361 {
01362 CHK(((block->g_modes[1] > G_80) AND (block->g_modes[1] < G_90)),
01363 NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE);
01364 }
01365 #endif
01366 #ifdef CC
01367 if (block->c_flag ISNT OFF)
01368 {
01369 CHK(((block->g_modes[1] > G_80) AND (block->g_modes[1] < G_90)),
01370 NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE);
01371 }
01372 #endif
01373 if (block->d_number ISNT -1)
01374 {
01375 CHK(((block->g_modes[7] ISNT G_41) AND (block->g_modes[7] ISNT G_42)),
01376 NCE_D_WORD_WITH_NO_G41_OR_G42);
01377 }
01378 if (block->h_number ISNT -1)
01379 {
01380 CHK((block->g_modes[8] ISNT G_43), NCE_H_WORD_WITH_NO_G43);
01381 }
01382
01383 if (block->i_flag IS ON)
01384 {
01385 CHK(((motion ISNT G_2) AND (motion ISNT G_3) AND (motion ISNT G_87)),
01386 NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
01387 }
01388
01389 if (block->j_flag IS ON)
01390 {
01391 CHK(((motion ISNT G_2) AND (motion ISNT G_3) AND (motion ISNT G_87)),
01392 NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
01393 }
01394
01395 if (block->k_flag IS ON)
01396 {
01397 CHK(((motion ISNT G_2) AND (motion ISNT G_3) AND (motion ISNT G_87)),
01398 NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
01399 }
01400
01401 if (block->l_number ISNT -1)
01402 {
01403 CHK((((motion < G_81) OR (motion > G_89)) AND
01404 (block->g_modes[0] ISNT G_10)),
01405 NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10);
01406 }
01407
01408 if (block->p_number ISNT -1.0)
01409 {
01410 CHK(((block->g_modes[0] ISNT G_10) AND
01411 (block->g_modes[0] ISNT G_4) AND
01412 (motion ISNT G_82) AND (motion ISNT G_86) AND
01413 (motion ISNT G_88) AND (motion ISNT G_89)),
01414 NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89);
01415 }
01416
01417 if (block->q_number ISNT -1.0)
01418 {
01419 CHK((motion ISNT G_83), NCE_Q_WORD_WITH_NO_G83);
01420 }
01421
01422 if (block->r_flag IS ON)
01423 {
01424 CHK((((motion ISNT G_2) AND (motion ISNT G_3)) AND
01425 ((motion < G_81) OR (motion > G_89))),
01426 NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT);
01427 }
01428
01429 return RS274NGC_OK;
01430 }
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474 static int close_and_downcase(
01475 char * line)
01476 {
01477 static char name[] SET_TO "close_and_downcase";
01478 int m;
01479 int n;
01480 int comment;
01481 char item;
01482 comment SET_TO 0;
01483 for (n SET_TO 0, m SET_TO 0; (item SET_TO line[m]) ISNT (char) NULL; m++)
01484 {
01485 if (comment)
01486 {
01487 line[n++] SET_TO item;
01488 if (item IS ')')
01489 {
01490 comment SET_TO 0;
01491 }
01492 else if (item IS '(')
01493 ERM(NCE_NESTED_COMMENT_FOUND);
01494 }
01495 else if ((item IS ' ') OR (item IS '\t') OR (item IS '\r'));
01496
01497 else if (item IS '\n')
01498 {
01499 CHK((line[m+1] ISNT 0), NCE_NULL_MISSING_AFTER_NEWLINE);
01500 }
01501 else if ((64 < item) AND (item < 91))
01502 {
01503 line[n++] SET_TO (32 + item);
01504 }
01505 else if (item IS '(')
01506 {
01507 comment SET_TO 1;
01508 line[n++] SET_TO item;
01509 }
01510 else
01511 {
01512 line[n++] SET_TO item;
01513 }
01514 }
01515 CHK((comment), NCE_UNCLOSED_COMMENT_FOUND);
01516 line[n] SET_TO 0;
01517 return RS274NGC_OK;
01518 }
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
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 static int convert_arc(
01575 int move,
01576 block_pointer block,
01577 setup_pointer settings)
01578 {
01579 static char name[] SET_TO "convert_arc";
01580 int status;
01581 int first;
01582 int ijk_flag;
01583 double end_x;
01584 double end_y;
01585 double end_z;
01586 #ifdef AA
01587 double AA_end;
01588 #endif
01589 #ifdef BB
01590 double BB_end;
01591 #endif
01592 #ifdef CC
01593 double CC_end;
01594 #endif
01595
01596 ijk_flag SET_TO
01597 ((block->i_flag OR block->j_flag) OR block->k_flag) ? ON : OFF;
01598 first SET_TO (settings->program_x IS UNKNOWN);
01599
01600 CHK(((block->r_flag ISNT ON) AND (ijk_flag ISNT ON)),
01601 NCE_R_I_J_K_WORDS_ALL_MISSING_FOR_ARC);
01602 CHK(((block->r_flag IS ON) AND (ijk_flag IS ON)),
01603 NCE_MIXED_RADIUS_IJK_FORMAT_FOR_ARC);
01604 if (settings->feed_mode IS UNITS_PER_MINUTE)
01605 {
01606 CHK((settings->feed_rate IS 0.0),
01607 NCE_CANNOT_MAKE_ARC_WITH_ZERO_FEED_RATE);
01608 }
01609 else if (settings->feed_mode IS INVERSE_TIME)
01610 {
01611 CHK((block->f_number IS -1.0),
01612 NCE_F_WORD_MISSING_WITH_INVERSE_TIME_ARC_MOVE);
01613 }
01614 if (ijk_flag)
01615 {
01616 if (settings->plane IS CANON_PLANE_XY)
01617 {
01618 CHK((block->k_flag), NCE_K_WORD_GIVEN_FOR_ARC_IN_XY_PLANE);
01619 if (block->i_flag IS OFF)
01620 block->i_number SET_TO 0.0;
01621 else if (block->j_flag IS OFF)
01622 block->j_number SET_TO 0.0;
01623 }
01624 else if (settings->plane IS CANON_PLANE_YZ)
01625 {
01626 CHK((block->i_flag), NCE_I_WORD_GIVEN_FOR_ARC_IN_YZ_PLANE);
01627 if (block->j_flag IS OFF)
01628 block->j_number SET_TO 0.0;
01629 else if (block->k_flag IS OFF)
01630 block->k_number SET_TO 0.0;
01631 }
01632 else if (settings->plane IS CANON_PLANE_XZ)
01633 {
01634 CHK((block->j_flag), NCE_J_WORD_GIVEN_FOR_ARC_IN_XZ_PLANE);
01635 if (block->i_flag IS OFF)
01636 block->i_number SET_TO 0.0;
01637 else if (block->k_flag IS OFF)
01638 block->k_number SET_TO 0.0;
01639 }
01640 else
01641 ERM(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ);
01642 }
01643 else;
01644
01645 if (settings->plane IS CANON_PLANE_XY)
01646 {
01647 CHK(((block->x_flag IS OFF) AND (block->y_flag IS OFF)),
01648 NCE_X_AND_Y_WORDS_MISSING_FOR_ARC_IN_XY_PLANE);
01649 }
01650 else if (settings->plane IS CANON_PLANE_YZ)
01651 {
01652 CHK(((block->y_flag IS OFF) AND (block->z_flag IS OFF)),
01653 NCE_Y_AND_Z_WORDS_MISSING_FOR_ARC_IN_YZ_PLANE);
01654 }
01655 else if (settings->plane IS CANON_PLANE_XZ)
01656 {
01657 CHK(((block->x_flag IS OFF) AND (block->z_flag IS OFF)),
01658 NCE_X_AND_Z_WORDS_MISSING_FOR_ARC_IN_XZ_PLANE);
01659 }
01660
01661 find_ends(block, settings, &end_x, &end_y,
01662 &end_z
01663 #ifdef AA
01664 , &AA_end
01665 #endif
01666
01667 #ifdef BB
01668 , &BB_end
01669 #endif
01670
01671 #ifdef CC
01672 , &CC_end
01673 #endif
01674 );
01675 settings->motion_mode SET_TO move;
01676
01677 if (settings->plane IS CANON_PLANE_XY)
01678 {
01679 if ((settings->cutter_comp_side IS OFF) OR
01680 (settings->cutter_comp_radius IS 0.0))
01681 {
01682 status SET_TO
01683 convert_arc2(move, block, settings,
01684 &(settings->current_x), &(settings->current_y),
01685 &(settings->current_z), end_x, end_y,
01686 end_z
01687 #ifdef AA
01688 , AA_end
01689 #endif
01690
01691 #ifdef BB
01692 , BB_end
01693 #endif
01694
01695 #ifdef CC
01696 , CC_end
01697 #endif
01698 , block->i_number,
01699 block->j_number);
01700 CHP(status);
01701 }
01702 else if (first)
01703 {
01704 status SET_TO
01705 convert_arc_comp1(move, block, settings, end_x, end_y,
01706 end_z
01707 #ifdef AA
01708 , AA_end
01709 #endif
01710
01711 #ifdef BB
01712 , BB_end
01713 #endif
01714
01715 #ifdef CC
01716 , CC_end
01717 #endif
01718 );
01719 CHP(status);
01720 }
01721 else
01722 {
01723 status SET_TO
01724 convert_arc_comp2(move, block, settings, end_x, end_y,
01725 end_z
01726 #ifdef AA
01727 , AA_end
01728 #endif
01729
01730 #ifdef BB
01731 , BB_end
01732 #endif
01733
01734 #ifdef CC
01735 , CC_end
01736 #endif
01737 );
01738
01739 CHP(status);
01740 }
01741 }
01742 else if (settings->plane IS CANON_PLANE_XZ)
01743 {
01744 status SET_TO
01745 convert_arc2 (move, block, settings,
01746 &(settings->current_z), &(settings->current_x),
01747 &(settings->current_y), end_z, end_x,
01748 end_y
01749 #ifdef AA
01750 , AA_end
01751 #endif
01752
01753 #ifdef BB
01754 , BB_end
01755 #endif
01756
01757 #ifdef CC
01758 , CC_end
01759 #endif
01760 , block->k_number,
01761 block->i_number);
01762 CHP(status);
01763 }
01764 else if (settings->plane IS CANON_PLANE_YZ)
01765 {
01766 status SET_TO
01767 convert_arc2 (move, block, settings,
01768 &(settings->current_y), &(settings->current_z),
01769 &(settings->current_x), end_y, end_z,
01770 end_x
01771 #ifdef AA
01772 , AA_end
01773 #endif
01774
01775 #ifdef BB
01776 , BB_end
01777 #endif
01778
01779 #ifdef CC
01780 , CC_end
01781 #endif
01782 , block->j_number,
01783 block->k_number);
01784 CHP(status);
01785 }
01786 else
01787 ERM(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ);
01788 return RS274NGC_OK;
01789 }
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811 static int convert_arc2(
01812 int move,
01813 block_pointer block,
01814 setup_pointer settings,
01815 double * current1,
01816 double * current2,
01817 double * current3,
01818 double end1,
01819 double end2,
01820 double end3,
01821 #ifdef AA
01822 double AA_end,
01823 #endif
01824 #ifdef BB
01825 double BB_end,
01826 #endif
01827 #ifdef CC
01828 double CC_end,
01829 #endif
01830 double offset1,
01831 double offset2)
01832 {
01833 static char name[] SET_TO "convert_arc2";
01834 double center1;
01835 double center2;
01836 int status;
01837 double tolerance;
01838 int turn;
01839
01840 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
01841 TOLERANCE_INCH : TOLERANCE_MM;
01842
01843 if (block->r_flag)
01844 {
01845 CHP(arc_data_r(move, *current1, *current2, end1, end2,
01846 block->r_number, ¢er1, ¢er2, &turn));
01847 }
01848 else
01849 {
01850 CHP(arc_data_ijk(move, *current1, *current2, end1, end2, offset1,
01851 offset2, ¢er1, ¢er2, &turn, tolerance));
01852 }
01853
01854 if (settings->feed_mode IS INVERSE_TIME)
01855 inverse_time_rate_arc(*current1, *current2, *current3, center1, center2,
01856 turn, end1, end2, end3, block, settings);
01857 ARC_FEED(end1, end2, center1, center2, turn,
01858 end3
01859 #ifdef AA
01860 , AA_end
01861 #else
01862 #ifdef ALL_AXES
01863 , 0
01864 #endif
01865 #endif
01866 #ifdef BB
01867 , BB_end
01868 #else
01869 #ifdef ALL_AXES
01870 , 0
01871 #endif
01872 #endif
01873 #ifdef CC
01874 , CC_end
01875 #else
01876 #ifdef ALL_AXES
01877 , 0
01878 #endif
01879 #endif
01880 );
01881 *current1 SET_TO end1;
01882 *current2 SET_TO end2;
01883 *current3 SET_TO end3;
01884 #ifdef AA
01885 settings->AA_current SET_TO AA_end;
01886 #endif
01887 #ifdef BB
01888 settings->BB_current SET_TO BB_end;
01889 #endif
01890 #ifdef CC
01891 settings->CC_current SET_TO CC_end;
01892 #endif
01893 return RS274NGC_OK;
01894 }
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924 static int convert_arc_comp1(
01925 int move,
01926 block_pointer block,
01927 setup_pointer settings,
01928 double end_x,
01929 double end_y,
01930 double end_z
01931 #ifdef AA
01932 , double AA_end
01933 #endif
01934 #ifdef BB
01935 , double BB_end
01936 #endif
01937 #ifdef CC
01938 , double CC_end
01939 #endif
01940 )
01941 {
01942 static char name[] SET_TO "convert_arc_comp1";
01943 double center_x;
01944 double center_y;
01945 double gamma;
01946 int side;
01947 int status;
01948 double tolerance;
01949 double tool_radius;
01950 int turn;
01951
01952 side SET_TO settings->cutter_comp_side;
01953 tool_radius SET_TO settings->cutter_comp_radius;
01954 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
01955 TOLERANCE_INCH : TOLERANCE_MM;
01956
01957 CHK((hypot((end_x - settings->current_x),
01958 (end_y - settings->current_y)) <= tool_radius),
01959 NCE_CUTTER_GOUGING_WITH_CUTTER_RADIUS_COMP);
01960
01961 if (block->r_flag)
01962 {
01963 CHP(arc_data_comp_r(move, side, tool_radius, settings->current_x,
01964 settings->current_y, end_x, end_y, block->r_number,
01965 ¢er_x, ¢er_y, &turn));
01966 }
01967 else
01968 {
01969 CHP(arc_data_comp_ijk(move, side, tool_radius, settings->current_x,
01970 settings->current_y, end_x, end_y,
01971 block->i_number, block->j_number,
01972 ¢er_x, ¢er_y, &turn, tolerance));
01973 }
01974
01975 gamma SET_TO
01976 (((side IS LEFT) AND (move IS G_3)) OR
01977 ((side IS RIGHT) AND (move IS G_2))) ?
01978 atan2 ((center_y - end_y), (center_x - end_x)) :
01979 atan2 ((end_y - center_y), (end_x - center_x));
01980
01981 settings->program_x SET_TO end_x;
01982 settings->program_y SET_TO end_y;
01983 end_x SET_TO (end_x + (tool_radius * cos(gamma)));
01984 end_y SET_TO (end_y + (tool_radius * sin(gamma)));
01985
01986 if (settings->feed_mode IS INVERSE_TIME)
01987 inverse_time_rate_arc(settings->current_x, settings->current_y,
01988 settings->current_z, center_x, center_y, turn,
01989 end_x, end_y, end_z, block, settings);
01990 ARC_FEED(end_x, end_y, center_x, center_y, turn,
01991 end_z
01992 #ifdef AA
01993 , AA_end
01994 #else
01995 #ifdef ALL_AXES
01996 , 0
01997 #endif
01998 #endif
01999 #ifdef BB
02000 , BB_end
02001 #else
02002 #ifdef ALL_AXES
02003 , 0
02004 #endif
02005 #endif
02006 #ifdef CC
02007 , CC_end
02008 #else
02009 #ifdef ALL_AXES
02010 , 0
02011 #endif
02012 #endif
02013 );
02014 settings->current_x SET_TO end_x;
02015 settings->current_y SET_TO end_y;
02016 settings->current_z SET_TO end_z;
02017 #ifdef AA
02018 settings->AA_current SET_TO AA_end;
02019 #endif
02020 #ifdef BB
02021 settings->BB_current SET_TO BB_end;
02022 #endif
02023 #ifdef CC
02024 settings->CC_current SET_TO CC_end;
02025 #endif
02026
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
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069 static int convert_arc_comp2(
02070 int move,
02071 block_pointer block,
02072 setup_pointer settings,
02073 double end_x,
02074 double end_y,
02075 double end_z
02076 #ifdef AA
02077 , double AA_end
02078 #endif
02079 #ifdef BB
02080 , double BB_end
02081 #endif
02082 #ifdef CC
02083 , double CC_end
02084 #endif
02085 )
02086 {
02087 static char name[] SET_TO "convert_arc_comp2";
02088 double alpha;
02089 double arc_radius;
02090 double beta;
02091 double center_x;
02092 double center_y;
02093 double delta;
02094 double gamma;
02095 double mid_x;
02096 double mid_y;
02097 int side;
02098 double small SET_TO TOLERANCE_CONCAVE_CORNER;
02099 double start_x;
02100 double start_y;
02101 int status;
02102 double theta;
02103 double tolerance;
02104 double tool_radius;
02105 int turn;
02106
02107
02108
02109 start_x SET_TO settings->program_x;
02110 start_y SET_TO settings->program_y;
02111 tolerance SET_TO (settings->length_units IS CANON_UNITS_INCHES) ?
02112 TOLERANCE_INCH : TOLERANCE_MM;
02113
02114 if (block->r_flag)
02115 {
02116 CHP(arc_data_r(move, start_x, start_y, end_x, end_y,
02117 block->r_number, ¢er_x, ¢er_y, &turn));
02118 }
02119 else
02120 {
02121 CHP(arc_data_ijk(move, start_x, start_y, end_x, end_y,
02122 block->i_number, block->j_number,
02123 ¢er_x, ¢er_y, &turn, tolerance));
02124 }
02125
02126
02127 side SET_TO settings->cutter_comp_side;
02128 tool_radius SET_TO settings->cutter_comp_radius;
02129 arc_radius SET_TO hypot((center_x - end_x), (center_y - end_y));
02130 theta SET_TO
02131 atan2(settings->current_y - start_y, settings->current_x - start_x);
02132 theta SET_TO (side IS LEFT) ? (theta - PI2) : (theta + PI2);
02133 delta SET_TO atan2(center_y - start_y, center_x - start_x);
02134 alpha SET_TO (move IS G_3) ? (delta - PI2) : (delta + PI2);
02135 beta SET_TO (side IS LEFT) ? (theta - alpha) : (alpha - theta);
02136 beta SET_TO (beta > (1.5 * PI)) ? (beta - TWO_PI) :
02137 (beta < -PI2) ? (beta + TWO_PI) : beta;
02138
02139 if (((side IS LEFT) AND (move IS G_3)) OR
02140 ((side IS RIGHT) AND (move IS G_2)))
02141 {
02142 gamma SET_TO atan2 ((center_y - end_y), (center_x - end_x));
02143 CHK((arc_radius <= tool_radius),
02144 NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP);
02145 }
02146 else
02147 {
02148 gamma SET_TO atan2 ((end_y - center_y), (end_x - center_x));
02149 delta SET_TO (delta + PI);
02150 }
02151
02152 settings->program_x SET_TO end_x;
02153 settings->program_y SET_TO end_y;
02154 end_x SET_TO (end_x + (tool_radius * cos(gamma)));
02155 end_y SET_TO (end_y + (tool_radius * sin(gamma)));
02156
02157
02158
02159 CHK(((beta < -small) OR (beta > (PI + small))),
02160 NCE_CONCAVE_CORNER_WITH_CUTTER_RADIUS_COMP);
02161 if (beta > small)
02162 {
02163 mid_x SET_TO (start_x + (tool_radius * cos(delta)));
02164 mid_y SET_TO (start_y + (tool_radius * sin(delta)));
02165 if (settings->feed_mode IS INVERSE_TIME)
02166 inverse_time_rate_arc2(start_x, start_y, (side IS LEFT) ? -1 : 1,
02167 mid_x, mid_y, center_x, center_y, turn,
02168 end_x, end_y, end_z, block, settings);
02169 ARC_FEED(mid_x, mid_y, start_x, start_y, ((side IS LEFT) ? -1 : 1),
02170 settings->current_z
02171 #ifdef AA
02172 , AA_end
02173 #else
02174 #ifdef ALL_AXES
02175 , 0
02176 #endif
02177 #endif
02178 #ifdef BB
02179 , BB_end
02180 #else
02181 #ifdef ALL_AXES
02182 , 0
02183 #endif
02184 #endif
02185 #ifdef CC
02186 , CC_end
02187 #else
02188 #ifdef ALL_AXES
02189 , 0
02190 #endif
02191 #endif
02192 );
02193 ARC_FEED(end_x, end_y, center_x, center_y, turn,
02194 end_z
02195 #ifdef AA
02196 , AA_end
02197 #else
02198 #ifdef ALL_AXES
02199 , 0
02200 #endif
02201 #endif
02202 #ifdef BB
02203 , BB_end
02204 #else
02205 #ifdef ALL_AXES
02206 , 0
02207 #endif
02208 #endif
02209 #ifdef CC
02210 , CC_end
02211 #else
02212 #ifdef ALL_AXES
02213 , 0
02214 #endif
02215 #endif
02216 );
02217 }
02218 else
02219 {
02220 if (settings->feed_mode IS INVERSE_TIME)
02221 inverse_time_rate_arc(settings->current_x, settings->current_y,
02222 settings->current_z, center_x, center_y, turn,
02223 end_x, end_y, end_z, block, settings);
02224 ARC_FEED(end_x, end_y, center_x, center_y, turn,
02225 end_z
02226 #ifdef AA
02227 , AA_end
02228 #else
02229 #ifdef ALL_AXES
02230 , 0
02231 #endif
02232 #endif
02233 #ifdef BB
02234 , BB_end
02235 #else
02236 #ifdef ALL_AXES
02237 , 0
02238 #endif
02239 #endif
02240 #ifdef CC
02241 , CC_end
02242 #else
02243 #ifdef ALL_AXES
02244 , 0
02245 #endif
02246 #endif
02247 );
02248 }
02249
02250 settings->current_x SET_TO end_x;
02251 settings->current_y SET_TO end_y;
02252 settings->current_z SET_TO end_z;
02253 #ifdef AA
02254 settings->AA_current SET_TO AA_end;
02255 #endif
02256 #ifdef BB
02257 settings->BB_current SET_TO BB_end;
02258 #endif
02259 #ifdef CC
02260 settings->CC_current SET_TO CC_end;
02261 #endif
02262
02263 return RS274NGC_OK;
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
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325 static int convert_axis_offsets(
02326 int g_code,
02327 block_pointer block,
02328 setup_pointer settings)
02329 {
02330 static char name[] SET_TO "convert_axis_offsets";
02331 double * pars;
02332
02333 CHK((settings->cutter_comp_side ISNT OFF),
02334 NCE_CANNOT_CHANGE_AXIS_OFFSETS_WITH_CUTTER_RADIUS_COMP);
02335 pars SET_TO settings->parameters;
02336 if (g_code IS G_92)
02337 {
02338 if (block->x_flag IS ON)
02339 {
02340 settings->axis_offset_x SET_TO
02341 (settings->current_x + settings->axis_offset_x - block->x_number);
02342 settings->current_x SET_TO block->x_number;
02343 }
02344
02345 if (block->y_flag IS ON)
02346 {
02347 settings->axis_offset_y SET_TO
02348 (settings->current_y + settings->axis_offset_y - block->y_number);
02349 settings->current_y SET_TO block->y_number;
02350 }
02351
02352 if (block->z_flag IS ON)
02353 {
02354 settings->axis_offset_z SET_TO
02355 (settings->current_z + settings->axis_offset_z - block->z_number);
02356 settings->current_z SET_TO block->z_number;
02357 }
02358
02359 #ifdef AA
02360 if (block->a_flag IS ON)
02361 #endif
02362 #ifdef AA
02363 {settings->AA_axis_offset SET_TO (settings->AA_current +
02364 #endif
02365 #ifdef AA
02366 settings->AA_axis_offset - block->a_number);
02367 #endif
02368 #ifdef AA
02369 settings->AA_current SET_TO block->a_number;}
02370 #endif
02371
02372 #ifdef BB
02373 if (block->b_flag IS ON)
02374 #endif
02375 #ifdef BB
02376 {settings->BB_axis_offset SET_TO (settings->BB_current +
02377 #endif
02378 #ifdef BB
02379 settings->BB_axis_offset - block->b_number);
02380 #endif
02381 #ifdef BB
02382 settings->BB_current SET_TO block->b_number;}
02383 #endif
02384
02385 #ifdef CC
02386 if (block->c_flag IS ON)
02387 #endif
02388 #ifdef CC
02389 {settings->CC_axis_offset SET_TO (settings->CC_current +
02390 #endif
02391 #ifdef CC
02392 settings->CC_axis_offset - block->c_number);
02393 #endif
02394 #ifdef CC
02395 settings->CC_current SET_TO block->c_number;}
02396 #endif
02397
02398 SET_ORIGIN_OFFSETS(settings->origin_offset_x + settings->axis_offset_x,
02399 settings->origin_offset_y + settings->axis_offset_y,
02400 settings->origin_offset_z + settings->axis_offset_z
02401 #ifdef AA
02402 , (settings->AA_origin_offset + settings->AA_axis_offset)
02403 #else
02404 #ifdef ALL_AXES
02405 , 0
02406 #endif
02407 #endif
02408 #ifdef BB
02409 , (settings->BB_origin_offset + settings->BB_axis_offset)
02410 #else
02411 #ifdef ALL_AXES
02412 , 0
02413 #endif
02414 #endif
02415 #ifdef CC
02416 , (settings->CC_origin_offset + settings->CC_axis_offset)
02417 #else
02418 #ifdef ALL_AXES
02419 , 0
02420 #endif
02421 #endif
02422 );
02423 pars[5211] SET_TO settings->axis_offset_x;
02424 pars[5212] SET_TO settings->axis_offset_y;
02425 pars[5213] SET_TO settings->axis_offset_z;
02426 #ifdef AA
02427 pars[5214] SET_TO settings->AA_axis_offset;
02428 #endif
02429 #ifdef BB
02430 pars[5215] SET_TO settings->BB_axis_offset;
02431 #endif
02432 #ifdef CC
02433 pars[5216] SET_TO settings->CC_axis_offset;
02434 #endif
02435
02436 }
02437 else if ((g_code IS G_92_1) OR (g_code IS G_92_2))
02438 {
02439 settings->current_x SET_TO
02440 settings->current_x + settings->axis_offset_x;
02441 settings->current_y SET_TO
02442 settings->current_y + settings->axis_offset_y;
02443 settings->current_z SET_TO
02444 settings->current_z + settings->axis_offset_z;
02445 #ifdef AA
02446 settings->AA_current SET_TO
02447 #endif
02448 #ifdef AA
02449 (settings->AA_current + settings->AA_axis_offset);
02450 #endif
02451 #ifdef BB
02452 settings->BB_current SET_TO
02453 #endif
02454 #ifdef BB
02455 (settings->BB_current + settings->BB_axis_offset);
02456 #endif
02457 #ifdef CC
02458 settings->CC_current SET_TO
02459 #endif
02460 #ifdef CC
02461 (settings->CC_current + settings->CC_axis_offset);
02462 #endif
02463 SET_ORIGIN_OFFSETS(settings->origin_offset_x,
02464 settings->origin_offset_y,
02465 settings->origin_offset_z
02466 #ifdef AA
02467 , settings->AA_origin_offset
02468 #else
02469 #ifdef ALL_AXES
02470 , 0
02471 #endif
02472 #endif
02473 #ifdef BB
02474 , settings->BB_origin_offset
02475 #else
02476 #ifdef ALL_AXES
02477 , 0
02478 #endif
02479 #endif
02480 #ifdef CC
02481 , settings->CC_origin_offset
02482 #else
02483 #ifdef ALL_AXES
02484 , 0
02485 #endif
02486 #endif
02487 );
02488 settings->axis_offset_x SET_TO 0.0;
02489 settings->axis_offset_y SET_TO 0.0;
02490 settings->axis_offset_z SET_TO 0.0;
02491 #ifdef AA
02492 settings->AA_axis_offset SET_TO 0.0;
02493 #endif
02494 #ifdef BB
02495 settings->BB_axis_offset SET_TO 0.0;
02496 #endif
02497 #ifdef CC
02498 settings->CC_axis_offset SET_TO 0.0;
02499 #endif
02500 if (g_code IS G_92_1)
02501 {
02502 pars[5211] SET_TO 0.0;
02503 pars[5212] SET_TO 0.0;
02504 pars[5213] SET_TO 0.0;
02505 #ifdef AA
02506 pars[5214] SET_TO 0.0;
02507 #endif
02508 #ifdef BB
02509 pars[5215] SET_TO 0.0;
02510 #endif
02511 #ifdef CC
02512 pars[5216] SET_TO 0.0;
02513 #endif
02514 }
02515 }
02516 else if (g_code IS G_92_3)
02517 {
02518 settings->current_x SET_TO
02519 settings->current_x + settings->axis_offset_x - pars[5211];
02520 settings->current_y SET_TO
02521 settings->current_y + settings->axis_offset_y - pars[5212];
02522 settings->current_z SET_TO
02523 settings->current_z + settings->axis_offset_z - pars[5213];
02524 #ifdef AA
02525 settings->AA_current SET_TO
02526 #endif
02527 #ifdef AA
02528 settings->AA_current + settings->AA_axis_offset - pars[5214];
02529 #endif
02530 #ifdef BB
02531 settings->BB_current SET_TO
02532 #endif
02533 #ifdef BB
02534 settings->BB_current + settings->BB_axis_offset - pars[5215];
02535 #endif
02536 #ifdef CC
02537 settings->CC_current SET_TO
02538 #endif
02539 #ifdef CC
02540 settings->CC_current + settings->CC_axis_offset - pars[5216];
02541 #endif
02542 settings->axis_offset_x SET_TO pars[5211];
02543 settings->axis_offset_y SET_TO pars[5212];
02544 settings->axis_offset_z SET_TO pars[5213];
02545 #ifdef AA
02546 settings->AA_axis_offset SET_TO pars[5214];
02547 #endif
02548 #ifdef BB
02549 settings->BB_axis_offset SET_TO pars[5215];
02550 #endif
02551 #ifdef CC
02552 settings->CC_axis_offset SET_TO pars[5216];
02553 #endif
02554 SET_ORIGIN_OFFSETS(settings->origin_offset_x + settings->axis_offset_x,
02555 settings->origin_offset_y + settings->axis_offset_y,
02556 settings->origin_offset_z + settings->axis_offset_z
02557 #ifdef AA
02558 , (settings->AA_origin_offset + settings->AA_axis_offset)
02559 #else
02560 #ifdef ALL_AXES
02561 , 0
02562 #endif
02563 #endif
02564 #ifdef BB
02565 , (settings->BB_origin_offset + settings->BB_axis_offset)
02566 #else
02567 #ifdef ALL_AXES
02568 , 0
02569 #endif
02570 #endif
02571 #ifdef CC
02572 , (settings->CC_origin_offset + settings->CC_axis_offset)
02573 #else
02574 #ifdef ALL_AXES
02575 , 0
02576 #endif
02577 #endif
02578 );
02579 }
02580 else
02581 ERM(NCE_BUG_CODE_NOT_IN_G92_SERIES);
02582
02583 return RS274NGC_OK;
02584 }
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609 static int convert_comment(
02610 char * comment)
02611 {
02612 int m;
02613 int item;
02614
02615 for (m SET_TO 0; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
02616 if ((item ISNT 'M') AND (item ISNT 'm'))
02617 {
02618 COMMENT(comment);
02619 return RS274NGC_OK;
02620 }
02621 for (m++; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
02622 if ((item ISNT 'S') AND (item ISNT 's'))
02623 {
02624 COMMENT(comment);
02625 return RS274NGC_OK;
02626 }
02627 for (m++; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
02628 if ((item ISNT 'G') AND (item ISNT 'g'))
02629 {
02630 COMMENT(comment);
02631 return RS274NGC_OK;
02632 }
02633 for (m++; ((item SET_TO comment[m]) IS ' ') OR (item IS '\t') ; m++);
02634 if (item ISNT ',')
02635 {
02636 COMMENT(comment);
02637 return RS274NGC_OK;
02638 }
02639 MESSAGE(comment + m + 1);
02640 return RS274NGC_OK;
02641 }
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676 static int convert_control_mode(
02677 int g_code,
02678 setup_pointer settings)
02679 {
02680 static char name[] SET_TO "convert_control_mode";
02681 if (g_code IS G_61)
02682 {
02683 SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH);
02684 settings->control_mode SET_TO CANON_EXACT_PATH;
02685 }
02686 else if (g_code IS G_61_1)
02687 {
02688 SET_MOTION_CONTROL_MODE(CANON_EXACT_STOP);
02689 settings->control_mode SET_TO CANON_EXACT_STOP;
02690 }
02691 else if (g_code IS G_64)
02692 {
02693 SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS);
02694 settings->control_mode SET_TO CANON_CONTINUOUS;
02695 }
02696 else
02697 ERM(NCE_BUG_CODE_NOT_G61_G61_1_OR_G64);
02698 return RS274NGC_OK;
02699 }
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772 static int convert_coordinate_system(
02773 int g_code,
02774 setup_pointer settings)
02775 {
02776 static char name[] SET_TO "convert_coordinate_system";
02777 int origin;
02778 double x;
02779 double y;
02780 double z;
02781 #ifdef AA
02782 double a;
02783 #endif
02784 #ifdef BB
02785 double b;
02786 #endif
02787 #ifdef CC
02788 double c;
02789 #endif
02790 double * parameters;
02791
02792 parameters SET_TO settings->parameters;
02793 switch(g_code)
02794 {
02795 case 540:
02796 origin SET_TO 1;
02797 break;
02798 case 550:
02799 origin SET_TO 2;
02800 break;
02801 case 560:
02802 origin SET_TO 3;
02803 break;
02804 case 570:
02805 origin SET_TO 4;
02806 break;
02807 case 580:
02808 origin SET_TO 5;
02809 break;
02810 case 590:
02811 origin SET_TO 6;
02812 break;
02813 case 591:
02814 origin SET_TO 7;
02815 break;
02816 case 592:
02817 origin SET_TO 8;
02818 break;
02819 case 593:
02820 origin SET_TO 9;
02821 break;
02822 default:
02823 ERM(NCE_BUG_CODE_NOT_IN_RANGE_G54_TO_G593);
02824 }
02825
02826 if (origin IS settings->origin_index)
02827 {
02828 #ifdef DEBUG_EMC
02829 COMMENT("interpreter: continuing to use same coordinate system");
02830 #endif
02831 return RS274NGC_OK;
02832 }
02833
02834 settings->origin_index SET_TO origin;
02835 parameters[5220] SET_TO (double)origin;
02836
02837
02838
02839
02840 settings->current_x SET_TO
02841 (settings->current_x + settings->origin_offset_x);
02842 settings->current_y SET_TO
02843 (settings->current_y + settings->origin_offset_y);
02844 settings->current_z SET_TO
02845 (settings->current_z + settings->origin_offset_z);
02846 #ifdef AA
02847 settings->AA_current SET_TO
02848 #endif
02849 #ifdef AA
02850 (settings->AA_current + settings->AA_origin_offset);
02851 #endif
02852 #ifdef BB
02853 settings->BB_current SET_TO
02854 #endif
02855 #ifdef BB
02856 (settings->BB_current + settings->BB_origin_offset);
02857 #endif
02858 #ifdef CC
02859 settings->CC_current SET_TO
02860 #endif
02861 #ifdef CC
02862 (settings->CC_current + settings->CC_origin_offset);
02863 #endif
02864
02865 x SET_TO parameters[5201 + (origin * 20)];
02866 y SET_TO parameters[5202 + (origin * 20)];
02867 z SET_TO parameters[5203 + (origin * 20)];
02868 #ifdef AA
02869 a SET_TO parameters[5204 + (origin * 20)];
02870 #endif
02871 #ifdef BB
02872 b SET_TO parameters[5205 + (origin * 20)];
02873 #endif
02874 #ifdef CC
02875 c SET_TO parameters[5206 + (origin * 20)];
02876 #endif
02877
02878 settings->origin_offset_x SET_TO x;
02879 settings->origin_offset_y SET_TO y;
02880 settings->origin_offset_z SET_TO z;
02881 #ifdef AA
02882 settings->AA_origin_offset SET_TO a;
02883 #endif
02884 #ifdef BB
02885 settings->BB_origin_offset SET_TO b;
02886 #endif
02887 #ifdef CC
02888 settings->CC_origin_offset SET_TO c;
02889 #endif
02890
02891 settings->current_x SET_TO (settings->current_x - x);
02892 settings->current_y SET_TO (settings->current_y - y);
02893 settings->current_z SET_TO (settings->current_z - z);
02894 #ifdef AA
02895 settings->AA_current SET_TO (settings->AA_current - a);
02896 #endif
02897 #ifdef BB
02898 settings->BB_current SET_TO (settings->BB_current - b);
02899 #endif
02900 #ifdef CC
02901 settings->CC_current SET_TO (settings->CC_current - c);
02902 #endif
02903
02904 SET_ORIGIN_OFFSETS(x + settings->axis_offset_x,
02905 y + settings->axis_offset_y,
02906 z + settings->axis_offset_z
02907 #ifdef AA
02908 , a + settings->AA_axis_offset
02909 #else
02910 #ifdef ALL_AXES
02911 , 0
02912 #endif
02913 #endif
02914 #ifdef BB
02915 , b + settings->BB_axis_offset
02916 #else
02917 #ifdef ALL_AXES
02918 , 0
02919 #endif
02920 #endif
02921 #ifdef CC
02922 , c + settings->CC_axis_offset
02923 #else
02924 #ifdef ALL_AXES
02925 , 0
02926 #endif
02927 #endif
02928 );
02929 return RS274NGC_OK;
02930 }
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957 static int convert_cutter_compensation(
02958 int g_code,
02959 block_pointer block,
02960 setup_pointer settings)
02961 {
02962 static char name[] SET_TO "convert_cutter_compensation";
02963 int status;
02964
02965 if (g_code IS G_40)
02966 {
02967 CHP(convert_cutter_compensation_off(settings));
02968 }
02969 else if (g_code IS G_41)
02970 {
02971 CHP(convert_cutter_compensation_on(LEFT, block, settings));
02972 }
02973 else if (g_code IS G_42)
02974 {
02975 CHP(convert_cutter_compensation_on(RIGHT, block, settings));
02976 }
02977 else
02978 ERM(NCE_BUG_CODE_NOT_G40_G41_OR_G42);
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 static int convert_cutter_compensation_off(
03001 setup_pointer settings)
03002 {
03003 #ifdef DEBUG_EMC
03004 COMMENT("interpreter: cutter radius compensation off");
03005 #endif
03006 settings->cutter_comp_side SET_TO OFF;
03007 settings->program_x SET_TO UNKNOWN;
03008 return RS274NGC_OK;
03009 }
03010
03011
03012
03013
03014
03015
03016
03017
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063 static int convert_cutter_compensation_on(
03064 int side,
03065 block_pointer block,
03066 setup_pointer settings)
03067 {
03068 static char name[] SET_TO "convert_cutter_compensation_on";
03069 double radius;
03070 int index;
03071
03072 CHK((settings->plane ISNT CANON_PLANE_XY),
03073 NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_OUT_OF_XY_PLANE);
03074 CHK((settings->cutter_comp_side ISNT OFF),
03075 NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_WHEN_ON);
03076 index SET_TO
03077 (block->d_number ISNT -1) ? block->d_number : settings->current_slot;
03078 radius SET_TO ((settings->tool_table[index].diameter)/2.0);
03079
03080 if (radius < 0.0)
03081 {
03082 radius SET_TO -radius;
03083 if (side IS RIGHT)
03084 side SET_TO LEFT;
03085 else
03086 side SET_TO RIGHT;
03087 }
03088
03089 #ifdef DEBUG_EMC
03090 if (side IS RIGHT)
03091 COMMENT("interpreter: cutter radius compensation on right");
03092 else
03093 COMMENT("interpreter: cutter radius compensation on left");
03094 #endif
03095
03096 settings->cutter_comp_radius SET_TO radius;
03097 settings->tool_table_index SET_TO index;
03098 settings->cutter_comp_side SET_TO side;
03099 return RS274NGC_OK;
03100 }
03101
03102
03103
03104
03105
03106
03107
03108
03109
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132 static int convert_cycle(
03133 int motion,
03134 block_pointer block,
03135 setup_pointer settings)
03136 {
03137 static char name[] SET_TO "convert_cycle";
03138 CANON_PLANE plane;
03139 int status;
03140
03141 plane SET_TO settings->plane;
03142 if (block->r_flag IS OFF)
03143 {
03144 if (settings->motion_mode IS motion)
03145 block->r_number SET_TO settings->cycle_r;
03146 else
03147 ERM(NCE_R_CLEARANCE_PLANE_UNSPECIFIED_IN_CYCLE);
03148 }
03149
03150 CHK((block->l_number IS 0), NCE_CANNOT_DO_ZERO_REPEATS_OF_CYCLE);
03151 if (block->l_number IS -1)
03152 block->l_number SET_TO 1;
03153
03154 if (plane IS CANON_PLANE_XY)
03155 {
03156 CHP(convert_cycle_xy(motion, block, settings));
03157 }
03158 else if (plane IS CANON_PLANE_YZ)
03159 {
03160 CHP(convert_cycle_yz(motion, block, settings));
03161 }
03162 else if (plane IS CANON_PLANE_XZ)
03163 {
03164 CHP(convert_cycle_zx(motion, block, settings));
03165 }
03166 else
03167 ERM(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ);
03168
03169 settings->cycle_l SET_TO block->l_number;
03170 settings->cycle_r SET_TO block->r_number;
03171 settings->motion_mode SET_TO motion;
03172 return RS274NGC_OK;
03173 }
03174
03175
03176
03177
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194
03195
03196
03197
03198
03199
03200
03201 static int convert_cycle_g81(
03202 CANON_PLANE plane,
03203 double x,
03204 double y,
03205 double clear_z,
03206 double bottom_z)
03207 {
03208 static char name[] SET_TO "convert_cycle_g81";
03209
03210 cycle_feed(plane, x, y, bottom_z);
03211 cycle_traverse(plane, x, y, clear_z);
03212
03213 return RS274NGC_OK;
03214 }
03215
03216
03217
03218
03219
03220
03221
03222
03223
03224
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239
03240
03241 static int convert_cycle_g82(
03242 CANON_PLANE plane,
03243 double x,
03244 double y,
03245 double clear_z,
03246 double bottom_z,
03247 double dwell)
03248 {
03249 static char name[] SET_TO "convert_cycle_g82";
03250
03251 cycle_feed(plane, x, y, bottom_z);
03252 DWELL(dwell);
03253 cycle_traverse(plane, x, y, clear_z);
03254
03255 return RS274NGC_OK;
03256 }
03257
03258
03259
03260
03261
03262
03263
03264
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 #define G83_RAPID_DELTA 0.010
03291
03292
03293 static int convert_cycle_g83(
03294 CANON_PLANE plane,
03295 double x,
03296 double y,
03297 double r,
03298 double clear_z,
03299 double bottom_z,
03300 double delta)
03301 {
03302 static char name[] SET_TO "convert_cycle_g83";
03303 double current_depth;
03304 double rapid_delta;
03305
03306 rapid_delta SET_TO G83_RAPID_DELTA;
03307 if (_setup.length_units IS CANON_UNITS_MM)
03308 rapid_delta SET_TO (rapid_delta * 25.4);
03309
03310 for (current_depth SET_TO (r - delta);
03311 current_depth > bottom_z;
03312 current_depth SET_TO (current_depth - delta))
03313 {
03314 cycle_feed(plane, x, y, current_depth);
03315 cycle_traverse(plane, x, y, clear_z);
03316 cycle_traverse(plane, x, y, current_depth + rapid_delta);
03317 }
03318 cycle_feed(plane, x, y, bottom_z);
03319 cycle_traverse(plane, x, y, clear_z);
03320
03321 return RS274NGC_OK;
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
03358 static int convert_cycle_g84(
03359 CANON_PLANE plane,
03360 double x,
03361 double y,
03362 double clear_z,
03363 double bottom_z,
03364 CANON_DIRECTION direction,
03365 CANON_SPEED_FEED_MODE mode)
03366 {
03367 static char name[] SET_TO "convert_cycle_g84";
03368
03369 CHK((direction ISNT CANON_CLOCKWISE),
03370 NCE_SPINDLE_NOT_TURNING_CLOCKWISE_IN_G84);
03371 START_SPEED_FEED_SYNCH();
03372 cycle_feed(plane, x, y, bottom_z);
03373 STOP_SPINDLE_TURNING();
03374 START_SPINDLE_COUNTERCLOCKWISE();
03375 cycle_feed(plane, x, y, clear_z);
03376 if (mode ISNT CANON_SYNCHED)
03377 STOP_SPEED_FEED_SYNCH();
03378 STOP_SPINDLE_TURNING();
03379 START_SPINDLE_CLOCKWISE();
03380
03381 return RS274NGC_OK;
03382 }
03383
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396
03397
03398
03399
03400
03401
03402
03403
03404
03405
03406
03407
03408
03409 static int convert_cycle_g85(
03410 CANON_PLANE plane,
03411 double x,
03412 double y,
03413 double clear_z,
03414 double bottom_z)
03415 {
03416 static char name[] SET_TO "convert_cycle_g85";
03417
03418 cycle_feed(plane, x, y, bottom_z);
03419 cycle_feed(plane, x, y, clear_z);
03420
03421 return RS274NGC_OK;
03422 }
03423
03424
03425
03426
03427
03428
03429
03430
03431
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444
03445
03446
03447
03448
03449
03450
03451
03452
03453
03454
03455 static int convert_cycle_g86(
03456 CANON_PLANE plane,
03457 double x,
03458 double y,
03459 double clear_z,
03460 double bottom_z,
03461 double dwell,
03462 CANON_DIRECTION direction)
03463 {
03464 static char name[] SET_TO "convert_cycle_g86";
03465
03466 CHK(((direction ISNT CANON_CLOCKWISE) AND
03467 (direction ISNT CANON_COUNTERCLOCKWISE)),
03468 NCE_SPINDLE_NOT_TURNING_IN_G86);
03469
03470 cycle_feed(plane, x, y, bottom_z);
03471 DWELL(dwell);
03472 STOP_SPINDLE_TURNING();
03473 cycle_traverse(plane, x, y, clear_z);
03474 if (direction IS CANON_CLOCKWISE)
03475 START_SPINDLE_CLOCKWISE();
03476 else
03477 START_SPINDLE_COUNTERCLOCKWISE();
03478
03479 return RS274NGC_OK;
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
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541 static int convert_cycle_g87(
03542 CANON_PLANE plane,
03543 double x,
03544 double offset_x,
03545 double y,
03546 double offset_y,
03547 double r,
03548 double clear_z,
03549 double middle_z,
03550 double bottom_z,
03551 CANON_DIRECTION direction)
03552 {
03553 static char name[] SET_TO "convert_cycle_g87";
03554
03555 CHK(((direction ISNT CANON_CLOCKWISE) AND
03556 (direction ISNT CANON_COUNTERCLOCKWISE)),
03557 NCE_SPINDLE_NOT_TURNING_IN_G87);
03558
03559 cycle_traverse(plane, offset_x, offset_y, r);
03560 STOP_SPINDLE_TURNING();
03561 ORIENT_SPINDLE(0.0, direction);
03562 cycle_traverse(plane, offset_x, offset_y, bottom_z);
03563 cycle_traverse(plane, x, y, bottom_z);
03564 if (direction IS CANON_CLOCKWISE)
03565 START_SPINDLE_CLOCKWISE();
03566 else
03567 START_SPINDLE_COUNTERCLOCKWISE();
03568 cycle_feed(plane, x, y, middle_z);
03569 cycle_feed(plane, x, y, bottom_z);
03570 STOP_SPINDLE_TURNING();
03571 ORIENT_SPINDLE(0.0, direction);
03572 cycle_traverse(plane, offset_x, offset_y, bottom_z);
03573 cycle_traverse(plane, offset_x, offset_y, clear_z);
03574 cycle_traverse(plane, x, y, clear_z);
03575 if (direction IS CANON_CLOCKWISE)
03576 START_SPINDLE_CLOCKWISE();
03577 else
03578 START_SPINDLE_COUNTERCLOCKWISE();
03579
03580 return RS274NGC_OK;
03581 }
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591
03592
03593
03594
03595
03596
03597
03598
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608
03609
03610
03611
03612
03613 static int convert_cycle_g88(
03614 CANON_PLANE plane,
03615 double x,
03616 double y,
03617 double bottom_z,
03618 double dwell,
03619 CANON_DIRECTION direction)
03620 {
03621 static char name[] SET_TO "convert_cycle_g88";
03622
03623 CHK(((direction ISNT CANON_CLOCKWISE) AND
03624 (direction ISNT CANON_COUNTERCLOCKWISE)),
03625 NCE_SPINDLE_NOT_TURNING_IN_G88);
03626
03627 cycle_feed(plane, x, y, bottom_z);
03628 DWELL(dwell);
03629 STOP_SPINDLE_TURNING();
03630 PROGRAM_STOP();
03631 if (direction IS CANON_CLOCKWISE)
03632 START_SPINDLE_CLOCKWISE();
03633 else
03634 START_SPINDLE_COUNTERCLOCKWISE();
03635
03636 return RS274NGC_OK;
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 static int convert_cycle_g89(
03664 CANON_PLANE plane,
03665 double x,
03666 double y,
03667 double clear_z,
03668 double bottom_z,
03669 double dwell)
03670 {
03671 static char name[] SET_TO "convert_cycle_g89";
03672
03673 cycle_feed(plane, x, y, bottom_z);
03674 DWELL(dwell);
03675 cycle_feed(plane, x, y, clear_z);
03676
03677 return RS274NGC_OK;
03678 }
03679
03680
03681
03682
03683
03684
03685
03686
03687
03688
03689
03690
03691
03692
03693
03694
03695
03696
03697
03698
03699
03700
03701
03702
03703
03704
03705
03706
03707
03708
03709
03710
03711
03712
03713
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723
03724
03725
03726
03727
03728
03729
03730
03731
03732
03733
03734
03735
03736
03737
03738
03739
03740
03741
03742
03743
03744
03745
03746
03747
03748
03749
03750
03751
03752
03753
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 #define CYCLE_MACRO(call) for (repeat SET_TO block->l_number; \
03785 repeat > 0; \
03786 repeat--) \
03787 { \
03788 aa SET_TO (aa + aa_increment); \
03789 bb SET_TO (bb + bb_increment); \
03790 cycle_traverse(plane, aa, bb, old_cc); \
03791 if (old_cc ISNT r) \
03792 cycle_traverse(plane, aa, bb, r); \
03793 CHP(call); \
03794 old_cc SET_TO clear_cc; \
03795 }
03796
03797 static int convert_cycle_xy(
03798 int motion,
03799 block_pointer block,
03800 setup_pointer settings)
03801 {
03802 static char name[] SET_TO "convert_cycle_xy";
03803 double aa;
03804 double aa_increment;
03805 double bb;
03806 double bb_increment;
03807 double cc;
03808 double clear_cc;
03809 double i;
03810 double j;
03811 double k;
03812 double old_cc;
03813 CANON_PLANE plane;
03814 double r;
03815 int repeat;
03816 CANON_MOTION_MODE save_mode;
03817 int status;
03818
03819 plane SET_TO CANON_PLANE_XY;
03820 if (settings->motion_mode ISNT motion)
03821 {
03822 CHK((block->z_flag IS OFF),
03823 NCE_Z_VALUE_UNSPECIFIED_IN_XY_PLANE_CANNED_CYCLE);
03824 }
03825 block->z_number SET_TO
03826 block->z_flag IS ON ? block->z_number : settings->cycle_cc;
03827 old_cc SET_TO settings->current_z;
03828
03829 if (settings->distance_mode IS MODE_ABSOLUTE)
03830 {
03831 aa_increment SET_TO 0.0;
03832 bb_increment SET_TO 0.0;
03833 r SET_TO block->r_number;
03834 cc SET_TO block->z_number;
03835 aa SET_TO block->x_flag IS ON ? block->x_number : settings->current_x;
03836 bb SET_TO block->y_flag IS ON ? block->y_number : settings->current_y;
03837 }
03838 else if (settings->distance_mode IS MODE_INCREMENTAL)
03839 {
03840 aa_increment SET_TO block->x_number;
03841 bb_increment SET_TO block->y_number;
03842 r SET_TO (block->r_number + old_cc);
03843 cc SET_TO (r + block->z_number);
03844 aa SET_TO settings->current_x;
03845 bb SET_TO settings->current_y;
03846 }
03847 else
03848 ERM(NCE_BUG_DISTANCE_MODE_NOT_G90_OR_G91);
03849 CHK((r < cc), NCE_R_LESS_THAN_Z_IN_CYCLE_IN_XY_PLANE);
03850
03851 if (old_cc < r)
03852 {
03853 STRAIGHT_TRAVERSE(settings->current_x, settings->current_y, r
03854 #ifdef AA
03855 , settings->AA_current
03856 #else
03857 #ifdef ALL_AXES
03858 , 0
03859 #endif
03860 #endif
03861 #ifdef BB
03862 , settings->BB_current
03863 #else
03864 #ifdef ALL_AXES
03865 , 0
03866 #endif
03867 #endif
03868 #ifdef CC
03869 , settings->CC_current
03870 #else
03871 #ifdef ALL_AXES
03872 , 0
03873 #endif
03874 #endif
03875 );
03876 old_cc SET_TO r;
03877 }
03878 clear_cc SET_TO (settings->retract_mode IS R_PLANE) ? r : old_cc;
03879
03880 save_mode SET_TO GET_EXTERNAL_MOTION_CONTROL_MODE();
03881 if (save_mode ISNT CANON_EXACT_PATH)
03882 SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH);
03883
03884 switch(motion)
03885 {
03886 case G_81:
03887 CYCLE_MACRO(convert_cycle_g81(CANON_PLANE_XY, aa, bb, clear_cc, cc))
03888 break;
03889 case G_82:
03890 CHK(((settings->motion_mode ISNT G_82) AND (block->p_number IS -1.0)),
03891 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G82);
03892 block->p_number SET_TO
03893 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
03894 CYCLE_MACRO(convert_cycle_g82 (CANON_PLANE_XY, aa, bb, clear_cc, cc,
03895 block->p_number))
03896 settings->cycle_p SET_TO block->p_number;
03897 break;
03898 case G_83:
03899 CHK(((settings->motion_mode ISNT G_83) AND (block->q_number IS -1.0)),
03900 NCE_Q_WORD_MISSING_WITH_G83);
03901 block->q_number SET_TO
03902 block->q_number IS -1.0 ? settings->cycle_q : block->q_number;
03903 CYCLE_MACRO(convert_cycle_g83 (CANON_PLANE_XY, aa, bb, r, clear_cc, cc,
03904 block->q_number))
03905 settings->cycle_q SET_TO block->q_number;
03906 break;
03907 case G_84:
03908 CYCLE_MACRO(convert_cycle_g84 (CANON_PLANE_XY, aa, bb, clear_cc, cc,
03909 settings->spindle_turning, settings->speed_feed_mode))
03910 break;
03911 case G_85:
03912 CYCLE_MACRO(convert_cycle_g85 (CANON_PLANE_XY, aa, bb, clear_cc, cc))
03913 break;
03914 case G_86:
03915 CHK(((settings->motion_mode ISNT G_86) AND (block->p_number IS -1.0)),
03916 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G86);
03917 block->p_number SET_TO
03918 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
03919 CYCLE_MACRO(convert_cycle_g86 (CANON_PLANE_XY, aa, bb, clear_cc, cc,
03920 block->p_number, settings->spindle_turning))
03921 settings->cycle_p SET_TO block->p_number;
03922 break;
03923 case G_87:
03924 if (settings->motion_mode ISNT G_87)
03925 {
03926 CHK((block->i_flag IS OFF), NCE_I_WORD_MISSING_WITH_G87);
03927 CHK((block->j_flag IS OFF), NCE_J_WORD_MISSING_WITH_G87);
03928 CHK((block->k_flag IS OFF), NCE_K_WORD_MISSING_WITH_G87);
03929 }
03930 i SET_TO block->i_flag IS ON ? block->i_number : settings->cycle_i;
03931 j SET_TO block->j_flag IS ON ? block->j_number : settings->cycle_j;
03932 k SET_TO block->k_flag IS ON ? block->k_number : settings->cycle_k;
03933 settings->cycle_i SET_TO i;
03934 settings->cycle_j SET_TO j;
03935 settings->cycle_k SET_TO k;
03936 if (settings->distance_mode IS MODE_INCREMENTAL)
03937 {
03938 k SET_TO (cc + k);
03939 }
03940 CYCLE_MACRO(convert_cycle_g87 (CANON_PLANE_XY, aa, (aa + i), bb,
03941 (bb + j), r, clear_cc, k, cc, settings->spindle_turning))
03942 break;
03943 case G_88:
03944 CHK(((settings->motion_mode ISNT G_88) AND (block->p_number IS -1.0)),
03945 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G88);
03946 block->p_number SET_TO
03947 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
03948 CYCLE_MACRO(convert_cycle_g88 (CANON_PLANE_XY, aa, bb, cc,
03949 block->p_number, settings->spindle_turning))
03950 settings->cycle_p SET_TO block->p_number;
03951 break;
03952 case G_89:
03953 CHK(((settings->motion_mode ISNT G_89) AND (block->p_number IS -1.0)),
03954 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G89);
03955 block->p_number SET_TO
03956 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
03957 CYCLE_MACRO(convert_cycle_g89 (CANON_PLANE_XY, aa, bb, clear_cc, cc,
03958 block->p_number))
03959 settings->cycle_p SET_TO block->p_number;
03960 break;
03961 default:
03962 ERM(NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
03963 }
03964 settings->current_x SET_TO aa;
03965 settings->current_y SET_TO bb;
03966 settings->current_z SET_TO clear_cc;
03967 settings->cycle_cc SET_TO block->z_number;
03968
03969 if (save_mode ISNT CANON_EXACT_PATH)
03970 SET_MOTION_CONTROL_MODE(save_mode);
03971
03972 return RS274NGC_OK;
03973 }
03974
03975
03976
03977
03978
03979
03980
03981
03982
03983
03984
03985
03986
03987
03988
03989
03990
03991
03992
03993
03994
03995
03996
03997
03998
03999
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009
04010
04011
04012
04013
04014
04015
04016
04017
04018
04019
04020
04021
04022
04023
04024 static int convert_cycle_yz(
04025 int motion,
04026 block_pointer block,
04027 setup_pointer settings)
04028 {
04029 static char name[] SET_TO "convert_cycle_yz";
04030 double aa;
04031 double aa_increment;
04032 double bb;
04033 double bb_increment;
04034 double cc;
04035 double clear_cc;
04036 double i;
04037 double j;
04038 double k;
04039 double old_cc;
04040 CANON_PLANE plane;
04041 double r;
04042 int repeat;
04043 CANON_MOTION_MODE save_mode;
04044 int status;
04045
04046 plane SET_TO CANON_PLANE_YZ;
04047 if (settings->motion_mode ISNT motion)
04048 {
04049 CHK((block->x_flag IS OFF),
04050 NCE_X_VALUE_UNSPECIFIED_IN_YZ_PLANE_CANNED_CYCLE);
04051 }
04052 block->x_number SET_TO
04053 block->x_flag IS ON ? block->x_number : settings->cycle_cc;
04054 old_cc SET_TO settings->current_x;
04055
04056 if (settings->distance_mode IS MODE_ABSOLUTE)
04057 {
04058 aa_increment SET_TO 0.0;
04059 bb_increment SET_TO 0.0;
04060 r SET_TO block->r_number;
04061 cc SET_TO block->x_number;
04062 aa SET_TO block->y_flag IS ON ? block->y_number : settings->current_y;
04063 bb SET_TO block->z_flag IS ON ? block->z_number : settings->current_z;
04064 }
04065 else if (settings->distance_mode IS MODE_INCREMENTAL)
04066 {
04067 aa_increment SET_TO block->y_number;
04068 bb_increment SET_TO block->z_number;
04069 r SET_TO (block->r_number + old_cc);
04070 cc SET_TO (r + block->x_number);
04071 aa SET_TO settings->current_y;
04072 bb SET_TO settings->current_z;
04073 }
04074 else
04075 ERM(NCE_BUG_DISTANCE_MODE_NOT_G90_OR_G91);
04076 CHK((r < cc), NCE_R_LESS_THAN_X_IN_CYCLE_IN_YZ_PLANE);
04077
04078 if (old_cc < r)
04079 {
04080 STRAIGHT_TRAVERSE(r, settings->current_y, settings->current_z
04081 #ifdef AA
04082 , settings->AA_current
04083 #else
04084 #ifdef ALL_AXES
04085 , 0
04086 #endif
04087 #endif
04088 #ifdef BB
04089 , settings->BB_current
04090 #else
04091 #ifdef ALL_AXES
04092 , 0
04093 #endif
04094 #endif
04095 #ifdef CC
04096 , settings->CC_current
04097 #else
04098 #ifdef ALL_AXES
04099 , 0
04100 #endif
04101 #endif
04102 );
04103 old_cc SET_TO r;
04104 }
04105 clear_cc SET_TO (settings->retract_mode IS R_PLANE) ? r : old_cc;
04106
04107 save_mode = GET_EXTERNAL_MOTION_CONTROL_MODE();
04108 if (save_mode ISNT CANON_EXACT_PATH)
04109 SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH);
04110
04111 switch(motion)
04112 {
04113 case G_81:
04114 CYCLE_MACRO(convert_cycle_g81(CANON_PLANE_YZ, aa, bb, clear_cc, cc))
04115 break;
04116 case G_82:
04117 CHK(((settings->motion_mode ISNT G_82) AND (block->p_number IS -1.0)),
04118 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G82);
04119 block->p_number SET_TO
04120 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04121 CYCLE_MACRO(convert_cycle_g82 (CANON_PLANE_YZ, aa, bb, clear_cc, cc,
04122 block->p_number))
04123 settings->cycle_p SET_TO block->p_number;
04124 break;
04125 case G_83:
04126 CHK(((settings->motion_mode ISNT G_83) AND (block->q_number IS -1.0)),
04127 NCE_Q_WORD_MISSING_WITH_G83);
04128 block->q_number SET_TO
04129 block->q_number IS -1.0 ? settings->cycle_q : block->q_number;
04130 CYCLE_MACRO(convert_cycle_g83 (CANON_PLANE_YZ, aa, bb, r, clear_cc, cc,
04131 block->q_number))
04132 settings->cycle_q SET_TO block->q_number;
04133 break;
04134 case G_84:
04135 CYCLE_MACRO(convert_cycle_g84 (CANON_PLANE_YZ, aa, bb, clear_cc, cc,
04136 settings->spindle_turning, settings->speed_feed_mode))
04137 break;
04138 case G_85:
04139 CYCLE_MACRO(convert_cycle_g85 (CANON_PLANE_YZ, aa, bb, clear_cc, cc))
04140 break;
04141 case G_86:
04142 CHK(((settings->motion_mode ISNT G_86) AND (block->p_number IS -1.0)),
04143 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G86);
04144 block->p_number SET_TO
04145 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04146 CYCLE_MACRO(convert_cycle_g86 (CANON_PLANE_YZ, aa, bb, clear_cc, cc,
04147 block->p_number, settings->spindle_turning))
04148 settings->cycle_p SET_TO block->p_number;
04149 break;
04150 case G_87:
04151 if (settings->motion_mode ISNT G_87)
04152 {
04153 CHK((block->i_flag IS OFF), NCE_I_WORD_MISSING_WITH_G87);
04154 CHK((block->j_flag IS OFF), NCE_J_WORD_MISSING_WITH_G87);
04155 CHK((block->k_flag IS OFF), NCE_K_WORD_MISSING_WITH_G87);
04156 }
04157 i SET_TO block->i_flag IS ON ? block->i_number : settings->cycle_i;
04158 j SET_TO block->j_flag IS ON ? block->j_number : settings->cycle_j;
04159 k SET_TO block->k_flag IS ON ? block->k_number : settings->cycle_k;
04160 settings->cycle_i SET_TO i;
04161 settings->cycle_j SET_TO j;
04162 settings->cycle_k SET_TO k;
04163 if (settings->distance_mode IS MODE_INCREMENTAL)
04164 {
04165 i SET_TO (cc + i);
04166 }
04167 CYCLE_MACRO(convert_cycle_g87 (CANON_PLANE_YZ, aa, (aa + j), bb,
04168 (bb + k), r, clear_cc, i, cc, settings->spindle_turning))
04169 break;
04170 case G_88:
04171 CHK(((settings->motion_mode ISNT G_88) AND (block->p_number IS -1.0)),
04172 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G88);
04173 block->p_number SET_TO
04174 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04175 CYCLE_MACRO(convert_cycle_g88 (CANON_PLANE_YZ, aa, bb, cc,
04176 block->p_number, settings->spindle_turning))
04177 settings->cycle_p SET_TO block->p_number;
04178 break;
04179 case G_89:
04180 CHK(((settings->motion_mode ISNT G_89) AND (block->p_number IS -1.0)),
04181 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G89);
04182 block->p_number SET_TO
04183 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04184 CYCLE_MACRO(convert_cycle_g89 (CANON_PLANE_YZ, aa, bb, clear_cc, cc,
04185 block->p_number))
04186 settings->cycle_p SET_TO block->p_number;
04187 break;
04188 default:
04189 ERM(NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
04190 }
04191 settings->current_y SET_TO aa;
04192 settings->current_z SET_TO bb;
04193 settings->current_x SET_TO clear_cc;
04194 settings->cycle_cc SET_TO block->x_number;
04195
04196 if (save_mode ISNT CANON_EXACT_PATH)
04197 SET_MOTION_CONTROL_MODE(save_mode);
04198
04199 return RS274NGC_OK;
04200 }
04201
04202
04203
04204
04205
04206
04207
04208
04209
04210
04211
04212
04213
04214
04215
04216
04217
04218
04219
04220
04221
04222
04223
04224
04225
04226
04227
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 static int convert_cycle_zx(
04260 int motion,
04261 block_pointer block,
04262 setup_pointer settings)
04263 {
04264 static char name[] SET_TO "convert_cycle_zx";
04265 double aa;
04266 double aa_increment;
04267 double bb;
04268 double bb_increment;
04269 double cc;
04270 double clear_cc;
04271 double i;
04272 double j;
04273 double k;
04274 double old_cc;
04275 CANON_PLANE plane;
04276 double r;
04277 int repeat;
04278 CANON_MOTION_MODE save_mode;
04279 int status;
04280
04281 plane SET_TO CANON_PLANE_XZ;
04282 if (settings->motion_mode ISNT motion)
04283 {
04284 CHK((block->y_flag IS OFF),
04285 NCE_Y_VALUE_UNSPECIFIED_IN_XZ_PLANE_CANNED_CYCLE);
04286 }
04287 block->y_number SET_TO
04288 block->y_flag IS ON ? block->y_number : settings->cycle_cc;
04289 old_cc SET_TO settings->current_y;
04290
04291 if (settings->distance_mode IS MODE_ABSOLUTE)
04292 {
04293 aa_increment SET_TO 0.0;
04294 bb_increment SET_TO 0.0;
04295 r SET_TO block->r_number;
04296 cc SET_TO block->y_number;
04297 aa SET_TO block->z_flag IS ON ? block->z_number : settings->current_z;
04298 bb SET_TO block->x_flag IS ON ? block->x_number : settings->current_x;
04299 }
04300 else if (settings->distance_mode IS MODE_INCREMENTAL)
04301 {
04302 aa_increment SET_TO block->z_number;
04303 bb_increment SET_TO block->x_number;
04304 r SET_TO (block->r_number + old_cc);
04305 cc SET_TO (r + block->y_number);
04306 aa SET_TO settings->current_z;
04307 bb SET_TO settings->current_x;
04308 }
04309 else
04310 ERM(NCE_BUG_DISTANCE_MODE_NOT_G90_OR_G91);
04311 CHK((r < cc), NCE_R_LESS_THAN_Y_IN_CYCLE_IN_XZ_PLANE);
04312
04313 if (old_cc < r)
04314 {
04315 STRAIGHT_TRAVERSE(settings->current_x, r, settings->current_z
04316 #ifdef AA
04317 , settings->AA_current
04318 #else
04319 #ifdef ALL_AXES
04320 , 0
04321 #endif
04322 #endif
04323 #ifdef BB
04324 , settings->BB_current
04325 #else
04326 #ifdef ALL_AXES
04327 , 0
04328 #endif
04329 #endif
04330 #ifdef CC
04331 , settings->CC_current
04332 #else
04333 #ifdef ALL_AXES
04334 , 0
04335 #endif
04336 #endif
04337 );
04338 old_cc SET_TO r;
04339 }
04340 clear_cc SET_TO (settings->retract_mode IS R_PLANE) ? r : old_cc;
04341
04342 save_mode = GET_EXTERNAL_MOTION_CONTROL_MODE();
04343 if (save_mode ISNT CANON_EXACT_PATH)
04344 SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH);
04345
04346 switch(motion)
04347 {
04348 case G_81:
04349 CYCLE_MACRO(convert_cycle_g81(CANON_PLANE_XZ, aa, bb, clear_cc, cc))
04350 break;
04351 case G_82:
04352 CHK(((settings->motion_mode ISNT G_82) AND (block->p_number IS -1.0)),
04353 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G82);
04354 block->p_number SET_TO
04355 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04356 CYCLE_MACRO(convert_cycle_g82 (CANON_PLANE_XZ, aa, bb, clear_cc, cc,
04357 block->p_number))
04358 settings->cycle_p SET_TO block->p_number;
04359 break;
04360 case G_83:
04361 CHK(((settings->motion_mode ISNT G_83) AND (block->q_number IS -1.0)),
04362 NCE_Q_WORD_MISSING_WITH_G83);
04363 block->q_number SET_TO
04364 block->q_number IS -1.0 ? settings->cycle_q : block->q_number;
04365 CYCLE_MACRO(convert_cycle_g83 (CANON_PLANE_XZ, aa, bb, r, clear_cc, cc,
04366 block->q_number))
04367 settings->cycle_q SET_TO block->q_number;
04368 break;
04369 case G_84:
04370 CYCLE_MACRO(convert_cycle_g84 (CANON_PLANE_XZ, aa, bb, clear_cc, cc,
04371 settings->spindle_turning, settings->speed_feed_mode))
04372 break;
04373 case G_85:
04374 CYCLE_MACRO(convert_cycle_g85 (CANON_PLANE_XZ, aa, bb, clear_cc, cc))
04375 break;
04376 case G_86:
04377 CHK(((settings->motion_mode ISNT G_86) AND (block->p_number IS -1.0)),
04378 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G86);
04379 block->p_number SET_TO
04380 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04381 CYCLE_MACRO(convert_cycle_g86 (CANON_PLANE_XZ, aa, bb, clear_cc, cc,
04382 block->p_number, settings->spindle_turning))
04383 settings->cycle_p SET_TO block->p_number;
04384 break;
04385 case G_87:
04386 if (settings->motion_mode ISNT G_87)
04387 {
04388 CHK((block->i_flag IS OFF), NCE_I_WORD_MISSING_WITH_G87);
04389 CHK((block->j_flag IS OFF), NCE_J_WORD_MISSING_WITH_G87);
04390 CHK((block->k_flag IS OFF), NCE_K_WORD_MISSING_WITH_G87);
04391 }
04392 i SET_TO block->i_flag IS ON ? block->i_number : settings->cycle_i;
04393 j SET_TO block->j_flag IS ON ? block->j_number : settings->cycle_j;
04394 k SET_TO block->k_flag IS ON ? block->k_number : settings->cycle_k;
04395 settings->cycle_i SET_TO i;
04396 settings->cycle_j SET_TO j;
04397 settings->cycle_k SET_TO k;
04398 if (settings->distance_mode IS MODE_INCREMENTAL)
04399 {
04400 j SET_TO (cc + j);
04401 }
04402 CYCLE_MACRO(convert_cycle_g87 (CANON_PLANE_XZ, aa, (aa + k), bb,
04403 (bb + i), r, clear_cc, j, cc, settings->spindle_turning))
04404 break;
04405 case G_88:
04406 CHK(((settings->motion_mode ISNT G_88) AND (block->p_number IS -1.0)),
04407 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G88);
04408 block->p_number SET_TO
04409 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04410 CYCLE_MACRO(convert_cycle_g88 (CANON_PLANE_XZ, aa, bb, cc,
04411 block->p_number, settings->spindle_turning))
04412 settings->cycle_p SET_TO block->p_number;
04413 break;
04414 case G_89:
04415 CHK(((settings->motion_mode ISNT G_89) AND (block->p_number IS -1.0)),
04416 NCE_DWELL_TIME_P_WORD_MISSING_WITH_G89);
04417 block->p_number SET_TO
04418 block->p_number IS -1.0 ? settings->cycle_p : block->p_number;
04419 CYCLE_MACRO(convert_cycle_g89 (CANON_PLANE_XZ, aa, bb, clear_cc, cc,
04420 block->p_number))
04421 settings->cycle_p SET_TO block->p_number;
04422 break;
04423 default:
04424 ERM(NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
04425 }
04426 settings->current_z SET_TO aa;
04427 settings->current_x SET_TO bb;
04428 settings->current_y SET_TO clear_cc;
04429 settings->cycle_cc SET_TO block->y_number;
04430
04431 if (save_mode ISNT CANON_EXACT_PATH)
04432 SET_MOTION_CONTROL_MODE(save_mode);
04433
04434 return RS274NGC_OK;
04435 }
04436
04437
04438
04439
04440
04441
04442
04443
04444
04445
04446
04447
04448
04449
04450
04451
04452
04453
04454
04455
04456
04457
04458
04459 static int convert_distance_mode(
04460 int g_code,
04461 setup_pointer settings)
04462 {
04463 static char name[] SET_TO "convert_distance_mode";
04464 if (g_code IS G_90)
04465 {
04466 if (settings->distance_mode ISNT MODE_ABSOLUTE)
04467 {
04468 #ifdef DEBUG_EMC
04469 COMMENT("interpreter: distance mode changed to absolute");
04470 #endif
04471 settings->distance_mode SET_TO MODE_ABSOLUTE;
04472 }
04473 }
04474 else if (g_code IS G_91)
04475 {
04476 if (settings->distance_mode ISNT MODE_INCREMENTAL)
04477 {
04478 #ifdef DEBUG_EMC
04479 COMMENT("interpreter: distance mode changed to incremental");
04480 #endif
04481 settings->distance_mode SET_TO MODE_INCREMENTAL;
04482 }
04483 }
04484 else
04485 ERM(NCE_BUG_CODE_NOT_G90_OR_G91);
04486 return RS274NGC_OK;
04487 }
04488
04489
04490
04491
04492
04493
04494
04495
04496
04497
04498
04499
04500
04501
04502 static int convert_dwell(
04503 double time)
04504 {
04505 DWELL(time);
04506 return RS274NGC_OK;
04507 }
04508
04509
04510
04511
04512
04513
04514
04515
04516
04517
04518
04519
04520
04521
04522
04523
04524
04525
04526
04527
04528
04529
04530
04531 static int convert_feed_mode(
04532 int g_code,
04533 setup_pointer settings)
04534 {
04535 static char name[] SET_TO "convert_feed_mode";
04536 if (g_code IS G_93)
04537 {
04538 #ifdef DEBUG_EMC
04539 COMMENT("interpreter: feed mode set to inverse time");
04540 #endif
04541 settings->feed_mode SET_TO INVERSE_TIME;
04542 }
04543 else if (g_code IS G_94)
04544 {
04545 #ifdef DEBUG_EMC
04546 COMMENT("interpreter: feed mode set to units per minute");
04547 #endif
04548 settings->feed_mode SET_TO UNITS_PER_MINUTE;
04549 }
04550 else
04551 ERM(NCE_BUG_CODE_NOT_G93_OR_G94);
04552 return RS274NGC_OK;
04553 }
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565
04566
04567
04568
04569
04570
04571
04572 static int convert_feed_rate(
04573 block_pointer block,
04574 setup_pointer settings)
04575 {
04576 SET_FEED_RATE(block->f_number);
04577 settings->feed_rate SET_TO block->f_number;
04578 return RS274NGC_OK;
04579 }
04580
04581
04582
04583
04584
04585
04586
04587
04588
04589
04590
04591
04592
04593
04594
04595
04596
04597
04598
04599
04600
04601
04602
04603
04604
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 static int convert_g(
04638 block_pointer block,
04639 setup_pointer settings)
04640 {
04641 static char name[] SET_TO "convert_g";
04642 int status;
04643
04644 if (block->g_modes[0] IS G_4)
04645 {
04646 CHP(convert_dwell(block->p_number));
04647 }
04648 if (block->g_modes[2] ISNT -1)
04649 {
04650 CHP(convert_set_plane(block->g_modes[2], settings));
04651 }
04652 if (block->g_modes[6] ISNT -1)
04653 {
04654 CHP(convert_length_units(block->g_modes[6], settings));
04655 }
04656 if (block->g_modes[7] ISNT -1)
04657 {
04658 CHP(convert_cutter_compensation(block->g_modes[7], block, settings));
04659 }
04660 if (block->g_modes[8] ISNT -1)
04661 {
04662 CHP(convert_tool_length_offset(block->g_modes[8], block, settings));
04663 }
04664 if (block->g_modes[12] ISNT -1)
04665 {
04666 CHP(convert_coordinate_system(block->g_modes[12], settings));
04667 }
04668 if (block->g_modes[13] ISNT -1)
04669 {
04670 CHP(convert_control_mode(block->g_modes[13], settings));
04671 }
04672 if (block->g_modes[3] ISNT -1)
04673 {
04674 CHP(convert_distance_mode(block->g_modes[3], settings));
04675 }
04676 if (block->g_modes[10] ISNT -1)
04677 {
04678 CHP(convert_retract_mode(block->g_modes[10], settings));
04679 }
04680 if (block->g_modes[0] ISNT -1)
04681 {
04682 CHP(convert_modal_0(block->g_modes[0], block, settings));
04683 }
04684 if (block->motion_to_be ISNT -1)
04685 {
04686 CHP(convert_motion(block->motion_to_be, block, settings));
04687 }
04688 return RS274NGC_OK;
04689 }
04690
04691
04692
04693
04694
04695
04696
04697
04698
04699
04700
04701
04702
04703
04704
04705
04706
04707
04708
04709
04710
04711
04712
04713
04714
04715
04716
04717
04718
04719
04720
04721 static int convert_home(
04722 int move,
04723 block_pointer block,
04724 setup_pointer settings)
04725 {
04726 static char name[] SET_TO "convert_home";
04727 double end_x;
04728 double end_y;
04729 double end_z;
04730 #ifdef AA
04731 double AA_end;
04732 #endif
04733 #ifdef AA
04734 double AA_end2;
04735 #endif
04736 #ifdef BB
04737 double BB_end;
04738 #endif
04739 #ifdef BB
04740 double BB_end2;
04741 #endif
04742 #ifdef CC
04743 double CC_end;
04744 #endif
04745 #ifdef CC
04746 double CC_end2;
04747 #endif
04748 double * parameters;
04749
04750 parameters SET_TO settings->parameters;
04751 find_ends(block, settings, &end_x, &end_y,
04752 &end_z
04753 #ifdef AA
04754 , &AA_end
04755 #endif
04756
04757 #ifdef BB
04758 , &BB_end
04759 #endif
04760
04761 #ifdef CC
04762 , &CC_end
04763 #endif
04764 );
04765
04766 CHK((settings->cutter_comp_side ISNT OFF),
04767 NCE_CANNOT_USE_G28_OR_G30_WITH_CUTTER_RADIUS_COMP);
04768 STRAIGHT_TRAVERSE(end_x, end_y, end_z
04769 #ifdef AA
04770 , AA_end
04771 #else
04772 #ifdef ALL_AXES
04773 , 0
04774 #endif
04775 #endif
04776 #ifdef BB
04777 , BB_end
04778 #else
04779 #ifdef ALL_AXES
04780 , 0
04781 #endif
04782 #endif
04783 #ifdef CC
04784 , CC_end
04785 #else
04786 #ifdef ALL_AXES
04787 , 0
04788 #endif
04789 #endif
04790 );
04791 if (move IS G_28)
04792 {
04793 find_relative
04794 (parameters[5161], parameters[5162], parameters[5163],
04795 #ifdef AA
04796 parameters[5164],
04797 #endif
04798 #ifdef BB
04799 parameters[5165],
04800 #endif
04801 #ifdef CC
04802 parameters[5166],
04803 #endif
04804 &end_x, &end_y, &end_z
04805 #ifdef AA
04806 , &AA_end2
04807 #endif
04808
04809 #ifdef BB
04810 , &BB_end2
04811 #endif
04812
04813 #ifdef CC
04814 , &CC_end2
04815 #endif
04816 , settings);
04817 }
04818 else if (move IS G_30)
04819 {
04820 find_relative
04821 (parameters[5181], parameters[5182], parameters[5183],
04822 #ifdef AA
04823 parameters[5184],
04824 #endif
04825 #ifdef BB
04826 parameters[5185],
04827 #endif
04828 #ifdef CC
04829 parameters[5186],
04830 #endif
04831 &end_x, &end_y, &end_z
04832 #ifdef AA
04833 , &AA_end2
04834 #endif
04835
04836 #ifdef BB
04837 , &BB_end2
04838 #endif
04839
04840 #ifdef CC
04841 , &CC_end2
04842 #endif
04843 , settings);
04844 }
04845 else
04846 ERM(NCE_BUG_CODE_NOT_G28_OR_G30);
04847 STRAIGHT_TRAVERSE(end_x, end_y, end_z
04848 #ifdef AA
04849 , AA_end
04850 #else
04851 #ifdef ALL_AXES
04852 , 0
04853 #endif
04854 #endif
04855 #ifdef BB
04856 , BB_end
04857 #else
04858 #ifdef ALL_AXES
04859 , 0
04860 #endif
04861 #endif
04862 #ifdef CC
04863 , CC_end
04864 #else
04865 #ifdef ALL_AXES
04866 , 0
04867 #endif
04868 #endif
04869 );
04870 settings->current_x SET_TO end_x;
04871 settings->current_y SET_TO end_y;
04872 settings->current_z SET_TO end_z;
04873 #ifdef AA
04874 settings->AA_current SET_TO AA_end2;
04875 #endif
04876 #ifdef BB
04877 settings->BB_current SET_TO BB_end2;
04878 #endif
04879 #ifdef CC
04880 settings->CC_current SET_TO CC_end2;
04881 #endif
04882 return RS274NGC_OK;
04883 }
04884
04885
04886
04887
04888
04889
04890
04891
04892
04893
04894
04895
04896
04897
04898
04899
04900
04901
04902
04903
04904
04905
04906
04907
04908
04909
04910
04911
04912
04913
04914
04915
04916
04917
04918
04919
04920
04921
04922
04923
04924
04925
04926
04927 static int convert_length_units(
04928 int g_code,
04929 setup_pointer settings)
04930 {
04931 static char name[] SET_TO "convert_length_units";
04932 CHK((settings->cutter_comp_side ISNT OFF),
04933 NCE_CANNOT_CHANGE_UNITS_WITH_CUTTER_RADIUS_COMP);
04934 if (g_code IS G_20)
04935 {
04936 USE_LENGTH_UNITS(CANON_UNITS_INCHES);
04937 if (settings->length_units ISNT CANON_UNITS_INCHES)
04938 {
04939 settings->length_units SET_TO CANON_UNITS_INCHES;
04940 settings->current_x SET_TO (settings->current_x * INCH_PER_MM);
04941 settings->current_y SET_TO (settings->current_y * INCH_PER_MM);
04942 settings->current_z SET_TO (settings->current_z * INCH_PER_MM);
04943 settings->axis_offset_x SET_TO
04944 (settings->axis_offset_x * INCH_PER_MM);
04945 settings->axis_offset_y SET_TO
04946 (settings->axis_offset_y * INCH_PER_MM);
04947 settings->axis_offset_z SET_TO
04948 (settings->axis_offset_z * INCH_PER_MM);
04949 settings->origin_offset_x SET_TO
04950 (settings->origin_offset_x * INCH_PER_MM);
04951 settings->origin_offset_y SET_TO
04952 (settings->origin_offset_y * INCH_PER_MM);
04953 settings->origin_offset_z SET_TO
04954 (settings->origin_offset_z * INCH_PER_MM);
04955 }
04956 }
04957 else if (g_code IS G_21)
04958 {
04959 USE_LENGTH_UNITS(CANON_UNITS_MM);
04960 if (settings->length_units ISNT CANON_UNITS_MM)
04961 {
04962 settings->length_units SET_TO CANON_UNITS_MM;
04963 settings->current_x SET_TO (settings->current_x * MM_PER_INCH);
04964 settings->current_y SET_TO (settings->current_y * MM_PER_INCH);
04965 settings->current_z SET_TO (settings->current_z * MM_PER_INCH);
04966 settings->axis_offset_x SET_TO
04967 (settings->axis_offset_x * MM_PER_INCH);
04968 settings->axis_offset_y SET_TO
04969 (settings->axis_offset_y * MM_PER_INCH);
04970 settings->axis_offset_z SET_TO
04971 (settings->axis_offset_z * MM_PER_INCH);
04972 settings->origin_offset_x SET_TO
04973 (settings->origin_offset_x * MM_PER_INCH);
04974 settings->origin_offset_y SET_TO
04975 (settings->origin_offset_y * MM_PER_INCH);
04976 settings->origin_offset_z SET_TO
04977 (settings->origin_offset_z * MM_PER_INCH);
04978 }
04979 }
04980 else
04981 ERM(NCE_BUG_CODE_NOT_G20_OR_G21);
04982 return RS274NGC_OK;
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 static int convert_m(
05014 block_pointer block,
05015 setup_pointer settings)
05016 {
05017 static char name[] SET_TO "convert_m";
05018 int status;
05019
05020 if (block->m_modes[6] ISNT -1)
05021 {
05022 CHP(convert_tool_change(settings));
05023 }
05024
05025 if (block->m_modes[7] IS 3)
05026 {
05027 START_SPINDLE_CLOCKWISE();
05028 settings->spindle_turning SET_TO CANON_CLOCKWISE;
05029 }
05030 else if (block->m_modes[7] IS 4)
05031 {
05032 START_SPINDLE_COUNTERCLOCKWISE();
05033 settings->spindle_turning SET_TO CANON_COUNTERCLOCKWISE;
05034 }
05035 else if (block->m_modes[7] IS 5)
05036 {
05037 STOP_SPINDLE_TURNING();
05038 settings->spindle_turning SET_TO CANON_STOPPED;
05039 }
05040
05041 if (block->m_modes[8] IS 7)
05042 {
05043 MIST_ON();
05044 settings->mist SET_TO ON;
05045 }
05046 else if (block->m_modes[8] IS 8)
05047 {
05048 FLOOD_ON();
05049 settings->flood SET_TO ON;
05050 }
05051 else if (block->m_modes[8] IS 9)
05052 {
05053 MIST_OFF();
05054 settings->mist SET_TO OFF;
05055 FLOOD_OFF();
05056 settings->flood SET_TO OFF;
05057 }
05058
05059
05060
05061
05062
05063
05064
05065
05066
05067
05068
05069
05070
05071
05072
05073
05074
05075
05076 if (block->m_modes[9] IS 48)
05077 {
05078 ENABLE_FEED_OVERRIDE();
05079 ENABLE_SPEED_OVERRIDE();
05080 settings->feed_override SET_TO ON;
05081 settings->speed_override SET_TO ON;
05082 }
05083 else if (block->m_modes[9] IS 49)
05084 {
05085 DISABLE_FEED_OVERRIDE();
05086 DISABLE_SPEED_OVERRIDE();
05087 settings->feed_override SET_TO OFF;
05088 settings->speed_override SET_TO OFF;
05089 }
05090
05091 return RS274NGC_OK;
05092 }
05093
05094
05095
05096
05097
05098
05099
05100
05101
05102
05103
05104
05105
05106
05107
05108
05109
05110
05111
05112
05113
05114
05115
05116
05117
05118
05119 static int convert_modal_0(
05120 int code,
05121 block_pointer block,
05122 setup_pointer settings)
05123 {
05124 static char name[] SET_TO "convert_modal_0";
05125 int status;
05126
05127 if (code IS G_10)
05128 {
05129 CHP(convert_setup(block, settings));
05130 }
05131 else if ((code IS G_28) OR (code IS G_30))
05132 {
05133 CHP(convert_home(code, block, settings));
05134 }
05135 else if ((code IS G_92) OR (code IS G_92_1) OR
05136 (code IS G_92_2) OR (code IS G_92_3))
05137 {
05138 CHP(convert_axis_offsets(code, block, settings));
05139 }
05140 else if ((code IS G_4) OR (code IS G_53));
05141 else
05142 ERM(NCE_BUG_CODE_NOT_G4_G10_G28_G30_G53_OR_G92_SERIES);
05143 return RS274NGC_OK;
05144 }
05145
05146
05147
05148
05149
05150
05151
05152
05153
05154
05155
05156
05157
05158
05159
05160
05161
05162
05163
05164
05165
05166
05167
05168
05169 static int convert_motion(
05170 int motion,
05171 block_pointer block,
05172 setup_pointer settings)
05173 {
05174 static char name[] SET_TO "convert_motion";
05175 int status;
05176
05177 if ((motion IS G_0) OR (motion IS G_1))
05178 {
05179 CHP(convert_straight(motion, block, settings));
05180 }
05181 else if ((motion IS G_3) OR (motion IS G_2))
05182 {
05183 CHP(convert_arc(motion, block, settings));
05184 }
05185 else if (motion IS G_38_2)
05186 {
05187 CHP(convert_probe(block, settings));
05188 }
05189 else if (motion IS G_80)
05190 {
05191 #ifdef DEBUG_EMC
05192 COMMENT("interpreter: motion mode set to none");
05193 #endif
05194 settings->motion_mode SET_TO G_80;
05195 }
05196 else if ((motion > G_80) AND (motion < G_90))
05197 {
05198 CHP(convert_cycle(motion, block, settings));
05199 }
05200 else
05201 ERM(NCE_BUG_UNKNOWN_MOTION_CODE);
05202
05203 return RS274NGC_OK;
05204 }
05205
05206
05207
05208
05209
05210
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
05240
05241
05242
05243 static int convert_probe(
05244 block_pointer block,
05245 setup_pointer settings)
05246 {
05247 static char name[] SET_TO "convert_probe";
05248 double distance;
05249 double end_x;
05250 double end_y;
05251 double end_z;
05252 #ifdef AA
05253 double AA_end;
05254 #endif
05255 #ifdef BB
05256 double BB_end;
05257 #endif
05258 #ifdef CC
05259 double CC_end;
05260 #endif
05261
05262 CHK((((block->x_flag IS OFF) AND (block->y_flag IS OFF)) AND
05263 (block->z_flag IS OFF)), NCE_X_Y_AND_Z_WORDS_ALL_MISSING_WITH_G38_2);
05264 CHK((settings->feed_mode IS INVERSE_TIME),
05265 NCE_CANNOT_PROBE_IN_INVERSE_TIME_FEED_MODE);
05266 CHK((settings->cutter_comp_side ISNT OFF),
05267 NCE_CANNOT_PROBE_WITH_CUTTER_RADIUS_COMP_ON);
05268 CHK((settings->feed_rate IS 0.0), NCE_CANNOT_PROBE_WITH_ZERO_FEED_RATE);
05269 find_ends(block, settings, &end_x, &end_y,
05270 &end_z
05271 #ifdef AA
05272 , &AA_end
05273 #endif
05274
05275 #ifdef BB
05276 , &BB_end
05277 #endif
05278
05279 #ifdef CC
05280 , &CC_end
05281 #endif
05282 );
05283 if (0
05284 #ifdef AA
05285 OR (AA_end ISNT settings->AA_current)
05286 #endif
05287 #ifdef BB
05288 OR (BB_end ISNT settings->BB_current)
05289 #endif
05290 #ifdef CC
05291 OR (CC_end ISNT settings->CC_current)
05292 #endif
05293 )
05294 ERM(NCE_CANNOT_MOVE_ROTARY_AXES_DURING_PROBING);
05295 distance SET_TO sqrt(pow((settings->current_x - end_x), 2) +
05296 pow((settings->current_y - end_y), 2) +
05297 pow((settings->current_z - end_z), 2));
05298 CHK((distance < ((settings->length_units IS CANON_UNITS_MM) ? 0.254 : 0.01)),
05299 NCE_START_POINT_TOO_CLOSE_TO_PROBE_POINT);
05300 TURN_PROBE_ON();
05301 STRAIGHT_PROBE(end_x, end_y, end_z
05302 #ifdef AA
05303 , AA_end
05304 #else
05305 #ifdef ALL_AXES
05306 , 0
05307 #endif
05308 #endif
05309 #ifdef BB
05310 , BB_end
05311 #else
05312 #ifdef ALL_AXES
05313 , 0
05314 #endif
05315 #endif
05316 #ifdef CC
05317 , CC_end
05318 #else
05319 #ifdef ALL_AXES
05320 , 0
05321 #endif
05322 #endif
05323 );
05324 TURN_PROBE_OFF();
05325 settings->motion_mode SET_TO G_38_2;
05326 settings->probe_flag SET_TO ON;
05327 return RS274NGC_OK;
05328 }
05329
05330
05331
05332
05333
05334
05335
05336
05337
05338
05339
05340
05341
05342
05343
05344
05345
05346
05347
05348
05349
05350
05351 static int convert_retract_mode(
05352 int g_code,
05353 setup_pointer settings)
05354 {
05355 static char name[] SET_TO "convert_retract_mode";
05356 if (g_code IS G_98)
05357 {
05358 #ifdef DEBUG_EMC
05359 COMMENT("interpreter: retract mode set to old_z");
05360 #endif
05361 settings->retract_mode SET_TO OLD_Z;
05362 }
05363 else if (g_code IS G_99)
05364 {
05365 #ifdef DEBUG_EMC
05366 COMMENT("interpreter: retract mode set to r_plane");
05367 #endif
05368 settings->retract_mode SET_TO R_PLANE;
05369 }
05370 else
05371 ERM(NCE_BUG_CODE_NOT_G98_OR_G99);
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 static int convert_setup(
05404 block_pointer block,
05405 setup_pointer settings)
05406 {
05407 static char name[] SET_TO "convert_setup";
05408 double x;
05409 double y;
05410 double z;
05411 #ifdef AA
05412 double a;
05413 #endif
05414 #ifdef BB
05415 double b;
05416 #endif
05417 #ifdef CC
05418 double c;
05419 #endif
05420 double * parameters;
05421 int p_int;
05422
05423 parameters SET_TO settings->parameters;
05424 p_int SET_TO (int)(block->p_number + 0.0001);
05425
05426 if (block->x_flag IS ON)
05427 {
05428 x SET_TO block->x_number;
05429 parameters[5201 + (p_int * 20)] SET_TO x;
05430 }
05431 else
05432 x SET_TO parameters[5201 + (p_int * 20)];
05433
05434 if (block->y_flag IS ON)
05435 {
05436 y SET_TO block->y_number;
05437 parameters[5202 + (p_int * 20)] SET_TO y;
05438 }
05439 else
05440 y SET_TO parameters[5202 + (p_int * 20)];
05441 if (block->z_flag IS ON)
05442 {
05443 z SET_TO block->z_number;
05444 parameters[5203 + (p_int * 20)] SET_TO z;
05445 }
05446 else
05447 z SET_TO parameters[5203 + (p_int * 20)];
05448
05449 #ifdef AA
05450 if (block->a_flag IS ON)
05451 {
05452 a SET_TO block->a_number;
05453 parameters[5204 + (p_int * 20)] SET_TO a;
05454 }
05455 else
05456 a SET_TO parameters[5204 + (p_int * 20)];
05457 #endif
05458
05459 #ifdef BB
05460 if (block->b_flag IS ON)
05461 {
05462 b SET_TO block->b_number;
05463 parameters[5205 + (p_int * 20)] SET_TO b;
05464 }
05465 else
05466 b SET_TO parameters[5205 + (p_int * 20)];
05467 #endif
05468
05469 #ifdef CC
05470 if (block->c_flag IS ON)
05471 {
05472 c SET_TO block->c_number;
05473 parameters[5206 + (p_int * 20)] SET_TO c;
05474 }
05475 else
05476 c SET_TO parameters[5206 + (p_int * 20)];
05477 #endif
05478
05479
05480
05481
05482 if (p_int IS settings->origin_index)
05483 {
05484 settings->current_x SET_TO
05485 (settings->current_x + settings->origin_offset_x);
05486 settings->current_y SET_TO
05487 (settings->current_y + settings->origin_offset_y);
05488 settings->current_z SET_TO
05489 (settings->current_z + settings->origin_offset_z);
05490 #ifdef AA
05491 settings->AA_current SET_TO
05492 #endif
05493 #ifdef AA
05494 (settings->AA_current + settings->AA_origin_offset);
05495 #endif
05496 #ifdef BB
05497 settings->BB_current SET_TO
05498 #endif
05499 #ifdef BB
05500 (settings->BB_current + settings->BB_origin_offset);
05501 #endif
05502 #ifdef CC
05503 settings->CC_current SET_TO
05504 #endif
05505 #ifdef CC
05506 (settings->CC_current + settings->CC_origin_offset);
05507 #endif
05508
05509 settings->origin_offset_x SET_TO x;
05510 settings->origin_offset_y SET_TO y;
05511 settings->origin_offset_z SET_TO z;
05512 #ifdef AA
05513 settings->AA_origin_offset SET_TO a;
05514 #endif
05515 #ifdef BB
05516 settings->BB_origin_offset SET_TO b;
05517 #endif
05518 #ifdef CC
05519 settings->CC_origin_offset SET_TO c;
05520 #endif
05521
05522 settings->current_x SET_TO (settings->current_x - x);
05523 settings->current_y SET_TO (settings->current_y - y);
05524 settings->current_z SET_TO (settings->current_z - z);
05525 #ifdef AA
05526 settings->AA_current SET_TO (settings->AA_current - a);
05527 #endif
05528 #ifdef BB
05529 settings->BB_current SET_TO (settings->BB_current - b);
05530 #endif
05531 #ifdef CC
05532 settings->CC_current SET_TO (settings->CC_current - c);
05533 #endif
05534
05535 SET_ORIGIN_OFFSETS(x + settings->axis_offset_x,
05536 y + settings->axis_offset_y,
05537 z + settings->axis_offset_z
05538 #ifdef AA
05539 , a + settings->AA_axis_offset
05540 #else
05541 #ifdef ALL_AXES
05542 , 0
05543 #endif
05544 #endif
05545 #ifdef BB
05546 , b + settings->BB_axis_offset
05547 #else
05548 #ifdef ALL_AXES
05549 , 0
05550 #endif
05551 #endif
05552 #ifdef CC
05553 , c + settings->CC_axis_offset
05554 #else
05555 #ifdef ALL_AXES
05556 , 0
05557 #endif
05558 #endif
05559 );
05560 }
05561 #ifdef DEBUG_EMC
05562 else
05563 COMMENT("interpreter: setting coordinate system origin");
05564 #endif
05565 return RS274NGC_OK;
05566 }
05567
05568
05569
05570
05571
05572
05573
05574
05575
05576
05577
05578
05579
05580
05581
05582
05583
05584
05585
05586
05587
05588 static int convert_set_plane(
05589 int g_code,
05590 setup_pointer settings)
05591 {
05592 static char name[] SET_TO "convert_set_plane";
05593 if (g_code IS G_17)
05594 {
05595 SELECT_PLANE(CANON_PLANE_XY);
05596 settings->plane SET_TO CANON_PLANE_XY;
05597 }
05598 else if (g_code IS G_18)
05599 {
05600 CHK((settings->cutter_comp_side ISNT OFF),
05601 NCE_CANNOT_USE_XZ_PLANE_WITH_CUTTER_RADIUS_COMP);
05602 SELECT_PLANE(CANON_PLANE_XZ);
05603 settings->plane SET_TO CANON_PLANE_XZ;
05604 }
05605 else if (g_code IS G_19)
05606 {
05607 CHK((settings->cutter_comp_side ISNT OFF),
05608 NCE_CANNOT_USE_YZ_PLANE_WITH_CUTTER_RADIUS_COMP);
05609 SELECT_PLANE(CANON_PLANE_YZ);
05610 settings->plane SET_TO CANON_PLANE_YZ;
05611 }
05612 else
05613 ERM(NCE_BUG_CODE_NOT_G17_G18_OR_G19);
05614 return RS274NGC_OK;
05615 }
05616
05617
05618
05619
05620
05621
05622
05623
05624
05625
05626
05627
05628
05629
05630
05631
05632 static int convert_speed(
05633 block_pointer block,
05634 setup_pointer settings)
05635 {
05636 SET_SPINDLE_SPEED(block->s_number);
05637 settings->speed SET_TO block->s_number;
05638 return RS274NGC_OK;
05639 }
05640
05641
05642
05643
05644
05645
05646
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
05679
05680
05681
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691
05692
05693
05694
05695
05696
05697
05698
05699
05700
05701
05702
05703
05704 static int convert_stop(
05705 block_pointer block,
05706 setup_pointer settings)
05707 {
05708 static char name[] SET_TO "convert_stop";
05709 int index;
05710 char * line;
05711 int length;
05712
05713 if (block->m_modes[4] IS 0)
05714 {
05715 PROGRAM_STOP();
05716 }
05717 else if (block->m_modes[4] IS 60)
05718 {
05719 PALLET_SHUTTLE();
05720 PROGRAM_STOP();
05721 }
05722 else if (block->m_modes[4] IS 1)
05723 {
05724 OPTIONAL_PROGRAM_STOP();
05725 }
05726 else if ((block->m_modes[4] IS 2) OR (block->m_modes[4] IS 30))
05727 {
05728
05729 settings->current_x SET_TO settings->current_x
05730 + settings->origin_offset_x + settings->axis_offset_x;
05731 settings->current_y SET_TO settings->current_y
05732 + settings->origin_offset_y + settings->axis_offset_y;
05733 settings->current_z SET_TO settings->current_z
05734 + settings->origin_offset_z + settings->axis_offset_z;
05735 #ifdef AA
05736 settings->AA_current SET_TO settings->AA_current
05737 #endif
05738 #ifdef AA
05739 + settings->AA_origin_offset + settings->AA_axis_offset;
05740 #endif
05741 #ifdef BB
05742 settings->BB_current SET_TO settings->BB_current
05743 #endif
05744 #ifdef BB
05745 + settings->BB_origin_offset + settings->BB_axis_offset;
05746 #endif
05747 #ifdef CC
05748 settings->CC_current SET_TO settings->CC_current
05749 #endif
05750 #ifdef CC
05751 + settings->CC_origin_offset + settings->CC_axis_offset;
05752 #endif
05753
05754 settings->origin_index SET_TO 1;
05755 settings->parameters[5220] SET_TO 1.0;
05756 settings->origin_offset_x SET_TO settings->parameters[5221];
05757 settings->origin_offset_y SET_TO settings->parameters[5222];
05758 settings->origin_offset_z SET_TO settings->parameters[5223];
05759 #ifdef AA
05760 settings->AA_origin_offset SET_TO settings->parameters[5224];
05761 #endif
05762 #ifdef BB
05763 settings->BB_origin_offset SET_TO settings->parameters[5225];
05764 #endif
05765 #ifdef CC
05766 settings->CC_origin_offset SET_TO settings->parameters[5226];
05767 #endif
05768
05769 settings->axis_offset_x SET_TO 0;
05770 settings->axis_offset_x SET_TO 0;
05771 settings->axis_offset_x SET_TO 0;
05772 #ifdef AA
05773 settings->AA_axis_offset SET_TO 0;
05774 #endif
05775 #ifdef BB
05776 settings->BB_axis_offset SET_TO 0;
05777 #endif
05778 #ifdef CC
05779 settings->CC_axis_offset SET_TO 0;
05780 #endif
05781
05782 settings->current_x SET_TO settings->current_x -
05783 settings->origin_offset_x;
05784 settings->current_y SET_TO settings->current_y -
05785 settings->origin_offset_y;
05786 settings->current_z SET_TO settings->current_z -
05787 settings->origin_offset_z;
05788 #ifdef AA
05789 settings->AA_current SET_TO settings->AA_current -
05790 #endif
05791 #ifdef AA
05792 settings->AA_origin_offset;
05793 #endif
05794 #ifdef BB
05795 settings->BB_current SET_TO settings->BB_current -
05796 #endif
05797 #ifdef BB
05798 settings->BB_origin_offset;
05799 #endif
05800 #ifdef CC
05801 settings->CC_current SET_TO settings->CC_current -
05802 #endif
05803 #ifdef CC
05804 settings->CC_origin_offset;
05805 #endif
05806
05807 SET_ORIGIN_OFFSETS(settings->origin_offset_x,
05808 settings->origin_offset_y,
05809 settings->origin_offset_z
05810 #ifdef AA
05811 , settings->AA_origin_offset
05812 #else
05813 #ifdef ALL_AXES
05814 , 0
05815 #endif
05816 #endif
05817 #ifdef BB
05818 , settings->BB_origin_offset
05819 #else
05820 #ifdef ALL_AXES
05821 , 0
05822 #endif
05823 #endif
05824 #ifdef CC
05825 , settings->CC_origin_offset
05826 #else
05827 #ifdef ALL_AXES
05828 , 0
05829 #endif
05830 #endif
05831 );
05832
05833 if (settings->plane ISNT CANON_PLANE_XY)
05834 {
05835 SELECT_PLANE(CANON_PLANE_XY);
05836 settings->plane SET_TO CANON_PLANE_XY;
05837 }
05838
05839 settings->distance_mode SET_TO MODE_ABSOLUTE;
05840
05841 settings->feed_mode SET_TO UNITS_PER_MINUTE;
05842
05843 if (settings->feed_override ISNT ON)
05844 {
05845 ENABLE_FEED_OVERRIDE();
05846 settings->feed_override SET_TO ON;
05847 }
05848 if (settings->speed_override ISNT ON)
05849 {
05850 ENABLE_SPEED_OVERRIDE();
05851 settings->speed_override SET_TO ON;
05852 }
05853
05854 settings->cutter_comp_side SET_TO OFF;
05855 settings->program_x SET_TO UNKNOWN;
05856
05857 STOP_SPINDLE_TURNING();
05858 settings->spindle_turning SET_TO CANON_STOPPED;
05859
05860 settings->motion_mode SET_TO G_1;
05861
05862 if (settings->mist IS ON)
05863 {
05864 MIST_OFF();
05865 settings->mist SET_TO OFF;
05866 }
05867 if (settings->flood IS ON)
05868 {
05869 FLOOD_OFF();
05870 settings->flood SET_TO OFF;
05871 }
05872
05873 if (block->m_modes[4] IS 30)
05874 PALLET_SHUTTLE();
05875 PROGRAM_END();
05876 if (_setup.percent_flag IS ON)
05877 {
05878 CHK((_setup.file_pointer IS NULL), NCE_UNABLE_TO_OPEN_FILE);
05879 line SET_TO _setup.linetext;
05880 for(; ;)
05881 {
05882 if (fgets(line, RS274NGC_TEXT_SIZE, _setup.file_pointer) IS NULL)
05883 {
05884 COMMENT
05885 ("interpreter: percent sign missing from end of file");
05886 break;
05887 }
05888 length SET_TO strlen(line);
05889 if (length IS (RS274NGC_TEXT_SIZE - 1))
05890 {
05891 for(;fgetc(_setup.file_pointer) ISNT '\n';);
05892 continue;
05893 }
05894 for(index SET_TO (length -1);
05895 (index >= 0) AND (isspace(line[index]));
05896 index--);
05897 if (line[index] IS '%')
05898 {
05899 for(index--; (index >= 0)AND(isspace(line[index])); index--);
05900 if (index IS -1)
05901 break;
05902 }
05903 }
05904 }
05905 return RS274NGC_EXIT;
05906 }
05907 else
05908 ERM(NCE_BUG_CODE_NOT_M0_M1_M2_M30_M60);
05909 return RS274NGC_OK;
05910 }
05911
05912
05913
05914
05915
05916
05917
05918
05919
05920
05921
05922
05923
05924
05925
05926
05927
05928
05929
05930
05931
05932
05933
05934
05935
05936
05937
05938
05939
05940
05941
05942
05943
05944
05945
05946
05947
05948
05949
05950
05951
05952
05953
05954 static int convert_straight(
05955 int move,
05956 block_pointer block,
05957 setup_pointer settings)
05958 {
05959 static char name[] SET_TO "convert_straight";
05960 double end_x;
05961 double end_y;
05962 double end_z;
05963 #ifdef AA
05964 double AA_end;
05965 #endif
05966 #ifdef BB
05967 double BB_end;
05968 #endif
05969 #ifdef CC
05970 double CC_end;
05971 #endif
05972 int status;
05973
05974 if (move IS G_1)
05975 {
05976 if (settings->feed_mode IS UNITS_PER_MINUTE)
05977 {
05978 CHK((settings->feed_rate IS 0.0),
05979 NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE);
05980 }
05981 else if (settings->feed_mode IS INVERSE_TIME)
05982 {
05983 CHK((block->f_number IS -1.0),
05984 NCE_F_WORD_MISSING_WITH_INVERSE_TIME_G1_MOVE);
05985 }
05986 }
05987
05988 settings->motion_mode SET_TO move;
05989 find_ends(block, settings, &end_x, &end_y,
05990 &end_z
05991 #ifdef AA
05992 , &AA_end
05993 #endif
05994
05995 #ifdef BB
05996 , &BB_end
05997 #endif
05998
05999 #ifdef CC
06000 , &CC_end
06001 #endif
06002 );
06003 if ((settings->cutter_comp_side ISNT OFF) AND
06004 (settings->cutter_comp_radius > 0.0))
06005 {
06006 CHK((block->g_modes[0] IS G_53),
06007 NCE_CANNOT_USE_G53_WITH_CUTTER_RADIUS_COMP);
06008 if (settings->program_x IS UNKNOWN)
06009 {
06010 status SET_TO
06011 convert_straight_comp1(move, block, settings, end_x, end_y,
06012 end_z
06013 #ifdef AA
06014 , AA_end
06015 #endif
06016
06017 #ifdef BB
06018 , BB_end
06019 #endif
06020
06021 #ifdef CC
06022 , CC_end
06023 #endif
06024 );
06025 CHP(status);
06026 }
06027 else
06028 {
06029 status SET_TO
06030 convert_straight_comp2 (move, block, settings, end_x, end_y,
06031 end_z
06032 #ifdef AA
06033 , AA_end
06034 #endif
06035
06036 #ifdef BB
06037 , BB_end
06038 #endif
06039
06040 #ifdef CC
06041 , CC_end
06042 #endif
06043 );
06044 CHP(status);
06045 }
06046 }
06047 else if (move IS G_0)
06048 {
06049 STRAIGHT_TRAVERSE(end_x, end_y, end_z
06050 #ifdef AA
06051 , AA_end
06052 #else
06053 #ifdef ALL_AXES
06054 , 0
06055 #endif
06056 #endif
06057 #ifdef BB
06058 , BB_end
06059 #else
06060 #ifdef ALL_AXES
06061 , 0
06062 #endif
06063 #endif
06064 #ifdef CC
06065 , CC_end
06066 #else
06067 #ifdef ALL_AXES
06068 , 0
06069 #endif
06070 #endif
06071 );
06072 settings->current_x SET_TO end_x;
06073 settings->current_y SET_TO end_y;
06074 }
06075 else if (move IS G_1)
06076 {
06077 if (settings->feed_mode IS INVERSE_TIME)
06078 inverse_time_rate_straight
06079 (end_x, end_y, end_z
06080 #ifdef AA
06081 , AA_end
06082 #endif
06083
06084 #ifdef BB
06085 , BB_end
06086 #endif
06087
06088 #ifdef CC
06089 , CC_end
06090 #endif
06091 , block, settings);
06092 STRAIGHT_FEED(end_x, end_y, end_z
06093 #ifdef AA
06094 , AA_end
06095 #else
06096 #ifdef ALL_AXES
06097 , 0
06098 #endif
06099 #endif
06100 #ifdef BB
06101 , BB_end
06102 #else
06103 #ifdef ALL_AXES
06104 , 0
06105 #endif
06106 #endif
06107 #ifdef CC
06108 , CC_end
06109 #else
06110 #ifdef ALL_AXES
06111 , 0
06112 #endif
06113 #endif
06114 );
06115 settings->current_x SET_TO end_x;
06116 settings->current_y SET_TO end_y;
06117 }
06118 else
06119 ERM(NCE_BUG_CODE_NOT_G0_OR_G1);
06120
06121 settings->current_z SET_TO end_z;
06122 #ifdef AA
06123 settings->AA_current SET_TO AA_end;
06124 #endif
06125 #ifdef BB
06126 settings->BB_current SET_TO BB_end;
06127 #endif
06128 #ifdef CC
06129 settings->CC_current SET_TO CC_end;
06130 #endif
06131 return RS274NGC_OK;
06132 }
06133
06134
06135
06136
06137
06138
06139
06140
06141
06142
06143
06144
06145
06146
06147
06148
06149
06150
06151
06152
06153
06154
06155
06156
06157
06158
06159
06160
06161
06162
06163
06164
06165
06166
06167
06168
06169
06170 static int convert_straight_comp1(
06171 int move,
06172 block_pointer block,
06173 setup_pointer settings,
06174 double px,
06175 double py,
06176 double end_z
06177 #ifdef AA
06178 , double AA_end
06179 #endif
06180 #ifdef BB
06181 , double BB_end
06182 #endif
06183 #ifdef CC
06184 , double CC_end
06185 #endif
06186 )
06187 {
06188 static char name[] SET_TO "convert_straight_comp1";
06189 double alpha;
06190 double cx;
06191 double cy;
06192 double distance;
06193 double radius;
06194 int side;
06195 double theta;
06196
06197 side SET_TO settings->cutter_comp_side;
06198 cx SET_TO settings->current_x;
06199 cy SET_TO settings->current_y;
06200
06201 radius SET_TO settings->cutter_comp_radius;
06202 distance SET_TO hypot((px - cx), (py -cy));
06203
06204 CHK(((side ISNT LEFT) AND (side ISNT RIGHT)),NCE_BUG_SIDE_NOT_RIGHT_OR_LEFT);
06205 CHK((distance <= radius), NCE_CUTTER_GOUGING_WITH_CUTTER_RADIUS_COMP);
06206
06207 theta SET_TO acos(radius/distance);
06208 alpha SET_TO (side IS LEFT) ? (atan2((cy - py), (cx - px)) - theta) :
06209 (atan2((cy - py), (cx - px)) + theta);
06210 cx SET_TO (px + (radius * cos(alpha)));
06211 cy SET_TO (py + (radius * sin(alpha)));
06212 if (move IS G_0)
06213 STRAIGHT_TRAVERSE(cx, cy, end_z
06214 #ifdef AA
06215 , AA_end
06216 #else
06217 #ifdef ALL_AXES
06218 , 0
06219 #endif
06220 #endif
06221 #ifdef BB
06222 , BB_end
06223 #else
06224 #ifdef ALL_AXES
06225 , 0
06226 #endif
06227 #endif
06228 #ifdef CC
06229 , CC_end
06230 #else
06231 #ifdef ALL_AXES
06232 , 0
06233 #endif
06234 #endif
06235 );
06236 else if (move IS G_1)
06237 {
06238 if (settings->feed_mode IS INVERSE_TIME)
06239 inverse_time_rate_straight
06240 (cx, cy, end_z
06241 #ifdef AA
06242 , AA_end
06243 #endif
06244
06245 #ifdef BB
06246 , BB_end
06247 #endif
06248
06249 #ifdef CC
06250 , CC_end
06251 #endif
06252 , block, settings);
06253 STRAIGHT_FEED(cx, cy, end_z
06254 #ifdef AA
06255 , AA_end
06256 #else
06257 #ifdef ALL_AXES
06258 , 0
06259 #endif
06260 #endif
06261 #ifdef BB
06262 , BB_end
06263 #else
06264 #ifdef ALL_AXES
06265 , 0
06266 #endif
06267 #endif
06268 #ifdef CC
06269 , CC_end
06270 #else
06271 #ifdef ALL_AXES
06272 , 0
06273 #endif
06274 #endif
06275 );
06276 }
06277 else
06278 ERM(NCE_BUG_CODE_NOT_G0_OR_G1);
06279
06280 settings->current_x SET_TO cx;
06281 settings->current_y SET_TO cy;
06282 settings->program_x SET_TO px;
06283 settings->program_y SET_TO py;
06284 return RS274NGC_OK;
06285 }
06286
06287
06288
06289
06290
06291
06292
06293
06294
06295
06296
06297
06298
06299
06300
06301
06302
06303
06304
06305
06306
06307
06308
06309
06310
06311
06312
06313
06314
06315
06316
06317
06318
06319
06320
06321
06322
06323
06324
06325
06326
06327
06328
06329
06330
06331
06332
06333
06334
06335
06336
06337
06338
06339
06340
06341
06342
06343
06344
06345
06346
06347
06348
06349
06350
06351
06352
06353
06354
06355
06356
06357
06358
06359 static int convert_straight_comp2(
06360 int move,
06361 block_pointer block,
06362 setup_pointer settings,
06363 double px,
06364 double py,
06365 double end_z
06366 #ifdef AA
06367 , double AA_end
06368 #endif
06369 #ifdef BB
06370 , double BB_end
06371 #endif
06372 #ifdef CC
06373 , double CC_end
06374 #endif
06375 )
06376 {
06377 static char name[] SET_TO "convert_straight_comp2";
06378 double alpha;
06379 double beta;
06380 double end_x;
06381 double end_y;
06382 double gamma;
06383 double mid_x;
06384 double mid_y;
06385 double radius;
06386 int side;
06387 double small SET_TO TOLERANCE_CONCAVE_CORNER;
06388 double start_x, start_y;
06389 double theta;
06390
06391 start_x SET_TO settings->program_x;
06392 start_y SET_TO settings->program_y;
06393 if ((py IS start_y) AND (px IS start_x))
06394 {
06395 end_x SET_TO settings->current_x;
06396 end_y SET_TO settings->current_y;
06397 if (move IS G_0)
06398 STRAIGHT_TRAVERSE(end_x, end_y, end_z
06399 #ifdef AA
06400 , AA_end
06401 #else
06402 #ifdef ALL_AXES
06403 , 0
06404 #endif
06405 #endif
06406 #ifdef BB
06407 , BB_end
06408 #else
06409 #ifdef ALL_AXES
06410 , 0
06411 #endif
06412 #endif
06413 #ifdef CC
06414 , CC_end
06415 #else
06416 #ifdef ALL_AXES
06417 , 0
06418 #endif
06419 #endif
06420 );
06421 else if (move IS G_1)
06422 {
06423 if (settings->feed_mode IS INVERSE_TIME)
06424 inverse_time_rate_straight
06425 (end_x, end_y, end_z
06426 #ifdef AA
06427 , AA_end
06428 #endif
06429
06430 #ifdef BB
06431 , BB_end
06432 #endif
06433
06434 #ifdef CC
06435 , CC_end
06436 #endif
06437 , block, settings);
06438 STRAIGHT_FEED(end_x, end_y, end_z
06439 #ifdef AA
06440 , AA_end
06441 #else
06442 #ifdef ALL_AXES
06443 , 0
06444 #endif
06445 #endif
06446 #ifdef BB
06447 , BB_end
06448 #else
06449 #ifdef ALL_AXES
06450 , 0
06451 #endif
06452 #endif
06453 #ifdef CC
06454 , CC_end
06455 #else
06456 #ifdef ALL_AXES
06457 , 0
06458 #endif
06459 #endif
06460 );
06461 }
06462 else
06463 ERM(NCE_BUG_CODE_NOT_G0_OR_G1);
06464 }
06465 else
06466 {
06467 side SET_TO settings->cutter_comp_side;
06468 radius SET_TO settings->cutter_comp_radius;
06469 theta SET_TO atan2(settings->current_y - start_y,
06470 settings->current_x - start_x);
06471 alpha SET_TO atan2(py - start_y, px - start_x);
06472
06473 if (side IS LEFT)
06474 {
06475 if (theta < alpha)
06476 theta SET_TO (theta + TWO_PI);
06477 beta SET_TO ((theta - alpha) - PI2);
06478 gamma SET_TO PI2;
06479 }
06480 else if (side IS RIGHT)
06481 {
06482 if (alpha < theta)
06483 alpha SET_TO (alpha + TWO_PI);
06484 beta SET_TO ((alpha - theta) - PI2);
06485 gamma SET_TO -PI2;
06486 }
06487 else
06488 ERM(NCE_BUG_SIDE_NOT_RIGHT_OR_LEFT);
06489 end_x SET_TO (px + (radius * cos(alpha + gamma)));
06490 end_y SET_TO (py + (radius * sin(alpha + gamma)));
06491 mid_x SET_TO (start_x + (radius * cos(alpha + gamma)));
06492 mid_y SET_TO (start_y + (radius * sin(alpha + gamma)));
06493
06494 CHK(((beta < -small) OR (beta > (PI + small))),
06495 NCE_CONCAVE_CORNER_WITH_CUTTER_RADIUS_COMP);
06496 if (move IS G_0)
06497 STRAIGHT_TRAVERSE(end_x, end_y, end_z
06498 #ifdef AA
06499 , AA_end
06500 #else
06501 #ifdef ALL_AXES
06502 , 0
06503 #endif
06504 #endif
06505 #ifdef BB
06506 , BB_end
06507 #else
06508 #ifdef ALL_AXES
06509 , 0
06510 #endif
06511 #endif
06512 #ifdef CC
06513 , CC_end
06514 #else
06515 #ifdef ALL_AXES
06516 , 0
06517 #endif
06518 #endif
06519 );
06520 else if (move IS G_1)
06521 {
06522 if (beta > small)
06523 {
06524 if (settings->feed_mode IS INVERSE_TIME)
06525 inverse_time_rate_as(start_x, start_y, (side IS LEFT) ? -1 : 1,
06526 mid_x, mid_y, end_x, end_y,
06527 end_z
06528 #ifdef AA
06529 , AA_end
06530 #endif
06531
06532 #ifdef BB
06533 , BB_end
06534 #endif
06535
06536 #ifdef CC
06537 , CC_end
06538 #endif
06539 ,
06540 block, settings);
06541 ARC_FEED(mid_x,mid_y,start_x, start_y,((side IS LEFT) ? -1 : 1),
06542 settings->current_z
06543 #ifdef AA
06544 , AA_end
06545 #else
06546 #ifdef ALL_AXES
06547 , 0
06548 #endif
06549 #endif
06550 #ifdef BB
06551 , BB_end
06552 #else
06553 #ifdef ALL_AXES
06554 , 0
06555 #endif
06556 #endif
06557 #ifdef CC
06558 , CC_end
06559 #else
06560 #ifdef ALL_AXES
06561 , 0
06562 #endif
06563 #endif
06564 );
06565 STRAIGHT_FEED(end_x, end_y, end_z
06566 #ifdef AA
06567 , AA_end
06568 #else
06569 #ifdef ALL_AXES
06570 , 0
06571 #endif
06572 #endif
06573 #ifdef BB
06574 , BB_end
06575 #else
06576 #ifdef ALL_AXES
06577 , 0
06578 #endif
06579 #endif
06580 #ifdef CC
06581 , CC_end
06582 #else
06583 #ifdef ALL_AXES
06584 , 0
06585 #endif
06586 #endif
06587 );
06588 }
06589 else
06590 {
06591 if (settings->feed_mode IS INVERSE_TIME)
06592 inverse_time_rate_straight
06593 (end_x,end_y,end_z
06594 #ifdef AA
06595 , AA_end
06596 #endif
06597
06598 #ifdef BB
06599 , BB_end
06600 #endif
06601
06602 #ifdef CC
06603 , CC_end
06604 #endif
06605 , block, settings);
06606 STRAIGHT_FEED(end_x, end_y, end_z
06607 #ifdef AA
06608 , AA_end
06609 #else
06610 #ifdef ALL_AXES
06611 , 0
06612 #endif
06613 #endif
06614 #ifdef BB
06615 , BB_end
06616 #else
06617 #ifdef ALL_AXES
06618 , 0
06619 #endif
06620 #endif
06621 #ifdef CC
06622 , CC_end
06623 #else
06624 #ifdef ALL_AXES
06625 , 0
06626 #endif
06627 #endif
06628 );
06629 }
06630 }
06631 else
06632 ERM(NCE_BUG_CODE_NOT_G0_OR_G1);
06633 }
06634
06635 settings->current_x SET_TO end_x;
06636 settings->current_y SET_TO end_y;
06637 settings->program_x SET_TO px;
06638 settings->program_y SET_TO py;
06639 return RS274NGC_OK;
06640 }
06641
06642
06643
06644
06645
06646
06647
06648
06649
06650
06651
06652
06653
06654
06655
06656
06657
06658
06659
06660
06661
06662
06663
06664
06665
06666
06667
06668
06669
06670
06671
06672
06673
06674
06675
06676
06677
06678
06679
06680
06681
06682
06683
06684
06685
06686
06687
06688
06689
06690
06691
06692
06693
06694
06695
06696
06697
06698
06699
06700
06701 static int convert_tool_change(
06702 setup_pointer settings)
06703 {
06704 static char name[] SET_TO "convert_tool_change";
06705
06706 CHANGE_TOOL(settings->selected_tool_slot);
06707 settings->current_slot SET_TO settings->selected_tool_slot;
06708 settings->spindle_turning SET_TO CANON_STOPPED;
06709
06710 return RS274NGC_OK;
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
06743
06744 static int convert_tool_length_offset(
06745 int g_code,
06746 block_pointer block,
06747 setup_pointer settings)
06748 {
06749 static char name[] SET_TO "convert_tool_length_offset";
06750 int index;
06751 double offset;
06752
06753 if (g_code IS G_49)
06754 {
06755 USE_TOOL_LENGTH_OFFSET(0.0);
06756 settings->current_z SET_TO (settings->current_z +
06757 settings->tool_length_offset);
06758 settings->tool_length_offset SET_TO 0.0;
06759 settings->length_offset_index SET_TO 0;
06760 }
06761 else if (g_code IS G_43)
06762 {
06763 index SET_TO block->h_number;
06764 CHK((index IS -1), NCE_OFFSET_INDEX_MISSING);
06765 offset SET_TO settings->tool_table[index].length;
06766 USE_TOOL_LENGTH_OFFSET(offset);
06767 settings->current_z SET_TO
06768 (settings->current_z + settings->tool_length_offset - offset);
06769 settings->tool_length_offset SET_TO offset;
06770 settings->length_offset_index SET_TO index;
06771 }
06772 else
06773 ERM(NCE_BUG_CODE_NOT_G43_OR_G49);
06774 return RS274NGC_OK;
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
06801
06802
06803 static int convert_tool_select(
06804 block_pointer block,
06805 setup_pointer settings)
06806 {
06807 static char name[] SET_TO "convert_tool_select";
06808
06809 CHK((block->t_number > settings->tool_max),
06810 NCE_SELECTED_TOOL_SLOT_NUMBER_TOO_LARGE);
06811 SELECT_TOOL(block->t_number);
06812 settings->selected_tool_slot SET_TO block->t_number;
06813 return RS274NGC_OK;
06814 }
06815
06816
06817
06818
06819
06820
06821
06822
06823
06824
06825
06826
06827
06828
06829
06830
06831
06832
06833
06834
06835
06836
06837
06838
06839
06840
06841 static int cycle_feed(
06842 CANON_PLANE plane,
06843 double end1,
06844 double end2,
06845 double end3)
06846 {
06847 static char name[] SET_TO "cycle_feed";
06848
06849 if (plane IS CANON_PLANE_XY)
06850 STRAIGHT_FEED(end1, end2, end3
06851 #ifdef AA
06852 , _setup.AA_current
06853 #else
06854 #ifdef ALL_AXES
06855 , 0
06856 #endif
06857 #endif
06858 #ifdef BB
06859 , _setup.BB_current
06860 #else
06861 #ifdef ALL_AXES
06862 , 0
06863 #endif
06864 #endif
06865 #ifdef CC
06866 , _setup.CC_current
06867 #else
06868 #ifdef ALL_AXES
06869 , 0
06870 #endif
06871 #endif
06872 );
06873 else if (plane IS CANON_PLANE_YZ)
06874 STRAIGHT_FEED(end3, end1, end2
06875 #ifdef AA
06876 , _setup.AA_current
06877 #else
06878 #ifdef ALL_AXES
06879 , 0
06880 #endif
06881 #endif
06882 #ifdef BB
06883 , _setup.BB_current
06884 #else
06885 #ifdef ALL_AXES
06886 , 0
06887 #endif
06888 #endif
06889 #ifdef CC
06890 , _setup.CC_current
06891 #else
06892 #ifdef ALL_AXES
06893 , 0
06894 #endif
06895 #endif
06896 );
06897 else
06898 STRAIGHT_FEED(end2, end3, end1
06899 #ifdef AA
06900 , _setup.AA_current
06901 #else
06902 #ifdef ALL_AXES
06903 , 0
06904 #endif
06905 #endif
06906 #ifdef BB
06907 , _setup.BB_current
06908 #else
06909 #ifdef ALL_AXES
06910 , 0
06911 #endif
06912 #endif
06913 #ifdef CC
06914 , _setup.CC_current
06915 #else
06916 #ifdef ALL_AXES
06917 , 0
06918 #endif
06919 #endif
06920 );
06921
06922 return RS274NGC_OK;
06923 }
06924
06925
06926
06927
06928
06929
06930
06931
06932
06933
06934
06935
06936
06937
06938
06939
06940
06941
06942
06943
06944
06945
06946
06947
06948
06949
06950 static int cycle_traverse(
06951 CANON_PLANE plane,
06952 double end1,
06953 double end2,
06954 double end3)
06955 {
06956 static char name[] SET_TO "cycle_traverse";
06957 if (plane IS CANON_PLANE_XY)
06958 STRAIGHT_TRAVERSE(end1, end2, end3
06959 #ifdef AA
06960 , _setup.AA_current
06961 #else
06962 #ifdef ALL_AXES
06963 , 0
06964 #endif
06965 #endif
06966 #ifdef BB
06967 , _setup.BB_current
06968 #else
06969 #ifdef ALL_AXES
06970 , 0
06971 #endif
06972 #endif
06973 #ifdef CC
06974 , _setup.CC_current
06975 #else
06976 #ifdef ALL_AXES
06977 , 0
06978 #endif
06979 #endif
06980 );
06981 else if (plane IS CANON_PLANE_YZ)
06982 STRAIGHT_TRAVERSE(end3, end1, end2
06983 #ifdef AA
06984 , _setup.AA_current
06985 #else
06986 #ifdef ALL_AXES
06987 , 0
06988 #endif
06989 #endif
06990 #ifdef BB
06991 , _setup.BB_current
06992 #else
06993 #ifdef ALL_AXES
06994 , 0
06995 #endif
06996 #endif
06997 #ifdef CC
06998 , _setup.CC_current
06999 #else
07000 #ifdef ALL_AXES
07001 , 0
07002 #endif
07003 #endif
07004 );
07005 else
07006 STRAIGHT_TRAVERSE(end2, end3, end1
07007 #ifdef AA
07008 , _setup.AA_current
07009 #else
07010 #ifdef ALL_AXES
07011 , 0
07012 #endif
07013 #endif
07014 #ifdef BB
07015 , _setup.BB_current
07016 #else
07017 #ifdef ALL_AXES
07018 , 0
07019 #endif
07020 #endif
07021 #ifdef CC
07022 , _setup.CC_current
07023 #else
07024 #ifdef ALL_AXES
07025 , 0
07026 #endif
07027 #endif
07028 );
07029 return RS274NGC_OK;
07030 }
07031
07032
07033
07034
07035
07036
07037
07038
07039
07040
07041
07042
07043
07044
07045
07046
07047
07048
07049
07050
07051
07052
07053
07054
07055
07056
07057
07058
07059
07060
07061
07062
07063
07064
07065
07066
07067
07068 static int enhance_block(
07069 block_pointer block,
07070 setup_pointer settings)
07071 {
07072 static char name[] SET_TO "enhance_block";
07073 int axis_flag;
07074 int mode_zero_covets_axes;
07075
07076 axis_flag SET_TO ((block->x_flag IS ON) OR
07077 (block->y_flag IS ON) OR
07078 #ifdef AA
07079 (block->a_flag IS ON) OR
07080 #endif
07081 #ifdef BB
07082 (block->b_flag IS ON) OR
07083 #endif
07084 #ifdef CC
07085 (block->c_flag IS ON) OR
07086 #endif
07087 (block->z_flag IS ON));
07088 mode_zero_covets_axes SET_TO ((block->g_modes[0] IS G_10) OR
07089 (block->g_modes[0] IS G_28) OR
07090 (block->g_modes[0] IS G_30) OR
07091 (block->g_modes[0] IS G_92));
07092
07093 if (block->g_modes[1] ISNT -1)
07094 {
07095 if (block->g_modes[1] IS G_80)
07096 {
07097 CHK((axis_flag AND (NOT mode_zero_covets_axes)),
07098 NCE_CANNOT_USE_AXIS_VALUES_WITH_G80);
07099 CHK(((NOT axis_flag) AND (block->g_modes[0] IS G_92)),
07100 NCE_ALL_AXES_MISSING_WITH_G92);
07101 }
07102 else
07103 {
07104 CHK(mode_zero_covets_axes,
07105 NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES);
07106 CHK((NOT axis_flag), NCE_ALL_AXES_MISSING_WITH_MOTION_CODE);
07107 }
07108 block->motion_to_be SET_TO block->g_modes[1];
07109 }
07110 else if (mode_zero_covets_axes)
07111 {
07112 CHK(((NOT axis_flag) AND (block->g_modes[0] IS G_92)),
07113 NCE_ALL_AXES_MISSING_WITH_G92);
07114 }
07115 else if (axis_flag)
07116 {
07117 CHK(((settings->motion_mode IS -1) OR (settings->motion_mode IS G_80)),
07118 NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM);
07119 block->motion_to_be SET_TO settings->motion_mode;
07120 }
07121 return RS274NGC_OK;
07122 }
07123
07124
07125
07126
07127
07128
07129
07130
07131
07132
07133
07134
07135
07136
07137
07138
07139
07140
07141
07142 static int execute_binary(
07143 double * left,
07144 int operation,
07145 double * right)
07146 {
07147 static char name[] SET_TO "execute_binary";
07148 int status;
07149
07150 if (operation < AND2)
07151 CHP(execute_binary1(left, operation, right));
07152 else
07153 CHP(execute_binary2(left, operation, right));
07154 return RS274NGC_OK;
07155 }
07156
07157
07158
07159
07160
07161
07162
07163
07164
07165
07166
07167
07168
07169
07170
07171
07172
07173
07174
07175
07176
07177
07178 static int execute_binary1(
07179 double * left,
07180 int operation,
07181 double * right)
07182 {
07183 static char name[] SET_TO "execute_binary1";
07184 switch (operation)
07185 {
07186 case DIVIDED_BY:
07187 CHK((*right IS 0.0), NCE_ATTEMPT_TO_DIVIDE_BY_ZERO);
07188 *left SET_TO (*left / *right);
07189 break;
07190 case MODULO:
07191 *left SET_TO fmod(*left, *right);
07192 if (*left < 0.0)
07193 {
07194 *left SET_TO (*left + fabs(*right));
07195 }
07196 break;
07197 case POWER:
07198 CHK(((*left < 0.0) AND (floor(*right) ISNT *right)),
07199 NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER);
07200 *left SET_TO pow(*left, *right);
07201 break;
07202 case TIMES:
07203 *left SET_TO (*left * *right);
07204 break;
07205 default:
07206 ERM(NCE_BUG_UNKNOWN_OPERATION);
07207 }
07208 return RS274NGC_OK;
07209 }
07210
07211
07212
07213
07214
07215
07216
07217
07218
07219
07220
07221
07222
07223
07224
07225
07226
07227
07228
07229
07230
07231
07232
07233
07234
07235 static int execute_binary2(
07236 double * left,
07237 int operation,
07238 double * right)
07239 {
07240 static char name[] SET_TO "execute_binary2";
07241 switch (operation)
07242 {
07243 case AND2:
07244 *left SET_TO ((*left IS 0.0) OR (*right IS 0.0)) ? 0.0 : 1.0;
07245 break;
07246 case EXCLUSIVE_OR:
07247 *left SET_TO (((*left IS 0.0) AND (*right ISNT 0.0)) OR
07248 ((*left ISNT 0.0) AND (*right IS 0.0))) ? 1.0 : 0.0;
07249 break;
07250 case MINUS:
07251 *left SET_TO (*left - *right);
07252 break;
07253 case NON_EXCLUSIVE_OR:
07254 *left SET_TO ((*left ISNT 0.0) OR (*right ISNT 0.0)) ? 1.0 : 0.0;
07255 break;
07256 case PLUS:
07257 *left SET_TO (*left + *right);
07258 break;
07259 default:
07260 ERM(NCE_BUG_UNKNOWN_OPERATION);
07261 }
07262 return RS274NGC_OK;
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
07298
07299
07300
07301
07302
07303
07304
07305
07306
07307
07308
07309
07310
07311
07312
07313 static int execute_block(
07314 block_pointer block,
07315 setup_pointer settings)
07316 {
07317 static char name[] SET_TO "execute_block";
07318 int status;
07319
07320 if (block->comment[0] ISNT 0)
07321 {
07322 CHP(convert_comment(block->comment));
07323 }
07324 if (block->g_modes[5] ISNT -1)
07325 {
07326 CHP(convert_feed_mode(block->g_modes[5], settings));
07327 }
07328 if (block->f_number > -1.0)
07329 {
07330 if (settings->feed_mode IS INVERSE_TIME);
07331 else
07332 {
07333 CHP(convert_feed_rate(block, settings));
07334 }
07335 }
07336 if (block->s_number > -1.0)
07337 {
07338 CHP(convert_speed(block, settings));
07339 }
07340 if (block->t_number ISNT -1)
07341 {
07342 CHP(convert_tool_select(block, settings));
07343 }
07344 CHP(convert_m(block, settings));
07345 CHP(convert_g(block, settings));
07346 if (block->m_modes[4] ISNT -1)
07347 {
07348 status SET_TO convert_stop(block, settings);
07349 if (status IS RS274NGC_EXIT)
07350 return RS274NGC_EXIT;
07351 else if (status ISNT RS274NGC_OK)
07352 ERP(status);
07353 }
07354 return ((settings->probe_flag IS ON) ? RS274NGC_EXECUTE_FINISH: RS274NGC_OK);
07355 }
07356
07357
07358
07359
07360
07361
07362
07363
07364
07365
07366
07367
07368
07369
07370
07371
07372
07373
07374
07375
07376
07377
07378
07379
07380
07381
07382
07383
07384
07385
07386
07387 static int execute_unary(
07388 double * double_ptr,
07389 int operation)
07390 {
07391 static char name[] SET_TO "execute_unary";
07392 switch (operation)
07393 {
07394 case ABS:
07395 if (*double_ptr < 0.0)
07396 *double_ptr SET_TO (-1.0 * *double_ptr);
07397 break;
07398 case ACOS:
07399 CHK(((*double_ptr < -1.0) OR (*double_ptr > 1.0)),
07400 NCE_ARGUMENT_TO_ACOS_OUT_OF_RANGE);
07401 *double_ptr SET_TO acos(*double_ptr);
07402 *double_ptr SET_TO ((*double_ptr * 180.0)/ PI);
07403 break;
07404 case ASIN:
07405 CHK(((*double_ptr < -1.0) OR (*double_ptr > 1.0)),
07406 NCE_ARGUMENT_TO_ASIN_OUT_OF_RANGE);
07407 *double_ptr SET_TO asin(*double_ptr);
07408 *double_ptr SET_TO ((*double_ptr * 180.0)/ PI);
07409 break;
07410 case COS:
07411 *double_ptr SET_TO cos((*double_ptr * PI)/180.0);
07412 break;
07413 case EXP:
07414 *double_ptr SET_TO exp(*double_ptr);
07415 break;
07416 case FIX:
07417 *double_ptr SET_TO floor(*double_ptr);
07418 break;
07419 case FUP:
07420 *double_ptr SET_TO ceil(*double_ptr);
07421 break;
07422 case LN:
07423 CHK((*double_ptr <= 0.0), NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN);
07424 *double_ptr SET_TO log(*double_ptr);
07425 break;
07426 case ROUND:
07427 *double_ptr SET_TO (double)
07428 ((int) (*double_ptr + ((*double_ptr < 0.0) ? -0.5 : 0.5)));
07429 break;
07430 case SIN:
07431 *double_ptr SET_TO sin((*double_ptr * PI)/180.0);
07432 break;
07433 case SQRT:
07434 CHK((*double_ptr < 0.0), NCE_NEGATIVE_ARGUMENT_TO_SQRT);
07435 *double_ptr SET_TO sqrt(*double_ptr);
07436 break;
07437 case TAN:
07438 *double_ptr SET_TO tan((*double_ptr * PI)/180.0);
07439 break;
07440 default:
07441 ERM(NCE_BUG_UNKNOWN_OPERATION);
07442 }
07443 return RS274NGC_OK;
07444 }
07445
07446
07447
07448
07449
07450
07451
07452
07453
07454
07455
07456
07457
07458
07459
07460
07461
07462
07463
07464
07465
07466
07467
07468
07469
07470
07471
07472
07473
07474
07475
07476
07477
07478
07479
07480
07481 static double find_arc_length(
07482 double x1,
07483 double y1,
07484 double z1,
07485 double center_x,
07486 double center_y,
07487 int turn,
07488 double x2,
07489 double y2,
07490 double z2)
07491 {
07492 double radius;
07493 double theta;
07494
07495 radius SET_TO hypot((center_x - x1), (center_y - y1));
07496 theta SET_TO find_turn(x1, y1, center_x, center_y, turn, x2, y2);
07497 if (z2 IS z1)
07498 return (radius * fabs(theta));
07499 else
07500 return hypot((radius * theta), (z2 - z1));
07501 }
07502
07503
07504
07505
07506
07507
07508
07509
07510
07511
07512
07513
07514
07515
07516
07517
07518
07519
07520
07521
07522
07523
07524
07525
07526
07527
07528
07529
07530
07531
07532
07533
07534
07535
07536
07537
07538
07539
07540
07541
07542
07543 static int find_ends(
07544 block_pointer block,
07545 setup_pointer settings,
07546 double * px,
07547 double * py,
07548 double * pz
07549 #ifdef AA
07550 , double * AA_p
07551 #endif
07552 #ifdef BB
07553 , double * BB_p
07554 #endif
07555 #ifdef CC
07556 , double * CC_p
07557 #endif
07558 )
07559 {
07560 int mode;
07561 int middle;
07562 int comp;
07563
07564 mode SET_TO settings->distance_mode;
07565 middle SET_TO (settings->program_x ISNT UNKNOWN);
07566 comp SET_TO (settings->cutter_comp_side ISNT OFF);
07567
07568 if (block->g_modes[0] IS G_53)
07569 {
07570 #ifdef DEBUG_EMC
07571 COMMENT("interpreter: offsets temporarily suspended");
07572 #endif
07573 *px SET_TO (block->x_flag IS ON) ? (block->x_number -
07574 (settings->origin_offset_x + settings->axis_offset_x)) :
07575 settings->current_x;
07576 *py SET_TO (block->y_flag IS ON) ? (block->y_number -
07577 (settings->origin_offset_y + settings->axis_offset_y)) :
07578 settings->current_y;
07579 *pz SET_TO (block->z_flag IS ON) ? (block->z_number -
07580 (settings->tool_length_offset + settings->origin_offset_z
07581 + settings->axis_offset_z)) : settings->current_z;
07582 #ifdef AA
07583 *AA_p SET_TO (block->a_flag IS ON) ? (block->a_number -
07584 #endif
07585 #ifdef AA
07586 (settings->AA_origin_offset + settings->AA_axis_offset)) :
07587 #endif
07588 #ifdef AA
07589 settings->AA_current;
07590 #endif
07591 #ifdef BB
07592 *BB_p SET_TO (block->b_flag IS ON) ? (block->b_number -
07593 #endif
07594 #ifdef BB
07595 (settings->BB_origin_offset + settings->BB_axis_offset)) :
07596 #endif
07597 #ifdef BB
07598 settings->BB_current;
07599 #endif
07600 #ifdef CC
07601 *CC_p SET_TO (block->c_flag IS ON) ? (block->c_number -
07602 #endif
07603 #ifdef CC
07604 (settings->tool_length_offset + settings->CC_origin_offset
07605 #endif
07606 #ifdef CC
07607 + settings->CC_axis_offset)) : settings->CC_current;
07608 #endif
07609 }
07610 else if (mode IS MODE_ABSOLUTE)
07611 {
07612 *px SET_TO (block->x_flag IS ON) ? block->x_number :
07613 (comp AND middle) ? settings->program_x :
07614 settings->current_x ;
07615
07616 *py SET_TO (block->y_flag IS ON) ? block->y_number :
07617 (comp AND middle) ? settings->program_y :
07618 settings->current_y ;
07619
07620 *pz SET_TO (block->z_flag IS ON) ? block->z_number :
07621 settings->current_z ;
07622 #ifdef AA
07623 *AA_p SET_TO (block->a_flag IS ON) ? block->a_number :
07624 #endif
07625 #ifdef AA
07626 settings->AA_current ;
07627 #endif
07628 #ifdef BB
07629 *BB_p SET_TO (block->b_flag IS ON) ? block->b_number :
07630 #endif
07631 #ifdef BB
07632 settings->BB_current ;
07633 #endif
07634 #ifdef CC
07635 *CC_p SET_TO (block->c_flag IS ON) ? block->c_number :
07636 #endif
07637 #ifdef CC
07638 settings->CC_current ;
07639 #endif
07640 }
07641 else
07642 {
07643 *px SET_TO (block->x_flag IS ON)
07644 ? ((comp AND middle) ? (block->x_number + settings->program_x)
07645 : (block->x_number + settings->current_x))
07646 : ((comp AND middle) ? settings->program_x
07647 : settings->current_x);
07648
07649 *py SET_TO (block->y_flag IS ON)
07650 ? ((comp AND middle) ? (block->y_number + settings->program_y)
07651 : (block->y_number + settings->current_y))
07652 : ((comp AND middle) ? settings->program_y
07653 : settings->current_y);
07654
07655 *pz SET_TO (block->z_flag IS ON) ?
07656 (settings->current_z + block->z_number) : settings->current_z;
07657 #ifdef AA
07658 *AA_p SET_TO (block->a_flag IS ON) ?
07659 #endif
07660 #ifdef AA
07661 (settings->AA_current + block->a_number) : settings->AA_current;
07662 #endif
07663 #ifdef BB
07664 *BB_p SET_TO (block->b_flag IS ON) ?
07665 #endif
07666 #ifdef BB
07667 (settings->BB_current + block->b_number) : settings->BB_current;
07668 #endif
07669 #ifdef CC
07670 *CC_p SET_TO (block->c_flag IS ON) ?
07671 #endif
07672 #ifdef CC
07673 (settings->CC_current + block->c_number) : settings->CC_current;
07674 #endif
07675 }
07676 return RS274NGC_OK;
07677 }
07678
07679
07680
07681
07682
07683
07684
07685
07686
07687
07688
07689
07690
07691
07692
07693
07694
07695
07696
07697
07698
07699
07700
07701 static int find_relative(
07702 double x1,
07703 double y1,
07704 double z1,
07705 #ifdef AA
07706 double AA_1,
07707 #endif
07708 #ifdef BB
07709 double BB_1,
07710 #endif
07711 #ifdef CC
07712 double CC_1,
07713 #endif
07714 double * x2,
07715 double * y2,
07716 double * z2,
07717 #ifdef AA
07718 double * AA_2,
07719 #endif
07720 #ifdef BB
07721 double * BB_2,
07722 #endif
07723 #ifdef CC
07724 double * CC_2,
07725 #endif
07726 setup_pointer settings)
07727 {
07728 *x2 SET_TO (x1 - (settings->origin_offset_x + settings->axis_offset_x));
07729 *y2 SET_TO (y1 - (settings->origin_offset_y + settings->axis_offset_y));
07730 *z2 SET_TO (z1 - (settings->tool_length_offset +
07731 settings->origin_offset_z + settings->axis_offset_z));
07732 #ifdef AA
07733 *AA_2 SET_TO (AA_1 - (settings->AA_origin_offset +
07734 #endif
07735 #ifdef AA
07736 settings->AA_axis_offset));
07737 #endif
07738 #ifdef BB
07739 *BB_2 SET_TO (BB_1 - (settings->BB_origin_offset +
07740 #endif
07741 #ifdef BB
07742 settings->BB_axis_offset));
07743 #endif
07744 #ifdef CC
07745 *CC_2 SET_TO (CC_1 - (settings->CC_origin_offset +
07746 #endif
07747 #ifdef CC
07748 settings->CC_axis_offset));
07749 #endif
07750 return RS274NGC_OK;
07751 }
07752
07753
07754
07755
07756
07757
07758
07759
07760
07761
07762
07763
07764
07765
07766
07767
07768
07769
07770
07771
07772
07773
07774
07775
07776
07777
07778
07779
07780
07781
07782
07783
07784
07785
07786 static double find_straight_length(
07787 double x2,
07788 double y2,
07789 double z2,
07790 #ifdef AA
07791 double AA_2,
07792 #endif
07793 #ifdef BB
07794 double BB_2,
07795 #endif
07796 #ifdef CC
07797 double CC_2,
07798 #endif
07799 double x1,
07800 double y1,
07801 double z1
07802 #ifdef AA
07803 , double AA_1
07804 #endif
07805 #ifdef BB
07806 , double BB_1
07807 #endif
07808 #ifdef CC
07809 , double CC_1
07810 #endif
07811 )
07812 {
07813 if ((x1 ISNT x2) OR (y1 ISNT y2) OR (z1 ISNT z2) OR
07814 (1
07815 #ifdef AA
07816 AND (AA_2 IS AA_1)
07817 #endif
07818 #ifdef BB
07819 AND (BB_2 IS BB_1)
07820 #endif
07821 #ifdef CC
07822 AND (CC_2 IS CC_1)
07823 #endif
07824 ))
07825 return sqrt(pow((x2 - x1),2) + pow((y2 - y1),2) + pow((z2 - z1),2));
07826 else
07827 return sqrt(0 +
07828 #ifdef AA
07829 pow((AA_2 - AA_1), 2) +
07830 #endif
07831 #ifdef BB
07832 pow((BB_2 - BB_1), 2) +
07833 #endif
07834 #ifdef CC
07835 pow((CC_2 - CC_1), 2) +
07836 #endif
07837 0);
07838 }
07839
07840
07841
07842
07843
07844
07845
07846
07847
07848
07849
07850
07851
07852
07853
07854 static double find_turn(
07855 double x1,
07856 double y1,
07857 double center_x,
07858 double center_y,
07859 int turn,
07860 double x2,
07861 double y2)
07862 {
07863 double alpha;
07864 double beta;
07865 double theta;
07866
07867 if (turn IS 0)
07868 return 0.0;
07869 alpha SET_TO atan2((y1 - center_y), (x1 - center_x));
07870 beta SET_TO atan2((y2 - center_y), (x2 - center_x));
07871 if (turn > 0)
07872 {
07873 if (beta <= alpha)
07874 beta SET_TO (beta + TWO_PI);
07875 theta SET_TO ((beta - alpha) + ((turn - 1) * TWO_PI));
07876 }
07877 else
07878 {
07879 if (alpha <= beta)
07880 alpha SET_TO (alpha + TWO_PI);
07881 theta SET_TO ((beta - alpha) + ((turn + 1) * TWO_PI));
07882 }
07883 return (theta);
07884 }
07885
07886
07887
07888
07889
07890
07891
07892
07893
07894
07895
07896
07897
07898
07899
07900
07901
07902
07903
07904
07905
07906
07907
07908
07909
07910
07911
07912
07913
07914
07915
07916
07917
07918
07919
07920
07921
07922
07923
07924 static int init_block(
07925 block_pointer block)
07926 {
07927 int n;
07928 #ifdef AA
07929 block->a_flag SET_TO OFF;
07930 #endif
07931 #ifdef BB
07932 block->b_flag SET_TO OFF;
07933 #endif
07934 #ifdef CC
07935 block->c_flag SET_TO OFF;
07936 #endif
07937 block->comment[0] SET_TO 0;
07938 block->d_number SET_TO -1;
07939 block->f_number SET_TO -1.0;
07940 for (n SET_TO 0; n < 14; n++)
07941 {
07942 block->g_modes[n] SET_TO -1;
07943 }
07944 block->h_number SET_TO -1;
07945 block->i_flag SET_TO OFF;
07946 block->j_flag SET_TO OFF;
07947 block->k_flag SET_TO OFF;
07948 block->l_number SET_TO -1;
07949 block->line_number SET_TO -1;
07950 block->motion_to_be SET_TO -1;
07951 block->m_count SET_TO 0;
07952 for (n SET_TO 0; n < 10; n++)
07953 {
07954 block->m_modes[n] SET_TO -1;
07955 }
07956 block->p_number SET_TO -1.0;
07957 block->q_number SET_TO -1.0;
07958 block->r_flag SET_TO OFF;
07959 block->s_number SET_TO -1.0;
07960 block->t_number SET_TO -1;
07961 block->x_flag SET_TO OFF;
07962 block->y_flag SET_TO OFF;
07963 block->z_flag SET_TO OFF;
07964
07965 return RS274NGC_OK;
07966 }
07967
07968
07969
07970
07971
07972
07973
07974
07975
07976
07977
07978
07979
07980
07981
07982
07983
07984
07985
07986
07987 static int inverse_time_rate_arc(
07988 double x1,
07989 double y1,
07990 double z1,
07991 double cx,
07992 double cy,
07993 int turn,
07994 double x2,
07995 double y2,
07996 double z2,
07997 block_pointer block,
07998 setup_pointer settings)
07999 {
08000 double length;
08001 double rate;
08002
08003 length SET_TO find_arc_length (x1, y1, z1, cx, cy, turn, x2, y2, z2);
08004 rate SET_TO MAX(0.1, (length * block->f_number));
08005 SET_FEED_RATE (rate);
08006 settings->feed_rate SET_TO rate;
08007
08008 return RS274NGC_OK;
08009 }
08010
08011
08012
08013
08014
08015
08016
08017
08018
08019
08020
08021
08022
08023
08024
08025
08026
08027
08028
08029
08030
08031
08032
08033
08034 static int inverse_time_rate_arc2(
08035 double start_x,
08036 double start_y,
08037 int turn1,
08038 double mid_x,
08039 double mid_y,
08040 double cx,
08041 double cy,
08042 int turn2,
08043 double end_x,
08044 double end_y,
08045 double end_z,
08046 block_pointer block,
08047 setup_pointer settings)
08048 {
08049 double length;
08050 double rate;
08051
08052 length SET_TO (find_arc_length (settings->current_x, settings->current_y,
08053 settings->current_z, start_x, start_y,
08054 turn1, mid_x, mid_y, settings->current_z) +
08055 find_arc_length(mid_x, mid_y, settings->current_z,
08056 cx, cy, turn2, end_x, end_y, end_z));
08057 rate SET_TO MAX(0.1, (length * block->f_number));
08058 SET_FEED_RATE (rate);
08059 settings->feed_rate SET_TO rate;
08060
08061 return RS274NGC_OK;
08062 }
08063
08064
08065
08066
08067
08068
08069
08070
08071
08072
08073
08074
08075
08076
08077
08078
08079
08080
08081
08082
08083
08084
08085
08086
08087 static int inverse_time_rate_as(
08088 double start_x,
08089 double start_y,
08090 int turn,
08091 double mid_x,
08092 double mid_y,
08093 double end_x,
08094 double end_y,
08095 double end_z,
08096 #ifdef AA
08097 double AA_end,
08098 #endif
08099 #ifdef BB
08100 double BB_end,
08101 #endif
08102 #ifdef CC
08103 double CC_end,
08104 #endif
08105 block_pointer block,
08106 setup_pointer settings)
08107 {
08108 double length;
08109 double rate;
08110
08111 length SET_TO (find_arc_length (settings->current_x, settings->current_y,
08112 settings->current_z, start_x, start_y,
08113 turn, mid_x, mid_y, settings->current_z) +
08114 find_straight_length(end_x, end_y,
08115 end_z
08116 #ifdef AA
08117 , AA_end
08118 #endif
08119
08120 #ifdef BB
08121 , BB_end
08122 #endif
08123
08124 #ifdef CC
08125 , CC_end
08126 #endif
08127 , mid_x, mid_y,
08128 settings->current_z
08129 #ifdef AA
08130 , AA_end
08131 #endif
08132
08133 #ifdef BB
08134 , BB_end
08135 #endif
08136
08137 #ifdef CC
08138 , CC_end
08139 #endif
08140 ));
08141 rate SET_TO MAX(0.1, (length * block->f_number));
08142 SET_FEED_RATE (rate);
08143 settings->feed_rate SET_TO rate;
08144
08145 return RS274NGC_OK;
08146 }
08147
08148
08149
08150
08151
08152
08153
08154
08155
08156
08157
08158
08159
08160
08161
08162
08163
08164
08165
08166 static int inverse_time_rate_straight(
08167 double end_x,
08168 double end_y,
08169 double end_z,
08170 #ifdef AA
08171 double AA_end,
08172 #endif
08173 #ifdef BB
08174 double BB_end,
08175 #endif
08176 #ifdef CC
08177 double CC_end,
08178 #endif
08179 block_pointer block,
08180 setup_pointer settings)
08181 {
08182 static char name[] SET_TO "inverse_time_rate_straight";
08183 double length;
08184 double rate;
08185
08186 length SET_TO find_straight_length
08187 (end_x, end_y, end_z
08188 #ifdef AA
08189 , AA_end
08190 #endif
08191
08192 #ifdef BB
08193 , BB_end
08194 #endif
08195
08196 #ifdef CC
08197 , CC_end
08198 #endif
08199 , settings->current_x,
08200 settings->current_y, settings->current_z
08201
08202 #ifdef AA
08203 , settings->AA_current
08204 #endif
08205
08206 #ifdef BB
08207 , settings->BB_current
08208 #endif
08209
08210 #ifdef CC
08211 , settings->CC_current
08212 #endif
08213 );
08214 rate SET_TO MAX(0.1, (length * block->f_number));
08215 SET_FEED_RATE (rate);
08216 settings->feed_rate SET_TO rate;
08217
08218 return RS274NGC_OK;
08219 }
08220
08221
08222
08223
08224
08225
08226
08227
08228
08229
08230
08231
08232
08233
08234
08235
08236
08237
08238
08239
08240
08241
08242 static int parse_line(
08243 char * line,
08244 block_pointer block,
08245 setup_pointer settings)
08246 {
08247 static char name[] SET_TO "parse_line";
08248 int status;
08249
08250 CHP(init_block (block));
08251 CHP(read_items(block, line, settings->parameters));
08252 CHP(enhance_block(block, settings));
08253 CHP(check_items (block, settings));
08254 return RS274NGC_OK;
08255 }
08256
08257
08258
08259
08260
08261
08262
08263
08264
08265
08266
08267
08268
08269
08270
08271
08272
08273 static int precedence(
08274 int an_operator)
08275 {
08276 if (an_operator IS RIGHT_BRACKET)
08277 return 1;
08278 else if (an_operator IS POWER)
08279 return 4;
08280 else if (an_operator >= AND2)
08281 return 2;
08282 else
08283 return 3;
08284 }
08285
08286
08287
08288
08289
08290
08291
08292
08293
08294
08295
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 static int read_a(
08326 char * line,
08327 int * counter,
08328 block_pointer block,
08329 double * parameters)
08330 {
08331 static char name[] SET_TO "read_a";
08332 double value;
08333 int status;
08334
08335 CHK((line[*counter] ISNT 'a'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08336 *counter SET_TO (*counter + 1);
08337 #ifdef AA
08338 CHK((block->a_flag ISNT OFF), NCE_MULTIPLE_A_WORDS_ON_ONE_LINE);
08339 #endif
08340 CHP(read_real_value(line, counter, &value, parameters));
08341 #ifdef AA
08342 block->a_flag SET_TO ON;
08343 block->a_number SET_TO value;
08344 #else
08345 #ifdef AXIS_ERROR
08346 ERM(NCE_CANNOT_USE_A_WORD);
08347 #endif
08348 #endif
08349 return RS274NGC_OK;
08350 }
08351
08352
08353
08354
08355
08356
08357
08358
08359
08360
08361
08362
08363
08364
08365
08366
08367
08368
08369
08370
08371
08372
08373
08374
08375
08376
08377
08378
08379
08380
08381
08382
08383
08384
08385
08386
08387
08388 static int read_atan(
08389 char * line,
08390 int * counter,
08391 double * double_ptr,
08392 double * parameters)
08393 {
08394 static char name[] SET_TO "read_atan";
08395 double argument2;
08396 int status;
08397
08398 CHK((line [*counter] ISNT '/'), NCE_SLASH_MISSING_AFTER_FIRST_ATAN_ARGUMENT);
08399 *counter SET_TO (*counter + 1);
08400 CHK((line[*counter] ISNT '['),
08401 NCE_LEFT_BRACKET_MISSING_AFTER_SLASH_WITH_ATAN);
08402 CHP(read_real_expression (line, counter, &argument2, parameters));
08403 *double_ptr SET_TO atan2(*double_ptr, argument2);
08404 *double_ptr SET_TO ((*double_ptr * 180.0)/PI);
08405 return RS274NGC_OK;
08406 }
08407
08408
08409
08410
08411
08412
08413
08414
08415
08416
08417
08418
08419
08420
08421
08422
08423
08424
08425
08426
08427
08428
08429
08430
08431
08432
08433
08434
08435
08436
08437
08438
08439
08440
08441
08442
08443
08444
08445
08446
08447 static int read_b(
08448 char * line,
08449 int * counter,
08450 block_pointer block,
08451 double * parameters)
08452 {
08453 static char name[] SET_TO "read_b";
08454 double value;
08455 int status;
08456
08457 CHK((line[*counter] ISNT 'b'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08458 *counter SET_TO (*counter + 1);
08459 #ifdef BB
08460 CHK((block->b_flag ISNT OFF), NCE_MULTIPLE_B_WORDS_ON_ONE_LINE);
08461 #endif
08462 CHP(read_real_value(line, counter, &value, parameters));
08463 #ifdef BB
08464 block->b_flag SET_TO ON;
08465 block->b_number SET_TO value;
08466 #else
08467 #ifdef AXIS_ERROR
08468 ERM(NCE_CANNOT_USE_B_WORD);
08469 #endif
08470 #endif
08471 return RS274NGC_OK;
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 static int read_c(
08514 char * line,
08515 int * counter,
08516 block_pointer block,
08517 double * parameters)
08518 {
08519 static char name[] SET_TO "read_c";
08520 double value;
08521 int status;
08522
08523 CHK((line[*counter] ISNT 'c'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08524 *counter SET_TO (*counter + 1);
08525 #ifdef CC
08526 CHK((block->c_flag ISNT OFF), NCE_MULTIPLE_C_WORDS_ON_ONE_LINE);
08527 #endif
08528 CHP(read_real_value(line, counter, &value, parameters));
08529 #ifdef CC
08530 block->c_flag SET_TO ON;
08531 block->c_number SET_TO value;
08532 #else
08533 #ifdef AXIS_ERROR
08534 ERM(NCE_CANNOT_USE_C_WORD);
08535 #endif
08536 #endif
08537 return RS274NGC_OK;
08538 }
08539
08540
08541
08542
08543
08544
08545
08546
08547
08548
08549
08550
08551
08552
08553
08554
08555
08556
08557
08558
08559
08560
08561
08562
08563
08564
08565
08566
08567
08568
08569
08570
08571
08572
08573
08574 static int read_comment(
08575 char * line,
08576 int * counter,
08577 block_pointer block,
08578 double * parameters)
08579 {
08580 static char name[] SET_TO "read_comment";
08581 int n;
08582
08583 CHK((line[*counter] ISNT '('), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08584 (*counter)++;
08585 for (n SET_TO 0; line[*counter] ISNT ')' ; (*counter)++, n++)
08586 {
08587 block->comment[n] SET_TO line[*counter];
08588 }
08589 block->comment[n] SET_TO 0;
08590 (*counter)++;
08591 return RS274NGC_OK;
08592 }
08593
08594
08595
08596
08597
08598
08599
08600
08601
08602
08603
08604
08605
08606
08607
08608
08609
08610
08611
08612
08613
08614
08615
08616
08617
08618
08619
08620
08621
08622
08623
08624
08625
08626
08627 static int read_d(
08628 char * line,
08629 int * counter,
08630 block_pointer block,
08631 double * parameters)
08632 {
08633 static char name[] SET_TO "read_d";
08634 int value;
08635 int status;
08636
08637 CHK((line[*counter] ISNT 'd'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08638 *counter SET_TO (*counter + 1);
08639 CHK((block->d_number > -1), NCE_MULTIPLE_D_WORDS_ON_ONE_LINE);
08640 CHP(read_integer_value(line, counter, &value, parameters));
08641 CHK((value < 0), NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED);
08642 CHK((value > _setup.tool_max), NCE_TOOL_RADIUS_INDEX_TOO_BIG);
08643 block->d_number SET_TO value;
08644 return RS274NGC_OK;
08645 }
08646
08647
08648
08649
08650
08651
08652
08653
08654
08655
08656
08657
08658
08659
08660
08661
08662
08663
08664
08665
08666
08667
08668
08669
08670
08671
08672
08673
08674
08675
08676
08677
08678
08679 static int read_f(
08680 char * line,
08681 int * counter,
08682 block_pointer block,
08683 double * parameters)
08684 {
08685 static char name[] SET_TO "read_f";
08686 double value;
08687 int status;
08688
08689 CHK((line[*counter] ISNT 'f'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08690 *counter SET_TO (*counter + 1);
08691 CHK((block->f_number > -1.0), NCE_MULTIPLE_F_WORDS_ON_ONE_LINE);
08692 CHP(read_real_value(line, counter, &value, parameters));
08693 CHK((value < 0.0), NCE_NEGATIVE_F_WORD_USED);
08694 block->f_number SET_TO value;
08695 return RS274NGC_OK;
08696 }
08697
08698
08699
08700
08701
08702
08703
08704
08705
08706
08707
08708
08709
08710
08711
08712
08713
08714
08715
08716
08717
08718
08719
08720
08721
08722
08723
08724
08725
08726
08727
08728
08729
08730
08731
08732
08733
08734
08735
08736
08737
08738
08739
08740
08741
08742
08743
08744
08745
08746
08747 static int read_g(
08748 char * line,
08749 int * counter,
08750 block_pointer block,
08751 double * parameters)
08752 {
08753 static char name[] SET_TO "read_g";
08754 double value_read;
08755 int value;
08756 int mode;
08757 int status;
08758
08759 CHK((line[*counter] ISNT 'g'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08760 *counter SET_TO (*counter + 1);
08761 CHP(read_real_value(line, counter, &value_read, parameters));
08762 value_read SET_TO (10.0 * value_read);
08763 value SET_TO (int)floor(value_read);
08764
08765 if ((value_read - value) > 0.999)
08766 value SET_TO (int)ceil(value_read);
08767 else if ((value_read - value) > 0.001)
08768 ERM(NCE_G_CODE_OUT_OF_RANGE);
08769
08770 CHK((value > 999), NCE_G_CODE_OUT_OF_RANGE);
08771 CHK((value < 0), NCE_NEGATIVE_G_CODE_USED);
08772 mode SET_TO _gees[value];
08773 CHK((mode IS -1), NCE_UNKNOWN_G_CODE_USED);
08774 CHK((block->g_modes[mode] ISNT -1),
08775 NCE_TWO_G_CODES_USED_FROM_SAME_MODAL_GROUP);
08776 block->g_modes[mode] SET_TO value;
08777 return RS274NGC_OK;
08778 }
08779
08780
08781
08782
08783
08784
08785
08786
08787
08788
08789
08790
08791
08792
08793
08794
08795
08796
08797
08798
08799
08800
08801
08802
08803
08804
08805
08806
08807
08808
08809
08810 static int read_h(
08811 char * line,
08812 int * counter,
08813 block_pointer block,
08814 double * parameters)
08815 {
08816 static char name[] SET_TO "read_h";
08817 int value;
08818 int status;
08819
08820 CHK((line[*counter] ISNT 'h'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08821 *counter SET_TO (*counter + 1);
08822 CHK((block->h_number > -1), NCE_MULTIPLE_H_WORDS_ON_ONE_LINE);
08823 CHP(read_integer_value(line, counter, &value, parameters));
08824 CHK((value < 0), NCE_NEGATIVE_H_WORD_TOOL_LENGTH_OFFSET_INDEX_USED);
08825 CHK((value > _setup.tool_max), NCE_TOOL_LENGTH_OFFSET_INDEX_TOO_BIG);
08826 block->h_number SET_TO value;
08827 return RS274NGC_OK;
08828 }
08829
08830
08831
08832
08833
08834
08835
08836
08837
08838
08839
08840
08841
08842
08843
08844
08845
08846
08847
08848
08849
08850
08851
08852
08853
08854
08855
08856
08857
08858
08859
08860
08861
08862
08863 static int read_i(
08864 char * line,
08865 int * counter,
08866 block_pointer block,
08867 double * parameters)
08868 {
08869 static char name[] SET_TO "read_i";
08870 double value;
08871 int status;
08872
08873 CHK((line[*counter] ISNT 'i'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
08874 *counter SET_TO (*counter + 1);
08875 CHK((block->i_flag ISNT OFF), NCE_MULTIPLE_I_WORDS_ON_ONE_LINE);
08876 CHP(read_real_value(line, counter, &value, parameters));
08877 block->i_flag SET_TO ON;
08878 block->i_number SET_TO value;
08879 return RS274NGC_OK;
08880 }
08881
08882
08883
08884
08885
08886
08887
08888
08889
08890
08891
08892
08893
08894
08895
08896
08897
08898
08899
08900
08901
08902
08903
08904
08905 static int read_integer_unsigned(
08906 char * line,
08907 int * counter,
08908 int * integer_ptr)
08909 {
08910 static char name[] SET_TO "read_integer_unsigned";
08911 int n;
08912 char c;
08913
08914 for (n SET_TO *counter; ; n++)
08915 {
08916 c SET_TO line[n];
08917 if ((c < 48) OR (c > 57))
08918 break;
08919 }
08920 CHK((n IS *counter), NCE_BAD_FORMAT_UNSIGNED_INTEGER);
08921 if (sscanf(line + *counter, "%d", integer_ptr) IS 0)
08922 ERM(NCE_SSCANF_FAILED);
08923 *counter SET_TO n;
08924 return RS274NGC_OK;
08925 }
08926
08927
08928
08929
08930
08931
08932
08933
08934
08935
08936
08937
08938
08939
08940
08941
08942
08943
08944
08945
08946
08947
08948
08949
08950
08951
08952
08953
08954
08955
08956
08957
08958
08959
08960
08961 static int read_integer_value(
08962 char * line,
08963 int * counter,
08964 int * integer_ptr,
08965 double * parameters)
08966 {
08967 static char name[] SET_TO "read_integer_value";
08968 double float_value;
08969 int status;
08970
08971 CHP(read_real_value(line, counter, &float_value, parameters));
08972 *integer_ptr SET_TO (int)floor(float_value);
08973 if ((float_value - *integer_ptr) > 0.9999)
08974 {
08975 *integer_ptr SET_TO (int)ceil(float_value);
08976 }
08977 else if ((float_value - *integer_ptr) > 0.0001)
08978 ERM(NCE_NON_INTEGER_VALUE_FOR_INTEGER);
08979 return RS274NGC_OK;
08980 }
08981
08982
08983
08984
08985
08986
08987
08988
08989
08990
08991
08992
08993
08994
08995
08996
08997
08998
08999
09000 static int read_items(
09001 block_pointer block,
09002 char * line,
09003 double * parameters)
09004 {
09005 static char name[] SET_TO "read_items";
09006 int counter;
09007 int length;
09008 int status;
09009
09010 length SET_TO strlen(line);
09011 counter SET_TO 0;
09012
09013 if (line[counter] IS '/')
09014 counter++;
09015 if (line[counter] IS 'n')
09016 {
09017 CHP(read_line_number(line, &counter, block));
09018 }
09019 for ( ; counter < length; )
09020 {
09021 CHP(read_one_item (line, &counter, block, parameters));
09022 }
09023 return RS274NGC_OK;
09024 }
09025
09026
09027
09028
09029
09030
09031
09032
09033
09034
09035
09036
09037
09038
09039
09040
09041
09042
09043
09044
09045
09046
09047
09048
09049
09050
09051
09052
09053
09054
09055
09056
09057
09058
09059 static int read_j(
09060 char * line,
09061 int * counter,
09062 block_pointer block,
09063 double * parameters)
09064 {
09065 static char name[] SET_TO "read_j";
09066 double value;
09067 int status;
09068
09069 CHK((line[*counter] ISNT 'j'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09070 *counter SET_TO (*counter + 1);
09071 CHK((block->j_flag ISNT OFF), NCE_MULTIPLE_J_WORDS_ON_ONE_LINE);
09072 CHP(read_real_value(line, counter, &value, parameters));
09073 block->j_flag SET_TO ON;
09074 block->j_number SET_TO value;
09075 return RS274NGC_OK;
09076 }
09077
09078
09079
09080
09081
09082
09083
09084
09085
09086
09087
09088
09089
09090
09091
09092
09093
09094
09095
09096
09097
09098
09099
09100
09101
09102
09103
09104
09105
09106
09107
09108
09109
09110
09111 static int read_k(
09112 char * line,
09113 int * counter,
09114 block_pointer block,
09115 double * parameters)
09116 {
09117 static char name[] SET_TO "read_k";
09118 double value;
09119 int status;
09120
09121 CHK((line[*counter] ISNT 'k'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09122 *counter SET_TO (*counter + 1);
09123 CHK((block->k_flag ISNT OFF), NCE_MULTIPLE_K_WORDS_ON_ONE_LINE);
09124 CHP(read_real_value(line, counter, &value, parameters));
09125 block->k_flag SET_TO ON;
09126 block->k_number SET_TO value;
09127 return RS274NGC_OK;
09128 }
09129
09130
09131
09132
09133
09134
09135
09136
09137
09138
09139
09140
09141
09142
09143
09144
09145
09146
09147
09148
09149
09150
09151
09152
09153
09154
09155
09156
09157
09158
09159
09160
09161 static int read_l(
09162 char * line,
09163 int * counter,
09164 block_pointer block,
09165 double * parameters)
09166 {
09167 static char name[] SET_TO "read_l";
09168 int value;
09169 int status;
09170
09171 CHK((line[*counter] ISNT 'l'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09172 *counter SET_TO (*counter + 1);
09173 CHK((block->l_number > -1), NCE_MULTIPLE_L_WORDS_ON_ONE_LINE);
09174 CHP(read_integer_value(line, counter, &value, parameters));
09175 CHK((value < 0), NCE_NEGATIVE_L_WORD_USED);
09176 block->l_number SET_TO value;
09177 return RS274NGC_OK;
09178 }
09179
09180
09181
09182
09183
09184
09185
09186
09187
09188
09189
09190
09191
09192
09193
09194
09195
09196
09197
09198
09199
09200
09201
09202
09203
09204
09205
09206
09207
09208
09209 static int read_line_number(
09210 char * line,
09211 int * counter,
09212 block_pointer block)
09213 {
09214 static char name[] SET_TO "read_line_number";
09215 int value;
09216 int status;
09217
09218 CHK((line[*counter] ISNT 'n'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09219 *counter SET_TO (*counter + 1);
09220 CHP(read_integer_unsigned(line, counter, &value));
09221 CHK((value > 99999), NCE_LINE_NUMBER_GREATER_THAN_99999);
09222 block->line_number SET_TO value;
09223 return RS274NGC_OK;
09224 }
09225
09226
09227
09228
09229
09230
09231
09232
09233
09234
09235
09236
09237
09238
09239
09240
09241
09242
09243
09244
09245
09246
09247
09248
09249
09250
09251
09252
09253
09254
09255
09256
09257
09258
09259
09260 static int read_m(
09261 char * line,
09262 int * counter,
09263 block_pointer block,
09264 double * parameters)
09265 {
09266 static char name[] SET_TO "read_m";
09267 int value;
09268 int mode;
09269 int status;
09270
09271 CHK((line[*counter] ISNT 'm'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09272 *counter SET_TO (*counter + 1);
09273 CHP(read_integer_value(line, counter, &value, parameters));
09274 CHK((value < 0), NCE_NEGATIVE_M_CODE_USED);
09275 CHK((value > 99), NCE_M_CODE_GREATER_THAN_99);
09276 mode SET_TO _ems[value];
09277 CHK((mode IS -1), NCE_UNKNOWN_M_CODE_USED);
09278 CHK((block->m_modes[mode] ISNT -1),
09279 NCE_TWO_M_CODES_USED_FROM_SAME_MODAL_GROUP);
09280 block->m_modes[mode] SET_TO value;
09281 block->m_count++;
09282 return RS274NGC_OK;
09283 }
09284
09285
09286
09287
09288
09289
09290
09291
09292
09293
09294
09295
09296
09297
09298
09299
09300
09301
09302
09303
09304
09305
09306
09307
09308
09309
09310
09311
09312
09313
09314
09315
09316
09317
09318
09319
09320
09321
09322
09323
09324
09325
09326
09327
09328
09329
09330 static int read_one_item(
09331 char * line,
09332 int * counter,
09333 block_pointer block,
09334 double * parameters)
09335 {
09336 static char name[] SET_TO "read_one_item";
09337 int status;
09338 read_function_pointer function_pointer;
09339 char letter;
09340
09341 letter SET_TO line[*counter];
09342 CHK(((letter < 0) OR (letter > 'z')), NCE_BAD_CHARACTER_USED);
09343 function_pointer SET_TO _readers[letter];
09344 CHK((function_pointer IS 0), NCE_BAD_CHARACTER_USED);
09345 CHP(function_pointer(line, counter, block, parameters));
09346 return RS274NGC_OK;
09347 }
09348
09349
09350
09351
09352
09353
09354
09355
09356
09357
09358
09359
09360
09361
09362
09363
09364
09365
09366
09367
09368
09369
09370
09371
09372
09373
09374
09375
09376
09377
09378 static int read_operation(
09379 char * line,
09380 int * counter,
09381 int * operation)
09382 {
09383 static char name[] SET_TO "read_operation";
09384 char c;
09385
09386 c SET_TO line[*counter];
09387 *counter SET_TO (*counter + 1);
09388 switch(c)
09389 {
09390 case '+':
09391 *operation SET_TO PLUS;
09392 break;
09393 case '-':
09394 *operation SET_TO MINUS;
09395 break;
09396 case '/':
09397 *operation SET_TO DIVIDED_BY;
09398 break;
09399 case '*':
09400 if(line[*counter] IS '*')
09401 {
09402 *operation SET_TO POWER;
09403 *counter SET_TO (*counter + 1);
09404 }
09405 else
09406 *operation SET_TO TIMES;
09407 break;
09408 case ']':
09409 *operation SET_TO RIGHT_BRACKET;
09410 break;
09411 case 'a':
09412 if((line[*counter] IS 'n') AND (line[(*counter)+1] IS 'd'))
09413 {
09414 *operation SET_TO AND2;
09415 *counter SET_TO (*counter + 2);
09416 }
09417 else
09418 ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_A);
09419 break;
09420 case 'm':
09421 if((line[*counter] IS 'o') AND (line[(*counter)+1] IS 'd'))
09422 {
09423 *operation SET_TO MODULO;
09424 *counter SET_TO (*counter + 2);
09425 }
09426 else
09427 ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_M);
09428 break;
09429 case 'o':
09430 if(line[*counter] IS 'r')
09431 {
09432 *operation SET_TO NON_EXCLUSIVE_OR;
09433 *counter SET_TO (*counter + 1);
09434 }
09435 else
09436 ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_O);
09437 break;
09438 case 'x':
09439 if((line[*counter] IS 'o') AND (line[(*counter)+1] IS 'r'))
09440 {
09441 *operation SET_TO EXCLUSIVE_OR;
09442 *counter SET_TO (*counter + 2);
09443 }
09444 else
09445 ERM(NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_X);
09446 break;
09447 case 0:
09448 ERM(NCE_UNCLOSED_EXPRESSION);
09449 default:
09450 ERM(NCE_UNKNOWN_OPERATION);
09451 }
09452 return RS274NGC_OK;
09453 }
09454
09455
09456
09457
09458
09459
09460
09461
09462
09463
09464
09465
09466
09467
09468
09469
09470
09471
09472
09473
09474
09475
09476
09477
09478
09479
09480
09481
09482
09483
09484
09485
09486
09487
09488 static int read_operation_unary(
09489 char * line,
09490 int * counter,
09491 int * operation)
09492 {
09493 static char name[] SET_TO "read_operation_unary";
09494 char c;
09495
09496 c SET_TO line[*counter];
09497 *counter SET_TO (*counter + 1);
09498 switch (c)
09499 {
09500 case 'a':
09501 if((line[*counter] IS 'b') AND (line[(*counter)+1] IS 's'))
09502 {
09503 *operation SET_TO ABS;
09504 *counter SET_TO (*counter + 2);
09505 }
09506 else if(strncmp((line + *counter), "cos", 3) IS 0)
09507 {
09508 *operation SET_TO ACOS;
09509 *counter SET_TO (*counter + 3);
09510 }
09511 else if(strncmp((line + *counter), "sin", 3) IS 0)
09512 {
09513 *operation SET_TO ASIN;
09514 *counter SET_TO (*counter + 3);
09515 }
09516 else if(strncmp((line + *counter), "tan", 3) IS 0)
09517 {
09518 *operation SET_TO ATAN;
09519 *counter SET_TO (*counter + 3);
09520 }
09521 else
09522 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_A);
09523 break;
09524 case 'c':
09525 if((line[*counter] IS 'o') AND (line[(*counter)+1] IS 's'))
09526 {
09527 *operation SET_TO COS;
09528 *counter SET_TO (*counter + 2);
09529 }
09530 else
09531 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_C);
09532 break;
09533 case 'e':
09534 if((line[*counter] IS 'x') AND (line[(*counter)+1] IS 'p'))
09535 {
09536 *operation SET_TO EXP;
09537 *counter SET_TO (*counter + 2);
09538 }
09539 else
09540 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_E);
09541 break;
09542 case 'f':
09543 if((line[*counter] IS 'i') AND (line[(*counter)+1] IS 'x'))
09544 {
09545 *operation SET_TO FIX;
09546 *counter SET_TO (*counter + 2);
09547 }
09548 else if((line[*counter] IS 'u') AND (line[(*counter)+1] IS 'p'))
09549 {
09550 *operation SET_TO FUP;
09551 *counter SET_TO (*counter + 2);
09552 }
09553 else
09554 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_F);
09555 break;
09556 case 'l':
09557 if(line[*counter] IS 'n')
09558 {
09559 *operation SET_TO LN;
09560 *counter SET_TO (*counter + 1);
09561 }
09562 else
09563 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_L);
09564 break;
09565 case 'r':
09566 if(strncmp((line + *counter), "ound", 4) IS 0)
09567 {
09568 *operation SET_TO ROUND;
09569 *counter SET_TO (*counter + 4);
09570 }
09571 else
09572 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_R);
09573 break;
09574 case 's':
09575 if((line[*counter] IS 'i') AND (line[(*counter)+1] IS 'n'))
09576 {
09577 *operation SET_TO SIN;
09578 *counter SET_TO (*counter + 2);
09579 }
09580 else if(strncmp((line + *counter), "qrt", 3) IS 0)
09581 {
09582 *operation SET_TO SQRT;
09583 *counter SET_TO (*counter + 3);
09584 }
09585 else
09586 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_S);
09587 break;
09588 case 't':
09589 if((line[*counter] IS 'a') AND (line[(*counter)+1] IS 'n'))
09590 {
09591 *operation SET_TO TAN;
09592 *counter SET_TO (*counter + 2);
09593 }
09594 else
09595 ERM(NCE_UNKNOWN_WORD_STARTING_WITH_T);
09596 break;
09597 default:
09598 ERM(NCE_UNKNOWN_WORD_WHERE_UNARY_OPERATION_COULD_BE);
09599 }
09600 return RS274NGC_OK;
09601 }
09602
09603
09604
09605
09606
09607
09608
09609
09610
09611
09612
09613
09614
09615
09616
09617
09618
09619
09620
09621
09622
09623
09624
09625
09626
09627
09628
09629
09630
09631
09632
09633
09634
09635 static int read_p(
09636 char * line,
09637 int * counter,
09638 block_pointer block,
09639 double * parameters)
09640 {
09641 static char name[] SET_TO "read_p";
09642 double value;
09643 int status;
09644
09645 CHK((line[*counter] ISNT 'p'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09646 *counter SET_TO (*counter + 1);
09647 CHK((block->p_number > -1.0), NCE_MULTIPLE_P_WORDS_ON_ONE_LINE);
09648 CHP(read_real_value(line, counter, &value, parameters));
09649 CHK((value < 0.0), NCE_NEGATIVE_P_WORD_USED);
09650 block->p_number SET_TO value;
09651 return RS274NGC_OK;
09652 }
09653
09654
09655
09656
09657
09658
09659
09660
09661
09662
09663
09664
09665
09666
09667
09668
09669
09670
09671
09672
09673
09674
09675
09676
09677
09678
09679
09680
09681
09682
09683
09684
09685
09686
09687
09688
09689
09690
09691 static int read_parameter(
09692 char * line,
09693 int * counter,
09694 double * double_ptr,
09695 double * parameters)
09696 {
09697 static char name[] SET_TO "read_parameter";
09698 int index;
09699 int status;
09700
09701 CHK((line[*counter] ISNT '#'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09702 *counter SET_TO (*counter + 1);
09703 CHP(read_integer_value(line, counter, &index, parameters));
09704 CHK(((index < 1) OR (index >= RS274NGC_MAX_PARAMETERS)),
09705 NCE_PARAMETER_NUMBER_OUT_OF_RANGE);
09706 *double_ptr SET_TO parameters[index];
09707 return RS274NGC_OK;
09708 }
09709
09710
09711
09712
09713
09714
09715
09716
09717
09718
09719
09720
09721
09722
09723
09724
09725
09726
09727
09728
09729
09730
09731
09732
09733
09734
09735
09736
09737
09738
09739
09740
09741
09742
09743
09744
09745
09746
09747
09748
09749
09750
09751
09752
09753
09754
09755
09756
09757
09758
09759
09760
09761
09762
09763
09764
09765
09766
09767
09768
09769
09770
09771
09772
09773
09774
09775
09776
09777 static int read_parameter_setting(
09778 char * line,
09779 int * counter,
09780 block_pointer block,
09781 double * parameters)
09782 {
09783 static char name[] SET_TO "read_parameter_setting";
09784 int index;
09785 double value;
09786 int status;
09787
09788 CHK((line[*counter] ISNT '#'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09789 *counter SET_TO (*counter + 1);
09790 CHP(read_integer_value(line, counter, &index, parameters));
09791 CHK(((index < 1) OR (index >= RS274NGC_MAX_PARAMETERS)),
09792 NCE_PARAMETER_NUMBER_OUT_OF_RANGE);
09793 CHK((line[*counter] ISNT '='), NCE_EQUAL_SIGN_MISSING_IN_PARAMETER_SETTING);
09794 *counter SET_TO (*counter + 1);
09795 CHP(read_real_value(line, counter, &value, parameters));
09796 _setup.parameter_numbers[_setup.parameter_occurrence] SET_TO index;
09797 _setup.parameter_values[_setup.parameter_occurrence] SET_TO value;
09798 _setup.parameter_occurrence++;
09799 return RS274NGC_OK;
09800 }
09801
09802
09803
09804
09805
09806
09807
09808
09809
09810
09811
09812
09813
09814
09815
09816
09817
09818
09819
09820
09821
09822
09823
09824
09825
09826
09827
09828
09829
09830
09831
09832
09833 static int read_q(
09834 char * line,
09835 int * counter,
09836 block_pointer block,
09837 double * parameters)
09838 {
09839 static char name[] SET_TO "read_q";
09840 double value;
09841 int status;
09842
09843 CHK((line[*counter] ISNT 'q'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09844 *counter SET_TO (*counter + 1);
09845 CHK((block->q_number > -1.0), NCE_MULTIPLE_Q_WORDS_ON_ONE_LINE);
09846 CHP(read_real_value(line, counter, &value, parameters));
09847 CHK((value <= 0.0), NCE_NEGATIVE_OR_ZERO_Q_VALUE_USED);
09848 block->q_number SET_TO value;
09849 return RS274NGC_OK;
09850 }
09851
09852
09853
09854
09855
09856
09857
09858
09859
09860
09861
09862
09863
09864
09865
09866
09867
09868
09869
09870
09871
09872
09873
09874
09875
09876
09877
09878
09879
09880
09881
09882
09883
09884
09885
09886
09887 static int read_r(
09888 char * line,
09889 int * counter,
09890 block_pointer block,
09891 double * parameters)
09892 {
09893 static char name[] SET_TO "read_r";
09894 double value;
09895 int status;
09896
09897 CHK((line[*counter] ISNT 'r'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
09898 *counter SET_TO (*counter + 1);
09899 CHK((block->r_flag ISNT OFF), NCE_MULTIPLE_R_WORDS_ON_ONE_LINE);
09900 CHP(read_real_value(line, counter, &value, parameters));
09901 block->r_flag SET_TO ON;
09902 block->r_number SET_TO value;
09903 return RS274NGC_OK;
09904 }
09905
09906
09907
09908
09909
09910
09911
09912
09913
09914
09915
09916
09917
09918
09919
09920
09921
09922
09923
09924
09925
09926
09927
09928
09929
09930
09931
09932
09933
09934
09935
09936
09937
09938
09939
09940
09941
09942
09943
09944
09945
09946
09947
09948
09949
09950
09951
09952
09953
09954
09955
09956
09957
09958
09959
09960
09961
09962
09963
09964
09965
09966
09967
09968
09969
09970
09971
09972
09973
09974
09975
09976
09977
09978
09979
09980
09981
09982
09983
09984
09985
09986
09987
09988
09989
09990
09991
09992
09993
09994
09995
09996
09997
09998
09999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104 #ifdef UNDEFINED
10105 static int read_real_expression(
10106 char * line,
10107 int * counter,
10108 double * value,
10109 double * parameters)
10110 {
10111 static char name[] SET_TO "read_real_expression";
10112 int next_operation;
10113 int status;
10114
10115 CHK((line[*counter] ISNT '['), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10116 *counter SET_TO (*counter + 1);
10117 CHP(read_real_value(line, counter, value, parameters));
10118 CHP(read_operation(line, counter, &next_operation));
10119 if (next_operation IS RIGHT_BRACKET);
10120 else if (next_operation < AND2)
10121 {
10122 CHP(read_rest_bop1(line, counter, value, &next_operation, parameters));
10123 if (next_operation IS RIGHT_BRACKET);
10124 else
10125 CHP(read_rest_bop2(line, counter, value, next_operation, parameters));
10126 }
10127 else
10128 CHP(read_rest_bop2(line, counter, value, next_operation, parameters));
10129 return RS274NGC_OK;
10130 }
10131 #endif
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153 #define MAX_STACK 5
10154
10155 static int read_real_expression(
10156 char * line,
10157 int * counter,
10158 double * value,
10159 double * parameters)
10160 {
10161 static char name[] SET_TO "read_real_expression";
10162 double values[MAX_STACK];
10163 int operators[MAX_STACK];
10164 int stack_index;
10165 int status;
10166
10167 CHK((line[*counter] ISNT '['), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10168 *counter SET_TO (*counter + 1);
10169 CHP(read_real_value(line, counter, values, parameters));
10170 CHP(read_operation(line, counter, operators));
10171 stack_index SET_TO 1;
10172 for(; operators[0] ISNT RIGHT_BRACKET ;)
10173 {
10174 CHP(read_real_value(line, counter, values+stack_index, parameters));
10175 CHP(read_operation(line, counter, operators+stack_index));
10176 if (precedence(operators[stack_index]) >
10177 precedence(operators[stack_index - 1]))
10178 stack_index++;
10179 else
10180 {
10181 for (;precedence(operators[stack_index]) <=
10182 precedence(operators[stack_index - 1]); )
10183 {
10184 CHP(execute_binary((values + stack_index - 1),
10185 operators[stack_index -1],
10186 (values + stack_index)));
10187 operators[stack_index - 1] SET_TO operators[stack_index];
10188 if ((stack_index > 1) AND
10189 (precedence(operators[stack_index - 1]) <=
10190 precedence(operators[stack_index - 2])))
10191 stack_index--;
10192 else
10193 break;
10194 }
10195 }
10196 }
10197 *value SET_TO values[0];
10198 return RS274NGC_OK;
10199 }
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239 static int read_real_number(
10240 char * line,
10241 int * counter,
10242 double * double_ptr)
10243 {
10244 static char name[] SET_TO "read_real_number";
10245 char c;
10246 int flag_digit;
10247 int flag_point;
10248 int n;
10249
10250 n SET_TO *counter;
10251 flag_point SET_TO OFF;
10252 flag_digit SET_TO OFF;
10253
10254
10255 c SET_TO line[n];
10256 if (c IS '+')
10257 {
10258 *counter SET_TO (*counter + 1);
10259 n++;
10260 }
10261 else if (c IS '-')
10262 {
10263 n++;
10264 }
10265 else if ((c ISNT '.') AND ((c < 48) OR (c > 57)))
10266 ERM(NCE_BAD_NUMBER_FORMAT);
10267
10268
10269 for (; (c SET_TO line[n]) ISNT (char) NULL; n++)
10270 {
10271 if (( 47 < c) AND ( c < 58))
10272 {
10273 flag_digit SET_TO ON;
10274 }
10275 else if (c IS '.')
10276 {
10277 if (flag_point IS OFF)
10278 {
10279 flag_point SET_TO ON;
10280 }
10281 else
10282 break;
10283 }
10284 else
10285 break;
10286 }
10287
10288 CHK((flag_digit IS OFF), NCE_NO_DIGITS_FOUND_WHERE_REAL_NUMBER_SHOULD_BE);
10289 line[n] SET_TO (char) NULL;
10290 if (sscanf(line + *counter, "%lf", double_ptr) IS 0)
10291 {
10292 line[n] SET_TO c;
10293 ERM(NCE_SSCANF_FAILED);
10294 }
10295 else
10296 {
10297 line[n] SET_TO c;
10298 *counter SET_TO n;
10299 }
10300 return RS274NGC_OK;
10301 }
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350 static int read_real_value(
10351 char * line,
10352 int * counter,
10353 double * double_ptr,
10354 double * parameters)
10355 {
10356 static char name[] SET_TO "read_real_value";
10357 char c;
10358 int status;
10359
10360 c SET_TO line[*counter];
10361 CHK((c IS 0), NCE_NO_CHARACTERS_FOUND_IN_READING_REAL_VALUE);
10362 if (c IS '[')
10363 CHP(read_real_expression (line, counter, double_ptr, parameters));
10364 else if (c IS '#')
10365 CHP(read_parameter(line, counter, double_ptr, parameters));
10366 else if ((c >= 'a') AND (c <= 'z'))
10367 CHP(read_unary(line, counter, double_ptr, parameters));
10368 else
10369 CHP(read_real_number(line, counter, double_ptr));
10370
10371 return RS274NGC_OK;
10372 }
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406 #ifdef UNDEFINED
10407 static int read_rest_bop1(
10408 char * line,
10409 int * counter,
10410 double * value,
10411 int * last_operation,
10412 double * parameters)
10413 {
10414 static char name[] SET_TO "read_rest_bop1";
10415 double next_value;
10416 int next_operation;
10417 int status;
10418
10419 for(; ; )
10420 {
10421 CHP(read_real_value(line, counter, &next_value, parameters));
10422 CHP(read_operation(line, counter, &next_operation));
10423 CHP(execute_binary1(value, *last_operation, &next_value));
10424 *last_operation SET_TO next_operation;
10425 if (next_operation >= AND2)
10426 break;
10427 }
10428 return RS274NGC_OK;
10429 }
10430 #endif
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463 #ifdef UNDEFINED
10464 static int read_rest_bop2(
10465 char * line,
10466 int * counter,
10467 double * value,
10468 int last_operation,
10469 double * parameters)
10470 {
10471 static char name[] SET_TO "read_rest_bop2";
10472 double next_value;
10473 int next_operation;
10474 int status;
10475
10476 for(; ; last_operation SET_TO next_operation)
10477 {
10478 CHP(read_real_value(line, counter, &next_value, parameters));
10479 CHP(read_operation(line, counter, &next_operation));
10480 if (next_operation < AND2)
10481 {
10482 CHP(read_rest_bop1(line, counter, &next_value,
10483 &next_operation, parameters));
10484 }
10485 CHP(execute_binary2(value, last_operation, &next_value));
10486 if (next_operation IS RIGHT_BRACKET)
10487 break;
10488 }
10489 return RS274NGC_OK;
10490 }
10491 #endif
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524 static int read_s(
10525 char * line,
10526 int * counter,
10527 block_pointer block,
10528 double * parameters)
10529 {
10530 static char name[] SET_TO "read_s";
10531 double value;
10532 int status;
10533
10534 CHK((line[*counter] ISNT 's'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10535 *counter SET_TO (*counter + 1);
10536 CHK((block->s_number > -1.0), NCE_MULTIPLE_S_WORDS_ON_ONE_LINE);
10537 CHP(read_real_value(line, counter, &value, parameters));
10538 CHK((value < 0.0), NCE_NEGATIVE_SPINDLE_SPEED_USED);
10539 block->s_number SET_TO value;
10540 return RS274NGC_OK;
10541 }
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574 static int read_t(
10575 char * line,
10576 int * counter,
10577 block_pointer block,
10578 double * parameters)
10579 {
10580 static char name[] SET_TO "read_t";
10581 int value;
10582 int status;
10583
10584 CHK((line[*counter] ISNT 't'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10585 *counter SET_TO (*counter + 1);
10586 CHK((block->t_number > -1), NCE_MULTIPLE_T_WORDS_ON_ONE_LINE);
10587 CHP(read_integer_value(line, counter, &value, parameters));
10588 CHK((value < 0), NCE_NEGATIVE_TOOL_ID_USED);
10589 block->t_number SET_TO value;
10590 return RS274NGC_OK;
10591 }
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658 static int read_text(
10659 const char * command,
10660 FILE * inport,
10661 char * raw_line,
10662 char * line,
10663 int * length)
10664 {
10665 static char name[] SET_TO "read_text";
10666 int status;
10667 int index;
10668
10669
10670 if (command IS NULL)
10671 {
10672 if(fgets(raw_line, RS274NGC_TEXT_SIZE, inport) IS NULL)
10673 {
10674 if (_setup.percent_flag IS ON)
10675 ERM(NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN);
10676 else
10677 ERM(NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN_OR_PROGRAM_END);
10678 }
10679 _setup.sequence_number++;
10680 if (strlen(raw_line) IS (RS274NGC_TEXT_SIZE - 1))
10681 {
10682 for(;fgetc(inport) ISNT '\n';){}
10683 ERM(NCE_COMMAND_TOO_LONG);
10684 }
10685 for(index SET_TO (strlen(raw_line) -1);
10686 (index >= 0) AND (isspace(raw_line[index]));
10687 index--)
10688 {
10689 raw_line[index] SET_TO 0;
10690 }
10691 strcpy(line, raw_line);
10692 CHP(close_and_downcase(line));
10693 if ((line[0] IS '%') AND (line[1] IS 0) AND (_setup.percent_flag IS ON))
10694 return RS274NGC_ENDFILE;
10695 }
10696 else
10697 {
10698 CHK((strlen(command) >= RS274NGC_TEXT_SIZE), NCE_COMMAND_TOO_LONG);
10699 strcpy(raw_line, command);
10700 strcpy(line, command);
10701 CHP(close_and_downcase(line));
10702 }
10703 _setup.parameter_occurrence SET_TO 0;
10704 if ((line[0] IS 0) OR ((line[0] IS '/') AND (line[1] IS 0)))
10705 *length SET_TO 0;
10706 else
10707 *length SET_TO strlen(line);
10708
10709 return ((line[0] IS '/')? RS274NGC_EXECUTE_FINISH : RS274NGC_OK);
10710 }
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741 static int read_unary(
10742 char * line,
10743 int * counter,
10744 double * double_ptr,
10745 double * parameters)
10746 {
10747 static char name[] SET_TO "read_unary";
10748 int operation;
10749 int status;
10750
10751 CHP(read_operation_unary (line, counter, &operation));
10752 CHK((line[*counter] ISNT '['),
10753 NCE_LEFT_BRACKET_MISSING_AFTER_UNARY_OPERATION_NAME);
10754 CHP(read_real_expression (line, counter, double_ptr, parameters));
10755
10756 if (operation IS ATAN)
10757 CHP(read_atan(line, counter, double_ptr, parameters));
10758 else
10759 CHP(execute_unary(double_ptr, operation));
10760 return RS274NGC_OK;
10761 }
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796 static int read_x(
10797 char * line,
10798 int * counter,
10799 block_pointer block,
10800 double * parameters)
10801 {
10802 static char name[] SET_TO "read_x";
10803 double value;
10804 int status;
10805
10806 CHK((line[*counter] ISNT 'x'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10807 *counter SET_TO (*counter + 1);
10808 CHK((block->x_flag ISNT OFF), NCE_MULTIPLE_X_WORDS_ON_ONE_LINE);
10809 CHP(read_real_value(line, counter, &value, parameters));
10810 block->x_flag SET_TO ON;
10811 block->x_number SET_TO value;
10812 return RS274NGC_OK;
10813 }
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848 static int read_y(
10849 char * line,
10850 int * counter,
10851 block_pointer block,
10852 double * parameters)
10853 {
10854 static char name[] SET_TO "read_y";
10855 double value;
10856 int status;
10857
10858 CHK((line[*counter] ISNT 'y'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10859 *counter SET_TO (*counter + 1);
10860 CHK((block->y_flag ISNT OFF), NCE_MULTIPLE_Y_WORDS_ON_ONE_LINE);
10861 CHP(read_real_value(line, counter, &value, parameters));
10862 block->y_flag SET_TO ON;
10863 block->y_number SET_TO value;
10864 return RS274NGC_OK;
10865 }
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900 static int read_z(
10901 char * line,
10902 int * counter,
10903 block_pointer block,
10904 double * parameters)
10905 {
10906 static char name[] SET_TO "read_z";
10907 double value;
10908 int status;
10909
10910 CHK((line[*counter] ISNT 'z'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
10911 *counter SET_TO (*counter + 1);
10912 CHK((block->z_flag ISNT OFF), NCE_MULTIPLE_Z_WORDS_ON_ONE_LINE);
10913 CHP(read_real_value(line, counter, &value, parameters));
10914 block->z_flag SET_TO ON;
10915 block->z_number SET_TO value;
10916 return RS274NGC_OK;
10917 }
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933 static int set_probe_data(
10934 setup_pointer settings)
10935 {
10936 static char name[] SET_TO "set_probe_data";
10937
10938 settings->current_x SET_TO GET_EXTERNAL_POSITION_X();
10939 settings->current_y SET_TO GET_EXTERNAL_POSITION_Y();
10940 settings->current_z SET_TO GET_EXTERNAL_POSITION_Z();
10941 #ifdef AA
10942 settings->AA_current SET_TO GET_EXTERNAL_POSITION_A();
10943 #endif
10944 #ifdef BB
10945 settings->BB_current SET_TO GET_EXTERNAL_POSITION_B();
10946 #endif
10947 #ifdef CC
10948 settings->CC_current SET_TO GET_EXTERNAL_POSITION_C();
10949 #endif
10950 settings->parameters[5061] SET_TO GET_EXTERNAL_PROBE_POSITION_X();
10951 settings->parameters[5062] SET_TO GET_EXTERNAL_PROBE_POSITION_Y();
10952 settings->parameters[5063] SET_TO GET_EXTERNAL_PROBE_POSITION_Z();
10953 #ifdef AA
10954 settings->parameters[5064] SET_TO GET_EXTERNAL_PROBE_POSITION_A();
10955 #endif
10956 #ifdef BB
10957 settings->parameters[5065] SET_TO GET_EXTERNAL_PROBE_POSITION_B();
10958 #endif
10959 #ifdef CC
10960 settings->parameters[5066] SET_TO GET_EXTERNAL_PROBE_POSITION_C();
10961 #endif
10962 settings->parameters[5067] SET_TO GET_EXTERNAL_PROBE_VALUE();
10963 return RS274NGC_OK;
10964 }
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010 static int write_g_codes(
11011 block_pointer block,
11012 setup_pointer settings)
11013 {
11014 int * gez;
11015
11016 gez SET_TO settings->active_g_codes;
11017 gez[0] SET_TO settings->sequence_number;
11018 gez[1] SET_TO settings->motion_mode;
11019 gez[2] SET_TO ((block IS NULL) ? -1 : block->g_modes[0]);
11020 gez[3] SET_TO
11021 (settings->plane IS CANON_PLANE_XY) ? G_17 :
11022 (settings->plane IS CANON_PLANE_XZ) ? G_18 : G_19;
11023 gez[4] SET_TO
11024 (settings->cutter_comp_side IS RIGHT) ? G_42 :
11025 (settings->cutter_comp_side IS LEFT) ? G_41 : G_40;
11026 gez[5] SET_TO
11027 (settings->length_units IS CANON_UNITS_INCHES) ? G_20 : G_21;
11028 gez[6] SET_TO
11029 (settings->distance_mode IS MODE_ABSOLUTE) ? G_90 : G_91;
11030 gez[7] SET_TO
11031 (settings->feed_mode IS INVERSE_TIME) ? G_93 : G_94;
11032 gez[8] SET_TO
11033 (settings->origin_index < 7) ? (530 + (10 * settings->origin_index)) :
11034 (584 + settings->origin_index);
11035 gez[9] SET_TO
11036 (settings->tool_length_offset IS 0.0) ? G_49 : G_43;
11037 gez[10] SET_TO
11038 (settings->retract_mode IS OLD_Z) ? G_98 : G_99;
11039 gez[11] SET_TO
11040 (settings->control_mode IS CANON_CONTINUOUS) ? G_64 :
11041 (settings->control_mode IS CANON_EXACT_PATH) ? G_61 : G_61_1;
11042
11043 return RS274NGC_OK;
11044 }
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064 static int write_m_codes(
11065 block_pointer block,
11066 setup_pointer settings)
11067 {
11068 int * emz;
11069
11070 emz SET_TO settings->active_m_codes;
11071 emz[0] SET_TO settings->sequence_number;
11072 emz[1] SET_TO
11073 (block IS NULL) ? -1 : block->m_modes[4];
11074 emz[2] SET_TO
11075 (settings->spindle_turning IS CANON_STOPPED) ? 5 :
11076 (settings->spindle_turning IS CANON_CLOCKWISE) ? 3 : 4;
11077 emz[3] SET_TO
11078 (block IS NULL) ? -1 : block->m_modes[6];
11079 emz[4] SET_TO
11080 (settings->mist IS ON) ? 7 :
11081 (settings->flood IS ON) ? -1 : 9;
11082 emz[5] SET_TO
11083 (settings->flood IS ON) ? 8 : -1;
11084 emz[6] SET_TO
11085 (settings->feed_override IS ON) ? 48 : 49;
11086
11087 return RS274NGC_OK;
11088 }
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106 static int write_settings(
11107 setup_pointer settings)
11108 {
11109 double * vals;
11110
11111 vals SET_TO settings->active_settings;
11112 vals[0] SET_TO settings->sequence_number;
11113 vals[1] SET_TO settings->feed_rate;
11114 vals[2] SET_TO settings->speed;
11115
11116 return RS274NGC_OK;
11117 }
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144 int rs274ngc_close()
11145 {
11146 if (_setup.file_pointer ISNT NULL)
11147 {
11148 fclose(_setup.file_pointer);
11149 _setup.file_pointer SET_TO NULL;
11150 }
11151 rs274ngc_reset();
11152
11153 return RS274NGC_OK;
11154 }
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178 #ifndef NOT_OLD_EMC_INTERP_COMPATIBLE
11179 int rs274ngc_execute(const char *command)
11180 #else
11181 int rs274ngc_execute()
11182 #endif
11183 {
11184 static char name[] SET_TO "rs274ngc_execute";
11185 int status;
11186 int n;
11187
11188 #ifndef NOT_OLD_EMC_INTERP_COMPATIBLE
11189 if(NULL != command)
11190 {
11191 status = rs274ngc_read(command);
11192 }
11193 #endif
11194
11195 for (n SET_TO 0; n < _setup.parameter_occurrence; n++)
11196 {
11197 _setup.parameters[_setup.parameter_numbers[n]]
11198 SET_TO _setup.parameter_values[n];
11199 }
11200 if (_setup.line_length ISNT 0)
11201 {
11202 status SET_TO execute_block (&(_setup.block1), &_setup);
11203 write_g_codes(&(_setup.block1), &_setup);
11204 write_m_codes(&(_setup.block1), &_setup);
11205 write_settings(&_setup);
11206 if ((status ISNT RS274NGC_OK) AND
11207 (status ISNT RS274NGC_EXECUTE_FINISH) AND
11208 (status ISNT RS274NGC_EXIT))
11209 ERP(status);
11210 }
11211 else
11212 status SET_TO RS274NGC_OK;
11213 return status;
11214 }
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233 int rs274ngc_exit()
11234 {
11235 char file_name[RS274NGC_TEXT_SIZE];
11236
11237 GET_EXTERNAL_PARAMETER_FILE_NAME(file_name, (RS274NGC_TEXT_SIZE - 1));
11238 rs274ngc_save_parameters
11239 (((file_name[0] IS 0) ? RS274NGC_PARAMETER_FILE_NAME_DEFAULT : file_name),
11240 _setup.parameters);
11241 rs274ngc_reset();
11242
11243 return RS274NGC_OK;
11244 }
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273 int rs274ngc_init()
11274 {
11275 static char name[] SET_TO "rs274ngc_init";
11276 int k;
11277 int status;
11278 char filename[RS274NGC_TEXT_SIZE];
11279 double * pars;
11280
11281 INIT_CANON();
11282 _setup.length_units SET_TO GET_EXTERNAL_LENGTH_UNIT_TYPE();
11283 USE_LENGTH_UNITS(_setup.length_units);
11284 GET_EXTERNAL_PARAMETER_FILE_NAME(filename, RS274NGC_TEXT_SIZE);
11285 if (filename[0] IS 0)
11286 strcpy(filename, RS274NGC_PARAMETER_FILE_NAME_DEFAULT);
11287 CHP(rs274ngc_restore_parameters(filename));
11288 pars SET_TO _setup.parameters;
11289 _setup.origin_index SET_TO (int)(pars[5220] + 0.0001);
11290 CHK(((_setup.origin_index < 1) OR (_setup.origin_index > 9)),
11291 NCE_COORDINATE_SYSTEM_INDEX_PARAMETER_5220_OUT_OF_RANGE);
11292 k SET_TO (5200 + (_setup.origin_index * 20));
11293 SET_ORIGIN_OFFSETS((pars[k + 1] + pars[5211]),
11294 (pars[k + 2] + pars[5212]),
11295 (pars[k + 3] + pars[5213])
11296 #ifdef AA
11297 , (pars[k + 4] + pars[5214])
11298 #else
11299 #ifdef ALL_AXES
11300 , 0
11301 #endif
11302 #endif
11303 #ifdef BB
11304 , (pars[k + 5] + pars[5215])
11305 #else
11306 #ifdef ALL_AXES
11307 , 0
11308 #endif
11309 #endif
11310 #ifdef CC
11311 , (pars[k + 6] + pars[5216])
11312 #else
11313 #ifdef ALL_AXES
11314 , 0
11315 #endif
11316 #endif
11317 );
11318 SET_FEED_REFERENCE(CANON_XYZ);
11319 #ifdef AA
11320 _setup.AA_axis_offset SET_TO pars[5214];
11321 #endif
11322
11323 #ifdef AA
11324 _setup.AA_origin_offset SET_TO pars[k + 4];
11325 #endif
11326
11327
11328
11329 _setup.axis_offset_x SET_TO pars[5211];
11330 _setup.axis_offset_y SET_TO pars[5212];
11331 _setup.axis_offset_z SET_TO pars[5213];
11332 #ifdef BB
11333 _setup.BB_axis_offset SET_TO pars[5215];
11334 #endif
11335
11336 #ifdef BB
11337 _setup.BB_origin_offset SET_TO pars[k + 5];
11338 #endif
11339
11340 _setup.blocktext[0] SET_TO 0;
11341 #ifdef CC
11342 _setup.CC_axis_offset SET_TO pars[5216];
11343 #endif
11344
11345 #ifdef CC
11346 _setup.CC_origin_offset SET_TO pars[k + 6];
11347 #endif
11348
11349
11350
11351
11352 _setup.cutter_comp_side SET_TO OFF;
11353
11354 _setup.distance_mode SET_TO MODE_ABSOLUTE;
11355 _setup.feed_mode SET_TO UNITS_PER_MINUTE;
11356 _setup.feed_override SET_TO ON;
11357
11358 _setup.filename[0] SET_TO 0;
11359 _setup.file_pointer SET_TO NULL;
11360
11361 _setup.length_offset_index SET_TO 1;
11362
11363 _setup.line_length SET_TO 0;
11364 _setup.linetext[0] SET_TO 0;
11365
11366 _setup.motion_mode SET_TO G_80;
11367
11368 _setup.origin_offset_x SET_TO pars[k + 1];
11369 _setup.origin_offset_y SET_TO pars[k + 2];
11370 _setup.origin_offset_z SET_TO pars[k + 3];
11371
11372
11373
11374
11375
11376
11377 _setup.probe_flag SET_TO OFF;
11378 _setup.program_x SET_TO UNKNOWN;
11379 _setup.program_y SET_TO UNKNOWN;
11380
11381
11382 _setup.sequence_number SET_TO 0;
11383
11384 _setup.speed_feed_mode SET_TO CANON_INDEPENDENT;
11385 _setup.speed_override SET_TO ON;
11386
11387
11388
11389 _setup.tool_length_offset SET_TO 0.0;
11390
11391
11392 _setup.tool_table_index SET_TO 1;
11393
11394
11395 write_g_codes((block_pointer)NULL, &_setup);
11396 write_m_codes((block_pointer)NULL, &_setup);
11397 write_settings(&_setup);
11398
11399
11400 rs274ngc_synch();
11401
11402 return RS274NGC_OK;
11403 }
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429 int rs274ngc_load_tool_table()
11430 {
11431 static char name[] SET_TO "rs274ngc_load_tool_table";
11432 int n;
11433
11434 CHK((_setup.tool_max > CANON_TOOL_MAX), NCE_TOOL_MAX_TOO_LARGE);
11435 for (n SET_TO 0; n <= _setup.tool_max; n++)
11436 {
11437 _setup.tool_table[n] SET_TO GET_EXTERNAL_TOOL_TABLE(n);
11438 }
11439 for(; n <= CANON_TOOL_MAX; n++)
11440 {
11441 _setup.tool_table[n].id SET_TO 0;
11442 _setup.tool_table[n].length SET_TO 0;
11443 _setup.tool_table[n].diameter SET_TO 0;
11444 }
11445
11446 return RS274NGC_OK;
11447 }
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495 int rs274ngc_open(
11496 const char * filename)
11497 {
11498 static char name[] SET_TO "rs274ngc_open";
11499 char * line;
11500 int index;
11501 int length;
11502
11503 CHK((_setup.file_pointer ISNT NULL), NCE_A_FILE_IS_ALREADY_OPEN);
11504 CHK((strlen(filename) > (RS274NGC_TEXT_SIZE - 1)), NCE_FILE_NAME_TOO_LONG);
11505 _setup.file_pointer SET_TO fopen(filename, "r");
11506 CHK((_setup.file_pointer IS NULL), NCE_UNABLE_TO_OPEN_FILE);
11507 line SET_TO _setup.linetext;
11508 for(index SET_TO -1; index IS -1;)
11509 {
11510 CHK((fgets(line, RS274NGC_TEXT_SIZE, _setup.file_pointer) IS NULL),
11511 NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN);
11512 length SET_TO strlen(line);
11513 if (length IS (RS274NGC_TEXT_SIZE - 1))
11514 {
11515 for(;fgetc(_setup.file_pointer) ISNT '\n';);
11516 ERM(NCE_COMMAND_TOO_LONG);
11517 }
11518 for(index SET_TO (length -1);
11519 (index >= 0) AND (isspace(line[index]));
11520 index--);
11521 }
11522 if(line[index] IS '%')
11523 {
11524 for(index--; (index >= 0) AND (isspace(line[index])); index--);
11525 if (index IS -1)
11526 {
11527 _setup.percent_flag SET_TO ON;
11528 _setup.sequence_number=1;
11529
11530 }
11531 else
11532 {
11533 fseek(_setup.file_pointer, 0, SEEK_SET);
11534 _setup.percent_flag SET_TO OFF;
11535 _setup.sequence_number=0;
11536 }
11537 }
11538 else
11539 {
11540 fseek(_setup.file_pointer, 0, SEEK_SET);
11541 _setup.percent_flag SET_TO OFF;
11542 _setup.sequence_number=0;
11543 }
11544 strcpy(_setup.filename, filename);
11545 rs274ngc_reset();
11546 return RS274NGC_OK;
11547 }
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580 int rs274ngc_read(
11581 const char * command)
11582 {
11583 static char name[] SET_TO "rs274ngc_read";
11584 int status;
11585 int read_status;
11586
11587 if (_setup.probe_flag IS ON)
11588 {
11589 CHK((GET_EXTERNAL_QUEUE_EMPTY() IS 0),
11590 NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING);
11591 set_probe_data(&_setup);
11592 _setup.probe_flag SET_TO OFF;
11593 }
11594 CHK(((command IS NULL) AND (_setup.file_pointer IS NULL)),
11595 NCE_FILE_NOT_OPEN);
11596 read_status SET_TO read_text(command, _setup.file_pointer, _setup.linetext,
11597 _setup.blocktext, &_setup.line_length);
11598 if ((read_status IS RS274NGC_EXECUTE_FINISH) OR
11599 (read_status IS RS274NGC_OK))
11600 {
11601 if (_setup.line_length ISNT 0)
11602 {
11603 CHP(parse_line(_setup.blocktext, &(_setup.block1), &_setup));
11604 }
11605 }
11606 else if (read_status IS RS274NGC_ENDFILE);
11607 else
11608 ERP(read_status);
11609 return read_status;
11610 }
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643 int rs274ngc_reset()
11644 {
11645 _setup.linetext[0] SET_TO 0;
11646 _setup.blocktext[0] SET_TO 0;
11647 _setup.line_length SET_TO 0;
11648
11649 return RS274NGC_OK;
11650 }
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689 int rs274ngc_restore_parameters(
11690 const char * filename)
11691 {
11692 static char name[] SET_TO "rs274ngc_restore_parameters";
11693 FILE * infile;
11694 char line[256];
11695 int variable;
11696 double value;
11697 int required;
11698 int index;
11699 double * pars;
11700 int k;
11701
11702
11703 infile SET_TO fopen(filename, "r");
11704 CHK((infile IS NULL), NCE_UNABLE_TO_OPEN_FILE);
11705
11706 pars SET_TO _setup.parameters;
11707 k SET_TO 0;
11708 index SET_TO 0;
11709 required SET_TO _required_parameters[index++];
11710 while (feof(infile) IS 0)
11711 {
11712 if (fgets(line, 256, infile) IS NULL)
11713 {
11714 break;
11715 }
11716
11717
11718 if (sscanf(line, "%d %lf", &variable, &value) IS 2)
11719 {
11720 CHK(((variable <= 0) OR (variable >= RS274NGC_MAX_PARAMETERS)),
11721 NCE_PARAMETER_NUMBER_OUT_OF_RANGE);
11722 for (; k < RS274NGC_MAX_PARAMETERS; k++)
11723 {
11724 if (k > variable)
11725 ERM(NCE_PARAMETER_FILE_OUT_OF_ORDER);
11726 else if (k IS variable)
11727 {
11728 pars[k] SET_TO value;
11729 if (k IS required)
11730 required SET_TO _required_parameters[index++];
11731 k++;
11732 break;
11733 }
11734 else
11735 {
11736 if (k IS required)
11737 ERM(NCE_REQUIRED_PARAMETER_MISSING);
11738 else
11739 pars[k] SET_TO 0;
11740 }
11741 }
11742 }
11743 }
11744 fclose(infile);
11745 CHK((required ISNT RS274NGC_MAX_PARAMETERS), NCE_REQUIRED_PARAMETER_MISSING);
11746 for (; k < RS274NGC_MAX_PARAMETERS; k++)
11747 {
11748 pars[k] SET_TO 0;
11749 }
11750 return RS274NGC_OK;
11751 }
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787 int rs274ngc_save_parameters(
11788 const char * filename,
11789 const double parameters[])
11790 {
11791 static char name[] SET_TO "rs274ngc_save_parameters";
11792 FILE * infile;
11793 FILE * outfile;
11794 char line[256];
11795 int variable;
11796 double value;
11797 int required;
11798 int index;
11799 int k;
11800
11801
11802 strcpy(line, filename);
11803 strcat(line, RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX);
11804 CHK((rename(filename, line) ISNT 0), NCE_CANNOT_CREATE_BACKUP_FILE);
11805
11806
11807 infile SET_TO fopen(line, "r");
11808 CHK((infile IS NULL), NCE_CANNOT_OPEN_BACKUP_FILE);
11809
11810
11811 outfile SET_TO fopen(filename, "w");
11812 CHK((outfile IS NULL), NCE_CANNOT_OPEN_VARIABLE_FILE);
11813
11814 k SET_TO 0;
11815 index SET_TO 0;
11816 required SET_TO _required_parameters[index++];
11817 while (feof(infile) IS 0)
11818 {
11819 if (fgets(line, 256, infile) IS NULL)
11820 {
11821 break;
11822 }
11823
11824 if (sscanf(line, "%d %lf", &variable, &value) IS 2)
11825 {
11826 CHK(((variable <= 0) OR (variable >= RS274NGC_MAX_PARAMETERS)),
11827 NCE_PARAMETER_NUMBER_OUT_OF_RANGE);
11828 for (; k < RS274NGC_MAX_PARAMETERS; k++)
11829 {
11830 if (k > variable)
11831 ERM(NCE_PARAMETER_FILE_OUT_OF_ORDER);
11832 else if (k IS variable)
11833 {
11834 sprintf(line, "%d\t%f\n", k, parameters[k]);
11835 fputs(line, outfile);
11836 if (k IS required)
11837 required SET_TO _required_parameters[index++];
11838 k++;
11839 break;
11840 }
11841 else if (k IS required)
11842 {
11843 sprintf(line, "%d\t%f\n", k, parameters[k]);
11844 fputs(line, outfile);
11845 required SET_TO _required_parameters[index++];
11846 }
11847 }
11848 }
11849 }
11850 fclose(infile);
11851 for (; k < RS274NGC_MAX_PARAMETERS; k++)
11852 {
11853 if (k IS required)
11854 {
11855 sprintf(line, "%d\t%f\n", k, parameters[k]);
11856 fputs(line, outfile);
11857 required SET_TO _required_parameters[index++];
11858 }
11859 }
11860 fclose(outfile);
11861
11862 return RS274NGC_OK;
11863 }
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884 int rs274ngc_synch()
11885 {
11886 _setup.control_mode SET_TO GET_EXTERNAL_MOTION_CONTROL_MODE();
11887 #ifdef AA
11888 _setup.AA_current SET_TO GET_EXTERNAL_POSITION_A();
11889 #endif
11890 #ifdef BB
11891 _setup.BB_current SET_TO GET_EXTERNAL_POSITION_B();
11892 #endif
11893 #ifdef CC
11894 _setup.CC_current SET_TO GET_EXTERNAL_POSITION_C();
11895 #endif
11896 _setup.current_slot SET_TO GET_EXTERNAL_TOOL_SLOT();
11897 _setup.current_x SET_TO GET_EXTERNAL_POSITION_X();
11898 _setup.current_y SET_TO GET_EXTERNAL_POSITION_Y();
11899 _setup.current_z SET_TO GET_EXTERNAL_POSITION_Z();
11900 _setup.feed_rate SET_TO GET_EXTERNAL_FEED_RATE();
11901 _setup.flood SET_TO (GET_EXTERNAL_FLOOD() ISNT 0) ? ON : OFF;
11902 _setup.length_units SET_TO GET_EXTERNAL_LENGTH_UNIT_TYPE();
11903 _setup.mist SET_TO (GET_EXTERNAL_MIST() ISNT 0) ? ON : OFF;
11904 _setup.plane SET_TO GET_EXTERNAL_PLANE();
11905 _setup.selected_tool_slot SET_TO GET_EXTERNAL_TOOL_SLOT();
11906 _setup.speed SET_TO GET_EXTERNAL_SPEED();
11907 _setup.spindle_turning SET_TO GET_EXTERNAL_SPINDLE();
11908 _setup.tool_max SET_TO GET_EXTERNAL_TOOL_MAX();
11909 _setup.traverse_rate SET_TO GET_EXTERNAL_TRAVERSE_RATE();
11910
11911 rs274ngc_load_tool_table();
11912
11913 return RS274NGC_OK;
11914 }
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940 void rs274ngc_active_g_codes(
11941 int * codes)
11942 {
11943 int n;
11944
11945 for (n SET_TO 0; n < RS274NGC_ACTIVE_G_CODES; n++)
11946 {
11947 codes[n] SET_TO _setup.active_g_codes[n];
11948 }
11949 }
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965 void rs274ngc_active_m_codes(
11966 int * codes)
11967 {
11968 int n;
11969
11970 for (n SET_TO 0; n < RS274NGC_ACTIVE_M_CODES; n++)
11971 {
11972 codes[n] SET_TO _setup.active_m_codes[n];
11973 }
11974 }
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990 void rs274ngc_active_settings(
11991 double * settings)
11992 {
11993 int n;
11994
11995 for (n SET_TO 0; n < RS274NGC_ACTIVE_SETTINGS; n++)
11996 {
11997 settings[n] SET_TO _setup.active_settings[n];
11998 }
11999 }
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020 void rs274ngc_error_text(
12021 int error_code,
12022 char * error_text,
12023 int max_size)
12024 {
12025 if (((error_code >= RS274NGC_MIN_ERROR) AND
12026 (error_code <= RS274NGC_MAX_ERROR)) AND
12027 (strlen(_rs274ngc_errors[error_code]) < ((size_t) max_size) ))
12028 {
12029 strcpy(error_text, _rs274ngc_errors[error_code]);
12030 }
12031 else
12032 error_text[0] SET_TO 0;
12033 }
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052 void rs274ngc_file_name(
12053 char * file_name,
12054 int max_size)
12055 {
12056 if (strlen(_setup.filename) < ((size_t) max_size) )
12057 strcpy(file_name, _setup.filename);
12058 else
12059 file_name[0] SET_TO 0;
12060 }
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074 int rs274ngc_line_length()
12075 {
12076 return _setup.line_length;
12077 }
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095 void rs274ngc_line_text(
12096 char * line_text,
12097 int max_size)
12098 {
12099 int n;
12100 char * the_text;
12101
12102 the_text SET_TO _setup.linetext;
12103 for (n SET_TO 0; n < (max_size - 1); n++)
12104 {
12105 if (the_text[n] ISNT 0)
12106 line_text[n] SET_TO the_text[n];
12107 else
12108 break;
12109 }
12110 line_text[n] SET_TO 0;
12111 }
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127 int rs274ngc_sequence_number()
12128 {
12129 return _setup.sequence_number;
12130 }
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156 void rs274ngc_stack_name(
12157 int stack_index,
12158 char * function_name,
12159 int max_size)
12160 {
12161 int n;
12162 char * the_name;
12163
12164 if ((stack_index > -1) AND (stack_index < 20))
12165 {
12166 the_name SET_TO _setup.stack[stack_index];
12167 for (n SET_TO 0; n < (max_size - 1); n++)
12168 {
12169 if (the_name[n] ISNT 0)
12170 function_name[n] SET_TO the_name[n];
12171 else
12172 break;
12173 }
12174 function_name[n] SET_TO 0;
12175 }
12176 else
12177 function_name[0] SET_TO 0;
12178 }
12179
12180
12181
12182