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 rs274ngc translator.
00008 
00009   Modification history:
00010 
00011   7-Aug-2000  FMP added decl of _interpreter_settings, so we can access
00012   them for viewing. Added RS274NGC_COMMENT_LEN as symbol for 256.
00013   2-Aug-2000  FMP took out RS274NGC_READ_OK,ERROR,EXIT, which weren't used,
00014   and put RS274NGC_EXECUTE_FINISH with the others that were used
00015   (RS274NGC_OK,ERROR,EXIT,ENDFILE), and changed the number of EXECUTE_FINISH
00016   from 2 to 3, since 2 was used by ENDFILE.
00017   10-Jun-1999  FMP added TOLERANCE_CONCAVE_CORNER
00018   14-May-1999  FMP added 'text' argument to error printing macros, so
00019   that the NC code would be printed.
00020   12-Feb-1999  FMP checked into RCS.
00021 */
00022 
00023 /**********************/
00024 /* INCLUDE DIRECTIVES */
00025 /**********************/
00026 
00027 #include "canon.hh"
00028 
00029 /**********************/
00030 /*!   COMPILER MACROS  */
00031 /**********************/
00032 
00033 #define AND              &&
00034 #define IS               ==
00035 #define ISNT             !=
00036 #define MAX(x, y)        ((x) > (y) ? (x) : (y))
00037 #define NOT              !
00038 #define OR               ||
00039 #define SET_TO           =
00040 
00041 #ifndef TRUE
00042 #define TRUE             1
00043 #endif
00044 
00045 #ifndef FALSE
00046 #define FALSE            0
00047 #endif
00048 
00049 #define INTERP_TEXT_SIZE 256
00050 
00051 /*! numerical constants */
00052 #define TOLERANCE_INCH 0.0002
00053 #define TOLERANCE_MM 0.002
00054 #define TOLERANCE_CONCAVE_CORNER 0.01 /* angle threshold for concavity for
00055                                          cutter compensation, in radians */
00056 #define TINY 1e-12 /* for arc_data_r */
00057 #define UNKNOWN 1e-20
00058 #define TWO_PI  6.2831853071795864
00059 
00060 #ifndef PI
00061 #define PI      3.1415926535897932
00062 #endif
00063 
00064 #ifndef PI2
00065 #define PI2     1.5707963267948966
00066 #endif
00067 
00068 #define MAX_GEES 4
00069 #define MAX_EMS  4
00070 #define MAX_ACTIVES 100
00071 
00072 /*! English - Metric conversion (long number keeps error buildup down) */
00073 #define MM_PER_INCH 25.4
00074 #define INCH_PER_MM 0.039370078740157477
00075 
00076 /*! on-off switch settings */
00077 #define OFF 0
00078 #define ON 1
00079 
00080 /*! feed_mode */
00081 #define UNITS_PER_MINUTE 0
00082 #define INVERSE_TIME 1
00083 
00084 /*! error and exit status */
00085 // FMP added prefix since MS VC++ conflicts
00086 #define RS274NGC_OK 0
00087 #define RS274NGC_ERROR -1
00088 #define RS274NGC_EXIT 1
00089 #define RS274NGC_ENDFILE 2
00090 #define RS274NGC_EXECUTE_FINISH 3
00091 
00092 /*! cutter radius compensation mode */
00093 /* #define OFF 0 - already defined */
00094 /* RIGHT and LEFT defined in canon.hh
00095 #define RIGHT 1
00096 #define LEFT 2
00097 */
00098 
00099 /*! unary operations */
00100 /*! These are not enums because the "&" operator is used in
00101 reading the operation names and is illegal with an enum */
00102 
00103 #define ABS 1
00104 #define ACOS 2
00105 #define ASIN 3
00106 #define ATAN 4
00107 #define COS 5
00108 #define EXP 6
00109 #define FIX 7
00110 #define FUP 8
00111 #define LN 9
00112 #define ROUND 10
00113 #define SIN 11
00114 #define SQRT 12
00115 #define TAN 13
00116 
00117 
00118 /*! binary operations */
00119 #define NO_OPERATION 0
00120 #define DIVIDED_BY 1
00121 #define MODULO 2
00122 #define POWER 3
00123 #define TIMES 4
00124 #define AND2 5
00125 #define EXCLUSIVE_OR 6
00126 #define MINUS 7
00127 #define NON_EXCLUSIVE_OR 8
00128 #define PLUS 9
00129 #define RIGHT_BRACKET 10
00130 
00131 /*! G Codes are symbolic to be dialect-independent in source code */
00132 #define G_0      0
00133 #define G_1     10
00134 #define G_2     20
00135 #define G_3     30
00136 #define G_4     40
00137 #define G_10   100
00138 #define G_17   170
00139 #define G_18   180
00140 #define G_19   190
00141 #define G_20   200
00142 #define G_21   210
00143 #define G_38_2 382
00144 #define G_40   400
00145 #define G_41   410
00146 #define G_42   420
00147 #define G_43   430
00148 #define G_49   490
00149 #define G_53   530
00150 #define G_54   540
00151 #define G_55   550
00152 #define G_56   560
00153 #define G_57   570
00154 #define G_58   580
00155 #define G_59   590
00156 #define G_59_1 591
00157 #define G_59_2 592
00158 #define G_59_3 593
00159 #define G_61   610
00160 #define G_64   640
00161 #define G_80   800
00162 #define G_81   810
00163 #define G_82   820
00164 #define G_83   830
00165 #define G_84   840
00166 #define G_85   850
00167 #define G_86   860
00168 #define G_87   870
00169 #define G_88   880
00170 #define G_89   890
00171 #define G_90   900
00172 #define G_91   910
00173 #define G_92   920
00174 #define G_92_2 922
00175 #define G_93   930
00176 #define G_94   940
00177 #define G_98   980
00178 #define G_99   990
00179 
00180 /*!
00181 
00182 To be sure errors are handled consistently and to shorten the source
00183 code, macros are used for dealing with errors. The error macros
00184 print the name of the function returning the error and a message about
00185 the error (if one is needed) with a newline. Then ERROR is returned.
00186 The weird if-else syntax is used so that is appropriate to use a
00187 semicolon at the end of the line of source code on which the error
00188 macro is used.
00189 
00190 If error handling is changed somewhat, only the macros will need
00191 changing.
00192 
00193 There are two types of error handling macro, one for handling errors
00194 in the input code (named ERROR_MACRO) and one (named BUG_MACRO) for
00195 handling situations that should never occur regardless of the input
00196 code, and will only occur if there is a bug in the program.
00197 
00198 */
00199 
00200 #ifdef STAND_ALONE_INTERP
00201 
00202 #define ERROR_MACRO(text, function_name, message) if (1) {     \
00203   fprintf(stderr, "%s\n%s: error %d:\n%s\n",                   \
00204               text,                                            \
00205               function_name,                                   \
00206               utility_error_number(message, interp_errors, 0), \
00207               message);                                        \
00208   return RS274NGC_ERROR;                                       \
00209 } else
00210 
00211 #else
00212 
00213 #define ERROR_MACRO(text, function_name, message) if (1) {     \
00214   CANON_ERROR("%s\n%s: error %d: %s",                      \
00215               text,                                            \
00216               function_name,                                   \
00217               utility_error_number(message, interp_errors, 0), \
00218               message);                                        \
00219   return RS274NGC_ERROR;                                       \
00220 } else
00221 
00222 #endif
00223 
00224 #ifdef STAND_ALONE_INTERP
00225 
00226 #define ERR_MACRO(text, function_name, message) if (1) {       \
00227   if (_interpreter_fp ISNT NULL)                               \
00228     {fclose(_interpreter_fp); _interpreter_fp SET_TO NULL;}    \
00229   fprintf(stderr, "%s\n%s: error %d:\n%s\n",                   \
00230               text,                                            \
00231               function_name,                                   \
00232               utility_error_number(message, interp_errors, 0), \
00233               message);                                        \
00234   return RS274NGC_ERROR;                                       \
00235 } else
00236 
00237 #else
00238 
00239 #define ERR_MACRO(text, function_name, message) if (1) {       \
00240   if (_interpreter_fp ISNT NULL)                               \
00241     {fclose(_interpreter_fp); _interpreter_fp SET_TO NULL;}    \
00242   CANON_ERROR("%s\n%s: error %d: %s",                      \
00243               text,                                            \
00244               function_name,                                   \
00245               utility_error_number(message, interp_errors, 0), \
00246               message);                                        \
00247   return RS274NGC_ERROR;                                       \
00248 } else
00249 
00250 #endif
00251 
00252 #define ERROR_MACRO_PASS(function_name) return RS274NGC_ERROR
00253 
00254 #define ERR_MACRO_PASS(function_name) if (1) {               \
00255   if (_interpreter_fp ISNT NULL)                             \
00256     {fclose(_interpreter_fp); _interpreter_fp SET_TO NULL;}  \
00257   return RS274NGC_ERROR;                                     \
00258 } else
00259 
00260 
00261 #ifdef STAND_ALONE_INTERP
00262 
00263 #define BUG_MACRO(function_name, message) if (1) {           \
00264   fprintf(stderr, "%s: bug %d:\n%s\n", function_name,        \
00265           utility_error_number(message, interp_errors, 200), \
00266           message);                                          \
00267   return RS274NGC_ERROR;                                     \
00268 } else
00269 
00270 #else
00271 
00272 #define BUG_MACRO(function_name, message) if (1) \
00273 { \
00274   CANON_ERROR("%s: bug %d: %s", \
00275               function_name, \
00276               utility_error_number(message, interp_errors, 200), \
00277               message); \
00278   return RS274NGC_ERROR; \
00279 } else
00280 
00281 #endif
00282 
00283 /**********************/
00284 /*      TYPEDEFS      */
00285 /**********************/
00286 
00287 /*! distance_mode */
00288 // FMP added prefix since ABSOLUTE conflicts with MS VC++
00289 typedef enum {MODE_ABSOLUTE, MODE_INCREMENTAL} DISTANCE_MODE;
00290 
00291 /*! retract_mode for cycles */
00292 typedef enum {R_PLANE, OLD_Z} RETRACT_MODE;
00293 
00294 /*!
00295 
00296 The current_x, current_y, and current_z are the location of the tool
00297 in the current coordinate system. current_x and current_y differ from
00298 program_x and program_y when cutter radius compensation is on.
00299 current_z is the position of the tool tip in program coordinates when
00300 tool length compensation is on; it is the position of the spindle when
00301 tool length compensation is off.
00302 
00303 */
00304 
00305 typedef int ON_OFF;
00306 
00307 #define RS274NGC_MAX_PARAMETERS 5400
00308 
00309 typedef struct setup_struct {
00310   double axis_offset_x;
00311   double axis_offset_y;
00312   double axis_offset_z;
00313   ON_OFF block_delete;
00314   CANON_MOTION_MODE control_mode;
00315   int current_slot;
00316   double current_x;
00317   double current_y;
00318   double current_z;
00319   int cutter_radius_compensation;
00320   double cycle_i;
00321   double cycle_j;
00322   double cycle_k;
00323   int cycle_l;
00324   double cycle_p;
00325   double cycle_q;
00326   double cycle_r;
00327   double cycle_z;
00328   DISTANCE_MODE distance_mode;
00329   int feed_mode;
00330   ON_OFF feed_override;
00331   double feed_rate;
00332   ON_OFF flood;
00333   int length_offset_index; /*! for use with tool length offsets */
00334   CANON_UNITS length_units;
00335   ON_OFF mist;
00336   int motion_mode;
00337   int origin_ngc;
00338   double origin_offset_x;
00339   double origin_offset_y;
00340   double origin_offset_z;
00341   double parameters[RS274NGC_MAX_PARAMETERS];
00342   CANON_PLANE plane;
00343   ON_OFF probe_flag;
00344   double program_x;  /*! used when cutter radius compensation is on */
00345   double program_y;
00346   RETRACT_MODE retract_mode;
00347   int selected_tool_slot;
00348   double speed;
00349   CANON_SPEED_FEED_MODE speed_feed_mode;
00350   ON_OFF speed_override;
00351   CANON_DIRECTION spindle_turning;
00352   double tool_length_offset;
00353   CANON_TOOL_TABLE tool_table[CANON_TOOL_MAX + 1]; //  7-Nov-1997 FMP
00354   int tool_table_index; /*! for use with cutter radius compensation */
00355   double traverse_rate;
00356 } setup;
00357 
00358 extern setup _interpreter_settings; //! global in rs274ngc.cc for all settings
00359 
00360 typedef setup * setup_pointer;
00361 
00362 #define RS274NGC_COMMENT_LEN 256
00363 typedef struct block_struct {
00364   char     comment[RS274NGC_COMMENT_LEN];
00365   int      d_number;
00366   double   f_number;
00367   int      g_count;
00368   int      g_modes[14];
00369   int      h_number;
00370   ON_OFF   i_flag;
00371   double   i_number;
00372   ON_OFF   j_flag;
00373   double   j_number;
00374   ON_OFF   k_flag;
00375   double   k_number;
00376   int      l_number;
00377   int      line_number;
00378   int      motion_to_be;
00379   int      m_count;
00380   int      m_modes[10];
00381   double   p_number;
00382   double   q_number;
00383   ON_OFF   r_flag;
00384   double   r_number;
00385   double   s_number;
00386   int      t_number;
00387   ON_OFF   x_flag;
00388   double   x_number;
00389   ON_OFF   y_flag;
00390   double   y_number;
00391   ON_OFF   z_flag;
00392   double   z_number;
00393 } block;
00394 
00395 typedef block * block_pointer;
00396 
00397 /*! calling interface */
00398 
00399 extern int rs274ngc_init();
00400 extern int rs274ngc_open(const char *filename);
00401 extern int rs274ngc_close();
00402 extern int rs274ngc_read();
00403 extern int rs274ngc_execute(const char * mdi = 0);
00404 extern int rs274ngc_reset();
00405 extern int rs274ngc_synch();
00406 extern int rs274ngc_exit();
00407 
00408 extern const char *rs274ngc_file();
00409 extern int rs274ngc_line();
00410 extern const char *rs274ngc_command();
00411 
00412 extern int rs274ngc_load_tool_table();
00413 
00414 //! name of parameter file for saving/restoring interpreter variables
00415 #define DEFAULT_RS274NGC_PARAMETER_FILE "rs274ngc.var"
00416 extern char RS274NGC_PARAMETER_FILE[INTERP_TEXT_SIZE];
00417 #define RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX ".bak"
00418 
00419 //! restore interpreter variables from file
00420 extern int rs274ngc_restore_parameters(const char *filename, double parameters[]);
00421 
00422 //! save interpreter variables to file
00423 extern int rs274ngc_save_parameters(const char *filename, const double parameters[]);
00424 
00425 //! load settings from INI file
00426 extern int rs274ngc_ini_load(const char *filename);
00427 
00428 //! copy active G codes into array [0]..[11]
00429 #define RS274NGC_ACTIVE_G_CODES 12
00430 extern int rs274ngc_active_g_codes(int *codes);
00431 
00432 //! copy active M codes into array [0]..[6]
00433 #define RS274NGC_ACTIVE_M_CODES 7
00434 extern int rs274ngc_active_m_codes(int *codes);
00435 
00436 //! copy active F, S settings into array [0]..[2]
00437 #define RS274NGC_ACTIVE_SETTINGS 3
00438 extern int rs274ngc_active_settings(double *settings);
00439 
00440 #endif

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