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 #include <stdlib.h>
00037 #include <string.h>
00038
00039 #include "emc.hh"
00040 #include "emcglb.h"
00041 #include "interpl.hh"
00042 #include "canon.hh"
00043 #include "rs274ngc.hh"
00044
00045
00046 #ifdef NEW_INTERPRETER
00047 #include "rs274ngc_return.hh"
00048 #endif
00049
00050
00051 #ifndef __GNUC__
00052 #ifndef __attribute__
00053 #define __attribute__(x)
00054 #endif
00055 #endif
00056
00057 static char __attribute__((unused)) ident[] = "$Id: emctask.cc,v 1.15 2001/11/14 19:07:12 wshackle Exp $";
00058
00059
00060 static int mdiOrAuto = EMC_TASK_MODE_AUTO;
00061
00062
00063
00064 int emcTaskInit()
00065 {
00066 return 0;
00067 }
00068
00069 int emcTaskHalt()
00070 {
00071 return 0;
00072 }
00073
00074 int emcTaskAbort()
00075 {
00076 emcMotionAbort();
00077 emcIoAbort();
00078
00079 return 0;
00080 }
00081
00082 int emcTaskSetMode(int mode)
00083 {
00084 int retval = 0;
00085
00086 switch (mode) {
00087 case EMC_TASK_MODE_MANUAL:
00088
00089 emcTrajSetMode(EMC_TRAJ_MODE_FREE);
00090 mdiOrAuto = EMC_TASK_MODE_AUTO;
00091 break;
00092
00093 case EMC_TASK_MODE_MDI:
00094
00095 emcTrajSetMode(EMC_TRAJ_MODE_COORD);
00096 emcTaskPlanSynch();
00097 mdiOrAuto = EMC_TASK_MODE_MDI;
00098 break;
00099
00100 case EMC_TASK_MODE_AUTO:
00101
00102 emcTrajSetMode(EMC_TRAJ_MODE_COORD);
00103 emcTaskPlanSynch();
00104 mdiOrAuto = EMC_TASK_MODE_AUTO;
00105 break;
00106
00107 default:
00108 retval = -1;
00109 break;
00110 }
00111
00112 return retval;
00113 }
00114
00115 int emcTaskSetState(int state)
00116 {
00117 int t;
00118 int retval = 0;
00119
00120 switch (state) {
00121 case EMC_TASK_STATE_OFF:
00122
00123 for (t = 0; t < emcStatus->motion.traj.axes; t++) {
00124 emcAxisDisable(t);
00125 }
00126 emcTrajDisable();
00127 emcLubeOff();
00128 break;
00129
00130 case EMC_TASK_STATE_ON:
00131
00132 emcTrajEnable();
00133 for (t = 0; t < emcStatus->motion.traj.axes; t++) {
00134 emcAxisEnable(t);
00135 }
00136 emcLubeOn();
00137 break;
00138
00139 case EMC_TASK_STATE_ESTOP_RESET:
00140
00141 if(emcStatus->io.aux.estopIn)
00142 {
00143 rcs_print("Can't come out of estop while the estop button is in.");
00144 }
00145 emcAuxEstopOff();
00146 emcLubeOff();
00147 break;
00148
00149 case EMC_TASK_STATE_ESTOP:
00150
00151 emcAuxEstopOn();
00152 for (t = 0; t < emcStatus->motion.traj.axes; t++) {
00153 emcAxisDisable(t);
00154 }
00155 emcTrajDisable();
00156 emcLubeOff();
00157 break;
00158
00159 default:
00160 retval = -1;
00161 break;
00162 }
00163
00164 return retval;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 static int determineMode()
00183 {
00184
00185 if (emcStatus->motion.traj.mode == EMC_TRAJ_MODE_FREE ||
00186 emcStatus->motion.traj.mode == EMC_TRAJ_MODE_TELEOP ) {
00187 return EMC_TASK_MODE_MANUAL;
00188 }
00189
00190
00191 return mdiOrAuto;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 static int determineState()
00209 {
00210 if (emcStatus->io.aux.estop) {
00211 return EMC_TASK_STATE_ESTOP;
00212 }
00213
00214 if (! emcStatus->motion.traj.enabled) {
00215 return EMC_TASK_STATE_ESTOP_RESET;
00216 }
00217
00218 return EMC_TASK_STATE_ON;
00219 }
00220
00221 static int waitFlag = 0;
00222
00223
00224 #ifdef NEW_INTERPRETER
00225 static char rs274ngc_error_text_buf[256];
00226 static char rs274ngc_stack_buf[256];
00227
00228 static void print_rs274ngc_error(int retval)
00229 {
00230 int index = 0;
00231 if(retval == 0)
00232 {
00233 return;
00234 }
00235
00236 if( 0 != emcStatus)
00237 {
00238 emcStatus->task.interpreter_errcode = retval;
00239 }
00240
00241 rs274ngc_error_text_buf[0]=0;
00242 rs274ngc_error_text(retval, rs274ngc_error_text_buf,256);
00243 if(0 != rs274ngc_error_text_buf[0])
00244 {
00245 rcs_print_error("rs274ngc_error: %s\n",rs274ngc_error_text_buf);
00246 }
00247 emcOperatorError(0,rs274ngc_error_text_buf);
00248 index=0;
00249 if (EMC_DEBUG & EMC_DEBUG_INTERP)
00250 {
00251 rcs_print("rs274ngc_stack: \t");
00252 while(index < 5)
00253 {
00254 rs274ngc_stack_buf[0]=0;
00255 rs274ngc_stack_name(index,rs274ngc_stack_buf,256);
00256 if(0 == rs274ngc_stack_buf[0])
00257 {
00258 break;
00259 }
00260 rcs_print(" - %s ",rs274ngc_stack_buf);
00261 index++;
00262 }
00263 rcs_print("\n");
00264 }
00265 }
00266
00267 #endif // NEW_INTERPRETER
00268
00269
00270 int emcTaskPlanInit()
00271 {
00272 rs274ngc_ini_load(EMC_INIFILE);
00273 waitFlag = 0;
00274
00275 int retval = rs274ngc_init();
00276 #ifdef NEW_INTERPRETER
00277 if(retval > RS274NGC_MIN_ERROR)
00278 {
00279 print_rs274ngc_error(retval);
00280 }
00281 else
00282 {
00283 if( 0 != RS274NGC_STARTUP_CODE[0])
00284 {
00285 retval = rs274ngc_execute(RS274NGC_STARTUP_CODE);
00286 if(retval > RS274NGC_MIN_ERROR)
00287 {
00288 print_rs274ngc_error(retval);
00289 }
00290 }
00291 }
00292 #else
00293 if( 0 != RS274NGC_STARTUP_CODE[0])
00294 {
00295 rs274ngc_execute(RS274NGC_STARTUP_CODE);
00296 }
00297 #endif
00298 return retval;
00299 }
00300
00301 int emcTaskPlanSetWait()
00302 {
00303 waitFlag = 1;
00304
00305 return 0;
00306 }
00307
00308 int emcTaskPlanIsWait()
00309 {
00310 return waitFlag;
00311 }
00312
00313 int emcTaskPlanClearWait()
00314 {
00315 waitFlag = 0;
00316
00317 return 0;
00318 }
00319
00320 int emcTaskPlanSynch()
00321 {
00322 return rs274ngc_synch();
00323 }
00324
00325 int emcTaskPlanExit()
00326 {
00327 return rs274ngc_exit();
00328 }
00329
00330 int emcTaskPlanOpen(const char *file)
00331 {
00332 if(emcStatus != 0)
00333 {
00334 emcStatus->task.motionLine = 0;
00335 emcStatus->task.currentLine = 0;
00336 emcStatus->task.readLine = 0;
00337 }
00338
00339 int retval = rs274ngc_open(file);
00340 #ifdef NEW_INTERPRETER
00341 if(retval > RS274NGC_MIN_ERROR)
00342 {
00343 print_rs274ngc_error(retval);
00344 return retval;
00345 }
00346 #endif
00347 taskplanopen=1;
00348 return retval;
00349 }
00350
00351
00352 int emcTaskPlanRead()
00353 {
00354 int retval = rs274ngc_read();
00355 #ifdef NEW_INTERPRETER
00356 if(retval == NCE_FILE_NOT_OPEN)
00357 {
00358 if(emcStatus->task.file[0] != 0)
00359 {
00360 retval = rs274ngc_open(emcStatus->task.file);
00361 if(retval > RS274NGC_MIN_ERROR)
00362 {
00363 print_rs274ngc_error(retval);
00364 }
00365 retval = rs274ngc_read();
00366 }
00367 }
00368 if(retval > RS274NGC_MIN_ERROR)
00369 {
00370 print_rs274ngc_error(retval);
00371 }
00372 #endif
00373 return retval;
00374 }
00375
00376 int emcTaskPlanExecute(const char *command)
00377 {
00378 if(command != 0)
00379 {
00380 if(*command != 0)
00381 {
00382 rs274ngc_synch();
00383 }
00384 }
00385 int retval = rs274ngc_execute(command);
00386 #ifdef NEW_INTERPRETER
00387 if(retval > RS274NGC_MIN_ERROR)
00388 {
00389 print_rs274ngc_error(retval);
00390 }
00391 #endif
00392 return retval;
00393 }
00394
00395 int emcTaskPlanClose()
00396 {
00397 int retval = rs274ngc_close();
00398 #ifdef NEW_INTERPRETER
00399 if(retval > RS274NGC_MIN_ERROR)
00400 {
00401 print_rs274ngc_error(retval);
00402 }
00403 #endif
00404
00405 taskplanopen=0;
00406 return retval;
00407 }
00408
00409 int emcTaskPlanLine()
00410 {
00411 return rs274ngc_line();
00412 }
00413
00414 int emcTaskPlanCommand(char *cmd)
00415 {
00416 strcpy(cmd, rs274ngc_command());
00417 return 0;
00418 }
00419
00420 int emcTaskUpdate(EMC_TASK_STAT *stat)
00421 {
00422 stat->mode = determineMode();
00423 stat->state = determineState();
00424
00425
00426
00427 if(emcStatus->motion.traj.id > 0)
00428 {
00429 stat->motionLine = emcStatus->motion.traj.id;
00430 }
00431
00432
00433
00434 strcpy(stat->file, rs274ngc_file());
00435
00436
00437
00438 rs274ngc_active_g_codes(&stat->activeGCodes[0]);
00439 rs274ngc_active_m_codes(&stat->activeMCodes[0]);
00440 rs274ngc_active_settings(&stat->activeSettings[0]);
00441
00442 stat->heartbeat++;
00443
00444 return 0;
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459