Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

rs274ngc.hh

Go to the documentation of this file.
00001 #ifndef RS274NGC_HH
00002 #define RS274NGC_HH
00003 
00004 /*
00005   rs274ngc.hh
00006 
00007   Declarations for the rs274abc translator.
00008 
00009 */
00010 
00011 /**********************/
00012 /* INCLUDE DIRECTIVES */
00013 /**********************/
00014 
00015 #include <stdio.h>
00016 #include "canon.hh"
00017 
00018 /**********************/
00019 /*   COMPILER MACROS  */
00020 /**********************/
00021 
00022 #define AND              &&
00023 #define IS               ==
00024 #define ISNT             !=
00025 #define MAX(x, y)        ((x) > (y) ? (x) : (y))
00026 #define NOT              !
00027 #define OR               ||
00028 #define SET_TO           =
00029 
00030 #ifndef TRUE
00031 #define TRUE             1
00032 #endif
00033 
00034 #ifndef FALSE
00035 #define FALSE            0
00036 #endif
00037 
00038 #define RS274NGC_TEXT_SIZE 256
00039 
00040 /* numerical constants */
00041 #define TOLERANCE_INCH 0.0002
00042 #define TOLERANCE_MM 0.002
00043 #define TOLERANCE_CONCAVE_CORNER 0.01 /* angle threshold for concavity for
00044                                          cutter compensation, in radians */
00045 #define TINY 1e-12 /* for arc_data_r */
00046 #define UNKNOWN 1e-20
00047 #define TWO_PI  6.2831853071795864
00048 
00049 #ifndef PI
00050 #define PI      3.1415926535897932
00051 #endif
00052 
00053 #ifndef PI2
00054 #define PI2     1.5707963267948966
00055 #endif
00056 
00057 // array sizes
00058 #define RS274NGC_ACTIVE_G_CODES 12
00059 #define RS274NGC_ACTIVE_M_CODES 7
00060 #define RS274NGC_ACTIVE_SETTINGS 3
00061 
00062 // name of parameter file for saving/restoring interpreter variables
00063 #define RS274NGC_PARAMETER_FILE_NAME_DEFAULT "rs274ngc.var"
00064 #define RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX ".bak"
00065 
00066 // max number of m codes on one line
00067 #define MAX_EMS  4
00068 
00069 // English - Metric conversion (long number keeps error buildup down)
00070 #define MM_PER_INCH 25.4
00071 #define INCH_PER_MM 0.039370078740157477
00072 
00073 // on-off switch settings
00074 #define OFF 0
00075 #define ON 1
00076 
00077 // feed_mode
00078 #define UNITS_PER_MINUTE 0
00079 #define INVERSE_TIME 1
00080 
00081 // cutter radius compensation mode, OFF already defined to 0
00082 // not using CANON_SIDE since interpreter handles cutter radius comp
00083 #define RIGHT 1
00084 #define LEFT 2
00085 
00086 // number of parameters in parameter table
00087 #define RS274NGC_MAX_PARAMETERS 5400
00088 
00089 // unary operations
00090 // These are not enums because the "&" operator is used in
00091 // reading the operation names and is illegal with an enum
00092 
00093 #define ABS 1
00094 #define ACOS 2
00095 #define ASIN 3
00096 #define ATAN 4
00097 #define COS 5
00098 #define EXP 6
00099 #define FIX 7
00100 #define FUP 8
00101 #define LN 9
00102 #define ROUND 10
00103 #define SIN 11
00104 #define SQRT 12
00105 #define TAN 13
00106 
00107 
00108 // binary operations
00109 #define NO_OPERATION 0
00110 #define DIVIDED_BY 1
00111 #define MODULO 2
00112 #define POWER 3
00113 #define TIMES 4
00114 #define AND2 5
00115 #define EXCLUSIVE_OR 6
00116 #define MINUS 7
00117 #define NON_EXCLUSIVE_OR 8
00118 #define PLUS 9
00119 #define RIGHT_BRACKET 10
00120 
00121 // G Codes are symbolic to be dialect-independent in source code
00122 #define G_0      0
00123 #define G_1     10
00124 #define G_2     20
00125 #define G_3     30
00126 #define G_4     40
00127 #define G_10   100
00128 #define G_17   170
00129 #define G_18   180
00130 #define G_19   190
00131 #define G_20   200
00132 #define G_21   210
00133 #define G_28   280
00134 #define G_30   300
00135 #define G_38_2 382
00136 #define G_40   400
00137 #define G_41   410
00138 #define G_42   420
00139 #define G_43   430
00140 #define G_49   490
00141 #define G_53   530
00142 #define G_54   540
00143 #define G_55   550
00144 #define G_56   560
00145 #define G_57   570
00146 #define G_58   580
00147 #define G_59   590
00148 #define G_59_1 591
00149 #define G_59_2 592
00150 #define G_59_3 593
00151 #define G_61   610
00152 #define G_61_1 611
00153 #define G_64   640
00154 #define G_80   800
00155 #define G_81   810
00156 #define G_82   820
00157 #define G_83   830
00158 #define G_84   840
00159 #define G_85   850
00160 #define G_86   860
00161 #define G_87   870
00162 #define G_88   880
00163 #define G_89   890
00164 #define G_90   900
00165 #define G_91   910
00166 #define G_92   920
00167 #define G_92_1 921
00168 #define G_92_2 922
00169 #define G_92_3 923
00170 #define G_93   930
00171 #define G_94   940
00172 #define G_98   980
00173 #define G_99   990
00174 
00175 /**********************/
00176 /*      TYPEDEFS      */
00177 /**********************/
00178 
00179 /* distance_mode */
00180 typedef enum {MODE_ABSOLUTE, MODE_INCREMENTAL} DISTANCE_MODE;
00181 
00182 /* retract_mode for cycles */
00183 typedef enum {R_PLANE, OLD_Z} RETRACT_MODE;
00184 
00185 typedef int ON_OFF;
00186 
00187 typedef struct block_struct {
00188 #ifdef AA
00189   ON_OFF   a_flag;
00190   double   a_number;
00191 #endif
00192 #ifdef BB
00193   ON_OFF   b_flag;
00194   double   b_number;
00195 #endif
00196 #ifdef CC
00197   ON_OFF   c_flag;
00198   double   c_number;
00199 #endif
00200   char     comment[256];
00201   int      d_number;
00202   double   f_number;
00203   int      g_modes[14];
00204   int      h_number;
00205   ON_OFF   i_flag;
00206   double   i_number;
00207   ON_OFF   j_flag;
00208   double   j_number;
00209   ON_OFF   k_flag;
00210   double   k_number;
00211   int      l_number;
00212   int      line_number;
00213   int      motion_to_be;
00214   int      m_count;
00215   int      m_modes[10];
00216   double   p_number;
00217   double   q_number;
00218   ON_OFF   r_flag;
00219   double   r_number;
00220   double   s_number;
00221   int      t_number;
00222   ON_OFF   x_flag;
00223   double   x_number;
00224   ON_OFF   y_flag;
00225   double   y_number;
00226   ON_OFF   z_flag;
00227   double   z_number;
00228 } block;
00229 
00230 typedef block * block_pointer;
00231 
00232 /*
00233 
00234 The current_x, current_y, and current_z are the location of the tool
00235 in the current coordinate system. current_x and current_y differ from
00236 program_x and program_y when cutter radius compensation is on.
00237 current_z is the position of the tool tip in program coordinates when
00238 tool length compensation is using the actual tool length; it is the
00239 position of the spindle when tool length is zero.
00240 
00241 In a setup, the axis_offset values are set by g92 and the origin_offset
00242 values are set by g54 - g59.3. The net origin offset uses both values
00243 and is not represented here
00244 
00245 */
00246 
00247 typedef struct setup_struct {
00248 #ifdef AA
00249   double AA_axis_offset;             // A-axis g92 offset
00250   double AA_current;                 // current A-axis position
00251   double AA_origin_offset;           // A-axis origin offset
00252 #endif
00253 #ifdef BB
00254   double BB_axis_offset;             // B-axis g92offset
00255   double BB_current;                 // current B-axis position
00256   double BB_origin_offset;           // B-axis origin offset
00257 #endif
00258 #ifdef CC
00259   double CC_axis_offset;             // C-axis g92offset
00260   double CC_current;                 // current C-axis position
00261   double CC_origin_offset;           // C-axis origin offset
00262 #endif
00263   int active_g_codes
00264       [RS274NGC_ACTIVE_G_CODES];     // array of active G codes
00265   int active_m_codes
00266       [RS274NGC_ACTIVE_M_CODES];     // array of active M codes
00267   double active_settings
00268       [RS274NGC_ACTIVE_SETTINGS];    // array of feed, speed, etc.
00269   double axis_offset_x;              // X-axis g92 offset
00270   double axis_offset_y;              // Y-axis g92 offset
00271   double axis_offset_z;              // Z-axis g92 offset
00272   block block1;                      // parsed next block
00273   char blocktext[RS274NGC_TEXT_SIZE];// linetext downcased, white space gone
00274   CANON_MOTION_MODE control_mode;    // exact path or cutting mode
00275   int current_slot;                  // carousel slot number of current tool
00276   double current_x;                  // current X-axis position
00277   double current_y;                  // current Y-axis position
00278   double current_z;                  // current Z-axis position
00279   double cutter_comp_radius;         // current cutter compensation radius
00280   int cutter_comp_side;              // current cutter compensation side
00281   double cycle_cc;                   // cc-value (normal) for canned cycles
00282   double cycle_i;                    // i-value for canned cycles
00283   double cycle_j;                    // j-value for canned cycles
00284   double cycle_k;                    // k-value for canned cycles
00285   int cycle_l;                       // l-value for canned cycles
00286   double cycle_p;                    // p-value (dwell) for canned cycles
00287   double cycle_q;                    // q-value for canned cycles
00288   double cycle_r;                    // r-value for canned cycles
00289   DISTANCE_MODE distance_mode;       // absolute or incremental
00290   int feed_mode;                     // G_93 (inverse time) or G_94 units/min
00291   ON_OFF feed_override;              // whether feed override is enabled
00292   double feed_rate;                  // feed rate in current units/min
00293   char filename[RS274NGC_TEXT_SIZE]; // name of currently open NC code file
00294   FILE * file_pointer;               // file pointer for open NC code file
00295   ON_OFF flood;                      // whether flood coolant is on
00296   int length_offset_index;           // for use with tool length offsets
00297   CANON_UNITS length_units;          // millimeters or inches
00298   int line_length;                   // length of line last read
00299   char linetext[RS274NGC_TEXT_SIZE]; // text of most recent line read
00300   ON_OFF mist;                       // whether mist coolant is on
00301   int motion_mode;                   // active G-code for motion
00302   int origin_index;                  // active origin (1=G54 to 9=G59.3)
00303   double origin_offset_x;            // origin offset x
00304   double origin_offset_y;            // origin offset y
00305   double origin_offset_z;            // origin offset z
00306   double parameters
00307       [RS274NGC_MAX_PARAMETERS];     // system parameters
00308   int parameter_occurrence;          // parameter buffer index
00309   int parameter_numbers[50];         // parameter number buffer
00310   double parameter_values[50];       // parameter value buffer
00311   ON_OFF percent_flag;               // ON means first line was percent sign
00312   CANON_PLANE plane;                 // active plane, XY-, YZ-, or XZ-plane
00313   ON_OFF probe_flag;                 // flag indicating probing done
00314   double program_x;                  // program x, used when cutter comp on
00315   double program_y;                  // program y, used when cutter comp on
00316   RETRACT_MODE retract_mode;         // for cycles, old_z or r_plane
00317   int selected_tool_slot;            // tool slot selected but not active
00318   int sequence_number;               // sequence number of line last read
00319   double speed;                      // current spindle speed in rpm
00320   CANON_SPEED_FEED_MODE speed_feed_mode;   // independent or synched
00321   ON_OFF speed_override;             // whether speed override is enabled
00322   CANON_DIRECTION spindle_turning;   // direction spindle is turning
00323   char stack[50][80];                // stack of calls for error reporting
00324   int stack_index;                   // index into the stack
00325   double tool_length_offset;         // current tool length offset
00326   int tool_max;                      // highest number tool slot in carousel
00327   CANON_TOOL_TABLE tool_table
00328        [CANON_TOOL_MAX + 1];         // index is slot number
00329   int tool_table_index;              // tool index used with cutter comp
00330   double traverse_rate;              // rate for traverse motions
00331 } setup;
00332 
00333 typedef setup * setup_pointer;
00334 
00335 // pointer to function that reads
00336 typedef int (*read_function_pointer) (char *, int *, block_pointer, double *);
00337 
00338 
00339 /*************************************************************************/
00340 /*
00341 
00342 Interface functions to call to tell the interpreter what to do.
00343 Return values indicate status of execution.
00344 These functions may change the state of the interpreter.
00345 
00346 */
00347 
00348 // close the currently open NC code file
00349 extern int rs274ngc_close();
00350 
00351 // execute a line of NC code
00352 #ifndef NOT_OLD_EMC_INTERP_COMPATIBLE
00353 extern int rs274ngc_execute(const char *command=0);
00354 #else
00355 extern int rs274ngc_execute();
00356 #endif
00357 
00358 // stop running
00359 extern int rs274ngc_exit();
00360 
00361 // get ready to run
00362 extern int rs274ngc_init();
00363 
00364 // load a tool table
00365 extern int rs274ngc_load_tool_table();
00366 
00367 // open a file of NC code
00368 extern int rs274ngc_open(const char *filename);
00369 
00370 // read the mdi or the next line of the open NC code file
00371 extern int rs274ngc_read(const char * mdi = 0);
00372 
00373 // reset yourself
00374 extern int rs274ngc_reset();
00375 
00376 // restore interpreter variables from a file
00377 extern int rs274ngc_restore_parameters(const char * filename);
00378 
00379 // save interpreter variables to file
00380 extern int rs274ngc_save_parameters(const char * filename,
00381                                     const double parameters[]);
00382 
00383 // synchronize your internal model with the external world
00384 extern int rs274ngc_synch();
00385 
00386 
00387 /*************************************************************************/
00388 /*
00389 
00390 Interface functions to call to get information from the interpreter.
00391 If a function has a return value, the return value contains the information.
00392 If a function returns nothing, information is copied into one of the
00393 arguments to the function. These functions do not change the state of
00394 the interpreter.
00395 
00396 */
00397 
00398 // copy active G codes into array [0]..[11]
00399 extern void rs274ngc_active_g_codes(int * codes);
00400 
00401 // copy active M codes into array [0]..[6]
00402 extern void rs274ngc_active_m_codes(int * codes);
00403 
00404 // copy active F, S settings into array [0]..[2]
00405 extern void rs274ngc_active_settings(double * settings);
00406 
00407 // copy the text of the error message whose number is error_code into the
00408 // error_text array, but stop at max_size if the text is longer.
00409 extern void rs274ngc_error_text(int error_code, char * error_text,
00410                                 int max_size);
00411 
00412 // copy the name of the currently open file into the file_name array,
00413 // but stop at max_size if the name is longer
00414 extern void rs274ngc_file_name(char * file_name, int max_size);
00415 
00416 // return the length of the most recently read line
00417 extern int rs274ngc_line_length();
00418 
00419 // copy the text of the most recently read line into the line_text array,
00420 // but stop at max_size if the text is longer
00421 extern void rs274ngc_line_text(char * line_text, int max_size);
00422 
00423 // return the current sequence number (how many lines read)
00424 extern int rs274ngc_sequence_number();
00425 
00426 // copy the function name from the stack_index'th position of the
00427 // function call stack at the time of the most recent error into
00428 // the function name string, but stop at max_size if the name is longer
00429 extern void rs274ngc_stack_name(int stack_index, char * function_name,
00430                                 int max_size);
00431 
00432 
00433 #ifndef NOT_OLD_EMC_INTERP_COMPATABLE
00434 // Get the parameter file name from the ini file.
00435 extern int rs274ngc_ini_load(const char *filename);
00436 static inline int rs274ngc_line() {return rs274ngc_sequence_number();}
00437 static inline const char *rs274ngc_command() { static char buf[100]; rs274ngc_line_text(buf,100); return buf;}
00438 static inline const char *rs274ngc_file() { static char buf[100]; rs274ngc_file_name(buf,100); return buf;}
00439 
00440 #endif
00441 
00442 
00443 
00444 #endif

Generated on Sun Dec 2 15:27:42 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001