Missed a few files in the last effort....

This commit is contained in:
Paul Corner 2005-05-23 01:54:48 +00:00
parent d21500c65e
commit c06400d4bd
46 changed files with 34832 additions and 34814 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,93 +1,93 @@
/********************************************************************
* Description: emcmotcfg.h
* Default values for compile-time parameters, used to initialize
* global variables in emcmotcfg.c.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCMOTCFG_H
#define EMCMOTCFG_H
/* default name of EMCMOT ini file */
#define DEFAULT_EMCMOT_INIFILE "emc.ini" /* same as for EMC-- we're in
touch */
/* number of axes supported
Note: this is not a global variable but a compile-time parameter
since it sets array sizes, etc. */
#define EMCMOT_MAX_AXIS 8
#define EMCMOT_ERROR_NUM 32 /* how many errors we can queue */
#define EMCMOT_ERROR_LEN 256 /* how long error string can be */
/*
Shared memory keys for simulated motion process. No base address
values need to be computed, since operating system does this for us
*/
#define DEFAULT_SHMEM_KEY 100
/* default comm timeout, in seconds */
#define DEFAULT_EMCMOT_COMM_TIMEOUT 1.0
/* seconds to delay between comm retries */
#define DEFAULT_EMCMOT_COMM_WAIT 0.010
/* default cycle time for trajectory calculations; cycle time
for emcmot.c main loop will be this times the interpolation rate */
#if defined(rtlinux) || defined(rtai)
#define DEFAULT_TRAJ_CYCLE_TIME 0.010
#define DEFAULT_SERVO_CYCLE_TIME 0.001
#else
#define DEFAULT_TRAJ_CYCLE_TIME 0.200
#define DEFAULT_SERVO_CYCLE_TIME 0.020
#endif
/* initial velocity, accel used for coordinated moves */
#define DEFAULT_VELOCITY 1.0
#define DEFAULT_ACCELERATION 10.0
/* maximum and minimum limit defaults for all axes */
#define DEFAULT_MAX_LIMIT 1000
#define DEFAULT_MIN_LIMIT -1000
/* output clamps before scaling */
#define DEFAULT_MAX_OUTPUT 10.0
#define DEFAULT_MIN_OUTPUT -10.0
/* size of motion queue */
#define DEFAULT_TC_QUEUE_SIZE 200
/* size of window for averages */
#define DEFAULT_MMXAVG_SIZE 100
/* max following error */
#define DEFAULT_MAX_FERROR 100
/* PID gains */
#define DEFAULT_P_GAIN 0.0
#define DEFAULT_I_GAIN 0.0
#define DEFAULT_D_GAIN 0.0
#define DEFAULT_FF0_GAIN 0.0
#define DEFAULT_FF1_GAIN 0.0
#define DEFAULT_FF2_GAIN 0.0
#define DEFAULT_BACKLASH 0.0
#define DEFAULT_BIAS 0.0
#define DEFAULT_MAX_ERROR 0.0
/* input, output scales */
#define DEFAULT_INPUT_SCALE 1.0
#define DEFAULT_INPUT_OFFSET 0.0
#define DEFAULT_OUTPUT_SCALE 1.0
#define DEFAULT_OUTPUT_OFFSET 0.0
#endif
/********************************************************************
* Description: emcmotcfg.h
* Default values for compile-time parameters, used to initialize
* global variables in emcmotcfg.c.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCMOTCFG_H
#define EMCMOTCFG_H
/* default name of EMCMOT ini file */
#define DEFAULT_EMCMOT_INIFILE "emc.ini" /* same as for EMC-- we're in
touch */
/* number of axes supported
Note: this is not a global variable but a compile-time parameter
since it sets array sizes, etc. */
#define EMCMOT_MAX_AXIS 8
#define EMCMOT_ERROR_NUM 32 /* how many errors we can queue */
#define EMCMOT_ERROR_LEN 256 /* how long error string can be */
/*
Shared memory keys for simulated motion process. No base address
values need to be computed, since operating system does this for us
*/
#define DEFAULT_SHMEM_KEY 100
/* default comm timeout, in seconds */
#define DEFAULT_EMCMOT_COMM_TIMEOUT 1.0
/* seconds to delay between comm retries */
#define DEFAULT_EMCMOT_COMM_WAIT 0.010
/* default cycle time for trajectory calculations; cycle time
for emcmot.c main loop will be this times the interpolation rate */
#if defined(rtlinux) || defined(rtai)
#define DEFAULT_TRAJ_CYCLE_TIME 0.010
#define DEFAULT_SERVO_CYCLE_TIME 0.001
#else
#define DEFAULT_TRAJ_CYCLE_TIME 0.200
#define DEFAULT_SERVO_CYCLE_TIME 0.020
#endif
/* initial velocity, accel used for coordinated moves */
#define DEFAULT_VELOCITY 1.0
#define DEFAULT_ACCELERATION 10.0
/* maximum and minimum limit defaults for all axes */
#define DEFAULT_MAX_LIMIT 1000
#define DEFAULT_MIN_LIMIT -1000
/* output clamps before scaling */
#define DEFAULT_MAX_OUTPUT 10.0
#define DEFAULT_MIN_OUTPUT -10.0
/* size of motion queue */
#define DEFAULT_TC_QUEUE_SIZE 200
/* size of window for averages */
#define DEFAULT_MMXAVG_SIZE 100
/* max following error */
#define DEFAULT_MAX_FERROR 100
/* PID gains */
#define DEFAULT_P_GAIN 0.0
#define DEFAULT_I_GAIN 0.0
#define DEFAULT_D_GAIN 0.0
#define DEFAULT_FF0_GAIN 0.0
#define DEFAULT_FF1_GAIN 0.0
#define DEFAULT_FF2_GAIN 0.0
#define DEFAULT_BACKLASH 0.0
#define DEFAULT_BIAS 0.0
#define DEFAULT_MAX_ERROR 0.0
/* input, output scales */
#define DEFAULT_INPUT_SCALE 1.0
#define DEFAULT_INPUT_OFFSET 0.0
#define DEFAULT_OUTPUT_SCALE 1.0
#define DEFAULT_OUTPUT_OFFSET 0.0
#endif

View file

@ -1,73 +1,73 @@
/********************************************************************
* Description: emcmotglb.c
* Compile-time configuration parameters
*
* Set the values in emcmotcfg.h; these vars will be set to those values
* and emcmot.c can reference the variables with their defaults. This file
* exists to avoid having to recompile emcmot.c every time a default is
* changed.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include "emcmotglb.h" /* these decls */
#include "emcmotcfg.h" /* initial values */
char EMCMOT_INIFILE[EMCMOT_INIFILE_LEN] = DEFAULT_EMCMOT_INIFILE;
unsigned int SHMEM_KEY = DEFAULT_SHMEM_KEY;
double EMCMOT_COMM_TIMEOUT = DEFAULT_EMCMOT_COMM_TIMEOUT;
double EMCMOT_COMM_WAIT = DEFAULT_EMCMOT_COMM_WAIT;
int num_axes = EMCMOT_MAX_AXIS;
double TRAJ_CYCLE_TIME = DEFAULT_TRAJ_CYCLE_TIME;
double SERVO_CYCLE_TIME = DEFAULT_SERVO_CYCLE_TIME;
double VELOCITY = DEFAULT_VELOCITY;
double ACCELERATION = DEFAULT_ACCELERATION;
double MAX_LIMIT = DEFAULT_MAX_LIMIT;
double MIN_LIMIT = DEFAULT_MIN_LIMIT;
double MAX_OUTPUT = DEFAULT_MAX_OUTPUT;
double MIN_OUTPUT = DEFAULT_MIN_OUTPUT;
int TC_QUEUE_SIZE = DEFAULT_TC_QUEUE_SIZE;
int MMXAVG_SIZE = DEFAULT_MMXAVG_SIZE;
#if 0
double tMmxavgSpace[DEFAULT_MMXAVG_SIZE];
double sMmxavgSpace[DEFAULT_MMXAVG_SIZE];
double nMmxavgSpace[DEFAULT_MMXAVG_SIZE];
#endif
double MAX_FERROR = DEFAULT_MAX_FERROR;
double P_GAIN = DEFAULT_P_GAIN;
double I_GAIN = DEFAULT_I_GAIN;
double D_GAIN = DEFAULT_D_GAIN;
double FF0_GAIN = DEFAULT_FF0_GAIN;
double FF1_GAIN = DEFAULT_FF1_GAIN;
double FF2_GAIN = DEFAULT_FF2_GAIN;
double BACKLASH = DEFAULT_BACKLASH;
double BIAS = DEFAULT_BIAS;
double MAX_ERROR = DEFAULT_MAX_ERROR;
double INPUT_SCALE = DEFAULT_INPUT_SCALE;
double INPUT_OFFSET = DEFAULT_INPUT_OFFSET;
double OUTPUT_SCALE = DEFAULT_OUTPUT_SCALE;
double OUTPUT_OFFSET = DEFAULT_OUTPUT_OFFSET;
/********************************************************************
* Description: emcmotglb.c
* Compile-time configuration parameters
*
* Set the values in emcmotcfg.h; these vars will be set to those values
* and emcmot.c can reference the variables with their defaults. This file
* exists to avoid having to recompile emcmot.c every time a default is
* changed.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include "emcmotglb.h" /* these decls */
#include "emcmotcfg.h" /* initial values */
char EMCMOT_INIFILE[EMCMOT_INIFILE_LEN] = DEFAULT_EMCMOT_INIFILE;
unsigned int SHMEM_KEY = DEFAULT_SHMEM_KEY;
double EMCMOT_COMM_TIMEOUT = DEFAULT_EMCMOT_COMM_TIMEOUT;
double EMCMOT_COMM_WAIT = DEFAULT_EMCMOT_COMM_WAIT;
int num_axes = EMCMOT_MAX_AXIS;
double TRAJ_CYCLE_TIME = DEFAULT_TRAJ_CYCLE_TIME;
double SERVO_CYCLE_TIME = DEFAULT_SERVO_CYCLE_TIME;
double VELOCITY = DEFAULT_VELOCITY;
double ACCELERATION = DEFAULT_ACCELERATION;
double MAX_LIMIT = DEFAULT_MAX_LIMIT;
double MIN_LIMIT = DEFAULT_MIN_LIMIT;
double MAX_OUTPUT = DEFAULT_MAX_OUTPUT;
double MIN_OUTPUT = DEFAULT_MIN_OUTPUT;
int TC_QUEUE_SIZE = DEFAULT_TC_QUEUE_SIZE;
int MMXAVG_SIZE = DEFAULT_MMXAVG_SIZE;
#if 0
double tMmxavgSpace[DEFAULT_MMXAVG_SIZE];
double sMmxavgSpace[DEFAULT_MMXAVG_SIZE];
double nMmxavgSpace[DEFAULT_MMXAVG_SIZE];
#endif
double MAX_FERROR = DEFAULT_MAX_FERROR;
double P_GAIN = DEFAULT_P_GAIN;
double I_GAIN = DEFAULT_I_GAIN;
double D_GAIN = DEFAULT_D_GAIN;
double FF0_GAIN = DEFAULT_FF0_GAIN;
double FF1_GAIN = DEFAULT_FF1_GAIN;
double FF2_GAIN = DEFAULT_FF2_GAIN;
double BACKLASH = DEFAULT_BACKLASH;
double BIAS = DEFAULT_BIAS;
double MAX_ERROR = DEFAULT_MAX_ERROR;
double INPUT_SCALE = DEFAULT_INPUT_SCALE;
double INPUT_OFFSET = DEFAULT_INPUT_OFFSET;
double OUTPUT_SCALE = DEFAULT_OUTPUT_SCALE;
double OUTPUT_OFFSET = DEFAULT_OUTPUT_OFFSET;

View file

@ -1,88 +1,88 @@
/********************************************************************
* Description: emcmotglb.h
* Declarations for globals whose default values are found in emcmotcfg.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCMOTGLB_H
#define EMCMOTGLB_H
#ifdef __cplusplus
extern "C" {
#endif
#define EMCMOT_INIFILE_LEN 256
/* FIXME - eventually want to convert all of these to lowercase,
uppercase is for constants only
*/
/* FIXME - want to move some of these out of here completely...
too many globals - put in emcmotXXX structs instead, perhaps?
*/
extern char EMCMOT_INIFILE[EMCMOT_INIFILE_LEN];
extern unsigned int SHMEM_KEY;
extern double EMCMOT_COMM_TIMEOUT; /* seconds until timeout */
extern double EMCMOT_COMM_WAIT; /* seconds to delay between tries */
extern int num_axes;
extern double VELOCITY;
extern double ACCELERATION;
extern double MAX_LIMIT;
extern double MIN_LIMIT;
extern double MAX_OUTPUT;
extern double MIN_OUTPUT;
extern int TC_QUEUE_SIZE;
extern int MMXAVG_SIZE;
#if 0
// Moved to emcmotDebug struct
extern double tMmxavgSpace[];
extern double sMmxavgSpace[];
extern double nMmxavgSpace[];
#endif
extern double MAX_FERROR;
#if 0
extern double P_GAIN;
extern double I_GAIN;
extern double D_GAIN;
extern double FF0_GAIN;
extern double FF1_GAIN;
extern double FF2_GAIN;
extern double BIAS;
extern double MAX_ERROR;
#endif
extern double BACKLASH;
#if 0
extern double INPUT_SCALE;
extern double INPUT_OFFSET;
extern double OUTPUT_SCALE;
extern double OUTPUT_OFFSET;
#endif
#ifdef __cplusplus
} /* matches extern "C" at top */
#endif
#endif /* EMCMOTGLB_H */
/********************************************************************
* Description: emcmotglb.h
* Declarations for globals whose default values are found in emcmotcfg.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCMOTGLB_H
#define EMCMOTGLB_H
#ifdef __cplusplus
extern "C" {
#endif
#define EMCMOT_INIFILE_LEN 256
/* FIXME - eventually want to convert all of these to lowercase,
uppercase is for constants only
*/
/* FIXME - want to move some of these out of here completely...
too many globals - put in emcmotXXX structs instead, perhaps?
*/
extern char EMCMOT_INIFILE[EMCMOT_INIFILE_LEN];
extern unsigned int SHMEM_KEY;
extern double EMCMOT_COMM_TIMEOUT; /* seconds until timeout */
extern double EMCMOT_COMM_WAIT; /* seconds to delay between tries */
extern int num_axes;
extern double VELOCITY;
extern double ACCELERATION;
extern double MAX_LIMIT;
extern double MIN_LIMIT;
extern double MAX_OUTPUT;
extern double MIN_OUTPUT;
extern int TC_QUEUE_SIZE;
extern int MMXAVG_SIZE;
#if 0
// Moved to emcmotDebug struct
extern double tMmxavgSpace[];
extern double sMmxavgSpace[];
extern double nMmxavgSpace[];
#endif
extern double MAX_FERROR;
#if 0
extern double P_GAIN;
extern double I_GAIN;
extern double D_GAIN;
extern double FF0_GAIN;
extern double FF1_GAIN;
extern double FF2_GAIN;
extern double BIAS;
extern double MAX_ERROR;
#endif
extern double BACKLASH;
#if 0
extern double INPUT_SCALE;
extern double INPUT_OFFSET;
extern double OUTPUT_SCALE;
extern double OUTPUT_OFFSET;
#endif
#ifdef __cplusplus
} /* matches extern "C" at top */
#endif
#endif /* EMCMOTGLB_H */

View file

@ -1,102 +1,102 @@
/********************************************************************
* Description: emcmotutil.c
* Utility functions shared between motion and other systems
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include "emcmotcfg.h" /* EMCMOT_ERROR_NUM,LEN */
#include "motion.h" /* these decls */
int emcmotErrorInit(emcmot_error_t * errlog)
{
if (errlog == 0) {
return -1;
}
errlog->head = 0;
errlog->start = 0;
errlog->end = 0;
errlog->num = 0;
errlog->tail = 0;
return 0;
}
int emcmotErrorPut(emcmot_error_t * errlog, const char *error)
{
char *p1;
const char *p2;
int i;
if (errlog == 0 || errlog->num == EMCMOT_ERROR_NUM) {
/* full */
return -1;
}
errlog->head++;
// strncpy(errlog->error[errlog->end], error, EMCMOT_ERROR_LEN);
// replaced strncpy with manual copy
p1 = errlog->error[errlog->end];
p2 = error;
i = 0;
while (*p2 && i < EMCMOT_ERROR_LEN) {
*p1 = *p2;
p1++;
p2++;
i++;
}
*p1 = 0;
errlog->end = (errlog->end + 1) % EMCMOT_ERROR_NUM;
errlog->num++;
errlog->tail = errlog->head;
return 0;
}
int emcmotErrorGet(emcmot_error_t * errlog, char *error)
{
char *p1;
const char *p2;
int i;
if (errlog == 0 || errlog->num == 0) {
/* empty */
return -1;
}
errlog->head++;
// strncpy(error, errlog->error[errlog->start], EMCMOT_ERROR_LEN);
// replaced strncpy with manual copy
p1 = error;
p2 = errlog->error[errlog->start];
i = 0;
while (*p2 && i < EMCMOT_ERROR_LEN) {
*p1 = *p2;
p1++;
p2++;
i++;
}
*p1 = 0;
errlog->start = (errlog->start + 1) % EMCMOT_ERROR_NUM;
errlog->num--;
errlog->tail = errlog->head;
return 0;
}
/********************************************************************
* Description: emcmotutil.c
* Utility functions shared between motion and other systems
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include "emcmotcfg.h" /* EMCMOT_ERROR_NUM,LEN */
#include "motion.h" /* these decls */
int emcmotErrorInit(emcmot_error_t * errlog)
{
if (errlog == 0) {
return -1;
}
errlog->head = 0;
errlog->start = 0;
errlog->end = 0;
errlog->num = 0;
errlog->tail = 0;
return 0;
}
int emcmotErrorPut(emcmot_error_t * errlog, const char *error)
{
char *p1;
const char *p2;
int i;
if (errlog == 0 || errlog->num == EMCMOT_ERROR_NUM) {
/* full */
return -1;
}
errlog->head++;
// strncpy(errlog->error[errlog->end], error, EMCMOT_ERROR_LEN);
// replaced strncpy with manual copy
p1 = errlog->error[errlog->end];
p2 = error;
i = 0;
while (*p2 && i < EMCMOT_ERROR_LEN) {
*p1 = *p2;
p1++;
p2++;
i++;
}
*p1 = 0;
errlog->end = (errlog->end + 1) % EMCMOT_ERROR_NUM;
errlog->num++;
errlog->tail = errlog->head;
return 0;
}
int emcmotErrorGet(emcmot_error_t * errlog, char *error)
{
char *p1;
const char *p2;
int i;
if (errlog == 0 || errlog->num == 0) {
/* empty */
return -1;
}
errlog->head++;
// strncpy(error, errlog->error[errlog->start], EMCMOT_ERROR_LEN);
// replaced strncpy with manual copy
p1 = error;
p2 = errlog->error[errlog->start];
i = 0;
while (*p2 && i < EMCMOT_ERROR_LEN) {
*p1 = *p2;
p1++;
p2++;
i++;
}
*p1 = 0;
errlog->start = (errlog->start + 1) % EMCMOT_ERROR_NUM;
errlog->num--;
errlog->tail = errlog->head;
return 0;
}

View file

@ -1,353 +1,353 @@
// NOTE: emcpid.c is no longer used by emc2, the PID function is
// supplied by the HAL when needed. Stepper based systems don't
// use PID at all. This file will eventually be deleted, but is
// being kept for reference for now.
/********************************************************************
* Description: emcpid.c
* C definitions for PID code
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifdef ULAPI
#include <stdio.h>
#include "inifile.h"
#endif
#include "rtapi.h" /* rtapi_print_msg */
#include "emcpid.h" /* these decls */
#define GAINS_SET 0x01
#define CYCLE_TIME_SET 0x02
#define ALL_SET (GAINS_SET | CYCLE_TIME_SET)
int pidInit(PID_STRUCT * pid)
{
#ifdef SMOOTH_D_FACTOR
int i;
#endif
if (0 == pid) {
return -1;
}
pid->p = 0.0;
pid->i = 0.0;
pid->d = 0.0;
pid->ff0 = 0.0;
pid->ff1 = 0.0;
pid->ff2 = 0.0;
pid->backlash = 0.0;
pid->bias = 0.0;
pid->maxError = 0.0;
pid->deadband = 0.0;
pid->cycleTime = 1.0;
pid->configured = 0;
#ifdef SMOOTH_D_FACTOR
for (i = 0; i < MAX_ERROR_WINDOW; i++) {
pid->oldErrors[i] = 0.0;
pid->errorWindowFactors[i] = 0.1;
}
pid->errorIndex = 0;
#endif
/* now clear out the state vars */
return pidReset(pid);
}
/* clear out the state vars */
int pidReset(PID_STRUCT * pid)
{
if (0 == pid) {
return -1;
}
pid->error = 0.0;
pid->lastError = 0.0;
pid->cumError = 0.0;
pid->lastSetpoint = 0.0;
pid->lastSetpoint_was_set = 0; /* lastSetpoint is no longer valid. */
pid->lastSetpointDot = 0.0;
pid->lastOutput = 0.0;
return 0;
}
int pidSetCycleTime(PID_STRUCT * pid, double seconds)
{
if (0 == pid || seconds <= 0.0) {
return -1;
}
pid->cycleTime = seconds;
pid->configured |= CYCLE_TIME_SET;
return 0;
}
int pidSetGains(PID_STRUCT * pid, PID_STRUCT parameters)
{
#ifdef SMOOTH_D_FACTOR
int i;
#endif
if (0 == pid) {
return -1;
}
pid->p = parameters.p;
pid->i = parameters.i;
pid->d = parameters.d;
pid->ff0 = parameters.ff0;
pid->ff1 = parameters.ff1;
pid->ff2 = parameters.ff2;
pid->backlash = parameters.backlash;
pid->bias = parameters.bias;
pid->maxError = parameters.maxError;
pid->deadband = parameters.deadband;
#ifdef SMOOTH_D_FACTOR
for (i = 0; i < MAX_ERROR_WINDOW; i++) {
pid->oldErrors[i] = 0.0;
#if 0
if (parameters.errorWindowFactors[0] > 0.0) {
pid->errorWindowFactors[i] = parameters.errorWindowFactors[i];
}
#endif
}
pid->errorIndex = 0;
#endif
pid->configured |= GAINS_SET;
return 0;
}
double pidRunCycle(PID_STRUCT * pid, double sample, double setpoint)
{
double setpointDot;
double error;
#ifdef SMOOTH_D_FACTOR
double smooth_d;
int i;
#endif
if (0 == pid) {
return 0;
}
if (pid->cycleTime < 1e-7 || pid->configured != ALL_SET) {
return 0.0;
}
if (!pid->lastSetpoint_was_set) {
pid->lastSetpoint = setpoint;
pid->lastSetpointDot = 0.0;
pid->lastSetpoint_was_set = 1;
}
/* calculate error and cumError */
error = setpoint - sample;
if (error > pid->deadband) {
pid->error = error - pid->deadband;
} else if (error < -pid->deadband) {
pid->error = error + pid->deadband;
} else {
pid->error = 0.0;
}
pid->cumError += pid->error * pid->cycleTime;
setpointDot = (setpoint - pid->lastSetpoint) / pid->cycleTime;
if (pid->cumError > pid->maxError) {
pid->cumError = pid->maxError;
} else if (pid->cumError < -pid->maxError) {
pid->cumError = -pid->maxError;
}
#ifdef THROWAWAY_CUMULATIVE_ERROR_ON_SIGN_CHANGES
if ((pid->error >= 0.0 && pid->lastError <= 0.0) ||
(pid->error <= 0.0 && pid->lastError >= 0.0)) {
pid->cumError = pid->error * pid->cycleTime;
}
#endif
#ifdef SMOOTH_D_FACTOR
smooth_d =
(pid->oldErrors[(pid->errorIndex +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]
- pid->oldErrors[(pid->errorIndex + 1 +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]) / MAX_ERROR_WINDOW;
#ifdef ULAPI
if (error != 0.0) {
for (i = 0; i < MAX_ERROR_WINDOW; i++) {
printf("%8.8f ",
(pid->oldErrors[(pid->errorIndex - i +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]
- pid->oldErrors[(pid->errorIndex - i - 1 +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]));
}
}
#endif
pid->errorIndex++;
pid->errorIndex %= MAX_ERROR_WINDOW;
pid->oldErrors[pid->errorIndex] = pid->error;
#ifdef ULAPI
if (error != 0.0) {
printf("\nerror=%8.8f,(error-lastError)=%8.8f,smooth_d=%8.8f\n",
pid->error, (pid->error - pid->lastError), smooth_d);
}
#endif
#endif
/* do compensation calculations */
pid->lastOutput = pid->bias +
pid->p * pid->error + pid->i * pid->cumError +
#ifdef SMOOTH_D_FACTOR
pid->d * smooth_d / pid->cycleTime +
#else
pid->d * (pid->error - pid->lastError) / pid->cycleTime +
#endif
pid->ff0 * setpoint +
pid->ff1 * setpointDot +
pid->ff2 * (setpointDot - pid->lastSetpointDot) / pid->cycleTime;
/* update history vars */
pid->lastSetpoint = setpoint;
pid->lastSetpointDot = setpointDot;
pid->lastError = pid->error;
return pid->lastOutput;
}
int pidIniLoad(PID_STRUCT * pid, const char *filename)
{
#ifdef ULAPI
PID_STRUCT params;
double cycleTime;
int retval = 0;
const char *inistring;
FILE *fp;
if (NULL == (fp = fopen(filename, "r"))) {
rtapi_print_msg(1, "can't open ini file %s\n", filename);
return -1;
}
/* forward gains */
if (NULL != (inistring = iniFind(fp, "P", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.p)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid P gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "I", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.i)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid I gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "D", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.d)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid D gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "FF0", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.ff0)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid FF0 gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "FF1", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.ff1)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid FF1 gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "FF2", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.ff2)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid FF2 gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "BACKLASH", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.backlash)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid backlash: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "BIAS", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.bias)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid bias: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "MAX_ERROR", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.maxError)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid max cum error: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "DEADBAND", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.deadband)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid deadband: %s\n", inistring);
retval = -1;
}
}
/* if they all read ok, stick them in pid */
if (retval == 0) {
pidSetGains(pid, params);
}
if (NULL != (inistring = iniFind(fp, "CYCLE_TIME", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &cycleTime)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid CYCLE_TIME: %s\n", inistring);
retval = -1;
} else {
pidSetCycleTime(pid, cycleTime);
}
}
/* close inifile */
fclose(fp);
return retval;
#else
return -1;
#endif
}
// NOTE: emcpid.c is no longer used by emc2, the PID function is
// supplied by the HAL when needed. Stepper based systems don't
// use PID at all. This file will eventually be deleted, but is
// being kept for reference for now.
/********************************************************************
* Description: emcpid.c
* C definitions for PID code
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifdef ULAPI
#include <stdio.h>
#include "inifile.h"
#endif
#include "rtapi.h" /* rtapi_print_msg */
#include "emcpid.h" /* these decls */
#define GAINS_SET 0x01
#define CYCLE_TIME_SET 0x02
#define ALL_SET (GAINS_SET | CYCLE_TIME_SET)
int pidInit(PID_STRUCT * pid)
{
#ifdef SMOOTH_D_FACTOR
int i;
#endif
if (0 == pid) {
return -1;
}
pid->p = 0.0;
pid->i = 0.0;
pid->d = 0.0;
pid->ff0 = 0.0;
pid->ff1 = 0.0;
pid->ff2 = 0.0;
pid->backlash = 0.0;
pid->bias = 0.0;
pid->maxError = 0.0;
pid->deadband = 0.0;
pid->cycleTime = 1.0;
pid->configured = 0;
#ifdef SMOOTH_D_FACTOR
for (i = 0; i < MAX_ERROR_WINDOW; i++) {
pid->oldErrors[i] = 0.0;
pid->errorWindowFactors[i] = 0.1;
}
pid->errorIndex = 0;
#endif
/* now clear out the state vars */
return pidReset(pid);
}
/* clear out the state vars */
int pidReset(PID_STRUCT * pid)
{
if (0 == pid) {
return -1;
}
pid->error = 0.0;
pid->lastError = 0.0;
pid->cumError = 0.0;
pid->lastSetpoint = 0.0;
pid->lastSetpoint_was_set = 0; /* lastSetpoint is no longer valid. */
pid->lastSetpointDot = 0.0;
pid->lastOutput = 0.0;
return 0;
}
int pidSetCycleTime(PID_STRUCT * pid, double seconds)
{
if (0 == pid || seconds <= 0.0) {
return -1;
}
pid->cycleTime = seconds;
pid->configured |= CYCLE_TIME_SET;
return 0;
}
int pidSetGains(PID_STRUCT * pid, PID_STRUCT parameters)
{
#ifdef SMOOTH_D_FACTOR
int i;
#endif
if (0 == pid) {
return -1;
}
pid->p = parameters.p;
pid->i = parameters.i;
pid->d = parameters.d;
pid->ff0 = parameters.ff0;
pid->ff1 = parameters.ff1;
pid->ff2 = parameters.ff2;
pid->backlash = parameters.backlash;
pid->bias = parameters.bias;
pid->maxError = parameters.maxError;
pid->deadband = parameters.deadband;
#ifdef SMOOTH_D_FACTOR
for (i = 0; i < MAX_ERROR_WINDOW; i++) {
pid->oldErrors[i] = 0.0;
#if 0
if (parameters.errorWindowFactors[0] > 0.0) {
pid->errorWindowFactors[i] = parameters.errorWindowFactors[i];
}
#endif
}
pid->errorIndex = 0;
#endif
pid->configured |= GAINS_SET;
return 0;
}
double pidRunCycle(PID_STRUCT * pid, double sample, double setpoint)
{
double setpointDot;
double error;
#ifdef SMOOTH_D_FACTOR
double smooth_d;
int i;
#endif
if (0 == pid) {
return 0;
}
if (pid->cycleTime < 1e-7 || pid->configured != ALL_SET) {
return 0.0;
}
if (!pid->lastSetpoint_was_set) {
pid->lastSetpoint = setpoint;
pid->lastSetpointDot = 0.0;
pid->lastSetpoint_was_set = 1;
}
/* calculate error and cumError */
error = setpoint - sample;
if (error > pid->deadband) {
pid->error = error - pid->deadband;
} else if (error < -pid->deadband) {
pid->error = error + pid->deadband;
} else {
pid->error = 0.0;
}
pid->cumError += pid->error * pid->cycleTime;
setpointDot = (setpoint - pid->lastSetpoint) / pid->cycleTime;
if (pid->cumError > pid->maxError) {
pid->cumError = pid->maxError;
} else if (pid->cumError < -pid->maxError) {
pid->cumError = -pid->maxError;
}
#ifdef THROWAWAY_CUMULATIVE_ERROR_ON_SIGN_CHANGES
if ((pid->error >= 0.0 && pid->lastError <= 0.0) ||
(pid->error <= 0.0 && pid->lastError >= 0.0)) {
pid->cumError = pid->error * pid->cycleTime;
}
#endif
#ifdef SMOOTH_D_FACTOR
smooth_d =
(pid->oldErrors[(pid->errorIndex +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]
- pid->oldErrors[(pid->errorIndex + 1 +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]) / MAX_ERROR_WINDOW;
#ifdef ULAPI
if (error != 0.0) {
for (i = 0; i < MAX_ERROR_WINDOW; i++) {
printf("%8.8f ",
(pid->oldErrors[(pid->errorIndex - i +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]
- pid->oldErrors[(pid->errorIndex - i - 1 +
2 * MAX_ERROR_WINDOW) % MAX_ERROR_WINDOW]));
}
}
#endif
pid->errorIndex++;
pid->errorIndex %= MAX_ERROR_WINDOW;
pid->oldErrors[pid->errorIndex] = pid->error;
#ifdef ULAPI
if (error != 0.0) {
printf("\nerror=%8.8f,(error-lastError)=%8.8f,smooth_d=%8.8f\n",
pid->error, (pid->error - pid->lastError), smooth_d);
}
#endif
#endif
/* do compensation calculations */
pid->lastOutput = pid->bias +
pid->p * pid->error + pid->i * pid->cumError +
#ifdef SMOOTH_D_FACTOR
pid->d * smooth_d / pid->cycleTime +
#else
pid->d * (pid->error - pid->lastError) / pid->cycleTime +
#endif
pid->ff0 * setpoint +
pid->ff1 * setpointDot +
pid->ff2 * (setpointDot - pid->lastSetpointDot) / pid->cycleTime;
/* update history vars */
pid->lastSetpoint = setpoint;
pid->lastSetpointDot = setpointDot;
pid->lastError = pid->error;
return pid->lastOutput;
}
int pidIniLoad(PID_STRUCT * pid, const char *filename)
{
#ifdef ULAPI
PID_STRUCT params;
double cycleTime;
int retval = 0;
const char *inistring;
FILE *fp;
if (NULL == (fp = fopen(filename, "r"))) {
rtapi_print_msg(1, "can't open ini file %s\n", filename);
return -1;
}
/* forward gains */
if (NULL != (inistring = iniFind(fp, "P", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.p)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid P gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "I", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.i)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid I gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "D", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.d)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid D gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "FF0", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.ff0)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid FF0 gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "FF1", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.ff1)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid FF1 gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "FF2", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.ff2)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid FF2 gain: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "BACKLASH", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.backlash)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid backlash: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "BIAS", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.bias)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid bias: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "MAX_ERROR", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.maxError)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid max cum error: %s\n", inistring);
retval = -1;
}
}
if (NULL != (inistring = iniFind(fp, "DEADBAND", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &params.deadband)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid deadband: %s\n", inistring);
retval = -1;
}
}
/* if they all read ok, stick them in pid */
if (retval == 0) {
pidSetGains(pid, params);
}
if (NULL != (inistring = iniFind(fp, "CYCLE_TIME", 0))) {
if (1 != sscanf((char *) inistring, "%lf", &cycleTime)) {
/* found, but invalid */
rtapi_print_msg(1, "invalid CYCLE_TIME: %s\n", inistring);
retval = -1;
} else {
pidSetCycleTime(pid, cycleTime);
}
}
/* close inifile */
fclose(fp);
return retval;
#else
return -1;
#endif
}

View file

@ -1,68 +1,68 @@
// NOTE: emcpid.h is no longer used by emc2, the PID function is
// supplied by the HAL when needed. Stepper based systems don't
// use PID at all. This file will eventually be deleted, but is
// being kept for reference for now.
/********************************************************************
* Description: emcpid.h
* Decls for PID control law data structure and class
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef PID_H
#define PID_H
/* Uncomment these lines if you like these mathematically impure effects. */
/* #define SMOOTH_D_FACTOR */
/* #define THROWAWAY_CUMULATIVE_ERROR_ON_SIGN_CHANGES */
typedef struct {
double p; /* proportional gain, volts/unit */
double i; /* integral gain, volts/unit */
double d; /* derivative gain, volts/unit per sec */
double ff0; /* 0th order feedforward, volts/unit */
double ff1; /* 1st order feedforward, volts/unit/sec */
double ff2; /* 2nd order feedforward, volts/unit/sec^2 */
double backlash; /* backlash */
double bias; /* bias for gravity comp, for example */
double maxError; /* ceiling for cumError */
double deadband; /* delta below which error is deemed to be 0 */
double cycleTime; /* copy of arg to setCycleTime() */
double error; /* error this cycle */
double lastError; /* last error computed */
double lastSetpoint; /* last setpoint received */
double lastOutput; /* last value output */
double lastSetpointDot; /* delta setpoint / delta t */
double cumError; /* cumulative error, all cycles */
int configured; /* configure flags */
#ifdef SMOOTH_D_FACTOR
#define MAX_ERROR_WINDOW 4
double oldErrors[MAX_ERROR_WINDOW]; /* This is a ring buffer that stores
the last MAX_ERROR_WINDOW errors. */
double errorWindowFactors[MAX_ERROR_WINDOW]; /* Weights to use in
smoothing error
factors. */
int errorIndex; /* Index into the oldErrors ring buffer. */
#endif
int lastSetpoint_was_set; /* true when lastSetpoint is valid. */
} PID_STRUCT;
extern int pidInit(PID_STRUCT * pid);
extern int pidReset(PID_STRUCT * pid);
extern int pidSetCycleTime(PID_STRUCT * pid, double seconds);
extern int pidSetGains(PID_STRUCT * pid, PID_STRUCT parameters);
extern double pidRunCycle(PID_STRUCT * pid, double sample, double setpoint);
extern int pidIniLoad(PID_STRUCT * pid, const char *filename);
#endif /* PID_H */
// NOTE: emcpid.h is no longer used by emc2, the PID function is
// supplied by the HAL when needed. Stepper based systems don't
// use PID at all. This file will eventually be deleted, but is
// being kept for reference for now.
/********************************************************************
* Description: emcpid.h
* Decls for PID control law data structure and class
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef PID_H
#define PID_H
/* Uncomment these lines if you like these mathematically impure effects. */
/* #define SMOOTH_D_FACTOR */
/* #define THROWAWAY_CUMULATIVE_ERROR_ON_SIGN_CHANGES */
typedef struct {
double p; /* proportional gain, volts/unit */
double i; /* integral gain, volts/unit */
double d; /* derivative gain, volts/unit per sec */
double ff0; /* 0th order feedforward, volts/unit */
double ff1; /* 1st order feedforward, volts/unit/sec */
double ff2; /* 2nd order feedforward, volts/unit/sec^2 */
double backlash; /* backlash */
double bias; /* bias for gravity comp, for example */
double maxError; /* ceiling for cumError */
double deadband; /* delta below which error is deemed to be 0 */
double cycleTime; /* copy of arg to setCycleTime() */
double error; /* error this cycle */
double lastError; /* last error computed */
double lastSetpoint; /* last setpoint received */
double lastOutput; /* last value output */
double lastSetpointDot; /* delta setpoint / delta t */
double cumError; /* cumulative error, all cycles */
int configured; /* configure flags */
#ifdef SMOOTH_D_FACTOR
#define MAX_ERROR_WINDOW 4
double oldErrors[MAX_ERROR_WINDOW]; /* This is a ring buffer that stores
the last MAX_ERROR_WINDOW errors. */
double errorWindowFactors[MAX_ERROR_WINDOW]; /* Weights to use in
smoothing error
factors. */
int errorIndex; /* Index into the oldErrors ring buffer. */
#endif
int lastSetpoint_was_set; /* true when lastSetpoint is valid. */
} PID_STRUCT;
extern int pidInit(PID_STRUCT * pid);
extern int pidReset(PID_STRUCT * pid);
extern int pidSetCycleTime(PID_STRUCT * pid, double seconds);
extern int pidSetGains(PID_STRUCT * pid, PID_STRUCT parameters);
extern double pidRunCycle(PID_STRUCT * pid, double sample, double setpoint);
extern int pidIniLoad(PID_STRUCT * pid, const char *filename);
#endif /* PID_H */

View file

@ -1,243 +1,243 @@
/********************************************************************
* Description: mot_priv.h
* Macros and declarations local to the realtime sources.
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
*
********************************************************************/
#ifndef MOT_PRIV_H
#define MOT_PRIV_H
/***********************************************************************
* TYPEDEFS, ENUMS, ETC. *
************************************************************************/
/* First we define structures for data shared with the HAL */
/* HAL visible data notations:
RPA: read only parameter
WPA: write only parameter
WRPA: read/write parameter
RPI: read only pin
WPI: write only pin
WRPI: read/write pin
*/
/* axis data */
typedef struct {
hal_float_t coarse_pos_cmd; /* RPA: commanded position, w/o comp */
hal_float_t joint_pos_cmd; /* RPA: commanded position, w/o comp */
hal_float_t joint_vel_cmd; /* RPA: commanded velocity, w/o comp */
hal_float_t backlash_corr; /* RPA: correction for backlash */
hal_float_t backlash_filt; /* RPA: filtered backlash correction */
hal_float_t *motor_pos_cmd; /* WPI: commanded position, with comp */
hal_float_t *motor_pos_fb; /* RPI: position feedback, with comp */
hal_float_t joint_pos_fb; /* RPA: position feedback, w/o comp */
hal_float_t f_error; /* RPA: following error */
hal_float_t f_error_lim; /* RPA: following error limit */
/* FIXME - these might not be HAL params forever, but they are usefull now */
hal_float_t free_pos_cmd; /* RPA: free traj planner pos cmd */
hal_float_t free_vel_lim; /* RPA: free traj planner vel limit */
hal_bit_t free_tp_enable; /* RPA: free traj planner is running */
hal_bit_t active; /* RPA: axis is active, whatever that means */
hal_bit_t in_position; /* RPA: axis is in position */
hal_bit_t error; /* RPA: axis has an error */
hal_bit_t psl; /* RPA: axis is at positive soft limit */
hal_bit_t nsl; /* RPA: axis is at negative soft limit */
hal_bit_t phl; /* RPA: axis is at positive hard limit */
hal_bit_t nhl; /* RPA: axis is at negative hard limit */
hal_bit_t homing; /* RPA: axis is homing */
hal_bit_t homed; /* RPA: axis was homed */
hal_bit_t f_errored; /* RPA: axis had too much following error */
hal_bit_t faulted; /* RPA: axis amp faulted */
hal_bit_t *pos_lim_sw; /* RPI: positive limit switch input */
hal_bit_t *neg_lim_sw; /* RPI: negative limit switch input */
hal_bit_t *home_sw; /* RPI: home switch input */
hal_bit_t *index_pulse; /* RPI: index pulse input */
hal_bit_t *amp_fault; /* RPI: amp fault input */
hal_bit_t *amp_enable; /* WPI: amp enable output */
hal_s8_t home_state; /* RPA: homing state machine state */
/* FIXME - these have been temporarily? deleted */
#if 0
/* for now we control the index model through the mode and model pins on
axis 0, later this may be done on a per axis basis */
hal_u32_t *mode; /* index model output */
hal_u32_t *model; /* index model input */
hal_bit_t *reset; /* index latch reset output */
hal_bit_t *latch; /* index latch input */
hal_bit_t *index; /* index input */
#endif
} axis_hal_t;
/* machine data */
typedef struct {
hal_bit_t *probe_input; /* RPI: probe switch input */
hal_bit_t motion_enable; /* RPA: motion enable for all axis */
hal_bit_t in_position; /* RPA: all axis are in position */
hal_bit_t coord_mode; /* RPA: TRUE if coord, FALSE if free */
hal_bit_t teleop_mode; /* RPA: TRUE if teleop mode */
hal_bit_t coord_error; /* RPA: TRUE if coord mode error */
hal_bit_t debug_bit_0; /* RPA: generic param, for debugging */
hal_bit_t debug_bit_1; /* RPA: generic param, for debugging */
hal_float_t debug_float_0; /* RPA: generic param, for debugging */
hal_float_t debug_float_1; /* RPA: generic param, for debugging */
axis_hal_t axis[EMCMOT_MAX_AXIS]; /* data for each axis */
} emcmot_hal_data_t;
/***********************************************************************
* GLOBAL VARIABLE DECLARATIONS *
************************************************************************/
/* HAL component ID for motion module */
extern int mot_comp_id;
/* pointer to emcmot_hal_data_t struct in HAL shmem, with all HAL data */
extern emcmot_hal_data_t *emcmot_hal_data;
/* pointer to array of joint structs with all joint data */
/* the actual array may be in shared memory or in kernel space, as
determined by the init code in motion.c
*/
extern emcmot_joint_t *joints;
/* Variable defs */
extern int kinType;
extern int rehomeAll;
extern int DEBUG_MOTION;
extern int logSkip;
extern int loggingAxis;
extern int logStartTime;
extern int EMCMOT_NO_FORWARD_KINEMATICS;
extern KINEMATICS_FORWARD_FLAGS fflags;
extern KINEMATICS_INVERSE_FLAGS iflags;
/* Struct pointers */
extern emcmot_struct_t *emcmotStruct;
extern emcmot_command_t *emcmotCommand;
extern emcmot_status_t *emcmotStatus;
extern emcmot_config_t *emcmotConfig;
extern emcmot_debug_t *emcmotDebug;
extern emcmot_internal_t *emcmotInternal;
extern emcmot_error_t *emcmotError;
extern emcmot_log_t *emcmotLog;
extern emcmot_log_struct_t ls;
/***********************************************************************
* PUBLIC FUNCTION PROTOTYPES *
************************************************************************/
/* function definitions */
extern void emcmotCommandHandler(void *arg, long period);
extern void emcmotController(void *arg, long period);
extern void emcmot_config_change(void);
extern void reportError(const char *fmt, ...); /* Use the rtapi_print call */
/* rtapi_get_time() returns a nanosecond value. In time, we should use a u64
value for all calcs and only do the conversion to seconds when it is
really needed. */
#define etime() (((double) rtapi_get_time()) / 1.0e9)
/* macros for reading, writing bit flags */
/* motion flags */
#define GET_MOTION_ERROR_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_ERROR_BIT ? 1 : 0)
#define SET_MOTION_ERROR_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_ERROR_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_ERROR_BIT;
#define GET_MOTION_COORD_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_COORD_BIT ? 1 : 0)
#define SET_MOTION_COORD_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_COORD_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_COORD_BIT;
#define GET_MOTION_TELEOP_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_TELEOP_BIT ? 1 : 0)
#define SET_MOTION_TELEOP_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_TELEOP_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_TELEOP_BIT;
#define GET_MOTION_INPOS_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_INPOS_BIT ? 1 : 0)
#define SET_MOTION_INPOS_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_INPOS_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_INPOS_BIT;
#define GET_MOTION_ENABLE_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_ENABLE_BIT ? 1 : 0)
#define SET_MOTION_ENABLE_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_ENABLE_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_ENABLE_BIT;
/* axis flags */
/* joint flags */
#define GET_JOINT_ENABLE_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_ENABLE_BIT ? 1 : 0)
#define SET_JOINT_ENABLE_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_ENABLE_BIT; else (joint)->flag &= ~EMCMOT_AXIS_ENABLE_BIT;
#define GET_JOINT_ACTIVE_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_ACTIVE_BIT ? 1 : 0)
#define SET_JOINT_ACTIVE_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_ACTIVE_BIT; else (joint)->flag &= ~EMCMOT_AXIS_ACTIVE_BIT;
#define GET_JOINT_INPOS_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_INPOS_BIT ? 1 : 0)
#define SET_JOINT_INPOS_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_INPOS_BIT; else (joint)->flag &= ~EMCMOT_AXIS_INPOS_BIT;
#define GET_JOINT_ERROR_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_ERROR_BIT ? 1 : 0)
#define SET_JOINT_ERROR_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_ERROR_BIT; else (joint)->flag &= ~EMCMOT_AXIS_ERROR_BIT;
#define GET_JOINT_PSL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MAX_SOFT_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_PSL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MAX_SOFT_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MAX_SOFT_LIMIT_BIT;
#define GET_JOINT_NSL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MIN_SOFT_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_NSL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MIN_SOFT_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MIN_SOFT_LIMIT_BIT;
#define GET_JOINT_PHL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MAX_HARD_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_PHL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MAX_HARD_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MAX_HARD_LIMIT_BIT;
#define GET_JOINT_NHL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MIN_HARD_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_NHL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MIN_HARD_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MIN_HARD_LIMIT_BIT;
#define GET_JOINT_HOME_SWITCH_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_HOME_SWITCH_BIT ? 1 : 0)
#define SET_JOINT_HOME_SWITCH_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_HOME_SWITCH_BIT; else (joint)->flag &= ~EMCMOT_AXIS_HOME_SWITCH_BIT;
#define GET_JOINT_HOMING_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_HOMING_BIT ? 1 : 0)
#define SET_JOINT_HOMING_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_HOMING_BIT; else (joint)->flag &= ~EMCMOT_AXIS_HOMING_BIT;
#define GET_JOINT_HOMED_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_HOMED_BIT ? 1 : 0)
#define SET_JOINT_HOMED_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_HOMED_BIT; else (joint)->flag &= ~EMCMOT_AXIS_HOMED_BIT;
#define GET_JOINT_AT_HOME_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_AT_HOME_BIT ? 1 : 0)
#define SET_JOINT_AT_HOME_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_AT_HOME_BIT; else (joint)->flag &= ~EMCMOT_AXIS_AT_HOME_BIT;
#define GET_JOINT_FERROR_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_FERROR_BIT ? 1 : 0)
#define SET_JOINT_FERROR_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_FERROR_BIT; else (joint)->flag &= ~EMCMOT_AXIS_FERROR_BIT;
#define GET_JOINT_FAULT_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_FAULT_BIT ? 1 : 0)
#define SET_JOINT_FAULT_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_FAULT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_FAULT_BIT;
#endif /* MOT_PRIV_H */
/********************************************************************
* Description: mot_priv.h
* Macros and declarations local to the realtime sources.
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
*
********************************************************************/
#ifndef MOT_PRIV_H
#define MOT_PRIV_H
/***********************************************************************
* TYPEDEFS, ENUMS, ETC. *
************************************************************************/
/* First we define structures for data shared with the HAL */
/* HAL visible data notations:
RPA: read only parameter
WPA: write only parameter
WRPA: read/write parameter
RPI: read only pin
WPI: write only pin
WRPI: read/write pin
*/
/* axis data */
typedef struct {
hal_float_t coarse_pos_cmd; /* RPA: commanded position, w/o comp */
hal_float_t joint_pos_cmd; /* RPA: commanded position, w/o comp */
hal_float_t joint_vel_cmd; /* RPA: commanded velocity, w/o comp */
hal_float_t backlash_corr; /* RPA: correction for backlash */
hal_float_t backlash_filt; /* RPA: filtered backlash correction */
hal_float_t *motor_pos_cmd; /* WPI: commanded position, with comp */
hal_float_t *motor_pos_fb; /* RPI: position feedback, with comp */
hal_float_t joint_pos_fb; /* RPA: position feedback, w/o comp */
hal_float_t f_error; /* RPA: following error */
hal_float_t f_error_lim; /* RPA: following error limit */
/* FIXME - these might not be HAL params forever, but they are usefull now */
hal_float_t free_pos_cmd; /* RPA: free traj planner pos cmd */
hal_float_t free_vel_lim; /* RPA: free traj planner vel limit */
hal_bit_t free_tp_enable; /* RPA: free traj planner is running */
hal_bit_t active; /* RPA: axis is active, whatever that means */
hal_bit_t in_position; /* RPA: axis is in position */
hal_bit_t error; /* RPA: axis has an error */
hal_bit_t psl; /* RPA: axis is at positive soft limit */
hal_bit_t nsl; /* RPA: axis is at negative soft limit */
hal_bit_t phl; /* RPA: axis is at positive hard limit */
hal_bit_t nhl; /* RPA: axis is at negative hard limit */
hal_bit_t homing; /* RPA: axis is homing */
hal_bit_t homed; /* RPA: axis was homed */
hal_bit_t f_errored; /* RPA: axis had too much following error */
hal_bit_t faulted; /* RPA: axis amp faulted */
hal_bit_t *pos_lim_sw; /* RPI: positive limit switch input */
hal_bit_t *neg_lim_sw; /* RPI: negative limit switch input */
hal_bit_t *home_sw; /* RPI: home switch input */
hal_bit_t *index_pulse; /* RPI: index pulse input */
hal_bit_t *amp_fault; /* RPI: amp fault input */
hal_bit_t *amp_enable; /* WPI: amp enable output */
hal_s8_t home_state; /* RPA: homing state machine state */
/* FIXME - these have been temporarily? deleted */
#if 0
/* for now we control the index model through the mode and model pins on
axis 0, later this may be done on a per axis basis */
hal_u32_t *mode; /* index model output */
hal_u32_t *model; /* index model input */
hal_bit_t *reset; /* index latch reset output */
hal_bit_t *latch; /* index latch input */
hal_bit_t *index; /* index input */
#endif
} axis_hal_t;
/* machine data */
typedef struct {
hal_bit_t *probe_input; /* RPI: probe switch input */
hal_bit_t motion_enable; /* RPA: motion enable for all axis */
hal_bit_t in_position; /* RPA: all axis are in position */
hal_bit_t coord_mode; /* RPA: TRUE if coord, FALSE if free */
hal_bit_t teleop_mode; /* RPA: TRUE if teleop mode */
hal_bit_t coord_error; /* RPA: TRUE if coord mode error */
hal_bit_t debug_bit_0; /* RPA: generic param, for debugging */
hal_bit_t debug_bit_1; /* RPA: generic param, for debugging */
hal_float_t debug_float_0; /* RPA: generic param, for debugging */
hal_float_t debug_float_1; /* RPA: generic param, for debugging */
axis_hal_t axis[EMCMOT_MAX_AXIS]; /* data for each axis */
} emcmot_hal_data_t;
/***********************************************************************
* GLOBAL VARIABLE DECLARATIONS *
************************************************************************/
/* HAL component ID for motion module */
extern int mot_comp_id;
/* pointer to emcmot_hal_data_t struct in HAL shmem, with all HAL data */
extern emcmot_hal_data_t *emcmot_hal_data;
/* pointer to array of joint structs with all joint data */
/* the actual array may be in shared memory or in kernel space, as
determined by the init code in motion.c
*/
extern emcmot_joint_t *joints;
/* Variable defs */
extern int kinType;
extern int rehomeAll;
extern int DEBUG_MOTION;
extern int logSkip;
extern int loggingAxis;
extern int logStartTime;
extern int EMCMOT_NO_FORWARD_KINEMATICS;
extern KINEMATICS_FORWARD_FLAGS fflags;
extern KINEMATICS_INVERSE_FLAGS iflags;
/* Struct pointers */
extern emcmot_struct_t *emcmotStruct;
extern emcmot_command_t *emcmotCommand;
extern emcmot_status_t *emcmotStatus;
extern emcmot_config_t *emcmotConfig;
extern emcmot_debug_t *emcmotDebug;
extern emcmot_internal_t *emcmotInternal;
extern emcmot_error_t *emcmotError;
extern emcmot_log_t *emcmotLog;
extern emcmot_log_struct_t ls;
/***********************************************************************
* PUBLIC FUNCTION PROTOTYPES *
************************************************************************/
/* function definitions */
extern void emcmotCommandHandler(void *arg, long period);
extern void emcmotController(void *arg, long period);
extern void emcmot_config_change(void);
extern void reportError(const char *fmt, ...); /* Use the rtapi_print call */
/* rtapi_get_time() returns a nanosecond value. In time, we should use a u64
value for all calcs and only do the conversion to seconds when it is
really needed. */
#define etime() (((double) rtapi_get_time()) / 1.0e9)
/* macros for reading, writing bit flags */
/* motion flags */
#define GET_MOTION_ERROR_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_ERROR_BIT ? 1 : 0)
#define SET_MOTION_ERROR_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_ERROR_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_ERROR_BIT;
#define GET_MOTION_COORD_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_COORD_BIT ? 1 : 0)
#define SET_MOTION_COORD_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_COORD_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_COORD_BIT;
#define GET_MOTION_TELEOP_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_TELEOP_BIT ? 1 : 0)
#define SET_MOTION_TELEOP_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_TELEOP_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_TELEOP_BIT;
#define GET_MOTION_INPOS_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_INPOS_BIT ? 1 : 0)
#define SET_MOTION_INPOS_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_INPOS_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_INPOS_BIT;
#define GET_MOTION_ENABLE_FLAG() (emcmotStatus->motionFlag & EMCMOT_MOTION_ENABLE_BIT ? 1 : 0)
#define SET_MOTION_ENABLE_FLAG(fl) if (fl) emcmotStatus->motionFlag |= EMCMOT_MOTION_ENABLE_BIT; else emcmotStatus->motionFlag &= ~EMCMOT_MOTION_ENABLE_BIT;
/* axis flags */
/* joint flags */
#define GET_JOINT_ENABLE_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_ENABLE_BIT ? 1 : 0)
#define SET_JOINT_ENABLE_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_ENABLE_BIT; else (joint)->flag &= ~EMCMOT_AXIS_ENABLE_BIT;
#define GET_JOINT_ACTIVE_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_ACTIVE_BIT ? 1 : 0)
#define SET_JOINT_ACTIVE_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_ACTIVE_BIT; else (joint)->flag &= ~EMCMOT_AXIS_ACTIVE_BIT;
#define GET_JOINT_INPOS_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_INPOS_BIT ? 1 : 0)
#define SET_JOINT_INPOS_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_INPOS_BIT; else (joint)->flag &= ~EMCMOT_AXIS_INPOS_BIT;
#define GET_JOINT_ERROR_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_ERROR_BIT ? 1 : 0)
#define SET_JOINT_ERROR_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_ERROR_BIT; else (joint)->flag &= ~EMCMOT_AXIS_ERROR_BIT;
#define GET_JOINT_PSL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MAX_SOFT_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_PSL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MAX_SOFT_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MAX_SOFT_LIMIT_BIT;
#define GET_JOINT_NSL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MIN_SOFT_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_NSL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MIN_SOFT_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MIN_SOFT_LIMIT_BIT;
#define GET_JOINT_PHL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MAX_HARD_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_PHL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MAX_HARD_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MAX_HARD_LIMIT_BIT;
#define GET_JOINT_NHL_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_MIN_HARD_LIMIT_BIT ? 1 : 0)
#define SET_JOINT_NHL_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_MIN_HARD_LIMIT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_MIN_HARD_LIMIT_BIT;
#define GET_JOINT_HOME_SWITCH_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_HOME_SWITCH_BIT ? 1 : 0)
#define SET_JOINT_HOME_SWITCH_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_HOME_SWITCH_BIT; else (joint)->flag &= ~EMCMOT_AXIS_HOME_SWITCH_BIT;
#define GET_JOINT_HOMING_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_HOMING_BIT ? 1 : 0)
#define SET_JOINT_HOMING_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_HOMING_BIT; else (joint)->flag &= ~EMCMOT_AXIS_HOMING_BIT;
#define GET_JOINT_HOMED_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_HOMED_BIT ? 1 : 0)
#define SET_JOINT_HOMED_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_HOMED_BIT; else (joint)->flag &= ~EMCMOT_AXIS_HOMED_BIT;
#define GET_JOINT_AT_HOME_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_AT_HOME_BIT ? 1 : 0)
#define SET_JOINT_AT_HOME_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_AT_HOME_BIT; else (joint)->flag &= ~EMCMOT_AXIS_AT_HOME_BIT;
#define GET_JOINT_FERROR_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_FERROR_BIT ? 1 : 0)
#define SET_JOINT_FERROR_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_FERROR_BIT; else (joint)->flag &= ~EMCMOT_AXIS_FERROR_BIT;
#define GET_JOINT_FAULT_FLAG(joint) ((joint)->flag & EMCMOT_AXIS_FAULT_BIT ? 1 : 0)
#define SET_JOINT_FAULT_FLAG(joint,fl) if (fl) (joint)->flag |= EMCMOT_AXIS_FAULT_BIT; else (joint)->flag &= ~EMCMOT_AXIS_FAULT_BIT;
#endif /* MOT_PRIV_H */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,103 +1,103 @@
/********************************************************************
* Description: usrmotintf.h
* Decls for interface functions (init, exit, read, write) for user
* processes which communicate with the real-time motion controller
* in emcmot.c
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef USRMOTINTF_H
#define USRMOTINTF_H
#include "motion.h" /* emcmot_status_t,CMD */
#ifdef __cplusplus
extern "C" {
#endif
/* usrmotIniLoad() loads params (SHMEM_KEY) from
named ini file */
extern int usrmotIniLoad(const char *file);
/* usrmotReadEmcmotStatus() gets the status info out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotStatus(emcmot_status_t * s);
/* usrmotReadEmcmotConfig() gets the config info out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotConfig(emcmot_config_t * s);
/* usrmotReadEmcmotDebug() gets the debug info out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotDebug(emcmot_debug_t * s);
/* usrmotReadEmcmotError() gets the earliest queued error string out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotError(char *e);
/* usrmotPrintEmcmotStatus() prints the status in s, using which
arg to select sub-prints */
extern void usrmotPrintEmcmotStatus(emcmot_status_t s, int which);
/* usrmotPrintEmcmotConfig() prints the config in s, using which
arg to select sub-prints */
extern void usrmotPrintEmcmotConfig(emcmot_config_t s, int which);
/* usrmotPrintEmcmotDebug() prints the debug in s, using which
arg to select sub-prints */
extern void usrmotPrintEmcmotDebug(emcmot_debug_t s, int which);
/* values returned by usrmotWriteEmcmotCommand; negative values
are all errors */
#define EMCMOT_COMM_OK 0 /* went through and honored */
#define EMCMOT_COMM_ERROR_CONNECT -1 /* can't even connect */
#define EMCMOT_COMM_ERROR_TIMEOUT -2 /* connected, but send timeout */
#define EMCMOT_COMM_ERROR_COMMAND -3 /* sent, but can't run command now */
#define EMCMOT_COMM_SPLIT_READ_TIMEOUT -4 /* can't read without split */
/* usrmotWriteEmcmotCommand() writes the command to the emcmot process.
Return values are as per the #defines above */
extern int usrmotWriteEmcmotCommand(emcmot_command_t * c);
/* usrmotInit() initializes communication with the emcmot process */
extern int usrmotInit(char *name);
/* usrmotExit() terminates communication with the emcmot process */
extern int usrmotExit(void);
/* usrmotDumpLog() dumps the logged data (if active) from the usrmot
process into the named filename */
extern int usrmotDumpLog(const char *filename, int include_header);
/* usrmotLoadComp() loads the compensation data in file into the axis */
extern int usrmotLoadComp(int axis, const char *file);
/* usrmotAlter() loads the alter value to modify the axis position */
extern int usrmotAlter(int axis, double alter);
/* usrmotQueryAlter() sets the alter ptr to the current alter value */
extern int usrmotQueryAlter(int axis, double *alter);
/* usrmotPrintComp() prints the axis compensation data for axis */
extern int usrmotPrintComp(int axis);
extern int usrmotSetIOWriteCount(unsigned short int count);
extern int usrmotSetIOReadCount(unsigned short int count);
extern int usrmotWriteIO(int index, unsigned char val);
extern unsigned char usrmotReadIO(int index);
#ifdef __cplusplus
}
#endif
#endif /* USRMOTINTF_H */
/********************************************************************
* Description: usrmotintf.h
* Decls for interface functions (init, exit, read, write) for user
* processes which communicate with the real-time motion controller
* in emcmot.c
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef USRMOTINTF_H
#define USRMOTINTF_H
#include "motion.h" /* emcmot_status_t,CMD */
#ifdef __cplusplus
extern "C" {
#endif
/* usrmotIniLoad() loads params (SHMEM_KEY) from
named ini file */
extern int usrmotIniLoad(const char *file);
/* usrmotReadEmcmotStatus() gets the status info out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotStatus(emcmot_status_t * s);
/* usrmotReadEmcmotConfig() gets the config info out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotConfig(emcmot_config_t * s);
/* usrmotReadEmcmotDebug() gets the debug info out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotDebug(emcmot_debug_t * s);
/* usrmotReadEmcmotError() gets the earliest queued error string out of
the emcmot controller and puts it in arg */
extern int usrmotReadEmcmotError(char *e);
/* usrmotPrintEmcmotStatus() prints the status in s, using which
arg to select sub-prints */
extern void usrmotPrintEmcmotStatus(emcmot_status_t s, int which);
/* usrmotPrintEmcmotConfig() prints the config in s, using which
arg to select sub-prints */
extern void usrmotPrintEmcmotConfig(emcmot_config_t s, int which);
/* usrmotPrintEmcmotDebug() prints the debug in s, using which
arg to select sub-prints */
extern void usrmotPrintEmcmotDebug(emcmot_debug_t s, int which);
/* values returned by usrmotWriteEmcmotCommand; negative values
are all errors */
#define EMCMOT_COMM_OK 0 /* went through and honored */
#define EMCMOT_COMM_ERROR_CONNECT -1 /* can't even connect */
#define EMCMOT_COMM_ERROR_TIMEOUT -2 /* connected, but send timeout */
#define EMCMOT_COMM_ERROR_COMMAND -3 /* sent, but can't run command now */
#define EMCMOT_COMM_SPLIT_READ_TIMEOUT -4 /* can't read without split */
/* usrmotWriteEmcmotCommand() writes the command to the emcmot process.
Return values are as per the #defines above */
extern int usrmotWriteEmcmotCommand(emcmot_command_t * c);
/* usrmotInit() initializes communication with the emcmot process */
extern int usrmotInit(char *name);
/* usrmotExit() terminates communication with the emcmot process */
extern int usrmotExit(void);
/* usrmotDumpLog() dumps the logged data (if active) from the usrmot
process into the named filename */
extern int usrmotDumpLog(const char *filename, int include_header);
/* usrmotLoadComp() loads the compensation data in file into the axis */
extern int usrmotLoadComp(int axis, const char *file);
/* usrmotAlter() loads the alter value to modify the axis position */
extern int usrmotAlter(int axis, double alter);
/* usrmotQueryAlter() sets the alter ptr to the current alter value */
extern int usrmotQueryAlter(int axis, double *alter);
/* usrmotPrintComp() prints the axis compensation data for axis */
extern int usrmotPrintComp(int axis);
extern int usrmotSetIOWriteCount(unsigned short int count);
extern int usrmotSetIOReadCount(unsigned short int count);
extern int usrmotWriteIO(int index, unsigned char val);
extern unsigned char usrmotReadIO(int index);
#ifdef __cplusplus
}
#endif
#endif /* USRMOTINTF_H */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,93 +1,93 @@
/********************************************************************
* Description: emcargs.cc
* Globals initialized to values in emccfg.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <string.h> /* strcpy() */
#include <stdio.h> /* fgets() */
#include "rcs.hh" /* nmlSetHostAlias() */
#include "emcglb.h" /* these decls */
#include "emccfg.h" /* their initial values */
int emcGetArgs(int argc, char *argv[])
{
int t;
/* process command line args, indexing argv[] from [1] */
for (t = 1; t < argc; t++) {
if (!strcmp(argv[t], "-ini")) {
if (t == argc - 1) {
return -1;
} else {
strcpy(EMC_INIFILE, argv[t + 1]);
t++;
}
continue;
}
if (!strcmp(argv[t], "-rcsdebug")) {
set_rcs_print_flag(PRINT_EVERYTHING);
max_rcs_errors_to_print = -1;
continue;
}
if (!strcmp(argv[t], "-queryhost")) {
char qhost[80];
printf("EMC Host?");
fgets(qhost, 80, stdin);
for (int i = 0; i < 80; i++) {
if (qhost[i] == '\r' || qhost[i] == '\n' || qhost[i] == ' ') {
qhost[i] = 0;
break;
}
}
nmlSetHostAlias(qhost, "localhost"); /* If localhost
appears in .nml
file it will
overriden by this
argument. */
nmlForceRemoteConnection();
/* The only good reason for aliasing the host that I know of is
to connect to a remote server so we will ignore the
LOCAL/REMOTE field in the .nml file and always connect
remotely. */
continue;
}
if (!strcmp(argv[t], "-host")) {
if (t == argc - 1) {
return -1;
} else {
nmlSetHostAlias(argv[t + 1], "localhost"); /* If
localhost
appears in
.nml file
it will
overriden
by this
argument. */
nmlForceRemoteConnection();
/* The only good reason for aliasing the host that I know of
is to connect to a remote server so we will ignore the
LOCAL/REMOTE field in the .nml file and always connect
remotely. */
t++;
}
continue;
}
}
/* else not recognized-- ignore */
return 0;
}
/********************************************************************
* Description: emcargs.cc
* Globals initialized to values in emccfg.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <string.h> /* strcpy() */
#include <stdio.h> /* fgets() */
#include "rcs.hh" /* nmlSetHostAlias() */
#include "emcglb.h" /* these decls */
#include "emccfg.h" /* their initial values */
int emcGetArgs(int argc, char *argv[])
{
int t;
/* process command line args, indexing argv[] from [1] */
for (t = 1; t < argc; t++) {
if (!strcmp(argv[t], "-ini")) {
if (t == argc - 1) {
return -1;
} else {
strcpy(EMC_INIFILE, argv[t + 1]);
t++;
}
continue;
}
if (!strcmp(argv[t], "-rcsdebug")) {
set_rcs_print_flag(PRINT_EVERYTHING);
max_rcs_errors_to_print = -1;
continue;
}
if (!strcmp(argv[t], "-queryhost")) {
char qhost[80];
printf("EMC Host?");
fgets(qhost, 80, stdin);
for (int i = 0; i < 80; i++) {
if (qhost[i] == '\r' || qhost[i] == '\n' || qhost[i] == ' ') {
qhost[i] = 0;
break;
}
}
nmlSetHostAlias(qhost, "localhost"); /* If localhost
appears in .nml
file it will
overriden by this
argument. */
nmlForceRemoteConnection();
/* The only good reason for aliasing the host that I know of is
to connect to a remote server so we will ignore the
LOCAL/REMOTE field in the .nml file and always connect
remotely. */
continue;
}
if (!strcmp(argv[t], "-host")) {
if (t == argc - 1) {
return -1;
} else {
nmlSetHostAlias(argv[t + 1], "localhost"); /* If
localhost
appears in
.nml file
it will
overriden
by this
argument. */
nmlForceRemoteConnection();
/* The only good reason for aliasing the host that I know of
is to connect to a remote server so we will ignore the
LOCAL/REMOTE field in the .nml file and always connect
remotely. */
t++;
}
continue;
}
}
/* else not recognized-- ignore */
return 0;
}

View file

@ -1,101 +1,101 @@
/********************************************************************
* Description: emccfg.h
* Compile-time defaults for EMC application. Defaults are used to
* initialize globals in emcglb.c. Include emcglb.h to access these
* globals.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCCFG_H
#define EMCCFG_H
#ifdef __cplusplus
extern "C" {
#endif
/* default name of EMC ini file */
#define DEFAULT_EMC_INIFILE "emc.ini"
/* default name of EMC NML file */
#define DEFAULT_EMC_NMLFILE "emc.nml"
/* cycle time for emctask, in seconds */
#define DEFAULT_EMC_TASK_CYCLE_TIME 0.100
/* cycle time for emctio, in seconds */
#define DEFAULT_EMC_IO_CYCLE_TIME 0.100
/* default name of EMC_TOOL tool table file */
#define DEFAULT_TOOL_TABLE_FILE "tool.tbl"
/* default feed rate, in user units per second */
#define DEFAULT_TRAJ_DEFAULT_VELOCITY 1.0
/* default traverse rate, in user units per second */
#define DEFAULT_TRAJ_MAX_VELOCITY 10.0
/* default axis traverse rate, in user units per second */
#define DEFAULT_AXIS_MAX_VELOCITY 1.0
/* default axis acceleration, in user units per second per second */
#define DEFAULT_AXIS_MAX_ACCELERATION 1.0
/* seconds after speed off to apply brake */
#define DEFAULT_SPINDLE_OFF_WAIT 2.0
/* seconds after brake off for spindle on */
#define DEFAULT_SPINDLE_ON_WAIT 2.0
/* bit locations for digital inputs */
#define DEFAULT_ESTOP_SENSE_INDEX 0
#define DEFAULT_LUBE_SENSE_INDEX 1
/* sense of digital inputs */
#define DEFAULT_ESTOP_SENSE_POLARITY 1
#define DEFAULT_LUBE_SENSE_POLARITY 0
/* point locations for analog outputs */
#define DEFAULT_SPINDLE_ON_INDEX 0
#define DEFAULT_MIN_VOLTS_PER_RPM -0.01
#define DEFAULT_MAX_VOLTS_PER_RPM 0.01
/* bit locations for digital outputs */
#define DEFAULT_SPINDLE_FORWARD_INDEX 0
#define DEFAULT_SPINDLE_REVERSE_INDEX 1
#define DEFAULT_SPINDLE_BRAKE_INDEX 2
#define DEFAULT_SPINDLE_DECREASE_INDEX 3
#define DEFAULT_SPINDLE_INCREASE_INDEX 4
#define DEFAULT_MIST_COOLANT_INDEX 5
#define DEFAULT_FLOOD_COOLANT_INDEX 6
#define DEFAULT_ESTOP_WRITE_INDEX 7
#define DEFAULT_SPINDLE_ENABLE_INDEX 8
#define DEFAULT_LUBE_WRITE_INDEX 9
/* sense of digital outputs */
#define DEFAULT_SPINDLE_FORWARD_POLARITY 1
#define DEFAULT_SPINDLE_REVERSE_POLARITY 1
#define DEFAULT_MIST_COOLANT_POLARITY 1
#define DEFAULT_FLOOD_COOLANT_POLARITY 1
#define DEFAULT_SPINDLE_DECREASE_POLARITY 1
#define DEFAULT_SPINDLE_INCREASE_POLARITY 1
#define DEFAULT_ESTOP_WRITE_POLARITY 1
#define DEFAULT_SPINDLE_BRAKE_POLARITY 1
#define DEFAULT_SPINDLE_ENABLE_POLARITY 1
#define DEFAULT_LUBE_WRITE_POLARITY 1
#ifdef __cplusplus
} /* matches extern "C" at top */
#endif
#endif
/********************************************************************
* Description: emccfg.h
* Compile-time defaults for EMC application. Defaults are used to
* initialize globals in emcglb.c. Include emcglb.h to access these
* globals.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCCFG_H
#define EMCCFG_H
#ifdef __cplusplus
extern "C" {
#endif
/* default name of EMC ini file */
#define DEFAULT_EMC_INIFILE "emc.ini"
/* default name of EMC NML file */
#define DEFAULT_EMC_NMLFILE "emc.nml"
/* cycle time for emctask, in seconds */
#define DEFAULT_EMC_TASK_CYCLE_TIME 0.100
/* cycle time for emctio, in seconds */
#define DEFAULT_EMC_IO_CYCLE_TIME 0.100
/* default name of EMC_TOOL tool table file */
#define DEFAULT_TOOL_TABLE_FILE "tool.tbl"
/* default feed rate, in user units per second */
#define DEFAULT_TRAJ_DEFAULT_VELOCITY 1.0
/* default traverse rate, in user units per second */
#define DEFAULT_TRAJ_MAX_VELOCITY 10.0
/* default axis traverse rate, in user units per second */
#define DEFAULT_AXIS_MAX_VELOCITY 1.0
/* default axis acceleration, in user units per second per second */
#define DEFAULT_AXIS_MAX_ACCELERATION 1.0
/* seconds after speed off to apply brake */
#define DEFAULT_SPINDLE_OFF_WAIT 2.0
/* seconds after brake off for spindle on */
#define DEFAULT_SPINDLE_ON_WAIT 2.0
/* bit locations for digital inputs */
#define DEFAULT_ESTOP_SENSE_INDEX 0
#define DEFAULT_LUBE_SENSE_INDEX 1
/* sense of digital inputs */
#define DEFAULT_ESTOP_SENSE_POLARITY 1
#define DEFAULT_LUBE_SENSE_POLARITY 0
/* point locations for analog outputs */
#define DEFAULT_SPINDLE_ON_INDEX 0
#define DEFAULT_MIN_VOLTS_PER_RPM -0.01
#define DEFAULT_MAX_VOLTS_PER_RPM 0.01
/* bit locations for digital outputs */
#define DEFAULT_SPINDLE_FORWARD_INDEX 0
#define DEFAULT_SPINDLE_REVERSE_INDEX 1
#define DEFAULT_SPINDLE_BRAKE_INDEX 2
#define DEFAULT_SPINDLE_DECREASE_INDEX 3
#define DEFAULT_SPINDLE_INCREASE_INDEX 4
#define DEFAULT_MIST_COOLANT_INDEX 5
#define DEFAULT_FLOOD_COOLANT_INDEX 6
#define DEFAULT_ESTOP_WRITE_INDEX 7
#define DEFAULT_SPINDLE_ENABLE_INDEX 8
#define DEFAULT_LUBE_WRITE_INDEX 9
/* sense of digital outputs */
#define DEFAULT_SPINDLE_FORWARD_POLARITY 1
#define DEFAULT_SPINDLE_REVERSE_POLARITY 1
#define DEFAULT_MIST_COOLANT_POLARITY 1
#define DEFAULT_FLOOD_COOLANT_POLARITY 1
#define DEFAULT_SPINDLE_DECREASE_POLARITY 1
#define DEFAULT_SPINDLE_INCREASE_POLARITY 1
#define DEFAULT_ESTOP_WRITE_POLARITY 1
#define DEFAULT_SPINDLE_BRAKE_POLARITY 1
#define DEFAULT_SPINDLE_ENABLE_POLARITY 1
#define DEFAULT_LUBE_WRITE_POLARITY 1
#ifdef __cplusplus
} /* matches extern "C" at top */
#endif
#endif

View file

@ -1,98 +1,98 @@
/********************************************************************
* Description: emcglb.c
* Globals initialized to values in emccfg.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <string.h> /* strcpy() */
#include "emcglb.h" /* these decls */
#include "emccfg.h" /* their initial values */
#include "emcpos.h" /* EmcPose */
char EMC_INIFILE[EMC_INIFILE_LEN] = DEFAULT_EMC_INIFILE;
char EMC_NMLFILE[EMC_NMLFILE_LEN] = DEFAULT_EMC_NMLFILE;
char RS274NGC_STARTUP_CODE[RS274NGC_STARTUP_CODE_MAX] =
DEFAULT_RS274NGC_STARTUP_CODE;
int EMC_DEBUG = 0; /* initially no debug messages */
double EMC_TASK_CYCLE_TIME = DEFAULT_EMC_TASK_CYCLE_TIME;
double EMC_IO_CYCLE_TIME = DEFAULT_EMC_IO_CYCLE_TIME;
char TOOL_TABLE_FILE[TOOL_TABLE_FILE_LEN] = DEFAULT_TOOL_TABLE_FILE;
double TRAJ_DEFAULT_VELOCITY = DEFAULT_TRAJ_DEFAULT_VELOCITY;
double TRAJ_MAX_VELOCITY = DEFAULT_TRAJ_MAX_VELOCITY;
double AXIS_MAX_VELOCITY[EMC_AXIS_MAX] = { 1.0 }; /* FIXME - I think
these should be
0.0 */
double AXIS_MAX_ACCELERATION[EMC_AXIS_MAX] = { 1.0 };
double SPINDLE_OFF_WAIT = DEFAULT_SPINDLE_OFF_WAIT;
double SPINDLE_ON_WAIT = DEFAULT_SPINDLE_ON_WAIT;
int ESTOP_SENSE_INDEX = DEFAULT_ESTOP_SENSE_INDEX;
int LUBE_SENSE_INDEX = DEFAULT_LUBE_SENSE_INDEX;
int ESTOP_SENSE_POLARITY = DEFAULT_ESTOP_SENSE_POLARITY;
int LUBE_SENSE_POLARITY = DEFAULT_LUBE_SENSE_POLARITY;
int LUBE_WRITE_INDEX = DEFAULT_LUBE_WRITE_INDEX;
int LUBE_WRITE_POLARITY = DEFAULT_LUBE_WRITE_POLARITY;
int SPINDLE_ON_INDEX = DEFAULT_SPINDLE_ON_INDEX;
double MIN_VOLTS_PER_RPM = DEFAULT_MIN_VOLTS_PER_RPM;
double MAX_VOLTS_PER_RPM = DEFAULT_MAX_VOLTS_PER_RPM;
int SPINDLE_FORWARD_INDEX = DEFAULT_SPINDLE_FORWARD_INDEX;
int SPINDLE_REVERSE_INDEX = DEFAULT_SPINDLE_REVERSE_INDEX;
int SPINDLE_BRAKE_INDEX = DEFAULT_SPINDLE_BRAKE_INDEX;
int SPINDLE_DECREASE_INDEX = DEFAULT_SPINDLE_DECREASE_INDEX;
int SPINDLE_INCREASE_INDEX = DEFAULT_SPINDLE_INCREASE_INDEX;
int SPINDLE_ENABLE_INDEX = DEFAULT_SPINDLE_ENABLE_INDEX;
int MIST_COOLANT_INDEX = DEFAULT_MIST_COOLANT_INDEX;
int FLOOD_COOLANT_INDEX = DEFAULT_FLOOD_COOLANT_INDEX;
int ESTOP_WRITE_INDEX = DEFAULT_ESTOP_WRITE_INDEX;
int SPINDLE_FORWARD_POLARITY = DEFAULT_SPINDLE_FORWARD_POLARITY;
int SPINDLE_REVERSE_POLARITY = DEFAULT_SPINDLE_REVERSE_POLARITY;
int MIST_COOLANT_POLARITY = DEFAULT_MIST_COOLANT_POLARITY;
int FLOOD_COOLANT_POLARITY = DEFAULT_FLOOD_COOLANT_POLARITY;
int SPINDLE_DECREASE_POLARITY = DEFAULT_SPINDLE_DECREASE_POLARITY;
int SPINDLE_INCREASE_POLARITY = DEFAULT_SPINDLE_INCREASE_POLARITY;
int ESTOP_WRITE_POLARITY = DEFAULT_ESTOP_WRITE_POLARITY;
int SPINDLE_BRAKE_POLARITY = DEFAULT_SPINDLE_BRAKE_POLARITY;
int SPINDLE_ENABLE_POLARITY = DEFAULT_SPINDLE_ENABLE_POLARITY;
int EMCLOG_INCLUDE_HEADER = DEFAULT_EMCLOG_INCLUDE_HEADER;
EmcPose TOOL_CHANGE_POSITION; /* no defaults */
unsigned char HAVE_TOOL_CHANGE_POSITION = 0; /* default is 'not there' */
EmcPose TOOL_HOLDER_CLEAR; /* no defaults */
unsigned char HAVE_TOOL_HOLDER_CLEAR; /* default is 'not there' */
int taskplanopen = 0;
void emcInitGlobals()
{
int t;
for (t = 0; t < EMC_AXIS_MAX; t++) {
AXIS_MAX_VELOCITY[t] = DEFAULT_AXIS_MAX_VELOCITY;
}
}
/********************************************************************
* Description: emcglb.c
* Globals initialized to values in emccfg.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <string.h> /* strcpy() */
#include "emcglb.h" /* these decls */
#include "emccfg.h" /* their initial values */
#include "emcpos.h" /* EmcPose */
char EMC_INIFILE[EMC_INIFILE_LEN] = DEFAULT_EMC_INIFILE;
char EMC_NMLFILE[EMC_NMLFILE_LEN] = DEFAULT_EMC_NMLFILE;
char RS274NGC_STARTUP_CODE[RS274NGC_STARTUP_CODE_MAX] =
DEFAULT_RS274NGC_STARTUP_CODE;
int EMC_DEBUG = 0; /* initially no debug messages */
double EMC_TASK_CYCLE_TIME = DEFAULT_EMC_TASK_CYCLE_TIME;
double EMC_IO_CYCLE_TIME = DEFAULT_EMC_IO_CYCLE_TIME;
char TOOL_TABLE_FILE[TOOL_TABLE_FILE_LEN] = DEFAULT_TOOL_TABLE_FILE;
double TRAJ_DEFAULT_VELOCITY = DEFAULT_TRAJ_DEFAULT_VELOCITY;
double TRAJ_MAX_VELOCITY = DEFAULT_TRAJ_MAX_VELOCITY;
double AXIS_MAX_VELOCITY[EMC_AXIS_MAX] = { 1.0 }; /* FIXME - I think
these should be
0.0 */
double AXIS_MAX_ACCELERATION[EMC_AXIS_MAX] = { 1.0 };
double SPINDLE_OFF_WAIT = DEFAULT_SPINDLE_OFF_WAIT;
double SPINDLE_ON_WAIT = DEFAULT_SPINDLE_ON_WAIT;
int ESTOP_SENSE_INDEX = DEFAULT_ESTOP_SENSE_INDEX;
int LUBE_SENSE_INDEX = DEFAULT_LUBE_SENSE_INDEX;
int ESTOP_SENSE_POLARITY = DEFAULT_ESTOP_SENSE_POLARITY;
int LUBE_SENSE_POLARITY = DEFAULT_LUBE_SENSE_POLARITY;
int LUBE_WRITE_INDEX = DEFAULT_LUBE_WRITE_INDEX;
int LUBE_WRITE_POLARITY = DEFAULT_LUBE_WRITE_POLARITY;
int SPINDLE_ON_INDEX = DEFAULT_SPINDLE_ON_INDEX;
double MIN_VOLTS_PER_RPM = DEFAULT_MIN_VOLTS_PER_RPM;
double MAX_VOLTS_PER_RPM = DEFAULT_MAX_VOLTS_PER_RPM;
int SPINDLE_FORWARD_INDEX = DEFAULT_SPINDLE_FORWARD_INDEX;
int SPINDLE_REVERSE_INDEX = DEFAULT_SPINDLE_REVERSE_INDEX;
int SPINDLE_BRAKE_INDEX = DEFAULT_SPINDLE_BRAKE_INDEX;
int SPINDLE_DECREASE_INDEX = DEFAULT_SPINDLE_DECREASE_INDEX;
int SPINDLE_INCREASE_INDEX = DEFAULT_SPINDLE_INCREASE_INDEX;
int SPINDLE_ENABLE_INDEX = DEFAULT_SPINDLE_ENABLE_INDEX;
int MIST_COOLANT_INDEX = DEFAULT_MIST_COOLANT_INDEX;
int FLOOD_COOLANT_INDEX = DEFAULT_FLOOD_COOLANT_INDEX;
int ESTOP_WRITE_INDEX = DEFAULT_ESTOP_WRITE_INDEX;
int SPINDLE_FORWARD_POLARITY = DEFAULT_SPINDLE_FORWARD_POLARITY;
int SPINDLE_REVERSE_POLARITY = DEFAULT_SPINDLE_REVERSE_POLARITY;
int MIST_COOLANT_POLARITY = DEFAULT_MIST_COOLANT_POLARITY;
int FLOOD_COOLANT_POLARITY = DEFAULT_FLOOD_COOLANT_POLARITY;
int SPINDLE_DECREASE_POLARITY = DEFAULT_SPINDLE_DECREASE_POLARITY;
int SPINDLE_INCREASE_POLARITY = DEFAULT_SPINDLE_INCREASE_POLARITY;
int ESTOP_WRITE_POLARITY = DEFAULT_ESTOP_WRITE_POLARITY;
int SPINDLE_BRAKE_POLARITY = DEFAULT_SPINDLE_BRAKE_POLARITY;
int SPINDLE_ENABLE_POLARITY = DEFAULT_SPINDLE_ENABLE_POLARITY;
int EMCLOG_INCLUDE_HEADER = DEFAULT_EMCLOG_INCLUDE_HEADER;
EmcPose TOOL_CHANGE_POSITION; /* no defaults */
unsigned char HAVE_TOOL_CHANGE_POSITION = 0; /* default is 'not there' */
EmcPose TOOL_HOLDER_CLEAR; /* no defaults */
unsigned char HAVE_TOOL_HOLDER_CLEAR; /* default is 'not there' */
int taskplanopen = 0;
void emcInitGlobals()
{
int t;
for (t = 0; t < EMC_AXIS_MAX; t++) {
AXIS_MAX_VELOCITY[t] = DEFAULT_AXIS_MAX_VELOCITY;
}
}

View file

@ -1,125 +1,125 @@
/********************************************************************
* Description: emcglb.h
* Declarations for globals found in emcglb.c
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCGLB_H
#define EMCGLB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "emcpos.h" /* EmcPose */
#define EMC_AXIS_MAX 8
#define EMC_INIFILE_LEN 256
extern char EMC_INIFILE[EMC_INIFILE_LEN];
#define EMC_NMLFILE_LEN 256
extern char EMC_NMLFILE[EMC_NMLFILE_LEN];
#define DEFAULT_RS274NGC_STARTUP_CODE ""
#define RS274NGC_STARTUP_CODE_MAX 256
extern char RS274NGC_STARTUP_CODE[RS274NGC_STARTUP_CODE_MAX];
/* debug bitflags */
/* Note: these may be hard-code referenced by the GUI (e.g., emcdebug.tcl).
If you change the assignments here, make sure and reflect that in
the GUI scripts that use these. Unfortunately there's no easy way to
get these into Tk automatically */
extern int EMC_DEBUG;
#define EMC_DEBUG_INVALID 0x00000001
#define EMC_DEBUG_CONFIG 0x00000002
#define EMC_DEBUG_DEFAULTS 0x00000004
#define EMC_DEBUG_VERSIONS 0x00000008
#define EMC_DEBUG_TASK_ISSUE 0x00000010
#define EMC_DEBUG_IO_POINTS 0x00000020
#define EMC_DEBUG_NML 0x00000040
#define EMC_DEBUG_MOTION_TIME 0x00000080
#define EMC_DEBUG_INTERP 0x00000100
#define EMC_DEBUG_RCS 0x00000200
#define EMC_DEBUG_TRAJ 0x00000400
#define EMC_DEBUG_INTERP_LIST 0x00000800
#define EMC_DEBUG_ALL 0x7FFFFFFF /* it's an int for %i to work
*/
extern double EMC_TASK_CYCLE_TIME;
extern double EMC_IO_CYCLE_TIME;
#define TOOL_TABLE_FILE_LEN 256
extern char TOOL_TABLE_FILE[TOOL_TABLE_FILE_LEN];
extern double TRAJ_DEFAULT_VELOCITY;
extern double TRAJ_MAX_VELOCITY;
extern double AXIS_MAX_VELOCITY[EMC_AXIS_MAX];
extern double AXIS_MAX_ACCELERATION[EMC_AXIS_MAX];
extern double SPINDLE_OFF_WAIT;
extern double SPINDLE_ON_WAIT;
extern int ESTOP_SENSE_INDEX;
extern int LUBE_SENSE_INDEX;
extern int ESTOP_SENSE_POLARITY;
extern int LUBE_SENSE_POLARITY;
extern int SPINDLE_ON_INDEX;
extern double MIN_VOLTS_PER_RPM;
extern double MAX_VOLTS_PER_RPM;
extern int SPINDLE_FORWARD_INDEX;
extern int SPINDLE_REVERSE_INDEX;
extern int SPINDLE_BRAKE_INDEX;
extern int SPINDLE_DECREASE_INDEX;
extern int SPINDLE_INCREASE_INDEX;
extern int SPINDLE_ENABLE_INDEX;
extern int MIST_COOLANT_INDEX;
extern int FLOOD_COOLANT_INDEX;
extern int ESTOP_WRITE_INDEX;
extern int LUBE_WRITE_INDEX;
extern int SPINDLE_FORWARD_POLARITY;
extern int SPINDLE_REVERSE_POLARITY;
extern int MIST_COOLANT_POLARITY;
extern int FLOOD_COOLANT_POLARITY;
extern int SPINDLE_DECREASE_POLARITY;
extern int SPINDLE_INCREASE_POLARITY;
extern int ESTOP_WRITE_POLARITY;
extern int SPINDLE_BRAKE_POLARITY;
extern int SPINDLE_ENABLE_POLARITY;
extern int LUBE_WRITE_POLARITY;
extern EmcPose TOOL_CHANGE_POSITION;
extern unsigned char HAVE_TOOL_CHANGE_POSITION;
extern EmcPose TOOL_HOLDER_CLEAR;
extern unsigned char HAVE_TOOL_HOLDER_CLEAR;
#define DEFAULT_EMCLOG_INCLUDE_HEADER (1)
extern int EMCLOG_INCLUDE_HEADER;
/*just used to keep track of unneccessary debug printing. */
extern int taskplanopen;
extern int emcGetArgs(int argc, char *argv[]);
extern void emcInitGlobals();
#ifdef __cplusplus
} /* matches extern "C" at top */
#endif
#endif /* EMCGLB_H */
/********************************************************************
* Description: emcglb.h
* Declarations for globals found in emcglb.c
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCGLB_H
#define EMCGLB_H
#ifdef __cplusplus
extern "C" {
#endif
#include "emcpos.h" /* EmcPose */
#define EMC_AXIS_MAX 8
#define EMC_INIFILE_LEN 256
extern char EMC_INIFILE[EMC_INIFILE_LEN];
#define EMC_NMLFILE_LEN 256
extern char EMC_NMLFILE[EMC_NMLFILE_LEN];
#define DEFAULT_RS274NGC_STARTUP_CODE ""
#define RS274NGC_STARTUP_CODE_MAX 256
extern char RS274NGC_STARTUP_CODE[RS274NGC_STARTUP_CODE_MAX];
/* debug bitflags */
/* Note: these may be hard-code referenced by the GUI (e.g., emcdebug.tcl).
If you change the assignments here, make sure and reflect that in
the GUI scripts that use these. Unfortunately there's no easy way to
get these into Tk automatically */
extern int EMC_DEBUG;
#define EMC_DEBUG_INVALID 0x00000001
#define EMC_DEBUG_CONFIG 0x00000002
#define EMC_DEBUG_DEFAULTS 0x00000004
#define EMC_DEBUG_VERSIONS 0x00000008
#define EMC_DEBUG_TASK_ISSUE 0x00000010
#define EMC_DEBUG_IO_POINTS 0x00000020
#define EMC_DEBUG_NML 0x00000040
#define EMC_DEBUG_MOTION_TIME 0x00000080
#define EMC_DEBUG_INTERP 0x00000100
#define EMC_DEBUG_RCS 0x00000200
#define EMC_DEBUG_TRAJ 0x00000400
#define EMC_DEBUG_INTERP_LIST 0x00000800
#define EMC_DEBUG_ALL 0x7FFFFFFF /* it's an int for %i to work
*/
extern double EMC_TASK_CYCLE_TIME;
extern double EMC_IO_CYCLE_TIME;
#define TOOL_TABLE_FILE_LEN 256
extern char TOOL_TABLE_FILE[TOOL_TABLE_FILE_LEN];
extern double TRAJ_DEFAULT_VELOCITY;
extern double TRAJ_MAX_VELOCITY;
extern double AXIS_MAX_VELOCITY[EMC_AXIS_MAX];
extern double AXIS_MAX_ACCELERATION[EMC_AXIS_MAX];
extern double SPINDLE_OFF_WAIT;
extern double SPINDLE_ON_WAIT;
extern int ESTOP_SENSE_INDEX;
extern int LUBE_SENSE_INDEX;
extern int ESTOP_SENSE_POLARITY;
extern int LUBE_SENSE_POLARITY;
extern int SPINDLE_ON_INDEX;
extern double MIN_VOLTS_PER_RPM;
extern double MAX_VOLTS_PER_RPM;
extern int SPINDLE_FORWARD_INDEX;
extern int SPINDLE_REVERSE_INDEX;
extern int SPINDLE_BRAKE_INDEX;
extern int SPINDLE_DECREASE_INDEX;
extern int SPINDLE_INCREASE_INDEX;
extern int SPINDLE_ENABLE_INDEX;
extern int MIST_COOLANT_INDEX;
extern int FLOOD_COOLANT_INDEX;
extern int ESTOP_WRITE_INDEX;
extern int LUBE_WRITE_INDEX;
extern int SPINDLE_FORWARD_POLARITY;
extern int SPINDLE_REVERSE_POLARITY;
extern int MIST_COOLANT_POLARITY;
extern int FLOOD_COOLANT_POLARITY;
extern int SPINDLE_DECREASE_POLARITY;
extern int SPINDLE_INCREASE_POLARITY;
extern int ESTOP_WRITE_POLARITY;
extern int SPINDLE_BRAKE_POLARITY;
extern int SPINDLE_ENABLE_POLARITY;
extern int LUBE_WRITE_POLARITY;
extern EmcPose TOOL_CHANGE_POSITION;
extern unsigned char HAVE_TOOL_CHANGE_POSITION;
extern EmcPose TOOL_HOLDER_CLEAR;
extern unsigned char HAVE_TOOL_HOLDER_CLEAR;
#define DEFAULT_EMCLOG_INCLUDE_HEADER (1)
extern int EMCLOG_INCLUDE_HEADER;
/*just used to keep track of unneccessary debug printing. */
extern int taskplanopen;
extern int emcGetArgs(int argc, char *argv[]);
extern void emcInitGlobals();
#ifdef __cplusplus
} /* matches extern "C" at top */
#endif
#endif /* EMCGLB_H */

View file

@ -1,258 +1,258 @@
/********************************************************************
* Description: emcops.cc
* Initialization and other ad hoc functions for NML. This complements
* the auto-generated emc.cc, which contains all the rote update
* methods for the message classes.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include "emc.hh"
EMC_AXIS_STAT::EMC_AXIS_STAT():
EMC_AXIS_STAT_MSG(EMC_AXIS_STAT_TYPE, sizeof(EMC_AXIS_STAT))
{
axisType = EMC_AXIS_LINEAR;
units = 1.0;
p = 0.0;
i = 0.0;
d = 0.0;
ff0 = 0.0;
ff1 = 0.0;
ff2 = 0.0;
backlash = 0.0;
bias = 0.0;
maxError = 0.0;
cycleTime = 1.0;
inputScale = 1.0;
inputOffset = 0.0;
outputScale = 1.0;
outputOffset = 0.0;
minPositionLimit = -1.0;
maxPositionLimit = 1.0;
minOutputLimit = -1.0;
maxOutputLimit = 1.0;
maxFerror = 1.0;
homingVel = 1.0;
setup_time = 1;
hold_time = 2;
enablePolarity = 1;
minLimitSwitchPolarity = 1;
maxLimitSwitchPolarity = 1;
homeSwitchPolarity = 1;
homingPolarity = 1;
faultPolarity = 1;
ferrorCurrent = 0.0;
ferrorHighMark = 0.0;
output = 0.0;
input = 0.0;
inpos = 1;
homing = 0;
homed = 0;
enabled = 0;
minSoftLimit = 0;
maxSoftLimit = 0;
minHardLimit = 0;
maxHardLimit = 0;
scale = 0.0;
}
EMC_TRAJ_STAT::EMC_TRAJ_STAT():
EMC_TRAJ_STAT_MSG(EMC_TRAJ_STAT_TYPE, sizeof(EMC_TRAJ_STAT))
{
linearUnits = 1.0;
angularUnits = 1.0;
axes = 1;
mode = EMC_TRAJ_MODE_FREE;
enabled = 0;
inpos = 1;
queue = 0;
activeQueue = 0;
queueFull = 0;
id = 0;
paused = 0;
position.tran.x = 0.0;
position.tran.y = 0.0;
position.tran.z = 0.0;
position.a = 0.0;
position.b = 0.0;
position.c = 0.0;
actualPosition.tran.x = 0.0;
actualPosition.tran.y = 0.0;
actualPosition.tran.z = 0.0;
actualPosition.a = 0.0;
actualPosition.b = 0.0;
actualPosition.c = 0.0;
velocity = 1.0;
acceleration = 1.0;
maxVelocity = 1.0;
maxAcceleration = 1.0;
}
EMC_TASK_STAT::EMC_TASK_STAT():
EMC_TASK_STAT_MSG(EMC_TASK_STAT_TYPE, sizeof(EMC_TASK_STAT))
{
int t;
mode = EMC_TASK_MODE_MANUAL;
state = EMC_TASK_STATE_ESTOP;
execState = EMC_TASK_EXEC_DONE;
interpState = EMC_TASK_INTERP_IDLE;
motionLine = 0;
currentLine = 0;
readLine = 0;
file[0] = 0;
command[0] = 0;
origin.tran.x = 0.0;
origin.tran.y = 0.0;
origin.tran.z = 0.0;
origin.a = 0.0;
origin.b = 0.0;
origin.c = 0.0;
toolOffset.tran.x = 0.0;
toolOffset.tran.y = 0.0;
toolOffset.tran.z = 0.0;
toolOffset.a = 0.0;
toolOffset.b = 0.0;
toolOffset.c = 0.0;
for (t = 0; t < ACTIVE_G_CODES; t++)
activeGCodes[t] = -1;
for (t = 0; t < ACTIVE_M_CODES; t++)
activeMCodes[t] = -1;
for (t = 0; t < ACTIVE_SETTINGS; t++)
activeSettings[t] = 0.0;
}
EMC_TOOL_STAT::EMC_TOOL_STAT():
EMC_TOOL_STAT_MSG(EMC_TOOL_STAT_TYPE, sizeof(EMC_TOOL_STAT))
{
int t;
toolPrepped = 0;
toolInSpindle = 0;
for (t = 0; t <= CANON_TOOL_MAX; t++) {
toolTable[t].id = 0;
toolTable[t].length = 0.0;
toolTable[t].diameter = 0.0;
}
}
EMC_AUX_STAT::EMC_AUX_STAT():
EMC_AUX_STAT_MSG(EMC_AUX_STAT_TYPE, sizeof(EMC_AUX_STAT))
{
int t;
estop = 1;
for (t = 0; t < EMC_AUX_MAX_DOUT; t++) {
dout[t] = 0;
}
for (t = 0; t < EMC_AUX_MAX_DIN; t++) {
din[t] = 0;
}
for (t = 0; t < EMC_AUX_MAX_AOUT; t++) {
aout[t] = 0;
}
for (t = 0; t < EMC_AUX_MAX_AIN; t++) {
ain[t] = 0;
}
}
EMC_SPINDLE_STAT::EMC_SPINDLE_STAT():
EMC_SPINDLE_STAT_MSG(EMC_SPINDLE_STAT_TYPE, sizeof(EMC_SPINDLE_STAT))
{
speed = 0.0;
direction = 0;
brake = 1;
increasing = 0;
enabled = 0;
}
EMC_COOLANT_STAT::EMC_COOLANT_STAT():EMC_COOLANT_STAT_MSG(EMC_COOLANT_STAT_TYPE,
sizeof(EMC_COOLANT_STAT))
{
mist = 0;
flood = 0;
}
EMC_LUBE_STAT::EMC_LUBE_STAT():
EMC_LUBE_STAT_MSG(EMC_LUBE_STAT_TYPE, sizeof(EMC_LUBE_STAT))
{
on = 0;
level = 1;
}
// overload = , since class has array elements
EMC_TOOL_STAT EMC_TOOL_STAT::operator =(EMC_TOOL_STAT s)
{
int t;
toolPrepped = s.toolPrepped;
toolInSpindle = s.toolInSpindle;
for (t = 0; t <= CANON_TOOL_MAX; t++) {
toolTable[t].id = s.toolTable[t].id;
toolTable[t].length = s.toolTable[t].length;
toolTable[t].diameter = s.toolTable[t].diameter;
}
return s;
}
// overload = , since class has array elements
EMC_AUX_STAT EMC_AUX_STAT::operator =(EMC_AUX_STAT s)
{
int t;
estop = s.estop;
for (t = 0; t < EMC_AUX_MAX_DOUT; t++) {
dout[t] = s.dout[t];
}
for (t = 0; t < EMC_AUX_MAX_DIN; t++) {
din[t] = s.din[t];
}
for (t = 0; t < EMC_AUX_MAX_AOUT; t++) {
aout[t] = s.aout[t];
}
for (t = 0; t < EMC_AUX_MAX_AIN; t++) {
ain[t] = s.ain[t];
}
return s;
}
EMC_STAT::EMC_STAT():EMC_STAT_MSG(EMC_STAT_TYPE, sizeof(EMC_STAT))
{
logFile[0] = 0;
logType = 0;
logSize = 0;
logSkip = 0;
logOpen = 0;
logStarted = 0;
logPoints = 0;
}
/********************************************************************
* Description: emcops.cc
* Initialization and other ad hoc functions for NML. This complements
* the auto-generated emc.cc, which contains all the rote update
* methods for the message classes.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include "emc.hh"
EMC_AXIS_STAT::EMC_AXIS_STAT():
EMC_AXIS_STAT_MSG(EMC_AXIS_STAT_TYPE, sizeof(EMC_AXIS_STAT))
{
axisType = EMC_AXIS_LINEAR;
units = 1.0;
p = 0.0;
i = 0.0;
d = 0.0;
ff0 = 0.0;
ff1 = 0.0;
ff2 = 0.0;
backlash = 0.0;
bias = 0.0;
maxError = 0.0;
cycleTime = 1.0;
inputScale = 1.0;
inputOffset = 0.0;
outputScale = 1.0;
outputOffset = 0.0;
minPositionLimit = -1.0;
maxPositionLimit = 1.0;
minOutputLimit = -1.0;
maxOutputLimit = 1.0;
maxFerror = 1.0;
homingVel = 1.0;
setup_time = 1;
hold_time = 2;
enablePolarity = 1;
minLimitSwitchPolarity = 1;
maxLimitSwitchPolarity = 1;
homeSwitchPolarity = 1;
homingPolarity = 1;
faultPolarity = 1;
ferrorCurrent = 0.0;
ferrorHighMark = 0.0;
output = 0.0;
input = 0.0;
inpos = 1;
homing = 0;
homed = 0;
enabled = 0;
minSoftLimit = 0;
maxSoftLimit = 0;
minHardLimit = 0;
maxHardLimit = 0;
scale = 0.0;
}
EMC_TRAJ_STAT::EMC_TRAJ_STAT():
EMC_TRAJ_STAT_MSG(EMC_TRAJ_STAT_TYPE, sizeof(EMC_TRAJ_STAT))
{
linearUnits = 1.0;
angularUnits = 1.0;
axes = 1;
mode = EMC_TRAJ_MODE_FREE;
enabled = 0;
inpos = 1;
queue = 0;
activeQueue = 0;
queueFull = 0;
id = 0;
paused = 0;
position.tran.x = 0.0;
position.tran.y = 0.0;
position.tran.z = 0.0;
position.a = 0.0;
position.b = 0.0;
position.c = 0.0;
actualPosition.tran.x = 0.0;
actualPosition.tran.y = 0.0;
actualPosition.tran.z = 0.0;
actualPosition.a = 0.0;
actualPosition.b = 0.0;
actualPosition.c = 0.0;
velocity = 1.0;
acceleration = 1.0;
maxVelocity = 1.0;
maxAcceleration = 1.0;
}
EMC_TASK_STAT::EMC_TASK_STAT():
EMC_TASK_STAT_MSG(EMC_TASK_STAT_TYPE, sizeof(EMC_TASK_STAT))
{
int t;
mode = EMC_TASK_MODE_MANUAL;
state = EMC_TASK_STATE_ESTOP;
execState = EMC_TASK_EXEC_DONE;
interpState = EMC_TASK_INTERP_IDLE;
motionLine = 0;
currentLine = 0;
readLine = 0;
file[0] = 0;
command[0] = 0;
origin.tran.x = 0.0;
origin.tran.y = 0.0;
origin.tran.z = 0.0;
origin.a = 0.0;
origin.b = 0.0;
origin.c = 0.0;
toolOffset.tran.x = 0.0;
toolOffset.tran.y = 0.0;
toolOffset.tran.z = 0.0;
toolOffset.a = 0.0;
toolOffset.b = 0.0;
toolOffset.c = 0.0;
for (t = 0; t < ACTIVE_G_CODES; t++)
activeGCodes[t] = -1;
for (t = 0; t < ACTIVE_M_CODES; t++)
activeMCodes[t] = -1;
for (t = 0; t < ACTIVE_SETTINGS; t++)
activeSettings[t] = 0.0;
}
EMC_TOOL_STAT::EMC_TOOL_STAT():
EMC_TOOL_STAT_MSG(EMC_TOOL_STAT_TYPE, sizeof(EMC_TOOL_STAT))
{
int t;
toolPrepped = 0;
toolInSpindle = 0;
for (t = 0; t <= CANON_TOOL_MAX; t++) {
toolTable[t].id = 0;
toolTable[t].length = 0.0;
toolTable[t].diameter = 0.0;
}
}
EMC_AUX_STAT::EMC_AUX_STAT():
EMC_AUX_STAT_MSG(EMC_AUX_STAT_TYPE, sizeof(EMC_AUX_STAT))
{
int t;
estop = 1;
for (t = 0; t < EMC_AUX_MAX_DOUT; t++) {
dout[t] = 0;
}
for (t = 0; t < EMC_AUX_MAX_DIN; t++) {
din[t] = 0;
}
for (t = 0; t < EMC_AUX_MAX_AOUT; t++) {
aout[t] = 0;
}
for (t = 0; t < EMC_AUX_MAX_AIN; t++) {
ain[t] = 0;
}
}
EMC_SPINDLE_STAT::EMC_SPINDLE_STAT():
EMC_SPINDLE_STAT_MSG(EMC_SPINDLE_STAT_TYPE, sizeof(EMC_SPINDLE_STAT))
{
speed = 0.0;
direction = 0;
brake = 1;
increasing = 0;
enabled = 0;
}
EMC_COOLANT_STAT::EMC_COOLANT_STAT():EMC_COOLANT_STAT_MSG(EMC_COOLANT_STAT_TYPE,
sizeof(EMC_COOLANT_STAT))
{
mist = 0;
flood = 0;
}
EMC_LUBE_STAT::EMC_LUBE_STAT():
EMC_LUBE_STAT_MSG(EMC_LUBE_STAT_TYPE, sizeof(EMC_LUBE_STAT))
{
on = 0;
level = 1;
}
// overload = , since class has array elements
EMC_TOOL_STAT EMC_TOOL_STAT::operator =(EMC_TOOL_STAT s)
{
int t;
toolPrepped = s.toolPrepped;
toolInSpindle = s.toolInSpindle;
for (t = 0; t <= CANON_TOOL_MAX; t++) {
toolTable[t].id = s.toolTable[t].id;
toolTable[t].length = s.toolTable[t].length;
toolTable[t].diameter = s.toolTable[t].diameter;
}
return s;
}
// overload = , since class has array elements
EMC_AUX_STAT EMC_AUX_STAT::operator =(EMC_AUX_STAT s)
{
int t;
estop = s.estop;
for (t = 0; t < EMC_AUX_MAX_DOUT; t++) {
dout[t] = s.dout[t];
}
for (t = 0; t < EMC_AUX_MAX_DIN; t++) {
din[t] = s.din[t];
}
for (t = 0; t < EMC_AUX_MAX_AOUT; t++) {
aout[t] = s.aout[t];
}
for (t = 0; t < EMC_AUX_MAX_AIN; t++) {
ain[t] = s.ain[t];
}
return s;
}
EMC_STAT::EMC_STAT():EMC_STAT_MSG(EMC_STAT_TYPE, sizeof(EMC_STAT))
{
logFile[0] = 0;
logType = 0;
logSize = 0;
logSkip = 0;
logOpen = 0;
logStarted = 0;
logPoints = 0;
}

View file

@ -1,27 +1,27 @@
/********************************************************************
* Description: emcpos.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCPOS_H
#define EMCPOS_H
#include "posemath.h" /* PmCartesian */
typedef struct _EmcPose {
PmCartesian tran;
double a, b, c;
} EmcPose;
#endif
/********************************************************************
* Description: emcpos.h
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef EMCPOS_H
#define EMCPOS_H
#include "posemath.h" /* PmCartesian */
typedef struct _EmcPose {
PmCartesian tran;
double a, b, c;
} EmcPose;
#endif

View file

@ -1,237 +1,237 @@
/********************************************************************
* Description: interpl.cc
* Mechanism for queueing NML messages, used by the interpreter and
* canonical interface to report list of NML statements from program
* files to HME.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
extern "C" {
#include <string.h> /* memcpy() */
#include <libintl.h>
}
#include "rcs.hh" // LinkedList
#include "interpl.hh" // these decls
#include "emcglb.h"
NML_INTERP_LIST interp_list; /* NML Union, for interpreter */
NML_INTERP_LIST::NML_INTERP_LIST()
{
linked_list_ptr = new LinkedList;
next_line_number = 0;
line_number = 0;
}
NML_INTERP_LIST::~NML_INTERP_LIST()
{
if (NULL != linked_list_ptr)
{
delete linked_list_ptr;
linked_list_ptr = NULL;
}
}
int NML_INTERP_LIST::append(NMLmsg &nml_msg)
{
/* check for invalid data */
if (0 == nml_msg.type)
{
rcs_print_error("NML_INTERP_LIST::append : attempt to append 0 type\n");
return -1;
}
if (NULL == linked_list_ptr)
{
return -1;
}
if(nml_msg.size > MAX_NML_COMMAND_SIZE -64)
{
rcs_print_error("NML_INTERP_LIST::append : command size is too large.");
return -1;
}
if(nml_msg.size < 4 )
{
rcs_print_error("NML_INTERP_LIST::append : command size is invalid.");
return -1;
}
#ifdef DEBUG_INTERPL
if(sizeof(temp_node) < MAX_NML_COMMAND_SIZE+4 ||
sizeof(temp_node) > MAX_NML_COMMAND_SIZE+16 )
{
rcs_print_error("NML_INTERP_LIST::append : assumptions about NML_INTERP_LIST_NODE have been violated.\n");
return -1;
}
#endif
// fill in the NML_INTERP_LIST_NODE
temp_node.line_number = next_line_number;
memcpy(temp_node.command.commandbuf, &nml_msg, nml_msg.size);
// stick it on the list
linked_list_ptr->store_at_tail(&temp_node, nml_msg.size+sizeof(temp_node.line_number)+sizeof(temp_node.dummy)+32+(32-nml_msg.size%32), 1);
#ifdef DEBUG_INTERPL
if(EMC_DEBUG & EMC_DEBUG_INTERP_LIST)
{
rcs_print("NML_INTERP_LIST::append(nml_msg{size=%d,type=%d}) : list_size=%d, line_number = %d\n",
nml_msg.size,nml_msg.type,linked_list_ptr->list_size,
temp_node.line_number);
}
#endif
return 0;
}
// sets the line number used for subsequent appends
int NML_INTERP_LIST::set_line_number(int line)
{
next_line_number = line;
return 0;
}
int NML_INTERP_LIST::append(NMLmsg *nml_msg_ptr)
{
/* check for invalid data */
if (NULL == nml_msg_ptr)
{
rcs_print_error("NML_INTERP_LIST::append : attempt to append NULL msg\n");
return -1;
}
if (0 == nml_msg_ptr->type)
{
rcs_print_error("NML_INTERP_LIST::append : attempt to append 0 type\n");
return -1;
}
if(nml_msg_ptr->size > MAX_NML_COMMAND_SIZE -64 )
{
rcs_print_error("NML_INTERP_LIST::append : command size is too large.");
return -1;
}
if(nml_msg_ptr->size < 4 )
{
rcs_print_error("NML_INTERP_LIST::append : command size is invalid.");
return -1;
}
#ifdef DEBUG_INTERPL
if(sizeof(temp_node) < MAX_NML_COMMAND_SIZE+4 ||
sizeof(temp_node) > MAX_NML_COMMAND_SIZE+16 ||
((void *) &temp_node.line_number) > ((void *) &temp_node.command.commandbuf))
{
rcs_print_error("NML_INTERP_LIST::append : assumptions about NML_INTERP_LIST_NODE have been violated.");
return -1;
}
#endif
if (NULL == linked_list_ptr)
{
return -1;
}
// fill in the NML_INTERP_LIST_NODE
temp_node.line_number = next_line_number;
memcpy(temp_node.command.commandbuf, nml_msg_ptr, nml_msg_ptr->size);
// stick it on the list
linked_list_ptr->store_at_tail(&temp_node, nml_msg_ptr->size+sizeof(temp_node.line_number)+sizeof(temp_node.dummy)+32+(32-nml_msg_ptr->size%32), 1);
#ifdef DEBUG_INTERPL
if(EMC_DEBUG & EMC_DEBUG_INTERP_LIST)
{
rcs_print("NML_INTERP_LIST::append(nml_msg{size=%d,type=%d}) : list_size=%d, line_number = %d\n",
nml_msg_ptr->size,nml_msg_ptr->type,linked_list_ptr->list_size,
temp_node.line_number);
}
#endif
return 0;
}
NMLmsg * NML_INTERP_LIST::get()
{
NMLmsg *ret;
NML_INTERP_LIST_NODE *node_ptr;
if (NULL == linked_list_ptr)
{
line_number = 0;
return NULL;
}
node_ptr = (NML_INTERP_LIST_NODE *) linked_list_ptr->retrieve_head();
if (NULL == node_ptr)
{
line_number = 0;
return NULL;
}
// save line number of this one, for use by get_line_number
line_number = node_ptr->line_number;
// get it off the front
ret = (NMLmsg *) ((char *) node_ptr->command.commandbuf);
return ret;
}
void NML_INTERP_LIST::clear()
{
if (NULL != linked_list_ptr)
{
linked_list_ptr->delete_members();
}
}
void NML_INTERP_LIST::print()
{
NMLmsg *nml_msg;
if (NULL == linked_list_ptr)
{
return;
}
nml_msg = (NMLmsg *) linked_list_ptr->get_head();
while (NULL != nml_msg)
{
rcs_print("%d ", nml_msg->type);
nml_msg = (NMLmsg *)linked_list_ptr->get_next();
}
rcs_print("\n");
}
int NML_INTERP_LIST::len()
{
if (NULL == linked_list_ptr)
{
return 0;
}
return ((int) linked_list_ptr->list_size);
}
int NML_INTERP_LIST::get_line_number()
{
return line_number;
}
/********************************************************************
* Description: interpl.cc
* Mechanism for queueing NML messages, used by the interpreter and
* canonical interface to report list of NML statements from program
* files to HME.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
extern "C" {
#include <string.h> /* memcpy() */
#include <libintl.h>
}
#include "rcs.hh" // LinkedList
#include "interpl.hh" // these decls
#include "emcglb.h"
NML_INTERP_LIST interp_list; /* NML Union, for interpreter */
NML_INTERP_LIST::NML_INTERP_LIST()
{
linked_list_ptr = new LinkedList;
next_line_number = 0;
line_number = 0;
}
NML_INTERP_LIST::~NML_INTERP_LIST()
{
if (NULL != linked_list_ptr)
{
delete linked_list_ptr;
linked_list_ptr = NULL;
}
}
int NML_INTERP_LIST::append(NMLmsg &nml_msg)
{
/* check for invalid data */
if (0 == nml_msg.type)
{
rcs_print_error("NML_INTERP_LIST::append : attempt to append 0 type\n");
return -1;
}
if (NULL == linked_list_ptr)
{
return -1;
}
if(nml_msg.size > MAX_NML_COMMAND_SIZE -64)
{
rcs_print_error("NML_INTERP_LIST::append : command size is too large.");
return -1;
}
if(nml_msg.size < 4 )
{
rcs_print_error("NML_INTERP_LIST::append : command size is invalid.");
return -1;
}
#ifdef DEBUG_INTERPL
if(sizeof(temp_node) < MAX_NML_COMMAND_SIZE+4 ||
sizeof(temp_node) > MAX_NML_COMMAND_SIZE+16 )
{
rcs_print_error("NML_INTERP_LIST::append : assumptions about NML_INTERP_LIST_NODE have been violated.\n");
return -1;
}
#endif
// fill in the NML_INTERP_LIST_NODE
temp_node.line_number = next_line_number;
memcpy(temp_node.command.commandbuf, &nml_msg, nml_msg.size);
// stick it on the list
linked_list_ptr->store_at_tail(&temp_node, nml_msg.size+sizeof(temp_node.line_number)+sizeof(temp_node.dummy)+32+(32-nml_msg.size%32), 1);
#ifdef DEBUG_INTERPL
if(EMC_DEBUG & EMC_DEBUG_INTERP_LIST)
{
rcs_print("NML_INTERP_LIST::append(nml_msg{size=%d,type=%d}) : list_size=%d, line_number = %d\n",
nml_msg.size,nml_msg.type,linked_list_ptr->list_size,
temp_node.line_number);
}
#endif
return 0;
}
// sets the line number used for subsequent appends
int NML_INTERP_LIST::set_line_number(int line)
{
next_line_number = line;
return 0;
}
int NML_INTERP_LIST::append(NMLmsg *nml_msg_ptr)
{
/* check for invalid data */
if (NULL == nml_msg_ptr)
{
rcs_print_error("NML_INTERP_LIST::append : attempt to append NULL msg\n");
return -1;
}
if (0 == nml_msg_ptr->type)
{
rcs_print_error("NML_INTERP_LIST::append : attempt to append 0 type\n");
return -1;
}
if(nml_msg_ptr->size > MAX_NML_COMMAND_SIZE -64 )
{
rcs_print_error("NML_INTERP_LIST::append : command size is too large.");
return -1;
}
if(nml_msg_ptr->size < 4 )
{
rcs_print_error("NML_INTERP_LIST::append : command size is invalid.");
return -1;
}
#ifdef DEBUG_INTERPL
if(sizeof(temp_node) < MAX_NML_COMMAND_SIZE+4 ||
sizeof(temp_node) > MAX_NML_COMMAND_SIZE+16 ||
((void *) &temp_node.line_number) > ((void *) &temp_node.command.commandbuf))
{
rcs_print_error("NML_INTERP_LIST::append : assumptions about NML_INTERP_LIST_NODE have been violated.");
return -1;
}
#endif
if (NULL == linked_list_ptr)
{
return -1;
}
// fill in the NML_INTERP_LIST_NODE
temp_node.line_number = next_line_number;
memcpy(temp_node.command.commandbuf, nml_msg_ptr, nml_msg_ptr->size);
// stick it on the list
linked_list_ptr->store_at_tail(&temp_node, nml_msg_ptr->size+sizeof(temp_node.line_number)+sizeof(temp_node.dummy)+32+(32-nml_msg_ptr->size%32), 1);
#ifdef DEBUG_INTERPL
if(EMC_DEBUG & EMC_DEBUG_INTERP_LIST)
{
rcs_print("NML_INTERP_LIST::append(nml_msg{size=%d,type=%d}) : list_size=%d, line_number = %d\n",
nml_msg_ptr->size,nml_msg_ptr->type,linked_list_ptr->list_size,
temp_node.line_number);
}
#endif
return 0;
}
NMLmsg * NML_INTERP_LIST::get()
{
NMLmsg *ret;
NML_INTERP_LIST_NODE *node_ptr;
if (NULL == linked_list_ptr)
{
line_number = 0;
return NULL;
}
node_ptr = (NML_INTERP_LIST_NODE *) linked_list_ptr->retrieve_head();
if (NULL == node_ptr)
{
line_number = 0;
return NULL;
}
// save line number of this one, for use by get_line_number
line_number = node_ptr->line_number;
// get it off the front
ret = (NMLmsg *) ((char *) node_ptr->command.commandbuf);
return ret;
}
void NML_INTERP_LIST::clear()
{
if (NULL != linked_list_ptr)
{
linked_list_ptr->delete_members();
}
}
void NML_INTERP_LIST::print()
{
NMLmsg *nml_msg;
if (NULL == linked_list_ptr)
{
return;
}
nml_msg = (NMLmsg *) linked_list_ptr->get_head();
while (NULL != nml_msg)
{
rcs_print("%d ", nml_msg->type);
nml_msg = (NMLmsg *)linked_list_ptr->get_next();
}
rcs_print("\n");
}
int NML_INTERP_LIST::len()
{
if (NULL == linked_list_ptr)
{
return 0;
}
return ((int) linked_list_ptr->list_size);
}
int NML_INTERP_LIST::get_line_number()
{
return line_number;
}

View file

@ -1,74 +1,74 @@
/********************************************************************
* Description: interpl.hh
* Mechanism for building lists of arbitrary NML messages, used by
* the canonical interface and interpreter to pass planned sequences
* to the HME.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef INTERP_LIST_HH
#define INTERP_LIST_HH
#define MAX_NML_COMMAND_SIZE 1000
// these go on the interp list
struct NML_INTERP_LIST_NODE
{
int line_number; // line number it was on
union _dummy_union {
int i;
long l;
double d;
float f;
long long ll;
long double ld;
} dummy; // paranoid alignment variable.
union _command_union {
char commandbuf[MAX_NML_COMMAND_SIZE]; // the NML command;
int i;
long l;
double d;
float f;
long long ll;
long double ld;
} command;
};
// here's the interp list itself
class NML_INTERP_LIST
{
public:
NML_INTERP_LIST();
~NML_INTERP_LIST();
int set_line_number(int line);
int get_line_number();
int append(NMLmsg &);
int append(NMLmsg *);
NMLmsg *get();
void clear();
void print();
int len();
private:
LinkedList *linked_list_ptr;
NML_INTERP_LIST_NODE temp_node; // filled in and put on the list
int next_line_number; // line number used to fill temp_node
int line_number; // line number of node from get()
};
extern NML_INTERP_LIST interp_list; /* NML Union, for interpreter */
#endif
/********************************************************************
* Description: interpl.hh
* Mechanism for building lists of arbitrary NML messages, used by
* the canonical interface and interpreter to pass planned sequences
* to the HME.
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef INTERP_LIST_HH
#define INTERP_LIST_HH
#define MAX_NML_COMMAND_SIZE 1000
// these go on the interp list
struct NML_INTERP_LIST_NODE
{
int line_number; // line number it was on
union _dummy_union {
int i;
long l;
double d;
float f;
long long ll;
long double ld;
} dummy; // paranoid alignment variable.
union _command_union {
char commandbuf[MAX_NML_COMMAND_SIZE]; // the NML command;
int i;
long l;
double d;
float f;
long long ll;
long double ld;
} command;
};
// here's the interp list itself
class NML_INTERP_LIST
{
public:
NML_INTERP_LIST();
~NML_INTERP_LIST();
int set_line_number(int line);
int get_line_number();
int append(NMLmsg &);
int append(NMLmsg *);
NMLmsg *get();
void clear();
void print();
int len();
private:
LinkedList *linked_list_ptr;
NML_INTERP_LIST_NODE temp_node; // filled in and put on the list
int next_line_number; // line number used to fill temp_node
int line_number; // line number of node from get()
};
extern NML_INTERP_LIST interp_list; /* NML Union, for interpreter */
#endif

View file

@ -1,340 +1,340 @@
/********************************************************************
* Description: interp_arc.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/***********************************************************************/
/*! arc_data_comp_ijk
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. The two calculable values of the radius differ by more than
tolerance: NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START
2. move is not G_2 or G_3: NCE_BUG_CODE_NOT_G2_OR_G3
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by: convert_arc_comp1
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc in ijk-format in the XY
plane. The center is computed easily from the current point and center
offsets, which are given. It is checked that the end point lies one
tool radius from the arc.
*/
int Interp::arc_data_comp_ijk(int move, //!<either G_2 (cw arc) or G_3 (ccw arc)
int side, //!<either RIGHT or LEFT
double tool_radius, //!<radius of the tool
double current_x, //!<first coordinate of current point
double current_y, //!<second coordinate of current point
double end_x, //!<first coordinate of arc end point
double end_y, //!<second coordinate of arc end point
double i_number, //!<first coordinate offset of center from current
double j_number, //!<second coordinate offset of center from current
double *center_x, //!<pointer to first coordinate of center of arc
double *center_y, //!<pointer to second coordinate of center of arc
int *turn, //!<pointer to number of full or partial circles CCW
double tolerance) //!<tolerance of differing radii
{
static char name[] = "arc_data_comp_ijk";
double arc_radius;
double radius2;
*center_x = (current_x + i_number);
*center_y = (current_y + j_number);
arc_radius = hypot(i_number, j_number);
radius2 = hypot((*center_x - end_x), (*center_y - end_y));
radius2 =
(((side == LEFT) && (move == 30)) ||
((side == RIGHT) && (move == 20))) ?
(radius2 - tool_radius) : (radius2 + tool_radius);
CHK((fabs(arc_radius - radius2) > tolerance),
NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START);
/* This catches an arc too small for the tool, also */
if (move == G_2)
*turn = -1;
else if (move == G_3)
*turn = 1;
else
ERM(NCE_BUG_CODE_NOT_G2_OR_G3);
return RS274NGC_OK;
}
/****************************************************************************/
/*! arc_data_comp_r
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. The arc radius is too small to reach the end point:
NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT
2. The arc radius is not greater than the tool_radius, but should be:
NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP
3. An imaginary value for offset would be found, which should never
happen if the theory is correct: NCE_BUG_IN_TOOL_RADIUS_COMP
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by: convert_arc_comp1
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc (call it arc1) in
r-format in the XY plane. Arc2 is constructed so that it is tangent
to a circle whose radius is tool_radius and whose center is at the
point (current_x, current_y) and passes through the point (end_x,
end_y). Arc1 has the same center as arc2. The radius of arc1 is one
tool radius larger or smaller than the radius of arc2.
If the value of the big_radius argument is negative, that means [NCMS,
page 21] that an arc larger than a semicircle is to be made.
Otherwise, an arc of a semicircle or less is made.
The algorithm implemented here is to construct a line L from the
current point to the end point, and a perpendicular to it from the
center of the arc which intersects L at point P. Since the distance
from the end point to the center and the distance from the current
point to the center are known, two equations for the length of the
perpendicular can be written. The right sides of the equations can be
set equal to one another and the resulting equation solved for the
length of the line from the current point to P. Then the location of
P, the length of the perpendicular, the angle of the perpendicular,
and the location of the center, can be found in turn.
This needs to be better documented, with figures. There are eight
possible arcs, since there are three binary possibilities: (1) tool
inside or outside arc, (2) clockwise or counterclockwise (3) two
positions for each arc (of the given radius) tangent to the tool
outline and through the end point. All eight are calculated below,
since theta, radius2, and turn may each have two values.
To see two positions for each arc, imagine the arc is a hoop, the
tool is a cylindrical pin, and the arc may rotate around the end point.
The rotation covers all possible positions of the arc. It is easy to
see the hoop is constrained by the pin at two different angles, whether
the pin is inside or outside the hoop.
*/
int Interp::arc_data_comp_r(int move, //!< either G_2 (cw arc) or G_3 (ccw arc)
int side, //!< either RIGHT or LEFT
double tool_radius, //!< radius of the tool
double current_x, //!< first coordinate of current point
double current_y, //!< second coordinate of current point
double end_x, //!< first coordinate of arc end point
double end_y, //!< second coordinate of arc end point
double big_radius, //!< radius of arc
double *center_x, //!< pointer to first coordinate of center of arc
double *center_y, //!< pointer to second coordinate of center of arc
int *turn) //!< pointer to number of full or partial circles CCW
{
static char name[] = "arc_data_comp_r";
double abs_radius; // absolute value of big_radius
double alpha; // direction of line from current to end
double distance; // length of line L from current to end
double mid_length; // length from current point to point P
double offset; // length of line from P to center
double radius2; // distance from center to current point
double mid_x; // x-value of point P
double mid_y; // y-value of point P
double theta; // direction of line from P to center
abs_radius = fabs(big_radius);
CHK(((abs_radius <= tool_radius) && (((side == LEFT) && (move == G_3)) ||
((side == RIGHT) && (move == G_2)))),
NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP);
distance = hypot((end_x - current_x), (end_y - current_y));
alpha = atan2((end_y - current_y), (end_x - current_x));
theta = (((move == G_3) && (big_radius > 0)) ||
((move == G_2) && (big_radius < 0))) ?
(alpha + M_PI_2l) : (alpha - M_PI_2l);
radius2 = (((side == LEFT) && (move == G_3)) ||
((side == RIGHT) && (move == G_2))) ?
(abs_radius - tool_radius) : (abs_radius + tool_radius);
CHK((distance > (radius2 + abs_radius)),
NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT);
mid_length = (((radius2 * radius2) + (distance * distance) -
(abs_radius * abs_radius)) / (2.0 * distance));
mid_x = (current_x + (mid_length * cos(alpha)));
mid_y = (current_y + (mid_length * sin(alpha)));
CHK(((radius2 * radius2) <= (mid_length * mid_length)),
NCE_BUG_IN_TOOL_RADIUS_COMP);
offset = sqrt((radius2 * radius2) - (mid_length * mid_length));
*center_x = mid_x + (offset * cos(theta));
*center_y = mid_y + (offset * sin(theta));
*turn = (move == G_2) ? -1 : 1;
return RS274NGC_OK;
}
/****************************************************************************/
/*! arc_data_ijk
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. The two calculable values of the radius differ by more than
tolerance: NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START
2. The move code is not G_2 or G_3: NCE_BUG_CODE_NOT_G2_OR_G3
3. Either of the two calculable values of the radius is zero:
NCE_ZERO_RADIUS_ARC
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by:
convert_arc2
convert_arc_comp2
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc in ijk-format. This
function is used by convert_arc2 for all three planes, so "x" and
"y" really mean "first_coordinate" and "second_coordinate" wherever
they are used here as suffixes of variable names. The i and j prefixes
are handled similarly.
*/
int Interp::arc_data_ijk(int move, //!< either G_2 (cw arc) or G_3 (ccw arc)
double current_x, //!< first coordinate of current point
double current_y, //!< second coordinate of current point
double end_x, //!< first coordinate of arc end point
double end_y, //!< second coordinate of arc end point
double i_number, //!< first coordinate offset of center from current
double j_number, //!< second coordinate offset of center from current
double *center_x, //!< pointer to first coordinate of center of arc
double *center_y, //!< pointer to second coordinate of center of arc
int *turn, //!< pointer to no. of full or partial circles CCW
double tolerance) //!< tolerance of differing radii
{
static char name[] = "arc_data_ijk";
double radius; /* radius to current point */
double radius2; /* radius to end point */
*center_x = (current_x + i_number);
*center_y = (current_y + j_number);
radius = hypot((*center_x - current_x), (*center_y - current_y));
radius2 = hypot((*center_x - end_x), (*center_y - end_y));
CHK(((radius == 0.0) || (radius2 == 0.0)), NCE_ZERO_RADIUS_ARC);
CHK((fabs(radius - radius2) > tolerance),
NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START);
if (move == G_2)
*turn = -1;
else if (move == G_3)
*turn = 1;
else
ERM(NCE_BUG_CODE_NOT_G2_OR_G3);
return RS274NGC_OK;
}
/****************************************************************************/
/*! arc_data_r
Returned Value: int
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. The radius is too small to reach the end point:
NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT
2. The current point is the same as the end point of the arc
(so that it is not possible to locate the center of the circle):
NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by:
convert_arc2
convert_arc_comp2
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc in the r format. This
function is used by convert_arc2 for all three planes, so "x" and
"y" really mean "first_coordinate" and "second_coordinate" wherever
they are used here as suffixes of variable names.
If the value of the radius argument is negative, that means [NCMS,
page 21] that an arc larger than a semicircle is to be made.
Otherwise, an arc of a semicircle or less is made.
The algorithm used here is based on finding the midpoint M of the line
L between the current point and the end point of the arc. The center
of the arc lies on a line through M perpendicular to L.
*/
int Interp::arc_data_r(int move, //!< either G_2 (cw arc) or G_3 (ccw arc)
double current_x, //!< first coordinate of current point
double current_y, //!< second coordinate of current point
double end_x, //!< first coordinate of arc end point
double end_y, //!< second coordinate of arc end point
double radius, //!< radius of arc
double *center_x, //!< pointer to first coordinate of center of arc
double *center_y, //!< pointer to second coordinate of center of arc
int *turn) //!< pointer to no. of full or partial circles CCW
{
static char name[] = "arc_data_r";
double abs_radius; /* absolute value of given radius */
double half_length; /* distance from M to end point */
double mid_x; /* first coordinate of M */
double mid_y; /* second coordinate of M */
double offset; /* distance from M to center */
double theta; /* angle of line from M to center */
double turn2; /* absolute value of half of turn */
CHK(((end_x == current_x) && (end_y == current_y)),
NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC);
abs_radius = fabs(radius);
mid_x = (end_x + current_x) / 2.0;
mid_y = (end_y + current_y) / 2.0;
half_length = hypot((mid_x - end_x), (mid_y - end_y));
CHK(((half_length / abs_radius) > (1 + TINY)),
NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT);
if ((half_length / abs_radius) > (1 - TINY))
half_length = abs_radius; /* allow a small error for semicircle */
/* check needed before calling asin */
if (((move == G_2) && (radius > 0)) || ((move == G_3) && (radius < 0)))
theta = atan2((end_y - current_y), (end_x - current_x)) - M_PI_2l;
else
theta = atan2((end_y - current_y), (end_x - current_x)) + M_PI_2l;
turn2 = asin(half_length / abs_radius);
offset = abs_radius * cos(turn2);
*center_x = mid_x + (offset * cos(theta));
*center_y = mid_y + (offset * sin(theta));
*turn = (move == G_2) ? -1 : 1;
return RS274NGC_OK;
}
/********************************************************************
* Description: interp_arc.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/***********************************************************************/
/*! arc_data_comp_ijk
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. The two calculable values of the radius differ by more than
tolerance: NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START
2. move is not G_2 or G_3: NCE_BUG_CODE_NOT_G2_OR_G3
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by: convert_arc_comp1
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc in ijk-format in the XY
plane. The center is computed easily from the current point and center
offsets, which are given. It is checked that the end point lies one
tool radius from the arc.
*/
int Interp::arc_data_comp_ijk(int move, //!<either G_2 (cw arc) or G_3 (ccw arc)
int side, //!<either RIGHT or LEFT
double tool_radius, //!<radius of the tool
double current_x, //!<first coordinate of current point
double current_y, //!<second coordinate of current point
double end_x, //!<first coordinate of arc end point
double end_y, //!<second coordinate of arc end point
double i_number, //!<first coordinate offset of center from current
double j_number, //!<second coordinate offset of center from current
double *center_x, //!<pointer to first coordinate of center of arc
double *center_y, //!<pointer to second coordinate of center of arc
int *turn, //!<pointer to number of full or partial circles CCW
double tolerance) //!<tolerance of differing radii
{
static char name[] = "arc_data_comp_ijk";
double arc_radius;
double radius2;
*center_x = (current_x + i_number);
*center_y = (current_y + j_number);
arc_radius = hypot(i_number, j_number);
radius2 = hypot((*center_x - end_x), (*center_y - end_y));
radius2 =
(((side == LEFT) && (move == 30)) ||
((side == RIGHT) && (move == 20))) ?
(radius2 - tool_radius) : (radius2 + tool_radius);
CHK((fabs(arc_radius - radius2) > tolerance),
NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START);
/* This catches an arc too small for the tool, also */
if (move == G_2)
*turn = -1;
else if (move == G_3)
*turn = 1;
else
ERM(NCE_BUG_CODE_NOT_G2_OR_G3);
return RS274NGC_OK;
}
/****************************************************************************/
/*! arc_data_comp_r
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. The arc radius is too small to reach the end point:
NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT
2. The arc radius is not greater than the tool_radius, but should be:
NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP
3. An imaginary value for offset would be found, which should never
happen if the theory is correct: NCE_BUG_IN_TOOL_RADIUS_COMP
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by: convert_arc_comp1
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc (call it arc1) in
r-format in the XY plane. Arc2 is constructed so that it is tangent
to a circle whose radius is tool_radius and whose center is at the
point (current_x, current_y) and passes through the point (end_x,
end_y). Arc1 has the same center as arc2. The radius of arc1 is one
tool radius larger or smaller than the radius of arc2.
If the value of the big_radius argument is negative, that means [NCMS,
page 21] that an arc larger than a semicircle is to be made.
Otherwise, an arc of a semicircle or less is made.
The algorithm implemented here is to construct a line L from the
current point to the end point, and a perpendicular to it from the
center of the arc which intersects L at point P. Since the distance
from the end point to the center and the distance from the current
point to the center are known, two equations for the length of the
perpendicular can be written. The right sides of the equations can be
set equal to one another and the resulting equation solved for the
length of the line from the current point to P. Then the location of
P, the length of the perpendicular, the angle of the perpendicular,
and the location of the center, can be found in turn.
This needs to be better documented, with figures. There are eight
possible arcs, since there are three binary possibilities: (1) tool
inside or outside arc, (2) clockwise or counterclockwise (3) two
positions for each arc (of the given radius) tangent to the tool
outline and through the end point. All eight are calculated below,
since theta, radius2, and turn may each have two values.
To see two positions for each arc, imagine the arc is a hoop, the
tool is a cylindrical pin, and the arc may rotate around the end point.
The rotation covers all possible positions of the arc. It is easy to
see the hoop is constrained by the pin at two different angles, whether
the pin is inside or outside the hoop.
*/
int Interp::arc_data_comp_r(int move, //!< either G_2 (cw arc) or G_3 (ccw arc)
int side, //!< either RIGHT or LEFT
double tool_radius, //!< radius of the tool
double current_x, //!< first coordinate of current point
double current_y, //!< second coordinate of current point
double end_x, //!< first coordinate of arc end point
double end_y, //!< second coordinate of arc end point
double big_radius, //!< radius of arc
double *center_x, //!< pointer to first coordinate of center of arc
double *center_y, //!< pointer to second coordinate of center of arc
int *turn) //!< pointer to number of full or partial circles CCW
{
static char name[] = "arc_data_comp_r";
double abs_radius; // absolute value of big_radius
double alpha; // direction of line from current to end
double distance; // length of line L from current to end
double mid_length; // length from current point to point P
double offset; // length of line from P to center
double radius2; // distance from center to current point
double mid_x; // x-value of point P
double mid_y; // y-value of point P
double theta; // direction of line from P to center
abs_radius = fabs(big_radius);
CHK(((abs_radius <= tool_radius) && (((side == LEFT) && (move == G_3)) ||
((side == RIGHT) && (move == G_2)))),
NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP);
distance = hypot((end_x - current_x), (end_y - current_y));
alpha = atan2((end_y - current_y), (end_x - current_x));
theta = (((move == G_3) && (big_radius > 0)) ||
((move == G_2) && (big_radius < 0))) ?
(alpha + M_PI_2l) : (alpha - M_PI_2l);
radius2 = (((side == LEFT) && (move == G_3)) ||
((side == RIGHT) && (move == G_2))) ?
(abs_radius - tool_radius) : (abs_radius + tool_radius);
CHK((distance > (radius2 + abs_radius)),
NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT);
mid_length = (((radius2 * radius2) + (distance * distance) -
(abs_radius * abs_radius)) / (2.0 * distance));
mid_x = (current_x + (mid_length * cos(alpha)));
mid_y = (current_y + (mid_length * sin(alpha)));
CHK(((radius2 * radius2) <= (mid_length * mid_length)),
NCE_BUG_IN_TOOL_RADIUS_COMP);
offset = sqrt((radius2 * radius2) - (mid_length * mid_length));
*center_x = mid_x + (offset * cos(theta));
*center_y = mid_y + (offset * sin(theta));
*turn = (move == G_2) ? -1 : 1;
return RS274NGC_OK;
}
/****************************************************************************/
/*! arc_data_ijk
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. The two calculable values of the radius differ by more than
tolerance: NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START
2. The move code is not G_2 or G_3: NCE_BUG_CODE_NOT_G2_OR_G3
3. Either of the two calculable values of the radius is zero:
NCE_ZERO_RADIUS_ARC
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by:
convert_arc2
convert_arc_comp2
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc in ijk-format. This
function is used by convert_arc2 for all three planes, so "x" and
"y" really mean "first_coordinate" and "second_coordinate" wherever
they are used here as suffixes of variable names. The i and j prefixes
are handled similarly.
*/
int Interp::arc_data_ijk(int move, //!< either G_2 (cw arc) or G_3 (ccw arc)
double current_x, //!< first coordinate of current point
double current_y, //!< second coordinate of current point
double end_x, //!< first coordinate of arc end point
double end_y, //!< second coordinate of arc end point
double i_number, //!< first coordinate offset of center from current
double j_number, //!< second coordinate offset of center from current
double *center_x, //!< pointer to first coordinate of center of arc
double *center_y, //!< pointer to second coordinate of center of arc
int *turn, //!< pointer to no. of full or partial circles CCW
double tolerance) //!< tolerance of differing radii
{
static char name[] = "arc_data_ijk";
double radius; /* radius to current point */
double radius2; /* radius to end point */
*center_x = (current_x + i_number);
*center_y = (current_y + j_number);
radius = hypot((*center_x - current_x), (*center_y - current_y));
radius2 = hypot((*center_x - end_x), (*center_y - end_y));
CHK(((radius == 0.0) || (radius2 == 0.0)), NCE_ZERO_RADIUS_ARC);
CHK((fabs(radius - radius2) > tolerance),
NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START);
if (move == G_2)
*turn = -1;
else if (move == G_3)
*turn = 1;
else
ERM(NCE_BUG_CODE_NOT_G2_OR_G3);
return RS274NGC_OK;
}
/****************************************************************************/
/*! arc_data_r
Returned Value: int
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. The radius is too small to reach the end point:
NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT
2. The current point is the same as the end point of the arc
(so that it is not possible to locate the center of the circle):
NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC
Side effects:
This finds and sets the values of center_x, center_y, and turn.
Called by:
convert_arc2
convert_arc_comp2
This finds the center coordinates and number of full or partial turns
counterclockwise of a helical or circular arc in the r format. This
function is used by convert_arc2 for all three planes, so "x" and
"y" really mean "first_coordinate" and "second_coordinate" wherever
they are used here as suffixes of variable names.
If the value of the radius argument is negative, that means [NCMS,
page 21] that an arc larger than a semicircle is to be made.
Otherwise, an arc of a semicircle or less is made.
The algorithm used here is based on finding the midpoint M of the line
L between the current point and the end point of the arc. The center
of the arc lies on a line through M perpendicular to L.
*/
int Interp::arc_data_r(int move, //!< either G_2 (cw arc) or G_3 (ccw arc)
double current_x, //!< first coordinate of current point
double current_y, //!< second coordinate of current point
double end_x, //!< first coordinate of arc end point
double end_y, //!< second coordinate of arc end point
double radius, //!< radius of arc
double *center_x, //!< pointer to first coordinate of center of arc
double *center_y, //!< pointer to second coordinate of center of arc
int *turn) //!< pointer to no. of full or partial circles CCW
{
static char name[] = "arc_data_r";
double abs_radius; /* absolute value of given radius */
double half_length; /* distance from M to end point */
double mid_x; /* first coordinate of M */
double mid_y; /* second coordinate of M */
double offset; /* distance from M to center */
double theta; /* angle of line from M to center */
double turn2; /* absolute value of half of turn */
CHK(((end_x == current_x) && (end_y == current_y)),
NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC);
abs_radius = fabs(radius);
mid_x = (end_x + current_x) / 2.0;
mid_y = (end_y + current_y) / 2.0;
half_length = hypot((mid_x - end_x), (mid_y - end_y));
CHK(((half_length / abs_radius) > (1 + TINY)),
NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT);
if ((half_length / abs_radius) > (1 - TINY))
half_length = abs_radius; /* allow a small error for semicircle */
/* check needed before calling asin */
if (((move == G_2) && (radius > 0)) || ((move == G_3) && (radius < 0)))
theta = atan2((end_y - current_y), (end_x - current_x)) - M_PI_2l;
else
theta = atan2((end_y - current_y), (end_x - current_x)) + M_PI_2l;
turn2 = asin(half_length / abs_radius);
offset = abs_radius * cos(turn2);
*center_x = mid_x + (offset * cos(theta));
*center_y = mid_y + (offset * sin(theta));
*turn = (move == G_2) ? -1 : 1;
return RS274NGC_OK;
}

View file

@ -1,259 +1,259 @@
/********************************************************************
* Description: interp_array.cc
*
* This file just allocates space for the static arrays used by the
* interpreter.
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
/* Interpreter global arrays for g_codes and m_codes. The nth entry
in each array is the modal group number corresponding to the nth
code. Entries which are -1 represent illegal codes. Remember g_codes
in this interpreter are multiplied by 10.
The modal g groups and group numbers defined in [NCMS, pages 71 - 73]
(see also [Fanuc, pages 43 - 45]) are used here, except the canned
cycles (g80 - g89), which comprise modal g group 9 in [Fanuc], are
treated here as being in the same modal group (group 1) with the
straight moves and arcs (g0, g1, g2,g3). [Fanuc, page 45] says only
one g_code from any one group may appear on a line, and we are
following that rule. The straight_probe move, g38.2, is in group 1; it
is not defined in [NCMS].
Some g_codes are non-modal (g4, g10, g28, g30, g53, g92, g92.1, g92.2,
and g92.3 here - many more in [NCMS]). [Fanuc] and [NCMS] put all
these in the same group 0, so we do also. Logically, there are two
subgroups, those which require coordinate values (g10, g28, g30, and
g92) and those which do not (g4, g53, g92.1, g92.2, and g92.3).
The subgroups are identified by itemization when necessary.
Those in group 0 which require coordinate values may not be on the
same line as those in group 1 (except g80) because they would be
competing for the coordinate values. Others in group 0 may be used on
the same line as those in group 1.
A total of 52 G-codes are implemented.
The groups are:
group 0 = {g4,g10,g28,g30,g53,g92,g92.1,g92.2,g92.3} - NON-MODAL
dwell, setup, return to ref1, return to ref2,
motion in machine coordinates, set and unset axis offsets
group 1 = {g0,g1,g2,g3,g33,g38.2,g80,g81,g82,g83,g84,g85,g86,g87,g88,g89} - motion
group 2 = {g17,g18,g19} - plane selection
group 3 = {g90,g91} - distance mode
group 5 = {g93,g94} - feed rate mode
group 6 = {g20,g21} - units
group 7 = {g40,g41,g42} - cutter diameter compensation
group 8 = {g43,g49} - tool length offset
group 10 = {g98,g99} - return mode in canned cycles
group 12 = {g54,g55,g56,g57,g58,g59,g59.1,g59.2,g59.3} - coordinate system
group 13 = {g61,g61.1,g64} - control mode
*/
// This stops indent from reformatting the following code.
// *INDENT-OFF*
const int Interp::_gees[] = {
/* 0 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 20 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 40 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 60 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 80 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 100 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 120 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 140 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 160 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 180 */ 2,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 200 */ 6,-1,-1,-1,-1,-1,-1,-1,-1,-1, 6,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 220 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 240 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 260 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 280 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 300 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 320 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 340 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 360 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 380 */ -1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 400 */ 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 7,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 420 */ 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 440 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 460 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 480 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 500 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 520 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 540 */ 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 560 */ 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 580 */ 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,12,12,12,-1,-1,-1,-1,-1,-1,
/* 600 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,13,13,-1,-1,-1,-1,-1,-1,-1,-1,
/* 620 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 640 */ 13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 660 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 680 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 700 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 720 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 740 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 760 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 780 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 800 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 820 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 840 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 860 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 880 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 900 */ 3,-1,-1,-1,-1,-1,-1,-1,-1,-1, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 920 */ 0, 0, 0, 0,-1,-1,-1,-1,-1,-1, 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 940 */ 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 960 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 980 */ 10,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1};
/*
Modal groups and modal group numbers for M codes are not described in
[Fanuc]. We have used the groups from [NCMS] and added M60, as an
extension of the language for pallet shuttle and stop. This version has
no codes related to axis clamping.
The groups are:
group 4 = {m0,m1,m2,m30,m60} - stopping
group 5 = {m62,m63,m64,m65} - turn I/O point on/off
group 6 = {m6} - tool change
group 7 = {m3,m4,m5} - spindle turning
group 8 = {m7,m8,m9} - coolant
group 9 = {m48,m49} - feed and speed override switch bypass
group 100+ = {m100..m199} - user-defined
*/
const int Interp::_ems[] = {
4, 4, 4, 7, 7, 7, 6, 8, 8, 8,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 9, 9,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4, -1, 5, 5, 5, 5, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199};
/*
This is an array of the index numbers of system parameters that must
be included in a file used with the rs274ngc_restore_parameters
function. The array is used by that function and by the
rs274ngc_save_parameters function.
*/
const int Interp::_required_parameters[] = {
5161, 5162, 5163, /* G28 home */
5164, 5165, 5166, /* A, B, & C */
5181, 5182, 5183, /* G30 home */
5184, 5185, 5186, /*A, B, & C */
5211, 5212, 5213, /* G92 offsets */
5214, 5215, 5216, /*A, B. & C */
5220, /* selected coordinate */
5221, 5222, 5223, /* coordinate system 1 */
5224, 5225, 5226, /* A, B, & C */
5241, 5242, 5243, /* coordinate system 2 */
5244, 5245, 5246, /* A, B, & C */
5261, 5262, 5263, /* coordinate system 3 */
5264, 5265, 5266, /* A, B, & C */
5281, 5282, 5283, /* coordinate system 4 */
5284, 5285, 5286, /* A, B, & C */
5301, 5302, 5303, /* coordinate system 5 */
5304, 5305, 5306, /* A, B, & C */
5321, 5322, 5323, /* coordinate system 6 */
5324, 5325, 5326, /* A, B, & C */
5341, 5342, 5343, /* coordinate system 7 */
5344, 5345, 5346, /* A, B, & C */
5361, 5362, 5363, /* coordinate system 8 */
5364, 5365, 5366, /* A, B, & C */
5381, 5382, 5383, /* coordinate system 9 */
5384, 5385, 5386, /* A, B, & C */
RS274NGC_MAX_PARAMETERS
};
/* _readers is an array of pointers to functions that read.
It is used by read_one_item.
Each read function is placed in the array according to the ASCII character it
corresponds to. Whilst a switch statement could have been used in read_one_item,
using an array of function pointers allows a new read_foo to be added quickly
in this one table.
At some point, it may be advantageous to add a read_$ or read_n for perhaps
macro or jump labels..
*/
const read_function_pointer Interp::_readers[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
&Interp::read_parameter_setting, // reads # or ASCII 0x23
0, 0, 0, 0,
&Interp::read_comment, // reads ( or ASCII 0x28
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
&Interp::read_a, // reads a or ASCII 0x61
&Interp::read_b, // reads b or ASCII 0x62
&Interp::read_c, // reads c or ASCII 0x63
&Interp::read_d, // reads d or ASCII 0x64
0,
&Interp::read_f, // reads f or ASCII 0x66
&Interp::read_g, // reads g or ASCII 0x67
&Interp::read_h, // reads h or ASCII 0x68
&Interp::read_i, // reads i or ASCII 0x69
&Interp::read_j, // reads j or ASCII 0x6A
&Interp::read_k, // reads k or ASCII 0x6B
&Interp::read_l, // reads l or ASCII 0x6C
&Interp::read_m, // reads m or ASCII 0x6D
0, 0,
&Interp::read_p, // reads p or ASCII 0x70
&Interp::read_q, // reads q or ASCII 0x71
&Interp::read_r, // reads r or ASCII 0x72
&Interp::read_s, // reads s or ASCII 0x73
&Interp::read_t, // reads t or ASCII 0x74
0, 0, 0,
&Interp::read_x, // reads x or ASCII 0x78
&Interp::read_y, // reads y or ASCII 0x79
&Interp::read_z}; // reads z or ASCII 0x7A
// *INDENT-ON*
// And now indent can continue.
/****************************************************************************/
/* There are four global variables*. The first three are _gees, _ems,
and _readers. The last one, declared here, is for interpreter settings */
setup Interp::_setup;
/* The notion of "global variables" is a misnomer - These last four should only
be accessable by the interpreter and not exported to the rest of emc */
/********************************************************************
* Description: interp_array.cc
*
* This file just allocates space for the static arrays used by the
* interpreter.
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
/* Interpreter global arrays for g_codes and m_codes. The nth entry
in each array is the modal group number corresponding to the nth
code. Entries which are -1 represent illegal codes. Remember g_codes
in this interpreter are multiplied by 10.
The modal g groups and group numbers defined in [NCMS, pages 71 - 73]
(see also [Fanuc, pages 43 - 45]) are used here, except the canned
cycles (g80 - g89), which comprise modal g group 9 in [Fanuc], are
treated here as being in the same modal group (group 1) with the
straight moves and arcs (g0, g1, g2,g3). [Fanuc, page 45] says only
one g_code from any one group may appear on a line, and we are
following that rule. The straight_probe move, g38.2, is in group 1; it
is not defined in [NCMS].
Some g_codes are non-modal (g4, g10, g28, g30, g53, g92, g92.1, g92.2,
and g92.3 here - many more in [NCMS]). [Fanuc] and [NCMS] put all
these in the same group 0, so we do also. Logically, there are two
subgroups, those which require coordinate values (g10, g28, g30, and
g92) and those which do not (g4, g53, g92.1, g92.2, and g92.3).
The subgroups are identified by itemization when necessary.
Those in group 0 which require coordinate values may not be on the
same line as those in group 1 (except g80) because they would be
competing for the coordinate values. Others in group 0 may be used on
the same line as those in group 1.
A total of 52 G-codes are implemented.
The groups are:
group 0 = {g4,g10,g28,g30,g53,g92,g92.1,g92.2,g92.3} - NON-MODAL
dwell, setup, return to ref1, return to ref2,
motion in machine coordinates, set and unset axis offsets
group 1 = {g0,g1,g2,g3,g33,g38.2,g80,g81,g82,g83,g84,g85,g86,g87,g88,g89} - motion
group 2 = {g17,g18,g19} - plane selection
group 3 = {g90,g91} - distance mode
group 5 = {g93,g94} - feed rate mode
group 6 = {g20,g21} - units
group 7 = {g40,g41,g42} - cutter diameter compensation
group 8 = {g43,g49} - tool length offset
group 10 = {g98,g99} - return mode in canned cycles
group 12 = {g54,g55,g56,g57,g58,g59,g59.1,g59.2,g59.3} - coordinate system
group 13 = {g61,g61.1,g64} - control mode
*/
// This stops indent from reformatting the following code.
// *INDENT-OFF*
const int Interp::_gees[] = {
/* 0 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 20 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 40 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 60 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 80 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 100 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 120 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 140 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 160 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 180 */ 2,-1,-1,-1,-1,-1,-1,-1,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 200 */ 6,-1,-1,-1,-1,-1,-1,-1,-1,-1, 6,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 220 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 240 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 260 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 280 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 300 */ 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 320 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 340 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 360 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 380 */ -1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 400 */ 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 7,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 420 */ 7,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 440 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 460 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 480 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 8,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 500 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 520 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 540 */ 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 560 */ 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 580 */ 12,-1,-1,-1,-1,-1,-1,-1,-1,-1,12,12,12,12,-1,-1,-1,-1,-1,-1,
/* 600 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,13,13,-1,-1,-1,-1,-1,-1,-1,-1,
/* 620 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 640 */ 13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 660 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 680 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 700 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 720 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 740 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 760 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 780 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 800 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 820 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 840 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 860 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 880 */ 1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 900 */ 3,-1,-1,-1,-1,-1,-1,-1,-1,-1, 3,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 920 */ 0, 0, 0, 0,-1,-1,-1,-1,-1,-1, 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 940 */ 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 960 */ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 980 */ 10,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,-1,-1,-1,-1,-1,-1,-1,-1,-1};
/*
Modal groups and modal group numbers for M codes are not described in
[Fanuc]. We have used the groups from [NCMS] and added M60, as an
extension of the language for pallet shuttle and stop. This version has
no codes related to axis clamping.
The groups are:
group 4 = {m0,m1,m2,m30,m60} - stopping
group 5 = {m62,m63,m64,m65} - turn I/O point on/off
group 6 = {m6} - tool change
group 7 = {m3,m4,m5} - spindle turning
group 8 = {m7,m8,m9} - coolant
group 9 = {m48,m49} - feed and speed override switch bypass
group 100+ = {m100..m199} - user-defined
*/
const int Interp::_ems[] = {
4, 4, 4, 7, 7, 7, 6, 8, 8, 8,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, 9, 9,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4, -1, 5, 5, 5, 5, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199};
/*
This is an array of the index numbers of system parameters that must
be included in a file used with the rs274ngc_restore_parameters
function. The array is used by that function and by the
rs274ngc_save_parameters function.
*/
const int Interp::_required_parameters[] = {
5161, 5162, 5163, /* G28 home */
5164, 5165, 5166, /* A, B, & C */
5181, 5182, 5183, /* G30 home */
5184, 5185, 5186, /*A, B, & C */
5211, 5212, 5213, /* G92 offsets */
5214, 5215, 5216, /*A, B. & C */
5220, /* selected coordinate */
5221, 5222, 5223, /* coordinate system 1 */
5224, 5225, 5226, /* A, B, & C */
5241, 5242, 5243, /* coordinate system 2 */
5244, 5245, 5246, /* A, B, & C */
5261, 5262, 5263, /* coordinate system 3 */
5264, 5265, 5266, /* A, B, & C */
5281, 5282, 5283, /* coordinate system 4 */
5284, 5285, 5286, /* A, B, & C */
5301, 5302, 5303, /* coordinate system 5 */
5304, 5305, 5306, /* A, B, & C */
5321, 5322, 5323, /* coordinate system 6 */
5324, 5325, 5326, /* A, B, & C */
5341, 5342, 5343, /* coordinate system 7 */
5344, 5345, 5346, /* A, B, & C */
5361, 5362, 5363, /* coordinate system 8 */
5364, 5365, 5366, /* A, B, & C */
5381, 5382, 5383, /* coordinate system 9 */
5384, 5385, 5386, /* A, B, & C */
RS274NGC_MAX_PARAMETERS
};
/* _readers is an array of pointers to functions that read.
It is used by read_one_item.
Each read function is placed in the array according to the ASCII character it
corresponds to. Whilst a switch statement could have been used in read_one_item,
using an array of function pointers allows a new read_foo to be added quickly
in this one table.
At some point, it may be advantageous to add a read_$ or read_n for perhaps
macro or jump labels..
*/
const read_function_pointer Interp::_readers[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
&Interp::read_parameter_setting, // reads # or ASCII 0x23
0, 0, 0, 0,
&Interp::read_comment, // reads ( or ASCII 0x28
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
&Interp::read_a, // reads a or ASCII 0x61
&Interp::read_b, // reads b or ASCII 0x62
&Interp::read_c, // reads c or ASCII 0x63
&Interp::read_d, // reads d or ASCII 0x64
0,
&Interp::read_f, // reads f or ASCII 0x66
&Interp::read_g, // reads g or ASCII 0x67
&Interp::read_h, // reads h or ASCII 0x68
&Interp::read_i, // reads i or ASCII 0x69
&Interp::read_j, // reads j or ASCII 0x6A
&Interp::read_k, // reads k or ASCII 0x6B
&Interp::read_l, // reads l or ASCII 0x6C
&Interp::read_m, // reads m or ASCII 0x6D
0, 0,
&Interp::read_p, // reads p or ASCII 0x70
&Interp::read_q, // reads q or ASCII 0x71
&Interp::read_r, // reads r or ASCII 0x72
&Interp::read_s, // reads s or ASCII 0x73
&Interp::read_t, // reads t or ASCII 0x74
0, 0, 0,
&Interp::read_x, // reads x or ASCII 0x78
&Interp::read_y, // reads y or ASCII 0x79
&Interp::read_z}; // reads z or ASCII 0x7A
// *INDENT-ON*
// And now indent can continue.
/****************************************************************************/
/* There are four global variables*. The first three are _gees, _ems,
and _readers. The last one, declared here, is for interpreter settings */
setup Interp::_setup;
/* The notion of "global variables" is a misnomer - These last four should only
be accessable by the interpreter and not exported to the rest of emc */

View file

@ -1,311 +1,311 @@
/********************************************************************
* Description: interp_check.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! check_g_codes
Returned Value: int
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. NCE_DWELL_TIME_MISSING_WITH_G4
2. NCE_MUST_USE_G0_OR_G1_WITH_G53
3. NCE_CANNOT_USE_G53_INCREMENTAL
4. NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2
5. NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2
6. NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2
7. NCE_BUG_BAD_G_CODE_MODAL_GROUP_0
Side effects: none
Called by: check_items
This runs checks on g_codes from a block of RS274/NGC instructions.
Currently, all checks are on g_codes in modal group 0.
The read_g function checks for errors which would foul up the reading.
The enhance_block function checks for logical errors in the use of
axis values by g-codes in modal groups 0 and 1.
This function checks for additional logical errors in g_codes.
[Fanuc, page 45, note 4] says there is no maximum for how many g_codes
may be put on the same line, [NCMS] says nothing one way or the other,
so the test for that is not used.
We are suspending any implicit motion g_code when a g_code from our
group 0 is used. The implicit motion g_code takes effect again
automatically after the line on which the group 0 g_code occurs. It
is not clear what the intent of [Fanuc] is in this regard. The
alternative is to require that any implicit motion be explicitly
cancelled.
Not all checks on g_codes are included here. Those checks that are
sensitive to whether other g_codes on the same line have been executed
yet are made by the functions called by convert_g.
Our reference sources differ regarding what codes may be used for
dwell time. [Fanuc, page 58] says use "p" or "x". [NCMS, page 23] says
use "p", "x", or "u". We are allowing "p" only, since it is consistent
with both sources and "x" would be confusing. However, "p" is also used
with G10, where it must be an integer, so reading "p" values is a bit
more trouble than would be nice.
*/
int Interp::check_g_codes(block_pointer block, //!< pointer to a block to be checked
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "check_g_codes";
int mode0;
int p_int;
mode0 = block->g_modes[0];
if (mode0 == -1) {
} else if (mode0 == G_4) {
CHK((block->p_number == -1.0), NCE_DWELL_TIME_MISSING_WITH_G4);
} else if (mode0 == G_10) {
p_int = (int) (block->p_number + 0.0001);
CHK((block->l_number != 2), NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2);
CHK((((block->p_number + 0.0001) - p_int) > 0.0002),
NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2);
CHK(((p_int < 1) || (p_int > 9)), NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2);
} else if (mode0 == G_28) {
} else if (mode0 == G_30) {
} else if (mode0 == G_53) {
CHK(((block->motion_to_be != G_0) && (block->motion_to_be != G_1)),
NCE_MUST_USE_G0_OR_G1_WITH_G53);
CHK(((block->g_modes[3] == G_91) ||
((block->g_modes[3] != G_90) &&
(settings->distance_mode == MODE_INCREMENTAL))),
NCE_CANNOT_USE_G53_INCREMENTAL);
} else if (mode0 == G_92) {
} else if ((mode0 == G_92_1) || (mode0 == G_92_2) || (mode0 == G_92_3)) {
} else
ERM(NCE_BUG_BAD_G_CODE_MODAL_GROUP_0);
return RS274NGC_OK;
}
/****************************************************************************/
/*! check_items
Returned Value: int
If any one of check_g_codes, check_m_codes, and check_other_codes
returns an error code, this returns that code.
Otherwise, it returns RS274NGC_OK.
Side effects: none
Called by: parse_line
This runs checks on a block of RS274 code.
The functions named read_XXXX check for errors which would foul up the
reading. This function checks for additional logical errors.
A block has an array of g_codes, which are initialized to -1
(meaning no code). This calls check_g_codes to check the g_codes.
A block has an array of m_codes, which are initialized to -1
(meaning no code). This calls check_m_codes to check the m_codes.
Items in the block which are not m or g codes are checked by
check_other_codes.
*/
int Interp::check_items(block_pointer block, //!< pointer to a block to be checked
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "check_items";
int status;
CHP(check_g_codes(block, settings));
CHP(check_m_codes(block));
CHP(check_other_codes(block));
return RS274NGC_OK;
}
/****************************************************************************/
/*! check_m_codes
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. There are too many m codes in the block: NCE_TOO_MANY_M_CODES_ON_LINE
Side effects: none
Called by: check_items
This runs checks on m_codes from a block of RS274/NGC instructions.
The read_m function checks for errors which would foul up the
reading. This function checks for additional errors in m_codes.
*/
int Interp::check_m_codes(block_pointer block) //!< pointer to a block to be checked
{
static char name[] = "check_m_codes";
CHK((block->m_count > MAX_EMS), NCE_TOO_MANY_M_CODES_ON_LINE);
return RS274NGC_OK;
}
/****************************************************************************/
/*! check_other_codes
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. An A-axis value is given with a canned cycle (g80 to g89):
NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE
2. A B-axis value is given with a canned cycle (g80 to g89):
NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE
3. A C-axis value is given with a canned cycle (g80 to g89):
NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE
4. A d word is in a block with no cutter_radius_compensation_on command:
NCE_D_WORD_WITH_NO_G41_OR_G42
5. An h_number is in a block with no tool length offset setting:
NCE_H_WORD_WITH_NO_G43
6. An i_number is in a block with no G code that uses it:
NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT
7. A j_number is in a block with no G code that uses it:
NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT
8. A k_number is in a block with no G code that uses it:
NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT
9. A l_number is in a block with no G code that uses it:
NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10
10. A p_number is in a block with no G code that uses it:
NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89
11. A q_number is in a block with no G code that uses it:
NCE_Q_WORD_WITH_NO_G83
12. An r_number is in a block with no G code that uses it:
NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT
13. A k word is missing from a G33 block:
NCE_K_WORD_MISSING_WITH_G33
Side effects: none
Called by: check_items
This runs checks on codes from a block of RS274/NGC code which are
not m or g codes.
The functions named read_XXXX check for errors which would foul up the
reading. This function checks for additional logical errors in codes.
*/
int Interp::check_other_codes(block_pointer block) //!< pointer to a block of RS274/NGC instructions
{
static char name[] = "check_other_codes";
int motion;
motion = block->motion_to_be;
#ifndef LATHE
if (block->a_flag != OFF) {
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE);
}
if (block->b_flag != OFF) {
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE);
}
if (block->c_flag != OFF) {
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE);
}
#else
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNED_CYCLES_NOT_SUPPORTED);
#endif
if (block->d_number != -1) {
CHK(((block->g_modes[7] != G_41) && (block->g_modes[7] != G_42)),
NCE_D_WORD_WITH_NO_G41_OR_G42);
}
if (block->h_number != -1) {
CHK((block->g_modes[8] != G_43), NCE_H_WORD_WITH_NO_G43);
}
if (block->i_flag == ON) { /* could still be useless if yz_plane arc */
CHK(((motion != G_2) && (motion != G_3) && (motion != G_87)),
NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
}
if (block->j_flag == ON) { /* could still be useless if xz_plane arc */
CHK(((motion != G_2) && (motion != G_3) && (motion != G_87)),
NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
}
if (block->k_flag == ON) { /* could still be useless if xy_plane arc */
CHK(((motion != G_2) && (motion != G_3) && (motion != G_33) && (motion != G_87)),
NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
}
if (motion == G_33) {
printf("\nG33 f=%f\n", block->f_number);
CHK((block->k_flag == OFF), NCE_K_WORD_MISSING_WITH_G33);
CHK((block->f_number != -1), NCE_F_WORD_USED_WITH_G33);
}
if (block->l_number != -1) {
CHK((((motion < G_81) || (motion > G_89)) &&
(block->g_modes[0] != G_10)),
NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10);
}
if (block->p_number != -1.0) {
CHK(((block->g_modes[0] != G_10) &&
(block->g_modes[0] != G_4) &&
(block->m_modes[5] != 62) &&
(block->m_modes[5] != 63) &&
(block->m_modes[5] != 64) &&
(block->m_modes[5] != 65) &&
(block->user_m != 1) &&
(motion != G_82) && (motion != G_86) &&
(motion != G_88) && (motion != G_89)),
NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89);
}
if (block->q_number != -1.0) {
CHK((motion != G_83) && (block->user_m != 1), NCE_Q_WORD_WITH_NO_G83);
}
if (block->r_flag == ON) {
CHK((((motion != G_2) && (motion != G_3)) &&
((motion < G_81) || (motion > G_89))),
NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT);
}
return RS274NGC_OK;
}
/********************************************************************
* Description: interp_check.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! check_g_codes
Returned Value: int
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. NCE_DWELL_TIME_MISSING_WITH_G4
2. NCE_MUST_USE_G0_OR_G1_WITH_G53
3. NCE_CANNOT_USE_G53_INCREMENTAL
4. NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2
5. NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2
6. NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2
7. NCE_BUG_BAD_G_CODE_MODAL_GROUP_0
Side effects: none
Called by: check_items
This runs checks on g_codes from a block of RS274/NGC instructions.
Currently, all checks are on g_codes in modal group 0.
The read_g function checks for errors which would foul up the reading.
The enhance_block function checks for logical errors in the use of
axis values by g-codes in modal groups 0 and 1.
This function checks for additional logical errors in g_codes.
[Fanuc, page 45, note 4] says there is no maximum for how many g_codes
may be put on the same line, [NCMS] says nothing one way or the other,
so the test for that is not used.
We are suspending any implicit motion g_code when a g_code from our
group 0 is used. The implicit motion g_code takes effect again
automatically after the line on which the group 0 g_code occurs. It
is not clear what the intent of [Fanuc] is in this regard. The
alternative is to require that any implicit motion be explicitly
cancelled.
Not all checks on g_codes are included here. Those checks that are
sensitive to whether other g_codes on the same line have been executed
yet are made by the functions called by convert_g.
Our reference sources differ regarding what codes may be used for
dwell time. [Fanuc, page 58] says use "p" or "x". [NCMS, page 23] says
use "p", "x", or "u". We are allowing "p" only, since it is consistent
with both sources and "x" would be confusing. However, "p" is also used
with G10, where it must be an integer, so reading "p" values is a bit
more trouble than would be nice.
*/
int Interp::check_g_codes(block_pointer block, //!< pointer to a block to be checked
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "check_g_codes";
int mode0;
int p_int;
mode0 = block->g_modes[0];
if (mode0 == -1) {
} else if (mode0 == G_4) {
CHK((block->p_number == -1.0), NCE_DWELL_TIME_MISSING_WITH_G4);
} else if (mode0 == G_10) {
p_int = (int) (block->p_number + 0.0001);
CHK((block->l_number != 2), NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2);
CHK((((block->p_number + 0.0001) - p_int) > 0.0002),
NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2);
CHK(((p_int < 1) || (p_int > 9)), NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2);
} else if (mode0 == G_28) {
} else if (mode0 == G_30) {
} else if (mode0 == G_53) {
CHK(((block->motion_to_be != G_0) && (block->motion_to_be != G_1)),
NCE_MUST_USE_G0_OR_G1_WITH_G53);
CHK(((block->g_modes[3] == G_91) ||
((block->g_modes[3] != G_90) &&
(settings->distance_mode == MODE_INCREMENTAL))),
NCE_CANNOT_USE_G53_INCREMENTAL);
} else if (mode0 == G_92) {
} else if ((mode0 == G_92_1) || (mode0 == G_92_2) || (mode0 == G_92_3)) {
} else
ERM(NCE_BUG_BAD_G_CODE_MODAL_GROUP_0);
return RS274NGC_OK;
}
/****************************************************************************/
/*! check_items
Returned Value: int
If any one of check_g_codes, check_m_codes, and check_other_codes
returns an error code, this returns that code.
Otherwise, it returns RS274NGC_OK.
Side effects: none
Called by: parse_line
This runs checks on a block of RS274 code.
The functions named read_XXXX check for errors which would foul up the
reading. This function checks for additional logical errors.
A block has an array of g_codes, which are initialized to -1
(meaning no code). This calls check_g_codes to check the g_codes.
A block has an array of m_codes, which are initialized to -1
(meaning no code). This calls check_m_codes to check the m_codes.
Items in the block which are not m or g codes are checked by
check_other_codes.
*/
int Interp::check_items(block_pointer block, //!< pointer to a block to be checked
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "check_items";
int status;
CHP(check_g_codes(block, settings));
CHP(check_m_codes(block));
CHP(check_other_codes(block));
return RS274NGC_OK;
}
/****************************************************************************/
/*! check_m_codes
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. There are too many m codes in the block: NCE_TOO_MANY_M_CODES_ON_LINE
Side effects: none
Called by: check_items
This runs checks on m_codes from a block of RS274/NGC instructions.
The read_m function checks for errors which would foul up the
reading. This function checks for additional errors in m_codes.
*/
int Interp::check_m_codes(block_pointer block) //!< pointer to a block to be checked
{
static char name[] = "check_m_codes";
CHK((block->m_count > MAX_EMS), NCE_TOO_MANY_M_CODES_ON_LINE);
return RS274NGC_OK;
}
/****************************************************************************/
/*! check_other_codes
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. An A-axis value is given with a canned cycle (g80 to g89):
NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE
2. A B-axis value is given with a canned cycle (g80 to g89):
NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE
3. A C-axis value is given with a canned cycle (g80 to g89):
NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE
4. A d word is in a block with no cutter_radius_compensation_on command:
NCE_D_WORD_WITH_NO_G41_OR_G42
5. An h_number is in a block with no tool length offset setting:
NCE_H_WORD_WITH_NO_G43
6. An i_number is in a block with no G code that uses it:
NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT
7. A j_number is in a block with no G code that uses it:
NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT
8. A k_number is in a block with no G code that uses it:
NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT
9. A l_number is in a block with no G code that uses it:
NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10
10. A p_number is in a block with no G code that uses it:
NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89
11. A q_number is in a block with no G code that uses it:
NCE_Q_WORD_WITH_NO_G83
12. An r_number is in a block with no G code that uses it:
NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT
13. A k word is missing from a G33 block:
NCE_K_WORD_MISSING_WITH_G33
Side effects: none
Called by: check_items
This runs checks on codes from a block of RS274/NGC code which are
not m or g codes.
The functions named read_XXXX check for errors which would foul up the
reading. This function checks for additional logical errors in codes.
*/
int Interp::check_other_codes(block_pointer block) //!< pointer to a block of RS274/NGC instructions
{
static char name[] = "check_other_codes";
int motion;
motion = block->motion_to_be;
#ifndef LATHE
if (block->a_flag != OFF) {
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE);
}
if (block->b_flag != OFF) {
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE);
}
if (block->c_flag != OFF) {
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE);
}
#else
CHK(((block->g_modes[1] > G_80) && (block->g_modes[1] < G_90)),
NCE_CANNED_CYCLES_NOT_SUPPORTED);
#endif
if (block->d_number != -1) {
CHK(((block->g_modes[7] != G_41) && (block->g_modes[7] != G_42)),
NCE_D_WORD_WITH_NO_G41_OR_G42);
}
if (block->h_number != -1) {
CHK((block->g_modes[8] != G_43), NCE_H_WORD_WITH_NO_G43);
}
if (block->i_flag == ON) { /* could still be useless if yz_plane arc */
CHK(((motion != G_2) && (motion != G_3) && (motion != G_87)),
NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
}
if (block->j_flag == ON) { /* could still be useless if xz_plane arc */
CHK(((motion != G_2) && (motion != G_3) && (motion != G_87)),
NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
}
if (block->k_flag == ON) { /* could still be useless if xy_plane arc */
CHK(((motion != G_2) && (motion != G_3) && (motion != G_33) && (motion != G_87)),
NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT);
}
if (motion == G_33) {
printf("\nG33 f=%f\n", block->f_number);
CHK((block->k_flag == OFF), NCE_K_WORD_MISSING_WITH_G33);
CHK((block->f_number != -1), NCE_F_WORD_USED_WITH_G33);
}
if (block->l_number != -1) {
CHK((((motion < G_81) || (motion > G_89)) &&
(block->g_modes[0] != G_10)),
NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10);
}
if (block->p_number != -1.0) {
CHK(((block->g_modes[0] != G_10) &&
(block->g_modes[0] != G_4) &&
(block->m_modes[5] != 62) &&
(block->m_modes[5] != 63) &&
(block->m_modes[5] != 64) &&
(block->m_modes[5] != 65) &&
(block->user_m != 1) &&
(motion != G_82) && (motion != G_86) &&
(motion != G_88) && (motion != G_89)),
NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89);
}
if (block->q_number != -1.0) {
CHK((motion != G_83) && (block->user_m != 1), NCE_Q_WORD_WITH_NO_G83);
}
if (block->r_flag == ON) {
CHK((((motion != G_2) && (motion != G_3)) &&
((motion < G_81) || (motion > G_89))),
NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT);
}
return RS274NGC_OK;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,334 +1,334 @@
/********************************************************************
* Description: interp_execute.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! execute binary
Returned value: int
If execute_binary1 or execute_binary2 returns an error code, this
returns that code.
Otherwise, it returns RS274NGC_OK.
Side effects: The value of left is set to the result of applying
the operation to left and right.
Called by: read_real_expression
This just calls either execute_binary1 or execute_binary2.
*/
int Interp::execute_binary(double *left, int operation, double *right)
{
static char name[] = "execute_binary";
int status;
if (operation < AND2)
CHP(execute_binary1(left, operation, right));
else
CHP(execute_binary2(left, operation, right));
return RS274NGC_OK;
}
/****************************************************************************/
/*! execute_binary1
Returned Value: int
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. operation is unknown: NCE_BUG_UNKNOWN_OPERATION
2. An attempt is made to divide by zero: NCE_ATTEMPT_TO_DIVIDE_BY_ZERO
3. An attempt is made to raise a negative number to a non-integer power:
NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER
Side effects:
The result from performing the operation is put into what left points at.
Called by: read_real_expression.
This executes the operations: DIVIDED_BY, MODULO, POWER, TIMES.
*/
int Interp::execute_binary1(double *left, //!< pointer to the left operand
int operation, //!< integer code for the operation
double *right) //!< pointer to the right operand
{
static char name[] = "execute_binary1";
switch (operation) {
case DIVIDED_BY:
CHK((*right == 0.0), NCE_ATTEMPT_TO_DIVIDE_BY_ZERO);
*left = (*left / *right);
break;
case MODULO: /* always calculates a positive answer */
*left = fmod(*left, *right);
if (*left < 0.0) {
*left = (*left + fabs(*right));
}
break;
case POWER:
CHK(((*left < 0.0) && (floor(*right) != *right)),
NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER);
*left = pow(*left, *right);
break;
case TIMES:
*left = (*left * *right);
break;
default:
ERM(NCE_BUG_UNKNOWN_OPERATION);
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! execute_binary2
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. operation is unknown: NCE_BUG_UNKNOWN_OPERATION
Side effects:
The result from performing the operation is put into what left points at.
Called by: read_real_expression.
This executes the operations: AND2, EXCLUSIVE_OR, MINUS,
NON_EXCLUSIVE_OR, PLUS. The RS274/NGC manual [NCMS] does not say what
the calculated value of the three logical operations should be. This
function calculates either 1.0 (meaning true) or 0.0 (meaning false).
Any non-zero input value is taken as meaning true, and only 0.0 means
false.
*/
int Interp::execute_binary2(double *left, //!< pointer to the left operand
int operation, //!< integer code for the operation
double *right) //!< pointer to the right operand
{
static char name[] = "execute_binary2";
switch (operation) {
case AND2:
*left = ((*left == 0.0) || (*right == 0.0)) ? 0.0 : 1.0;
break;
case EXCLUSIVE_OR:
*left = (((*left == 0.0) && (*right != 0.0))
|| ((*left != 0.0) && (*right == 0.0))) ? 1.0 : 0.0;
break;
case MINUS:
*left = (*left - *right);
break;
case NON_EXCLUSIVE_OR:
*left = ((*left != 0.0) || (*right != 0.0)) ? 1.0 : 0.0;
break;
case PLUS:
*left = (*left + *right);
break;
default:
ERM(NCE_BUG_UNKNOWN_OPERATION);
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! execute_block
Returned Value: int
If convert_stop returns RS274NGC_EXIT, this returns RS274NGC_EXIT.
If any of the following functions is called and returns an error code,
this returns that code.
convert_comment
convert_feed_mode
convert_feed_rate
convert_g
convert_m
convert_speed
convert_stop
convert_tool_select
Otherwise, if the probe_flag in the settings is ON, this returns
RS274NGC_EXECUTE_FINISH.
Otherwise, it returns RS274NGC_OK.
Side effects:
One block of RS274/NGC instructions is executed.
Called by:
rs274ngc_execute
This converts a block to zero to many actions. The order of execution
of items in a block is critical to safe and effective machine operation,
but is not specified clearly in the RS274/NGC documentation.
Actions are executed in the following order:
1. any comment.
2. a feed mode setting (g93, g94)
3. a feed rate (f) setting if in units_per_minute feed mode.
4. a spindle speed (s) setting.
5. a tool selection (t).
6. "m" commands as described in convert_m (includes tool change).
7. any g_codes (except g93, g94) as described in convert_g.
8. stopping commands (m0, m1, m2, m30, or m60).
In inverse time feed mode, the explicit and implicit g code executions
include feed rate setting with g1, g2, and g3. Also in inverse time
feed mode, attempting a canned cycle cycle (g81 to g89) or setting a
feed rate with g0 is illegal and will be detected and result in an
error message.
*/
int Interp::execute_block(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "execute_block";
int status;
if (block->comment[0] != 0) {
CHP(convert_comment(block->comment));
}
if (block->g_modes[5] != -1) {
CHP(convert_feed_mode(block->g_modes[5], settings));
}
if (block->f_number > -1.0) {
if (settings->feed_mode == INVERSE_TIME); /* handle elsewhere */
else {
CHP(convert_feed_rate(block, settings));
}
}
if (block->s_number > -1.0) {
CHP(convert_speed(block, settings));
}
if (block->t_number != -1) {
CHP(convert_tool_select(block, settings));
}
CHP(convert_m(block, settings));
CHP(convert_g(block, settings));
if (block->m_modes[4] != -1) { /* converts m0, m1, m2, m30, or m60 */
status = convert_stop(block, settings);
if (status == RS274NGC_EXIT)
return RS274NGC_EXIT;
else if (status != RS274NGC_OK)
ERP(status);
}
return ((settings->probe_flag ==
ON) ? RS274NGC_EXECUTE_FINISH : RS274NGC_OK);
}
/****************************************************************************/
/*! execute_unary
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. the operation is unknown: NCE_BUG_UNKNOWN_OPERATION
2. the argument to acos is not between minus and plus one:
NCE_ARGUMENT_TO_ACOS_OUT_RANGE
3. the argument to asin is not between minus and plus one:
NCE_ARGUMENT_TO_ASIN_OUT_RANGE
4. the argument to the natural logarithm is not positive:
NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN
5. the argument to square root is negative:
NCE_NEGATIVE_ARGUMENT_TO_SQRT
Side effects:
The result from performing the operation on the value in double_ptr
is put into what double_ptr points at.
Called by: read_unary.
This executes the operations: ABS, ACOS, ASIN, COS, EXP, FIX, FUP, LN
ROUND, SIN, SQRT, TAN
All angle measures in the input or output are in degrees.
*/
int Interp::execute_unary(double *double_ptr, //!< pointer to the operand
int operation) //!< integer code for the operation
{
static char name[] = "execute_unary";
switch (operation) {
case ABS:
if (*double_ptr < 0.0)
*double_ptr = (-1.0 * *double_ptr);
break;
case ACOS:
CHK(((*double_ptr < -1.0) || (*double_ptr > 1.0)),
NCE_ARGUMENT_TO_ACOS_OUT_OF_RANGE);
*double_ptr = acos(*double_ptr);
*double_ptr = ((*double_ptr * 180.0) / M_PIl);
break;
case ASIN:
CHK(((*double_ptr < -1.0) || (*double_ptr > 1.0)),
NCE_ARGUMENT_TO_ASIN_OUT_OF_RANGE);
*double_ptr = asin(*double_ptr);
*double_ptr = ((*double_ptr * 180.0) / M_PIl);
break;
case COS:
*double_ptr = cos((*double_ptr * M_PIl) / 180.0);
break;
case EXP:
*double_ptr = exp(*double_ptr);
break;
case FIX:
*double_ptr = floor(*double_ptr);
break;
case FUP:
*double_ptr = ceil(*double_ptr);
break;
case LN:
CHK((*double_ptr <= 0.0), NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN);
*double_ptr = log(*double_ptr);
break;
case ROUND:
*double_ptr = (double)
((int) (*double_ptr + ((*double_ptr < 0.0) ? -0.5 : 0.5)));
break;
case SIN:
*double_ptr = sin((*double_ptr * M_PIl) / 180.0);
break;
case SQRT:
CHK((*double_ptr < 0.0), NCE_NEGATIVE_ARGUMENT_TO_SQRT);
*double_ptr = sqrt(*double_ptr);
break;
case TAN:
*double_ptr = tan((*double_ptr * M_PIl) / 180.0);
break;
default:
ERM(NCE_BUG_UNKNOWN_OPERATION);
}
return RS274NGC_OK;
}
/********************************************************************
* Description: interp_execute.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! execute binary
Returned value: int
If execute_binary1 or execute_binary2 returns an error code, this
returns that code.
Otherwise, it returns RS274NGC_OK.
Side effects: The value of left is set to the result of applying
the operation to left and right.
Called by: read_real_expression
This just calls either execute_binary1 or execute_binary2.
*/
int Interp::execute_binary(double *left, int operation, double *right)
{
static char name[] = "execute_binary";
int status;
if (operation < AND2)
CHP(execute_binary1(left, operation, right));
else
CHP(execute_binary2(left, operation, right));
return RS274NGC_OK;
}
/****************************************************************************/
/*! execute_binary1
Returned Value: int
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. operation is unknown: NCE_BUG_UNKNOWN_OPERATION
2. An attempt is made to divide by zero: NCE_ATTEMPT_TO_DIVIDE_BY_ZERO
3. An attempt is made to raise a negative number to a non-integer power:
NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER
Side effects:
The result from performing the operation is put into what left points at.
Called by: read_real_expression.
This executes the operations: DIVIDED_BY, MODULO, POWER, TIMES.
*/
int Interp::execute_binary1(double *left, //!< pointer to the left operand
int operation, //!< integer code for the operation
double *right) //!< pointer to the right operand
{
static char name[] = "execute_binary1";
switch (operation) {
case DIVIDED_BY:
CHK((*right == 0.0), NCE_ATTEMPT_TO_DIVIDE_BY_ZERO);
*left = (*left / *right);
break;
case MODULO: /* always calculates a positive answer */
*left = fmod(*left, *right);
if (*left < 0.0) {
*left = (*left + fabs(*right));
}
break;
case POWER:
CHK(((*left < 0.0) && (floor(*right) != *right)),
NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER);
*left = pow(*left, *right);
break;
case TIMES:
*left = (*left * *right);
break;
default:
ERM(NCE_BUG_UNKNOWN_OPERATION);
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! execute_binary2
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. operation is unknown: NCE_BUG_UNKNOWN_OPERATION
Side effects:
The result from performing the operation is put into what left points at.
Called by: read_real_expression.
This executes the operations: AND2, EXCLUSIVE_OR, MINUS,
NON_EXCLUSIVE_OR, PLUS. The RS274/NGC manual [NCMS] does not say what
the calculated value of the three logical operations should be. This
function calculates either 1.0 (meaning true) or 0.0 (meaning false).
Any non-zero input value is taken as meaning true, and only 0.0 means
false.
*/
int Interp::execute_binary2(double *left, //!< pointer to the left operand
int operation, //!< integer code for the operation
double *right) //!< pointer to the right operand
{
static char name[] = "execute_binary2";
switch (operation) {
case AND2:
*left = ((*left == 0.0) || (*right == 0.0)) ? 0.0 : 1.0;
break;
case EXCLUSIVE_OR:
*left = (((*left == 0.0) && (*right != 0.0))
|| ((*left != 0.0) && (*right == 0.0))) ? 1.0 : 0.0;
break;
case MINUS:
*left = (*left - *right);
break;
case NON_EXCLUSIVE_OR:
*left = ((*left != 0.0) || (*right != 0.0)) ? 1.0 : 0.0;
break;
case PLUS:
*left = (*left + *right);
break;
default:
ERM(NCE_BUG_UNKNOWN_OPERATION);
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! execute_block
Returned Value: int
If convert_stop returns RS274NGC_EXIT, this returns RS274NGC_EXIT.
If any of the following functions is called and returns an error code,
this returns that code.
convert_comment
convert_feed_mode
convert_feed_rate
convert_g
convert_m
convert_speed
convert_stop
convert_tool_select
Otherwise, if the probe_flag in the settings is ON, this returns
RS274NGC_EXECUTE_FINISH.
Otherwise, it returns RS274NGC_OK.
Side effects:
One block of RS274/NGC instructions is executed.
Called by:
rs274ngc_execute
This converts a block to zero to many actions. The order of execution
of items in a block is critical to safe and effective machine operation,
but is not specified clearly in the RS274/NGC documentation.
Actions are executed in the following order:
1. any comment.
2. a feed mode setting (g93, g94)
3. a feed rate (f) setting if in units_per_minute feed mode.
4. a spindle speed (s) setting.
5. a tool selection (t).
6. "m" commands as described in convert_m (includes tool change).
7. any g_codes (except g93, g94) as described in convert_g.
8. stopping commands (m0, m1, m2, m30, or m60).
In inverse time feed mode, the explicit and implicit g code executions
include feed rate setting with g1, g2, and g3. Also in inverse time
feed mode, attempting a canned cycle cycle (g81 to g89) or setting a
feed rate with g0 is illegal and will be detected and result in an
error message.
*/
int Interp::execute_block(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "execute_block";
int status;
if (block->comment[0] != 0) {
CHP(convert_comment(block->comment));
}
if (block->g_modes[5] != -1) {
CHP(convert_feed_mode(block->g_modes[5], settings));
}
if (block->f_number > -1.0) {
if (settings->feed_mode == INVERSE_TIME); /* handle elsewhere */
else {
CHP(convert_feed_rate(block, settings));
}
}
if (block->s_number > -1.0) {
CHP(convert_speed(block, settings));
}
if (block->t_number != -1) {
CHP(convert_tool_select(block, settings));
}
CHP(convert_m(block, settings));
CHP(convert_g(block, settings));
if (block->m_modes[4] != -1) { /* converts m0, m1, m2, m30, or m60 */
status = convert_stop(block, settings);
if (status == RS274NGC_EXIT)
return RS274NGC_EXIT;
else if (status != RS274NGC_OK)
ERP(status);
}
return ((settings->probe_flag ==
ON) ? RS274NGC_EXECUTE_FINISH : RS274NGC_OK);
}
/****************************************************************************/
/*! execute_unary
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. the operation is unknown: NCE_BUG_UNKNOWN_OPERATION
2. the argument to acos is not between minus and plus one:
NCE_ARGUMENT_TO_ACOS_OUT_RANGE
3. the argument to asin is not between minus and plus one:
NCE_ARGUMENT_TO_ASIN_OUT_RANGE
4. the argument to the natural logarithm is not positive:
NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN
5. the argument to square root is negative:
NCE_NEGATIVE_ARGUMENT_TO_SQRT
Side effects:
The result from performing the operation on the value in double_ptr
is put into what double_ptr points at.
Called by: read_unary.
This executes the operations: ABS, ACOS, ASIN, COS, EXP, FIX, FUP, LN
ROUND, SIN, SQRT, TAN
All angle measures in the input or output are in degrees.
*/
int Interp::execute_unary(double *double_ptr, //!< pointer to the operand
int operation) //!< integer code for the operation
{
static char name[] = "execute_unary";
switch (operation) {
case ABS:
if (*double_ptr < 0.0)
*double_ptr = (-1.0 * *double_ptr);
break;
case ACOS:
CHK(((*double_ptr < -1.0) || (*double_ptr > 1.0)),
NCE_ARGUMENT_TO_ACOS_OUT_OF_RANGE);
*double_ptr = acos(*double_ptr);
*double_ptr = ((*double_ptr * 180.0) / M_PIl);
break;
case ASIN:
CHK(((*double_ptr < -1.0) || (*double_ptr > 1.0)),
NCE_ARGUMENT_TO_ASIN_OUT_OF_RANGE);
*double_ptr = asin(*double_ptr);
*double_ptr = ((*double_ptr * 180.0) / M_PIl);
break;
case COS:
*double_ptr = cos((*double_ptr * M_PIl) / 180.0);
break;
case EXP:
*double_ptr = exp(*double_ptr);
break;
case FIX:
*double_ptr = floor(*double_ptr);
break;
case FUP:
*double_ptr = ceil(*double_ptr);
break;
case LN:
CHK((*double_ptr <= 0.0), NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN);
*double_ptr = log(*double_ptr);
break;
case ROUND:
*double_ptr = (double)
((int) (*double_ptr + ((*double_ptr < 0.0) ? -0.5 : 0.5)));
break;
case SIN:
*double_ptr = sin((*double_ptr * M_PIl) / 180.0);
break;
case SQRT:
CHK((*double_ptr < 0.0), NCE_NEGATIVE_ARGUMENT_TO_SQRT);
*double_ptr = sqrt(*double_ptr);
break;
case TAN:
*double_ptr = tan((*double_ptr * M_PIl) / 180.0);
break;
default:
ERM(NCE_BUG_UNKNOWN_OPERATION);
}
return RS274NGC_OK;
}

View file

@ -1,379 +1,379 @@
/********************************************************************
* Description: interp_find.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! find_arc_length
Returned Value: double (length of path between start and end points)
Side effects: none
Called by:
inverse_time_rate_arc
inverse_time_rate_arc2
inverse_time_rate_as
This calculates the length of the path that will be made relative to
the XYZ axes for a motion in which the X,Y,Z, motion is a circular or
helical arc with its axis parallel to the Z-axis. If tool length
compensation is on, this is the path of the tool tip; if off, the
length of the path of the spindle tip. Any rotary axis motion is
ignored.
If the arc is helical, it is coincident with the hypotenuse of a right
triangle wrapped around a cylinder. If the triangle is unwrapped, its
base is [the radius of the cylinder times the number of radians in the
helix] and its height is [z2 - z1], and the path length can be found
by the Pythagorean theorem.
This is written as though it is only for arcs whose axis is parallel to
the Z-axis, but it will serve also for arcs whose axis is parallel
to the X-axis or Y-axis, with suitable permutation of the arguments.
This works correctly when turn is zero (find_turn returns 0 in that
case).
*/
double Interp::find_arc_length(double x1, //!< X-coordinate of start point
double y1, //!< Y-coordinate of start point
double z1, //!< Z-coordinate of start point
double center_x, //!< X-coordinate of arc center
double center_y, //!< Y-coordinate of arc center
int turn, //!< no. of full or partial circles CCW
double x2, //!< X-coordinate of end point
double y2, //!< Y-coordinate of end point
double z2) //!< Z-coordinate of end point
{
double radius;
double theta; /* amount of turn of arc in radians */
radius = hypot((center_x - x1), (center_y - y1));
theta = find_turn(x1, y1, center_x, center_y, turn, x2, y2);
if (z2 == z1)
return (radius * fabs(theta));
else
return hypot((radius * theta), (z2 - z1));
}
/****************************************************************************/
/*! find_ends
Returned Value: int (RS274NGC_OK)
Side effects:
The values of px, py, pz, aa_p, bb_p, and cc_p are set
Called by:
convert_arc
convert_home
convert_probe
convert_straight
This finds the coordinates of a point, "end", in the currently
active coordinate system, and sets the values of the pointers to the
coordinates (which are the arguments to the function).
In all cases, if no value for the coodinate is given in the block, the
current value for the coordinate is used. When cutter radius
compensation is on, this function is called before compensation
calculations are performed, so the current value of the programmed
point is used, not the current value of the actual current_point.
There are three cases for when the coordinate is included in the block:
1. G_53 is active. This means to interpret the coordinates as machine
coordinates. That is accomplished by adding the two offsets to the
coordinate given in the block.
2. Absolute coordinate mode is in effect. The coordinate in the block
is used.
3. Incremental coordinate mode is in effect. The coordinate in the
block plus either (i) the programmed current position - when cutter
radius compensation is in progress, or (2) the actual current position.
*/
int Interp::find_ends(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings, //!< pointer to machine settings
double *px, //!< pointer to end_x
double *py, //!< pointer to end_y
double *pz, //!< pointer to end_z
double *AA_p, //!< pointer to end_a
double *BB_p, //!< pointer to end_b
double *CC_p) //!< pointer to end_c
{
int mode;
int middle;
int comp;
mode = settings->distance_mode;
middle = (settings->program_x != UNKNOWN);
comp = (settings->cutter_comp_side != OFF);
if (block->g_modes[0] == G_53) { /* distance mode is absolute in this case */
#ifdef DEBUG_EMC
COMMENT("interpreter: offsets temporarily suspended");
#endif
*px = (block->x_flag == ON) ? (block->x_number -
(settings->origin_offset_x +
settings->
axis_offset_x)) : settings->current_x;
*py =
(block->y_flag ==
ON) ? (block->y_number - (settings->origin_offset_y +
settings->
axis_offset_y)) : settings->current_y;
*pz =
(block->z_flag ==
ON) ? (block->z_number - (settings->tool_length_offset +
settings->origin_offset_z +
settings->
axis_offset_z)) : settings->current_z;
#ifndef LATHE
*AA_p = (block->a_flag == ON) ? (block->a_number -
(settings->AA_origin_offset +
settings->
AA_axis_offset)) : settings->AA_current;
*BB_p =
(block->b_flag ==
ON) ? (block->b_number - (settings->BB_origin_offset +
settings->
BB_axis_offset)) : settings->BB_current;
*CC_p =
(block->c_flag ==
ON) ? (block->c_number - (settings->tool_length_offset +
settings->CC_origin_offset +
settings->
CC_axis_offset)) : settings->CC_current;
#endif
} else if (mode == MODE_ABSOLUTE) {
*px = (block->x_flag == ON) ? block->x_number :
(comp && middle) ? settings->program_x : settings->current_x;
*py = (block->y_flag == ON) ? block->y_number :
(comp && middle) ? settings->program_y : settings->current_y;
*pz = (block->z_flag == ON) ? block->z_number : settings->current_z;
#ifndef LATHE
*AA_p = (block->a_flag == ON) ? block->a_number : settings->AA_current;
*BB_p = (block->b_flag == ON) ? block->b_number : settings->BB_current;
*CC_p = (block->c_flag == ON) ? block->c_number : settings->CC_current;
#endif
} else { /* mode is MODE_INCREMENTAL */
*px = (block->x_flag == ON)
? ((comp
&& middle) ? (block->x_number +
settings->program_x) : (block->x_number +
settings->current_x))
: ((comp && middle) ? settings->program_x : settings->current_x);
*py = (block->y_flag == ON)
? ((comp
&& middle) ? (block->y_number +
settings->program_y) : (block->y_number +
settings->current_y))
: ((comp && middle) ? settings->program_y : settings->current_y);
*pz = (block->z_flag == ON) ?
(settings->current_z + block->z_number) : settings->current_z;
#ifndef LATHE
*AA_p = (block->a_flag == ON) ?
(settings->AA_current + block->a_number) : settings->AA_current;
*BB_p =
(block->b_flag ==
ON) ? (settings->BB_current + block->b_number) : settings->BB_current;
*CC_p =
(block->c_flag ==
ON) ? (settings->CC_current + block->c_number) : settings->CC_current;
#endif
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! find_relative
Returned Value: int (RS274NGC_OK)
Side effects:
The values of x2, y2, z2, aa_2, bb_2, and cc_2 are set.
(NOTE: aa_2 etc. are written with lower case letters in this
documentation because upper case would confuse the pre-preprocessor.)
Called by:
convert_home
This finds the coordinates in the current system, under the current
tool length offset, of a point (x1, y1, z1, aa_1, bb_1, cc_1) whose absolute
coordinates are known.
Don't confuse this with the inverse operation.
*/
int Interp::find_relative(double x1, //!< absolute x position
double y1, //!< absolute y position
double z1, //!< absolute z position
double AA_1, //!< absolute a position
double BB_1, //!< absolute b position
double CC_1, //!< absolute c position
double *x2, //!< pointer to relative x
double *y2, //!< pointer to relative y
double *z2, //!< pointer to relative z
double *AA_2, //!< pointer to relative a
double *BB_2, //!< pointer to relative b
double *CC_2, //!< pointer to relative c
setup_pointer settings) //!< pointer to machine settings
{
*x2 = (x1 - (settings->origin_offset_x + settings->axis_offset_x));
*y2 = (y1 - (settings->origin_offset_y + settings->axis_offset_y));
*z2 =
(z1 -
(settings->tool_length_offset + settings->origin_offset_z +
settings->axis_offset_z));
#ifndef LATHE
*AA_2 = (AA_1 - (settings->AA_origin_offset + settings->AA_axis_offset));
*BB_2 = (BB_1 - (settings->BB_origin_offset + settings->BB_axis_offset));
*CC_2 = (CC_1 - (settings->CC_origin_offset + settings->CC_axis_offset));
#endif
return RS274NGC_OK;
}
/****************************************************************************/
/*! find_straight_length
Returned Value: double (length of path between start and end points)
Side effects: none
Called by:
inverse_time_rate_straight
inverse_time_rate_as
This calculates a number to use in feed rate calculations when inverse
time feed mode is used, for a motion in which X,Y,Z,A,B, and C each change
linearly or not at all from their initial value to their end value.
This is used when the feed_reference mode is CANON_XYZ, which is
always in rs274NGC.
If any of the X, Y, or Z axes move or the A-axis, B-axis, and C-axis
do not move, this is the length of the path relative to the XYZ axes
from the first point to the second, and any rotary axis motion is
ignored. The length is the simple Euclidean distance.
The formula for the Euclidean distance "length" of a move involving
only the A, B and C axes is based on a conversation with Jim Frohardt at
Boeing, who says that the Fanuc controller on their 5-axis machine
interprets the feed rate this way. Note that if only one rotary axis
moves, this formula returns the absolute value of that axis move,
which is what is desired.
*/
double Interp::find_straight_length(double x2, //!< X-coordinate of end point
double y2, //!< Y-coordinate of end point
double z2, //!< Z-coordinate of end point
double AA_2, //!< A-coordinate of end point
double BB_2, //!< B-coordinate of end point
double CC_2, //!< C-coordinate of end point
double x1, //!< X-coordinate of start point
double y1, //!< Y-coordinate of start point
double z1, //!< Z-coordinate of start point
double AA_1, //!< A-coordinate of start point
double BB_1, //!< B-coordinate of start point
double CC_1 //!< C-coordinate of start point
)
{
if ((x1 != x2) || (y1 != y2) || (z1 != z2) || (1
#ifndef LATHE
&& (AA_2 == AA_1)
&& (BB_2 == BB_1)
&& (CC_2 == CC_1)
#endif
)) /* straight line */
return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2) + pow((z2 - z1), 2));
else
return sqrt(0 +
#ifndef LATHE
pow((AA_2 - AA_1), 2) +
pow((BB_2 - BB_1), 2) + pow((CC_2 - CC_1), 2) +
#endif
0);
}
/****************************************************************************/
/*! find_turn
Returned Value: double (angle in radians between two radii of a circle)
Side effects: none
Called by: find_arc_length
All angles are in radians.
*/
double Interp::find_turn(double x1, //!< X-coordinate of start point
double y1, //!< Y-coordinate of start point
double center_x, //!< X-coordinate of arc center
double center_y, //!< Y-coordinate of arc center
int turn, //!< no. of full or partial circles CCW
double x2, //!< X-coordinate of end point
double y2) //!< Y-coordinate of end point
{
double alpha; /* angle of first radius */
double beta; /* angle of second radius */
double theta; /* amount of turn of arc CCW - negative if CW */
if (turn == 0)
return 0.0;
alpha = atan2((y1 - center_y), (x1 - center_x));
beta = atan2((y2 - center_y), (x2 - center_x));
if (turn > 0) {
if (beta <= alpha)
beta = (beta + (2 * M_PIl));
theta = ((beta - alpha) + ((turn - 1) * (2 * M_PIl)));
} else { /* turn < 0 */
if (alpha <= beta)
alpha = (alpha + (2 * M_PIl));
theta = ((beta - alpha) + ((turn + 1) * (2 * M_PIl)));
}
return (theta);
}
/********************************************************************
* Description: interp_find.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! find_arc_length
Returned Value: double (length of path between start and end points)
Side effects: none
Called by:
inverse_time_rate_arc
inverse_time_rate_arc2
inverse_time_rate_as
This calculates the length of the path that will be made relative to
the XYZ axes for a motion in which the X,Y,Z, motion is a circular or
helical arc with its axis parallel to the Z-axis. If tool length
compensation is on, this is the path of the tool tip; if off, the
length of the path of the spindle tip. Any rotary axis motion is
ignored.
If the arc is helical, it is coincident with the hypotenuse of a right
triangle wrapped around a cylinder. If the triangle is unwrapped, its
base is [the radius of the cylinder times the number of radians in the
helix] and its height is [z2 - z1], and the path length can be found
by the Pythagorean theorem.
This is written as though it is only for arcs whose axis is parallel to
the Z-axis, but it will serve also for arcs whose axis is parallel
to the X-axis or Y-axis, with suitable permutation of the arguments.
This works correctly when turn is zero (find_turn returns 0 in that
case).
*/
double Interp::find_arc_length(double x1, //!< X-coordinate of start point
double y1, //!< Y-coordinate of start point
double z1, //!< Z-coordinate of start point
double center_x, //!< X-coordinate of arc center
double center_y, //!< Y-coordinate of arc center
int turn, //!< no. of full or partial circles CCW
double x2, //!< X-coordinate of end point
double y2, //!< Y-coordinate of end point
double z2) //!< Z-coordinate of end point
{
double radius;
double theta; /* amount of turn of arc in radians */
radius = hypot((center_x - x1), (center_y - y1));
theta = find_turn(x1, y1, center_x, center_y, turn, x2, y2);
if (z2 == z1)
return (radius * fabs(theta));
else
return hypot((radius * theta), (z2 - z1));
}
/****************************************************************************/
/*! find_ends
Returned Value: int (RS274NGC_OK)
Side effects:
The values of px, py, pz, aa_p, bb_p, and cc_p are set
Called by:
convert_arc
convert_home
convert_probe
convert_straight
This finds the coordinates of a point, "end", in the currently
active coordinate system, and sets the values of the pointers to the
coordinates (which are the arguments to the function).
In all cases, if no value for the coodinate is given in the block, the
current value for the coordinate is used. When cutter radius
compensation is on, this function is called before compensation
calculations are performed, so the current value of the programmed
point is used, not the current value of the actual current_point.
There are three cases for when the coordinate is included in the block:
1. G_53 is active. This means to interpret the coordinates as machine
coordinates. That is accomplished by adding the two offsets to the
coordinate given in the block.
2. Absolute coordinate mode is in effect. The coordinate in the block
is used.
3. Incremental coordinate mode is in effect. The coordinate in the
block plus either (i) the programmed current position - when cutter
radius compensation is in progress, or (2) the actual current position.
*/
int Interp::find_ends(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings, //!< pointer to machine settings
double *px, //!< pointer to end_x
double *py, //!< pointer to end_y
double *pz, //!< pointer to end_z
double *AA_p, //!< pointer to end_a
double *BB_p, //!< pointer to end_b
double *CC_p) //!< pointer to end_c
{
int mode;
int middle;
int comp;
mode = settings->distance_mode;
middle = (settings->program_x != UNKNOWN);
comp = (settings->cutter_comp_side != OFF);
if (block->g_modes[0] == G_53) { /* distance mode is absolute in this case */
#ifdef DEBUG_EMC
COMMENT("interpreter: offsets temporarily suspended");
#endif
*px = (block->x_flag == ON) ? (block->x_number -
(settings->origin_offset_x +
settings->
axis_offset_x)) : settings->current_x;
*py =
(block->y_flag ==
ON) ? (block->y_number - (settings->origin_offset_y +
settings->
axis_offset_y)) : settings->current_y;
*pz =
(block->z_flag ==
ON) ? (block->z_number - (settings->tool_length_offset +
settings->origin_offset_z +
settings->
axis_offset_z)) : settings->current_z;
#ifndef LATHE
*AA_p = (block->a_flag == ON) ? (block->a_number -
(settings->AA_origin_offset +
settings->
AA_axis_offset)) : settings->AA_current;
*BB_p =
(block->b_flag ==
ON) ? (block->b_number - (settings->BB_origin_offset +
settings->
BB_axis_offset)) : settings->BB_current;
*CC_p =
(block->c_flag ==
ON) ? (block->c_number - (settings->tool_length_offset +
settings->CC_origin_offset +
settings->
CC_axis_offset)) : settings->CC_current;
#endif
} else if (mode == MODE_ABSOLUTE) {
*px = (block->x_flag == ON) ? block->x_number :
(comp && middle) ? settings->program_x : settings->current_x;
*py = (block->y_flag == ON) ? block->y_number :
(comp && middle) ? settings->program_y : settings->current_y;
*pz = (block->z_flag == ON) ? block->z_number : settings->current_z;
#ifndef LATHE
*AA_p = (block->a_flag == ON) ? block->a_number : settings->AA_current;
*BB_p = (block->b_flag == ON) ? block->b_number : settings->BB_current;
*CC_p = (block->c_flag == ON) ? block->c_number : settings->CC_current;
#endif
} else { /* mode is MODE_INCREMENTAL */
*px = (block->x_flag == ON)
? ((comp
&& middle) ? (block->x_number +
settings->program_x) : (block->x_number +
settings->current_x))
: ((comp && middle) ? settings->program_x : settings->current_x);
*py = (block->y_flag == ON)
? ((comp
&& middle) ? (block->y_number +
settings->program_y) : (block->y_number +
settings->current_y))
: ((comp && middle) ? settings->program_y : settings->current_y);
*pz = (block->z_flag == ON) ?
(settings->current_z + block->z_number) : settings->current_z;
#ifndef LATHE
*AA_p = (block->a_flag == ON) ?
(settings->AA_current + block->a_number) : settings->AA_current;
*BB_p =
(block->b_flag ==
ON) ? (settings->BB_current + block->b_number) : settings->BB_current;
*CC_p =
(block->c_flag ==
ON) ? (settings->CC_current + block->c_number) : settings->CC_current;
#endif
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! find_relative
Returned Value: int (RS274NGC_OK)
Side effects:
The values of x2, y2, z2, aa_2, bb_2, and cc_2 are set.
(NOTE: aa_2 etc. are written with lower case letters in this
documentation because upper case would confuse the pre-preprocessor.)
Called by:
convert_home
This finds the coordinates in the current system, under the current
tool length offset, of a point (x1, y1, z1, aa_1, bb_1, cc_1) whose absolute
coordinates are known.
Don't confuse this with the inverse operation.
*/
int Interp::find_relative(double x1, //!< absolute x position
double y1, //!< absolute y position
double z1, //!< absolute z position
double AA_1, //!< absolute a position
double BB_1, //!< absolute b position
double CC_1, //!< absolute c position
double *x2, //!< pointer to relative x
double *y2, //!< pointer to relative y
double *z2, //!< pointer to relative z
double *AA_2, //!< pointer to relative a
double *BB_2, //!< pointer to relative b
double *CC_2, //!< pointer to relative c
setup_pointer settings) //!< pointer to machine settings
{
*x2 = (x1 - (settings->origin_offset_x + settings->axis_offset_x));
*y2 = (y1 - (settings->origin_offset_y + settings->axis_offset_y));
*z2 =
(z1 -
(settings->tool_length_offset + settings->origin_offset_z +
settings->axis_offset_z));
#ifndef LATHE
*AA_2 = (AA_1 - (settings->AA_origin_offset + settings->AA_axis_offset));
*BB_2 = (BB_1 - (settings->BB_origin_offset + settings->BB_axis_offset));
*CC_2 = (CC_1 - (settings->CC_origin_offset + settings->CC_axis_offset));
#endif
return RS274NGC_OK;
}
/****************************************************************************/
/*! find_straight_length
Returned Value: double (length of path between start and end points)
Side effects: none
Called by:
inverse_time_rate_straight
inverse_time_rate_as
This calculates a number to use in feed rate calculations when inverse
time feed mode is used, for a motion in which X,Y,Z,A,B, and C each change
linearly or not at all from their initial value to their end value.
This is used when the feed_reference mode is CANON_XYZ, which is
always in rs274NGC.
If any of the X, Y, or Z axes move or the A-axis, B-axis, and C-axis
do not move, this is the length of the path relative to the XYZ axes
from the first point to the second, and any rotary axis motion is
ignored. The length is the simple Euclidean distance.
The formula for the Euclidean distance "length" of a move involving
only the A, B and C axes is based on a conversation with Jim Frohardt at
Boeing, who says that the Fanuc controller on their 5-axis machine
interprets the feed rate this way. Note that if only one rotary axis
moves, this formula returns the absolute value of that axis move,
which is what is desired.
*/
double Interp::find_straight_length(double x2, //!< X-coordinate of end point
double y2, //!< Y-coordinate of end point
double z2, //!< Z-coordinate of end point
double AA_2, //!< A-coordinate of end point
double BB_2, //!< B-coordinate of end point
double CC_2, //!< C-coordinate of end point
double x1, //!< X-coordinate of start point
double y1, //!< Y-coordinate of start point
double z1, //!< Z-coordinate of start point
double AA_1, //!< A-coordinate of start point
double BB_1, //!< B-coordinate of start point
double CC_1 //!< C-coordinate of start point
)
{
if ((x1 != x2) || (y1 != y2) || (z1 != z2) || (1
#ifndef LATHE
&& (AA_2 == AA_1)
&& (BB_2 == BB_1)
&& (CC_2 == CC_1)
#endif
)) /* straight line */
return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2) + pow((z2 - z1), 2));
else
return sqrt(0 +
#ifndef LATHE
pow((AA_2 - AA_1), 2) +
pow((BB_2 - BB_1), 2) + pow((CC_2 - CC_1), 2) +
#endif
0);
}
/****************************************************************************/
/*! find_turn
Returned Value: double (angle in radians between two radii of a circle)
Side effects: none
Called by: find_arc_length
All angles are in radians.
*/
double Interp::find_turn(double x1, //!< X-coordinate of start point
double y1, //!< Y-coordinate of start point
double center_x, //!< X-coordinate of arc center
double center_y, //!< Y-coordinate of arc center
int turn, //!< no. of full or partial circles CCW
double x2, //!< X-coordinate of end point
double y2) //!< Y-coordinate of end point
{
double alpha; /* angle of first radius */
double beta; /* angle of second radius */
double theta; /* amount of turn of arc CCW - negative if CW */
if (turn == 0)
return 0.0;
alpha = atan2((y1 - center_y), (x1 - center_x));
beta = atan2((y2 - center_y), (x2 - center_x));
if (turn > 0) {
if (beta <= alpha)
beta = (beta + (2 * M_PIl));
theta = ((beta - alpha) + ((turn - 1) * (2 * M_PIl)));
} else { /* turn < 0 */
if (alpha <= beta)
alpha = (alpha + (2 * M_PIl));
theta = ((beta - alpha) + ((turn + 1) * (2 * M_PIl)));
}
return (theta);
}

View file

@ -1,365 +1,365 @@
/********************************************************************
* Description: interp_internal.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
/****************************************************************************/
/*! close_and_downcase
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. A left parenthesis is found inside a comment:
NCE_NESTED_COMMENT_FOUND
2. The line ends before an open comment is closed:
NCE_UNCLOSED_COMMENT_FOUND
3. A newline character is found that is not followed by null:
NCE_NULL_MISSING_AFTER_NEWLINE
Side effects: See below
Called by: read_text
To simplify handling upper case letters, spaces, and tabs, this
function removes spaces and and tabs and downcases everything on a
line which is not part of a comment.
Comments are left unchanged in place. Comments are anything
enclosed in parentheses. Nested comments, indicated by a left
parenthesis inside a comment, are illegal.
The line must have a null character at the end when it comes in.
The line may have one newline character just before the end. If
there is a newline, it will be removed.
Although this software system detects and rejects all illegal characters
and illegal syntax, this particular function does not detect problems
with anything but comments.
We are treating RS274 code here as case-insensitive and spaces and
tabs as if they have no meaning. [RS274D, page 6] says spaces and tabs
are to be ignored by control.
The KT and NGC manuals say nothing about case or spaces and tabs.
*/
int Interp::close_and_downcase(char *line) //!< string: one line of NC code
{
static char name[] = "close_and_downcase";
int m;
int n;
int comment;
char item;
comment = 0;
for (n = 0, m = 0; (item = line[m]) != (char) NULL; m++) {
if (comment) {
line[n++] = item;
if (item == ')') {
comment = 0;
} else if (item == '(')
ERM(NCE_NESTED_COMMENT_FOUND);
} else if ((item == ' ') || (item == '\t') || (item == '\r'));
/* don't copy blank or tab or CR */
else if (item == '\n') { /* don't copy newline *//* but check null follows */
CHK((line[m + 1] != 0), NCE_NULL_MISSING_AFTER_NEWLINE);
} else if ((64 < item) && (item < 91)) { /* downcase upper case letters */
line[n++] = (32 + item);
} else if (item == '(') { /* comment is starting */
comment = 1;
line[n++] = item;
} else {
line[n++] = item; /* copy anything else */
}
}
CHK((comment), NCE_UNCLOSED_COMMENT_FOUND);
line[n] = 0;
return RS274NGC_OK;
}
/****************************************************************************/
/*! enhance_block
Returned Value:
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. A g80 is in the block, no modal group 0 code that uses axes
is in the block, and one or more axis values is given:
NCE_CANNOT_USE_AXIS_VALUES_WITH_G80
2. A g92 is in the block and no axis value is given:
NCE_ALL_AXES_MISSING_WITH_G92
3. One g-code from group 1 and one from group 0, both of which can use
axis values, are in the block:
NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES
4. A g-code (other than 0 or 1, for which we are allowing all axes
missing) from group 1 which can use axis values is in the block,
but no axis value is given: NCE_ALL_AXES_MISSING_WITH_MOTION_CODE
5. Axis values are given, but there is neither a g-code in the block
nor an active previously given modal g-code that uses axis values:
NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM
Side effects:
The value of motion_to_be in the block is set.
Called by: parse_line
If there is a g-code for motion in the block (in g_modes[1]),
set motion_to_be to that. Otherwise, if there is an axis value in the
block and no g-code to use it (any such would be from group 0 in
g_modes[0]), set motion_to_be to be the last motion saved (in
settings->motion mode).
This also make the checks described above.
*/
int Interp::enhance_block(block_pointer block, //!< pointer to a block to be checked
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "enhance_block";
int axis_flag;
int mode_zero_covets_axes;
int mode0;
int mode1;
axis_flag = ((block->x_flag == ON) || (block->y_flag == ON) ||
#ifndef LATHE
(block->a_flag == ON) ||
(block->b_flag == ON) || (block->c_flag == ON) ||
#endif
(block->z_flag == ON));
mode0 = block->g_modes[0];
mode1 = block->g_modes[1];
mode_zero_covets_axes =
((mode0 == G_10) || (mode0 == G_28) || (mode0 == G_30)
|| (mode0 == G_92));
if (mode1 != -1) {
if (mode1 == G_80) {
CHK((axis_flag && (!mode_zero_covets_axes)),
NCE_CANNOT_USE_AXIS_VALUES_WITH_G80);
CHK(((!axis_flag) && (mode0 == G_92)), NCE_ALL_AXES_MISSING_WITH_G92);
} else {
CHK(mode_zero_covets_axes,
NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES);
CHK(((!axis_flag) && (mode1 != G_0) && (mode1 != G_1)),
NCE_ALL_AXES_MISSING_WITH_MOTION_CODE);
}
block->motion_to_be = mode1;
} else if (mode_zero_covets_axes) { /* other 3 can get by without axes but not G92 */
CHK(((!axis_flag) && (block->g_modes[0] == G_92)),
NCE_ALL_AXES_MISSING_WITH_G92);
} else if (axis_flag) {
CHK(((settings->motion_mode == -1)
|| (settings->motion_mode == G_80)),
NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM);
block->motion_to_be = settings->motion_mode;
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! init_block
Returned Value: int (RS274NGC_OK)
Side effects:
Values in the block are reset as described below.
Called by: parse_line
This system reuses the same block over and over, rather than building
a new one for each line of NC code. The block is re-initialized before
each new line of NC code is read.
The block contains many slots for values which may or may not be present
on a line of NC code. For some of these slots, there is a flag which
is turned on (at the time time value of the slot is read) if the item
is present. For slots whose values are to be read which do not have a
flag, there is always some excluded range of values. Setting the
initial value of these slot to some number in the excluded range
serves to show that a value for that slot has not been read.
The rules for the indicators for slots whose values may be read are:
1. If the value may be an arbitrary real number (which is always stored
internally as a double), a flag is needed to indicate if a value has
been read. All such flags are initialized to OFF.
Note that the value itself is not initialized; there is no point in it.
2. If the value must be a non-negative real number (which is always stored
internally as a double), a value of -1.0 indicates the item is not present.
3. If the value must be an unsigned integer (which is always stored
internally as an int), a value of -1 indicates the item is not present.
(RS274/NGC does not use any negative integers.)
4. If the value is a character string (only the comment slot is one), the
first character is set to 0 (NULL).
*/
int Interp::init_block(block_pointer block) //!< pointer to a block to be initialized or reset
{
int n;
#ifndef LATHE
block->a_flag = OFF;
block->b_flag = OFF;
block->c_flag = OFF;
#endif
block->comment[0] = 0;
block->d_number = -1;
block->f_number = -1.0;
for (n = 0; n < 14; n++) {
block->g_modes[n] = -1;
}
block->h_number = -1;
block->i_flag = OFF;
block->j_flag = OFF;
block->k_flag = OFF;
block->l_number = -1;
block->line_number = -1;
block->motion_to_be = -1;
block->m_count = 0;
for (n = 0; n < 200; n++) {
block->m_modes[n] = -1;
}
block->user_m = 0;
block->p_number = -1.0;
block->q_number = -1.0;
block->r_flag = OFF;
block->s_number = -1.0;
block->t_number = -1;
block->x_flag = OFF;
block->y_flag = OFF;
block->z_flag = OFF;
return RS274NGC_OK;
}
/****************************************************************************/
/*! parse_line
Returned Value: int
If any of the following functions returns an error code,
this returns that code.
init_block
read_items
enhance_block
check_items
Otherwise, it returns RS274NGC_OK.
Side effects:
One RS274 line is read into a block and the block is checked for
errors. System parameters may be reset.
Called by: rs274ngc_read
*/
int Interp::parse_line(char *line, //!< array holding a line of RS274 code
block_pointer block, //!< pointer to a block to be filled
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "parse_line";
int status;
CHP(init_block(block));
CHP(read_items(block, line, settings->parameters));
CHP(enhance_block(block, settings));
CHP(check_items(block, settings));
return RS274NGC_OK;
}
/****************************************************************************/
/*! precedence
Returned Value: int
This returns an integer representing the precedence level of an_operator
Side Effects: None
Called by: read_real_expression
To add additional levels of operator precedence, edit this function.
*/
int Interp::precedence(int an_operator)
{
if (an_operator == RIGHT_BRACKET)
return 1;
else if (an_operator == POWER)
return 4;
else if (an_operator >= AND2)
return 2;
else
return 3;
}
/****************************************************************************/
/*! set_probe_data
Returned Value: int (RS274NGC_OK)
Side effects:
The current position is set.
System parameters for probe position are set.
Called by: rs274ngc_read
*/
int Interp::set_probe_data(setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "set_probe_data";
settings->current_x = GET_EXTERNAL_POSITION_X();
settings->current_y = GET_EXTERNAL_POSITION_Y();
settings->current_z = GET_EXTERNAL_POSITION_Z();
#ifndef LATHE
settings->AA_current = GET_EXTERNAL_POSITION_A();
settings->BB_current = GET_EXTERNAL_POSITION_B();
settings->CC_current = GET_EXTERNAL_POSITION_C();
#endif
settings->parameters[5061] = GET_EXTERNAL_PROBE_POSITION_X();
settings->parameters[5062] = GET_EXTERNAL_PROBE_POSITION_Y();
settings->parameters[5063] = GET_EXTERNAL_PROBE_POSITION_Z();
#ifndef LATHE
settings->parameters[5064] = GET_EXTERNAL_PROBE_POSITION_A();
settings->parameters[5065] = GET_EXTERNAL_PROBE_POSITION_B();
settings->parameters[5066] = GET_EXTERNAL_PROBE_POSITION_C();
#endif
settings->parameters[5067] = GET_EXTERNAL_PROBE_VALUE();
return RS274NGC_OK;
}
/********************************************************************
* Description: interp_internal.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
/****************************************************************************/
/*! close_and_downcase
Returned Value: int
If any of the following errors occur, this returns the error code shown.
Otherwise, it returns RS274NGC_OK.
1. A left parenthesis is found inside a comment:
NCE_NESTED_COMMENT_FOUND
2. The line ends before an open comment is closed:
NCE_UNCLOSED_COMMENT_FOUND
3. A newline character is found that is not followed by null:
NCE_NULL_MISSING_AFTER_NEWLINE
Side effects: See below
Called by: read_text
To simplify handling upper case letters, spaces, and tabs, this
function removes spaces and and tabs and downcases everything on a
line which is not part of a comment.
Comments are left unchanged in place. Comments are anything
enclosed in parentheses. Nested comments, indicated by a left
parenthesis inside a comment, are illegal.
The line must have a null character at the end when it comes in.
The line may have one newline character just before the end. If
there is a newline, it will be removed.
Although this software system detects and rejects all illegal characters
and illegal syntax, this particular function does not detect problems
with anything but comments.
We are treating RS274 code here as case-insensitive and spaces and
tabs as if they have no meaning. [RS274D, page 6] says spaces and tabs
are to be ignored by control.
The KT and NGC manuals say nothing about case or spaces and tabs.
*/
int Interp::close_and_downcase(char *line) //!< string: one line of NC code
{
static char name[] = "close_and_downcase";
int m;
int n;
int comment;
char item;
comment = 0;
for (n = 0, m = 0; (item = line[m]) != (char) NULL; m++) {
if (comment) {
line[n++] = item;
if (item == ')') {
comment = 0;
} else if (item == '(')
ERM(NCE_NESTED_COMMENT_FOUND);
} else if ((item == ' ') || (item == '\t') || (item == '\r'));
/* don't copy blank or tab or CR */
else if (item == '\n') { /* don't copy newline *//* but check null follows */
CHK((line[m + 1] != 0), NCE_NULL_MISSING_AFTER_NEWLINE);
} else if ((64 < item) && (item < 91)) { /* downcase upper case letters */
line[n++] = (32 + item);
} else if (item == '(') { /* comment is starting */
comment = 1;
line[n++] = item;
} else {
line[n++] = item; /* copy anything else */
}
}
CHK((comment), NCE_UNCLOSED_COMMENT_FOUND);
line[n] = 0;
return RS274NGC_OK;
}
/****************************************************************************/
/*! enhance_block
Returned Value:
If any of the following errors occur, this returns the error shown.
Otherwise, it returns RS274NGC_OK.
1. A g80 is in the block, no modal group 0 code that uses axes
is in the block, and one or more axis values is given:
NCE_CANNOT_USE_AXIS_VALUES_WITH_G80
2. A g92 is in the block and no axis value is given:
NCE_ALL_AXES_MISSING_WITH_G92
3. One g-code from group 1 and one from group 0, both of which can use
axis values, are in the block:
NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES
4. A g-code (other than 0 or 1, for which we are allowing all axes
missing) from group 1 which can use axis values is in the block,
but no axis value is given: NCE_ALL_AXES_MISSING_WITH_MOTION_CODE
5. Axis values are given, but there is neither a g-code in the block
nor an active previously given modal g-code that uses axis values:
NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM
Side effects:
The value of motion_to_be in the block is set.
Called by: parse_line
If there is a g-code for motion in the block (in g_modes[1]),
set motion_to_be to that. Otherwise, if there is an axis value in the
block and no g-code to use it (any such would be from group 0 in
g_modes[0]), set motion_to_be to be the last motion saved (in
settings->motion mode).
This also make the checks described above.
*/
int Interp::enhance_block(block_pointer block, //!< pointer to a block to be checked
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "enhance_block";
int axis_flag;
int mode_zero_covets_axes;
int mode0;
int mode1;
axis_flag = ((block->x_flag == ON) || (block->y_flag == ON) ||
#ifndef LATHE
(block->a_flag == ON) ||
(block->b_flag == ON) || (block->c_flag == ON) ||
#endif
(block->z_flag == ON));
mode0 = block->g_modes[0];
mode1 = block->g_modes[1];
mode_zero_covets_axes =
((mode0 == G_10) || (mode0 == G_28) || (mode0 == G_30)
|| (mode0 == G_92));
if (mode1 != -1) {
if (mode1 == G_80) {
CHK((axis_flag && (!mode_zero_covets_axes)),
NCE_CANNOT_USE_AXIS_VALUES_WITH_G80);
CHK(((!axis_flag) && (mode0 == G_92)), NCE_ALL_AXES_MISSING_WITH_G92);
} else {
CHK(mode_zero_covets_axes,
NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES);
CHK(((!axis_flag) && (mode1 != G_0) && (mode1 != G_1)),
NCE_ALL_AXES_MISSING_WITH_MOTION_CODE);
}
block->motion_to_be = mode1;
} else if (mode_zero_covets_axes) { /* other 3 can get by without axes but not G92 */
CHK(((!axis_flag) && (block->g_modes[0] == G_92)),
NCE_ALL_AXES_MISSING_WITH_G92);
} else if (axis_flag) {
CHK(((settings->motion_mode == -1)
|| (settings->motion_mode == G_80)),
NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM);
block->motion_to_be = settings->motion_mode;
}
return RS274NGC_OK;
}
/****************************************************************************/
/*! init_block
Returned Value: int (RS274NGC_OK)
Side effects:
Values in the block are reset as described below.
Called by: parse_line
This system reuses the same block over and over, rather than building
a new one for each line of NC code. The block is re-initialized before
each new line of NC code is read.
The block contains many slots for values which may or may not be present
on a line of NC code. For some of these slots, there is a flag which
is turned on (at the time time value of the slot is read) if the item
is present. For slots whose values are to be read which do not have a
flag, there is always some excluded range of values. Setting the
initial value of these slot to some number in the excluded range
serves to show that a value for that slot has not been read.
The rules for the indicators for slots whose values may be read are:
1. If the value may be an arbitrary real number (which is always stored
internally as a double), a flag is needed to indicate if a value has
been read. All such flags are initialized to OFF.
Note that the value itself is not initialized; there is no point in it.
2. If the value must be a non-negative real number (which is always stored
internally as a double), a value of -1.0 indicates the item is not present.
3. If the value must be an unsigned integer (which is always stored
internally as an int), a value of -1 indicates the item is not present.
(RS274/NGC does not use any negative integers.)
4. If the value is a character string (only the comment slot is one), the
first character is set to 0 (NULL).
*/
int Interp::init_block(block_pointer block) //!< pointer to a block to be initialized or reset
{
int n;
#ifndef LATHE
block->a_flag = OFF;
block->b_flag = OFF;
block->c_flag = OFF;
#endif
block->comment[0] = 0;
block->d_number = -1;
block->f_number = -1.0;
for (n = 0; n < 14; n++) {
block->g_modes[n] = -1;
}
block->h_number = -1;
block->i_flag = OFF;
block->j_flag = OFF;
block->k_flag = OFF;
block->l_number = -1;
block->line_number = -1;
block->motion_to_be = -1;
block->m_count = 0;
for (n = 0; n < 200; n++) {
block->m_modes[n] = -1;
}
block->user_m = 0;
block->p_number = -1.0;
block->q_number = -1.0;
block->r_flag = OFF;
block->s_number = -1.0;
block->t_number = -1;
block->x_flag = OFF;
block->y_flag = OFF;
block->z_flag = OFF;
return RS274NGC_OK;
}
/****************************************************************************/
/*! parse_line
Returned Value: int
If any of the following functions returns an error code,
this returns that code.
init_block
read_items
enhance_block
check_items
Otherwise, it returns RS274NGC_OK.
Side effects:
One RS274 line is read into a block and the block is checked for
errors. System parameters may be reset.
Called by: rs274ngc_read
*/
int Interp::parse_line(char *line, //!< array holding a line of RS274 code
block_pointer block, //!< pointer to a block to be filled
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "parse_line";
int status;
CHP(init_block(block));
CHP(read_items(block, line, settings->parameters));
CHP(enhance_block(block, settings));
CHP(check_items(block, settings));
return RS274NGC_OK;
}
/****************************************************************************/
/*! precedence
Returned Value: int
This returns an integer representing the precedence level of an_operator
Side Effects: None
Called by: read_real_expression
To add additional levels of operator precedence, edit this function.
*/
int Interp::precedence(int an_operator)
{
if (an_operator == RIGHT_BRACKET)
return 1;
else if (an_operator == POWER)
return 4;
else if (an_operator >= AND2)
return 2;
else
return 3;
}
/****************************************************************************/
/*! set_probe_data
Returned Value: int (RS274NGC_OK)
Side effects:
The current position is set.
System parameters for probe position are set.
Called by: rs274ngc_read
*/
int Interp::set_probe_data(setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "set_probe_data";
settings->current_x = GET_EXTERNAL_POSITION_X();
settings->current_y = GET_EXTERNAL_POSITION_Y();
settings->current_z = GET_EXTERNAL_POSITION_Z();
#ifndef LATHE
settings->AA_current = GET_EXTERNAL_POSITION_A();
settings->BB_current = GET_EXTERNAL_POSITION_B();
settings->CC_current = GET_EXTERNAL_POSITION_C();
#endif
settings->parameters[5061] = GET_EXTERNAL_PROBE_POSITION_X();
settings->parameters[5062] = GET_EXTERNAL_PROBE_POSITION_Y();
settings->parameters[5063] = GET_EXTERNAL_PROBE_POSITION_Z();
#ifndef LATHE
settings->parameters[5064] = GET_EXTERNAL_PROBE_POSITION_A();
settings->parameters[5065] = GET_EXTERNAL_PROBE_POSITION_B();
settings->parameters[5066] = GET_EXTERNAL_PROBE_POSITION_C();
#endif
settings->parameters[5067] = GET_EXTERNAL_PROBE_VALUE();
return RS274NGC_OK;
}

View file

@ -1,379 +1,379 @@
/********************************************************************
* Description: interp_internal.hh
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef INTERP_INTERNAL_HH
#define INTERP_INTERNAL_HH
#include <stdio.h>
#include "global_defs.h"
#include "canon.hh"
/**********************/
/* COMPILER MACROS */
/**********************/
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define round_to_int(x) ((int) ((x) < 0.0 ? ((x) - 0.5) : ((x) + 0.5)))
/* how far above hole bottom for rapid return, in inches */
#define G83_RAPID_DELTA 0.010
/* numerical constants */
#define TOLERANCE_INCH 0.0005
#define TOLERANCE_MM 0.005
#define TOLERANCE_CONCAVE_CORNER 0.05 /* angle threshold for concavity for
cutter compensation, in radians */
#define TINY 1e-12 /* for arc_data_r */
#define UNKNOWN 1e-20
// max number of m codes on one line
#define MAX_EMS 4
// English - Metric conversion (long number keeps error buildup down)
#define MM_PER_INCH 25.4
//#define INCH_PER_MM 0.039370078740157477
// on-off switch settings
#define OFF 0
#define ON 1
// feed_mode
#define UNITS_PER_MINUTE 0
#define INVERSE_TIME 1
// cutter radius compensation mode, OFF already defined to 0
// not using CANON_SIDE since interpreter handles cutter radius comp
#define RIGHT 1
#define LEFT 2
// unary operations
// These are not enums because the "&" operator is used in
// reading the operation names and is illegal with an enum
#define ABS 1
#define ACOS 2
#define ASIN 3
#define ATAN 4
#define COS 5
#define EXP 6
#define FIX 7
#define FUP 8
#define LN 9
#define ROUND 10
#define SIN 11
#define SQRT 12
#define TAN 13
// binary operations
#define NO_OPERATION 0
#define DIVIDED_BY 1
#define MODULO 2
#define POWER 3
#define TIMES 4
#define AND2 5
#define EXCLUSIVE_OR 6
#define MINUS 7
#define NON_EXCLUSIVE_OR 8
#define PLUS 9
#define RIGHT_BRACKET 10
// G Codes are symbolic to be dialect-independent in source code
#define G_0 0
#define G_1 10
#define G_2 20
#define G_3 30
#define G_4 40
#define G_10 100
#define G_17 170
#define G_18 180
#define G_19 190
#define G_20 200
#define G_21 210
#define G_28 280
#define G_30 300
#define G_33 330
#define G_38_2 382
#define G_40 400
#define G_41 410
#define G_42 420
#define G_43 430
#define G_49 490
#define G_53 530
#define G_54 540
#define G_55 550
#define G_56 560
#define G_57 570
#define G_58 580
#define G_59 590
#define G_59_1 591
#define G_59_2 592
#define G_59_3 593
#define G_61 610
#define G_61_1 611
#define G_64 640
#define G_80 800
#define G_81 810
#define G_82 820
#define G_83 830
#define G_84 840
#define G_85 850
#define G_86 860
#define G_87 870
#define G_88 880
#define G_89 890
#define G_90 900
#define G_91 910
#define G_92 920
#define G_92_1 921
#define G_92_2 922
#define G_92_3 923
#define G_93 930
#define G_94 940
#define G_98 980
#define G_99 990
// name of parameter file for saving/restoring interpreter variables
#define RS274NGC_PARAMETER_FILE_NAME_DEFAULT "rs274ngc.var"
#define RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX ".bak"
// number of parameters in parameter table
#define RS274NGC_MAX_PARAMETERS 5400
/**********************/
/* TYPEDEFS */
/**********************/
/* distance_mode */
typedef enum
{ MODE_ABSOLUTE, MODE_INCREMENTAL }
DISTANCE_MODE;
/* retract_mode for cycles */
typedef enum
{ R_PLANE, OLD_Z }
RETRACT_MODE;
typedef int ON_OFF;
typedef struct block_struct
{
#ifndef LATHE
ON_OFF a_flag;
double a_number;
ON_OFF b_flag;
double b_number;
ON_OFF c_flag;
double c_number;
#endif
char comment[256];
int d_number;
double f_number;
int g_modes[14];
int h_number;
ON_OFF i_flag;
double i_number;
ON_OFF j_flag;
double j_number;
ON_OFF k_flag;
double k_number;
int l_number;
int line_number;
int motion_to_be;
int m_count;
int m_modes[200];
int user_m;
double p_number;
double q_number;
ON_OFF r_flag;
double r_number;
double s_number;
int t_number;
ON_OFF x_flag;
double x_number;
ON_OFF y_flag;
double y_number;
ON_OFF z_flag;
double z_number;
}
block;
typedef block *block_pointer;
// Declare class so that we can use it in the typedef.
class Interp;
typedef int (Interp::*read_function_pointer) (char *, int *, block_pointer, double *);
/*
The current_x, current_y, and current_z are the location of the tool
in the current coordinate system. current_x and current_y differ from
program_x and program_y when cutter radius compensation is on.
current_z is the position of the tool tip in program coordinates when
tool length compensation is using the actual tool length; it is the
position of the spindle when tool length is zero.
In a setup, the axis_offset values are set by g92 and the origin_offset
values are set by g54 - g59.3. The net origin offset uses both values
and is not represented here
*/
typedef struct setup_struct
{
#ifndef LATHE
double AA_axis_offset; // A-axis g92 offset
double AA_current; // current A-axis position
double AA_origin_offset; // A-axis origin offset
double BB_axis_offset; // B-axis g92offset
double BB_current; // current B-axis position
double BB_origin_offset; // B-axis origin offset
double CC_axis_offset; // C-axis g92offset
double CC_current; // current C-axis position
double CC_origin_offset; // C-axis origin offset
#endif
int active_g_codes[ACTIVE_G_CODES]; // array of active G codes
int active_m_codes[ACTIVE_M_CODES]; // array of active M codes
double active_settings[ACTIVE_SETTINGS]; // array of feed, speed, etc.
double axis_offset_x; // X-axis g92 offset
double axis_offset_y; // Y-axis g92 offset
double axis_offset_z; // Z-axis g92 offset
block block1; // parsed next block
char blocktext[LINELEN]; // linetext downcased, white space gone
CANON_MOTION_MODE control_mode; // exact path or cutting mode
int current_slot; // carousel slot number of current tool
double current_x; // current X-axis position
double current_y; // current Y-axis position
double current_z; // current Z-axis position
double cutter_comp_radius; // current cutter compensation radius
int cutter_comp_side; // current cutter compensation side
double cycle_cc; // cc-value (normal) for canned cycles
double cycle_i; // i-value for canned cycles
double cycle_j; // j-value for canned cycles
double cycle_k; // k-value for canned cycles
int cycle_l; // l-value for canned cycles
double cycle_p; // p-value (dwell) for canned cycles
double cycle_q; // q-value for canned cycles
double cycle_r; // r-value for canned cycles
DISTANCE_MODE distance_mode; // absolute or incremental
int feed_mode; // G_93 (inverse time) or G_94 units/min
ON_OFF feed_override; // whether feed override is enabled
double feed_rate; // feed rate in current units/min
char filename[LINELEN]; // name of currently open NC code file
FILE *file_pointer; // file pointer for open NC code file
ON_OFF flood; // whether flood coolant is on
int length_offset_index; // for use with tool length offsets
CANON_UNITS length_units; // millimeters or inches
int line_length; // length of line last read
char linetext[LINELEN]; // text of most recent line read
ON_OFF mist; // whether mist coolant is on
int motion_mode; // active G-code for motion
int origin_index; // active origin (1=G54 to 9=G59.3)
double origin_offset_x; // origin offset x
double origin_offset_y; // origin offset y
double origin_offset_z; // origin offset z
double parameters[RS274NGC_MAX_PARAMETERS]; // system parameters
int parameter_occurrence; // parameter buffer index
int parameter_numbers[50]; // parameter number buffer
double parameter_values[50]; // parameter value buffer
ON_OFF percent_flag; // ON means first line was percent sign
CANON_PLANE plane; // active plane, XY-, YZ-, or XZ-plane
ON_OFF probe_flag; // flag indicating probing done
double program_x; // program x, used when cutter comp on
double program_y; // program y, used when cutter comp on
RETRACT_MODE retract_mode; // for cycles, old_z or r_plane
int selected_tool_slot; // tool slot selected but not active
int sequence_number; // sequence number of line last read
double speed; // current spindle speed in rpm
CANON_SPEED_FEED_MODE speed_feed_mode; // independent or synched
ON_OFF speed_override; // whether speed override is enabled
CANON_DIRECTION spindle_turning; // direction spindle is turning
char stack[50][80]; // stack of calls for error reporting
int stack_index; // index into the stack
double tool_length_offset; // current tool length offset
int tool_max; // highest number tool slot in carousel
CANON_TOOL_TABLE tool_table[CANON_TOOL_MAX + 1]; // index is slot number
int tool_table_index; // tool index used with cutter comp
double traverse_rate; // rate for traverse motions
}
setup;
typedef setup *setup_pointer;
/*
The _setup model includes a stack array for the names of function
calls. This stack is written into if an error occurs. Just before each
function returns an error code, it writes its name in the next
available string, initializes the following string, and increments
the array index. The following four macros do the work.
The size of the stack array is 50. An error in the middle of a very
complex expression would cause the ERP and CHP macros to write past the
bounds of the array if a check were not provided. No real program
would contain such a thing, but the check is included to make the
macros totally crash-proof. If the function call stack is deeper than
49, the top of the stack will be missing.
*/
#define ERM(error_code) if (1) { \
_setup.stack_index = 0; \
strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return error_code; \
} else
#define ERP(error_code) if (_setup.stack_index < 49) { \
strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return error_code; \
} else return error_code
#define CHK(bad, error_code) if (bad) { \
_setup.stack_index = 0; \
strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return error_code; \
} else
#define CHP(try_this) \
if ((status = (try_this)) != RS274NGC_OK) { \
if (_setup.stack_index < 49) \
{strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return status;} \
else {return status;} \
} else
#define CYCLE_MACRO(call) for (repeat = block->l_number; \
repeat > 0; \
repeat--) \
{ \
aa = (aa + aa_increment); \
bb = (bb + bb_increment); \
cycle_traverse(plane, aa, bb, old_cc); \
if (old_cc != r) \
cycle_traverse(plane, aa, bb, r); \
CHP(call); \
old_cc = clear_cc; \
}
#endif // INTERP_INTERNAL_HH
/********************************************************************
* Description: interp_internal.hh
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef INTERP_INTERNAL_HH
#define INTERP_INTERNAL_HH
#include <stdio.h>
#include "global_defs.h"
#include "canon.hh"
/**********************/
/* COMPILER MACROS */
/**********************/
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define round_to_int(x) ((int) ((x) < 0.0 ? ((x) - 0.5) : ((x) + 0.5)))
/* how far above hole bottom for rapid return, in inches */
#define G83_RAPID_DELTA 0.010
/* numerical constants */
#define TOLERANCE_INCH 0.0005
#define TOLERANCE_MM 0.005
#define TOLERANCE_CONCAVE_CORNER 0.05 /* angle threshold for concavity for
cutter compensation, in radians */
#define TINY 1e-12 /* for arc_data_r */
#define UNKNOWN 1e-20
// max number of m codes on one line
#define MAX_EMS 4
// English - Metric conversion (long number keeps error buildup down)
#define MM_PER_INCH 25.4
//#define INCH_PER_MM 0.039370078740157477
// on-off switch settings
#define OFF 0
#define ON 1
// feed_mode
#define UNITS_PER_MINUTE 0
#define INVERSE_TIME 1
// cutter radius compensation mode, OFF already defined to 0
// not using CANON_SIDE since interpreter handles cutter radius comp
#define RIGHT 1
#define LEFT 2
// unary operations
// These are not enums because the "&" operator is used in
// reading the operation names and is illegal with an enum
#define ABS 1
#define ACOS 2
#define ASIN 3
#define ATAN 4
#define COS 5
#define EXP 6
#define FIX 7
#define FUP 8
#define LN 9
#define ROUND 10
#define SIN 11
#define SQRT 12
#define TAN 13
// binary operations
#define NO_OPERATION 0
#define DIVIDED_BY 1
#define MODULO 2
#define POWER 3
#define TIMES 4
#define AND2 5
#define EXCLUSIVE_OR 6
#define MINUS 7
#define NON_EXCLUSIVE_OR 8
#define PLUS 9
#define RIGHT_BRACKET 10
// G Codes are symbolic to be dialect-independent in source code
#define G_0 0
#define G_1 10
#define G_2 20
#define G_3 30
#define G_4 40
#define G_10 100
#define G_17 170
#define G_18 180
#define G_19 190
#define G_20 200
#define G_21 210
#define G_28 280
#define G_30 300
#define G_33 330
#define G_38_2 382
#define G_40 400
#define G_41 410
#define G_42 420
#define G_43 430
#define G_49 490
#define G_53 530
#define G_54 540
#define G_55 550
#define G_56 560
#define G_57 570
#define G_58 580
#define G_59 590
#define G_59_1 591
#define G_59_2 592
#define G_59_3 593
#define G_61 610
#define G_61_1 611
#define G_64 640
#define G_80 800
#define G_81 810
#define G_82 820
#define G_83 830
#define G_84 840
#define G_85 850
#define G_86 860
#define G_87 870
#define G_88 880
#define G_89 890
#define G_90 900
#define G_91 910
#define G_92 920
#define G_92_1 921
#define G_92_2 922
#define G_92_3 923
#define G_93 930
#define G_94 940
#define G_98 980
#define G_99 990
// name of parameter file for saving/restoring interpreter variables
#define RS274NGC_PARAMETER_FILE_NAME_DEFAULT "rs274ngc.var"
#define RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX ".bak"
// number of parameters in parameter table
#define RS274NGC_MAX_PARAMETERS 5400
/**********************/
/* TYPEDEFS */
/**********************/
/* distance_mode */
typedef enum
{ MODE_ABSOLUTE, MODE_INCREMENTAL }
DISTANCE_MODE;
/* retract_mode for cycles */
typedef enum
{ R_PLANE, OLD_Z }
RETRACT_MODE;
typedef int ON_OFF;
typedef struct block_struct
{
#ifndef LATHE
ON_OFF a_flag;
double a_number;
ON_OFF b_flag;
double b_number;
ON_OFF c_flag;
double c_number;
#endif
char comment[256];
int d_number;
double f_number;
int g_modes[14];
int h_number;
ON_OFF i_flag;
double i_number;
ON_OFF j_flag;
double j_number;
ON_OFF k_flag;
double k_number;
int l_number;
int line_number;
int motion_to_be;
int m_count;
int m_modes[200];
int user_m;
double p_number;
double q_number;
ON_OFF r_flag;
double r_number;
double s_number;
int t_number;
ON_OFF x_flag;
double x_number;
ON_OFF y_flag;
double y_number;
ON_OFF z_flag;
double z_number;
}
block;
typedef block *block_pointer;
// Declare class so that we can use it in the typedef.
class Interp;
typedef int (Interp::*read_function_pointer) (char *, int *, block_pointer, double *);
/*
The current_x, current_y, and current_z are the location of the tool
in the current coordinate system. current_x and current_y differ from
program_x and program_y when cutter radius compensation is on.
current_z is the position of the tool tip in program coordinates when
tool length compensation is using the actual tool length; it is the
position of the spindle when tool length is zero.
In a setup, the axis_offset values are set by g92 and the origin_offset
values are set by g54 - g59.3. The net origin offset uses both values
and is not represented here
*/
typedef struct setup_struct
{
#ifndef LATHE
double AA_axis_offset; // A-axis g92 offset
double AA_current; // current A-axis position
double AA_origin_offset; // A-axis origin offset
double BB_axis_offset; // B-axis g92offset
double BB_current; // current B-axis position
double BB_origin_offset; // B-axis origin offset
double CC_axis_offset; // C-axis g92offset
double CC_current; // current C-axis position
double CC_origin_offset; // C-axis origin offset
#endif
int active_g_codes[ACTIVE_G_CODES]; // array of active G codes
int active_m_codes[ACTIVE_M_CODES]; // array of active M codes
double active_settings[ACTIVE_SETTINGS]; // array of feed, speed, etc.
double axis_offset_x; // X-axis g92 offset
double axis_offset_y; // Y-axis g92 offset
double axis_offset_z; // Z-axis g92 offset
block block1; // parsed next block
char blocktext[LINELEN]; // linetext downcased, white space gone
CANON_MOTION_MODE control_mode; // exact path or cutting mode
int current_slot; // carousel slot number of current tool
double current_x; // current X-axis position
double current_y; // current Y-axis position
double current_z; // current Z-axis position
double cutter_comp_radius; // current cutter compensation radius
int cutter_comp_side; // current cutter compensation side
double cycle_cc; // cc-value (normal) for canned cycles
double cycle_i; // i-value for canned cycles
double cycle_j; // j-value for canned cycles
double cycle_k; // k-value for canned cycles
int cycle_l; // l-value for canned cycles
double cycle_p; // p-value (dwell) for canned cycles
double cycle_q; // q-value for canned cycles
double cycle_r; // r-value for canned cycles
DISTANCE_MODE distance_mode; // absolute or incremental
int feed_mode; // G_93 (inverse time) or G_94 units/min
ON_OFF feed_override; // whether feed override is enabled
double feed_rate; // feed rate in current units/min
char filename[LINELEN]; // name of currently open NC code file
FILE *file_pointer; // file pointer for open NC code file
ON_OFF flood; // whether flood coolant is on
int length_offset_index; // for use with tool length offsets
CANON_UNITS length_units; // millimeters or inches
int line_length; // length of line last read
char linetext[LINELEN]; // text of most recent line read
ON_OFF mist; // whether mist coolant is on
int motion_mode; // active G-code for motion
int origin_index; // active origin (1=G54 to 9=G59.3)
double origin_offset_x; // origin offset x
double origin_offset_y; // origin offset y
double origin_offset_z; // origin offset z
double parameters[RS274NGC_MAX_PARAMETERS]; // system parameters
int parameter_occurrence; // parameter buffer index
int parameter_numbers[50]; // parameter number buffer
double parameter_values[50]; // parameter value buffer
ON_OFF percent_flag; // ON means first line was percent sign
CANON_PLANE plane; // active plane, XY-, YZ-, or XZ-plane
ON_OFF probe_flag; // flag indicating probing done
double program_x; // program x, used when cutter comp on
double program_y; // program y, used when cutter comp on
RETRACT_MODE retract_mode; // for cycles, old_z or r_plane
int selected_tool_slot; // tool slot selected but not active
int sequence_number; // sequence number of line last read
double speed; // current spindle speed in rpm
CANON_SPEED_FEED_MODE speed_feed_mode; // independent or synched
ON_OFF speed_override; // whether speed override is enabled
CANON_DIRECTION spindle_turning; // direction spindle is turning
char stack[50][80]; // stack of calls for error reporting
int stack_index; // index into the stack
double tool_length_offset; // current tool length offset
int tool_max; // highest number tool slot in carousel
CANON_TOOL_TABLE tool_table[CANON_TOOL_MAX + 1]; // index is slot number
int tool_table_index; // tool index used with cutter comp
double traverse_rate; // rate for traverse motions
}
setup;
typedef setup *setup_pointer;
/*
The _setup model includes a stack array for the names of function
calls. This stack is written into if an error occurs. Just before each
function returns an error code, it writes its name in the next
available string, initializes the following string, and increments
the array index. The following four macros do the work.
The size of the stack array is 50. An error in the middle of a very
complex expression would cause the ERP and CHP macros to write past the
bounds of the array if a check were not provided. No real program
would contain such a thing, but the check is included to make the
macros totally crash-proof. If the function call stack is deeper than
49, the top of the stack will be missing.
*/
#define ERM(error_code) if (1) { \
_setup.stack_index = 0; \
strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return error_code; \
} else
#define ERP(error_code) if (_setup.stack_index < 49) { \
strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return error_code; \
} else return error_code
#define CHK(bad, error_code) if (bad) { \
_setup.stack_index = 0; \
strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return error_code; \
} else
#define CHP(try_this) \
if ((status = (try_this)) != RS274NGC_OK) { \
if (_setup.stack_index < 49) \
{strcpy(_setup.stack[_setup.stack_index++], name); \
_setup.stack[_setup.stack_index][0] = 0; \
return status;} \
else {return status;} \
} else
#define CYCLE_MACRO(call) for (repeat = block->l_number; \
repeat > 0; \
repeat--) \
{ \
aa = (aa + aa_increment); \
bb = (bb + bb_increment); \
cycle_traverse(plane, aa, bb, old_cc); \
if (old_cc != r) \
cycle_traverse(plane, aa, bb, r); \
CHP(call); \
old_cc = clear_cc; \
}
#endif // INTERP_INTERNAL_HH

View file

@ -1,240 +1,240 @@
/********************************************************************
* Description: interp_inverse.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! inverse_time_rate_arc
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by:
convert_arc2
convert_arc_comp1
convert_arc_comp2
This finds the feed rate needed by an inverse time move. The move
consists of an a single arc. Most of the work here is in finding the
length of the arc.
*/
int Interp::inverse_time_rate_arc(double x1, //!< x coord of start point of arc
double y1, //!< y coord of start point of arc
double z1, //!< z coord of start point of arc
double cx, //!< x coord of center of arc
double cy, //!< y coord of center of arc
int turn, //!< turn of arc
double x2, //!< x coord of end point of arc
double y2, //!< y coord of end point of arc
double z2, //!< z coord of end point of arc
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
double length;
double rate;
length = find_arc_length(x1, y1, z1, cx, cy, turn, x2, y2, z2);
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/****************************************************************************/
/*! inverse_time_rate_arc2
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by: convert_arc_comp2
This finds the feed rate needed by an inverse time move in
convert_arc_comp2. The move consists of an extra arc and a main
arc. Most of the work here is in finding the lengths of the two arcs.
All rotary motion is assumed to occur on the extra arc, as done by
convert_arc_comp2.
All z motion is assumed to occur on the main arc, as done by
convert_arc_comp2.
*/
int Interp::inverse_time_rate_arc2(double start_x, //!< x coord of last program point, extra arc center x
double start_y, //!< y coord of last program point, extra arc center y
int turn1, //!< turn of extra arc
double mid_x, //!< x coord of end point of extra arc
double mid_y, //!< y coord of end point of extra arc
double cx, //!< x coord of center of main arc
double cy, //!< y coord of center of main arc
int turn2, //!< turn of main arc
double end_x, //!< x coord of end point of main arc
double end_y, //!< y coord of end point of main arc
double end_z, //!< z coord of end point of main arc
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
double length;
double rate;
length =
(find_arc_length
(settings->current_x, settings->current_y, settings->current_z,
start_x, start_y, turn1, mid_x, mid_y,
settings->current_z) + find_arc_length(mid_x, mid_y,
settings->current_z,
cx, cy, turn2, end_x,
end_y, end_z));
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/****************************************************************************/
/*! inverse_time_rate_as
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by: convert_straight_comp2
This finds the feed rate needed by an inverse time move in
convert_straight_comp2. The move consists of an extra arc and a straight
line. Most of the work here is in finding the lengths of the arc and
the line.
All rotary motion is assumed to occur on the arc, as done by
convert_straight_comp2.
All z motion is assumed to occur on the line, as done by
convert_straight_comp2.
*/
int Interp::inverse_time_rate_as(double start_x, //!< x coord of last program point, extra arc center x
double start_y, //!< y coord of last program point, extra arc center y
int turn, //!< turn of extra arc
double mid_x, //!< x coord of end point of extra arc
double mid_y, //!< y coord of end point of extra arc
double end_x, //!< x coord of end point of straight line
double end_y, //!< y coord of end point of straight line
double end_z, //!< z coord of end point of straight line
double AA_end, //!< A coord of end point of straight line
double BB_end, //!< B coord of end point of straight line
double CC_end, //!< C coord of end point of straight line
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
double length;
double rate;
length =
(find_arc_length
(settings->current_x, settings->current_y, settings->current_z,
start_x, start_y, turn, mid_x, mid_y,
settings->current_z) + find_straight_length(end_x, end_y, end_z,
#ifndef LATHE
AA_end, BB_end, CC_end,
#else
0, 0, 0,
#endif
mid_x, mid_y, settings->current_z,
#ifndef LATHE
AA_end, BB_end, CC_end));
#else
0, 0, 0));
#endif
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/****************************************************************************/
/*! inverse_time_rate_straight
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by:
convert_straight
convert_straight_comp1
convert_straight_comp2
This finds the feed rate needed by an inverse time straight move. Most
of the work here is in finding the length of the line.
*/
int Interp::inverse_time_rate_straight(double end_x, //!< x coordinate of end point of straight line
double end_y, //!< y coordinate of end point of straight line
double end_z, //!< z coordinate of end point of straight line
double AA_end, //!< A coordinate of end point of straight line/*AA*/
double BB_end, //!< B coordinate of end point of straight line/*BB*/
double CC_end, //!< C coordinate of end point of straight line/*CC*/
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "inverse_time_rate_straight";
double length;
double rate;
length = find_straight_length(end_x, end_y, end_z,
#ifndef LATHE
AA_end, BB_end, CC_end,
#else
0, 0, 0,
#endif
settings->current_x, settings->current_y, settings->current_z,
#ifndef LATHE
settings->AA_current, settings->BB_current, settings->CC_current);
#else
0, 0, 0);
#endif
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/********************************************************************
* Description: interp_inverse.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! inverse_time_rate_arc
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by:
convert_arc2
convert_arc_comp1
convert_arc_comp2
This finds the feed rate needed by an inverse time move. The move
consists of an a single arc. Most of the work here is in finding the
length of the arc.
*/
int Interp::inverse_time_rate_arc(double x1, //!< x coord of start point of arc
double y1, //!< y coord of start point of arc
double z1, //!< z coord of start point of arc
double cx, //!< x coord of center of arc
double cy, //!< y coord of center of arc
int turn, //!< turn of arc
double x2, //!< x coord of end point of arc
double y2, //!< y coord of end point of arc
double z2, //!< z coord of end point of arc
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
double length;
double rate;
length = find_arc_length(x1, y1, z1, cx, cy, turn, x2, y2, z2);
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/****************************************************************************/
/*! inverse_time_rate_arc2
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by: convert_arc_comp2
This finds the feed rate needed by an inverse time move in
convert_arc_comp2. The move consists of an extra arc and a main
arc. Most of the work here is in finding the lengths of the two arcs.
All rotary motion is assumed to occur on the extra arc, as done by
convert_arc_comp2.
All z motion is assumed to occur on the main arc, as done by
convert_arc_comp2.
*/
int Interp::inverse_time_rate_arc2(double start_x, //!< x coord of last program point, extra arc center x
double start_y, //!< y coord of last program point, extra arc center y
int turn1, //!< turn of extra arc
double mid_x, //!< x coord of end point of extra arc
double mid_y, //!< y coord of end point of extra arc
double cx, //!< x coord of center of main arc
double cy, //!< y coord of center of main arc
int turn2, //!< turn of main arc
double end_x, //!< x coord of end point of main arc
double end_y, //!< y coord of end point of main arc
double end_z, //!< z coord of end point of main arc
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
double length;
double rate;
length =
(find_arc_length
(settings->current_x, settings->current_y, settings->current_z,
start_x, start_y, turn1, mid_x, mid_y,
settings->current_z) + find_arc_length(mid_x, mid_y,
settings->current_z,
cx, cy, turn2, end_x,
end_y, end_z));
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/****************************************************************************/
/*! inverse_time_rate_as
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by: convert_straight_comp2
This finds the feed rate needed by an inverse time move in
convert_straight_comp2. The move consists of an extra arc and a straight
line. Most of the work here is in finding the lengths of the arc and
the line.
All rotary motion is assumed to occur on the arc, as done by
convert_straight_comp2.
All z motion is assumed to occur on the line, as done by
convert_straight_comp2.
*/
int Interp::inverse_time_rate_as(double start_x, //!< x coord of last program point, extra arc center x
double start_y, //!< y coord of last program point, extra arc center y
int turn, //!< turn of extra arc
double mid_x, //!< x coord of end point of extra arc
double mid_y, //!< y coord of end point of extra arc
double end_x, //!< x coord of end point of straight line
double end_y, //!< y coord of end point of straight line
double end_z, //!< z coord of end point of straight line
double AA_end, //!< A coord of end point of straight line
double BB_end, //!< B coord of end point of straight line
double CC_end, //!< C coord of end point of straight line
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
double length;
double rate;
length =
(find_arc_length
(settings->current_x, settings->current_y, settings->current_z,
start_x, start_y, turn, mid_x, mid_y,
settings->current_z) + find_straight_length(end_x, end_y, end_z,
#ifndef LATHE
AA_end, BB_end, CC_end,
#else
0, 0, 0,
#endif
mid_x, mid_y, settings->current_z,
#ifndef LATHE
AA_end, BB_end, CC_end));
#else
0, 0, 0));
#endif
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}
/****************************************************************************/
/*! inverse_time_rate_straight
Returned Value: int (RS274NGC_OK)
Side effects: a call is made to SET_FEED_RATE and _setup.feed_rate is set.
Called by:
convert_straight
convert_straight_comp1
convert_straight_comp2
This finds the feed rate needed by an inverse time straight move. Most
of the work here is in finding the length of the line.
*/
int Interp::inverse_time_rate_straight(double end_x, //!< x coordinate of end point of straight line
double end_y, //!< y coordinate of end point of straight line
double end_z, //!< z coordinate of end point of straight line
double AA_end, //!< A coordinate of end point of straight line/*AA*/
double BB_end, //!< B coordinate of end point of straight line/*BB*/
double CC_end, //!< C coordinate of end point of straight line/*CC*/
block_pointer block, //!< pointer to a block of RS274 instructions
setup_pointer settings) //!< pointer to machine settings
{
static char name[] = "inverse_time_rate_straight";
double length;
double rate;
length = find_straight_length(end_x, end_y, end_z,
#ifndef LATHE
AA_end, BB_end, CC_end,
#else
0, 0, 0,
#endif
settings->current_x, settings->current_y, settings->current_z,
#ifndef LATHE
settings->AA_current, settings->BB_current, settings->CC_current);
#else
0, 0, 0);
#endif
rate = MAX(0.1, (length * block->f_number));
SET_FEED_RATE(rate);
settings->feed_rate = rate;
return RS274NGC_OK;
}

File diff suppressed because it is too large Load diff

View file

@ -1,172 +1,172 @@
/********************************************************************
* Description: interp_write.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! write_g_codes
Returned Value: int (RS274NGC_OK)
Side effects:
The active_g_codes in the settings are updated.
Called by:
rs274ngc_execute
rs274ngc_init
The block may be NULL.
This writes active g_codes into the settings->active_g_codes array by
examining the interpreter settings. The array of actives is composed
of ints, so (to handle codes like 59.1) all g_codes are reported as
ints ten times the actual value. For example, 59.1 is reported as 591.
The correspondence between modal groups and array indexes is as follows
(no apparent logic to it).
The group 0 entry is taken from the block (if there is one), since its
codes are not modal.
group 0 - gez[2] g4, g10, g28, g30, g53, g92 g92.1, g92.2, g92.3 - misc
group 1 - gez[1] g0, g1, g2, g3, g38.2, g80, g81, g82, g83, g84, g85,
g86, g87, g88, g89 - motion
group 2 - gez[3] g17, g18, g19 - plane selection
group 3 - gez[6] g90, g91 - distance mode
group 4 - no such group
group 5 - gez[7] g93, g94 - feed rate mode
group 6 - gez[5] g20, g21 - units
group 7 - gez[4] g40, g41, g42 - cutter radius compensation
group 8 - gez[9] g43, g49 - tool length offse
group 9 - no such group
group 10 - gez[10] g98, g99 - return mode in canned cycles
group 11 - no such group
group 12 - gez[8] g54, g55, g56, g57, g58, g59, g59.1, g59.2, g59.3
- coordinate system
group 13 - gez[11] g61, g61.1, g64 - control mode
*/
int Interp::write_g_codes(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings) //!< pointer to machine settings
{
int *gez;
gez = settings->active_g_codes;
gez[0] = settings->sequence_number;
gez[1] = settings->motion_mode;
gez[2] = ((block == NULL) ? -1 : block->g_modes[0]);
gez[3] =
(settings->plane == CANON_PLANE_XY) ? G_17 :
(settings->plane == CANON_PLANE_XZ) ? G_18 : G_19;
gez[4] =
(settings->cutter_comp_side == RIGHT) ? G_42 :
(settings->cutter_comp_side == LEFT) ? G_41 : G_40;
gez[5] = (settings->length_units == CANON_UNITS_INCHES) ? G_20 : G_21;
gez[6] = (settings->distance_mode == MODE_ABSOLUTE) ? G_90 : G_91;
gez[7] = (settings->feed_mode == INVERSE_TIME) ? G_93 : G_94;
gez[8] =
(settings->origin_index <
7) ? (530 + (10 * settings->origin_index)) : (584 +
settings->origin_index);
gez[9] = (settings->tool_length_offset == 0.0) ? G_49 : G_43;
gez[10] = (settings->retract_mode == OLD_Z) ? G_98 : G_99;
gez[11] =
(settings->control_mode == CANON_CONTINUOUS) ? G_64 :
(settings->control_mode == CANON_EXACT_PATH) ? G_61 : G_61_1;
return RS274NGC_OK;
}
/****************************************************************************/
/*! write_m_codes
Returned Value: int (RS274NGC_OK)
Side effects:
The settings->active_m_codes are updated.
Called by:
rs274ngc_execute
rs274ngc_init
This is testing only the feed override to see if overrides is on.
Might add check of speed override.
*/
int Interp::write_m_codes(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings) //!< pointer to machine settings
{
int *emz;
emz = settings->active_m_codes;
emz[0] = settings->sequence_number; /* 0 seq number */
emz[1] = (block == NULL) ? -1 : block->m_modes[4]; /* 1 stopping */
emz[2] = (settings->spindle_turning == CANON_STOPPED) ? 5 : /* 2 spindle */
(settings->spindle_turning == CANON_CLOCKWISE) ? 3 : 4;
emz[3] = /* 3 tool change */
(block == NULL) ? -1 : block->m_modes[6];
emz[4] = /* 4 mist */
(settings->mist == ON) ? 7 : (settings->flood == ON) ? -1 : 9;
emz[5] = /* 5 flood */
(settings->flood == ON) ? 8 : -1;
emz[6] = /* 6 overrides */
(settings->feed_override == ON) ? 48 : 49;
return RS274NGC_OK;
}
/****************************************************************************/
/*! write_settings
Returned Value: int (RS274NGC_OK)
Side effects:
The settings->active_settings array of doubles is updated with the
sequence number, feed, and speed settings.
Called by:
rs274ngc_execute
rs274ngc_init
*/
int Interp::write_settings(setup_pointer settings) //!< pointer to machine settings
{
double *vals;
vals = settings->active_settings;
vals[0] = settings->sequence_number; /* 0 sequence number */
vals[1] = settings->feed_rate; /* 1 feed rate */
vals[2] = settings->speed; /* 2 spindle speed */
return RS274NGC_OK;
}
/****************************************************************************/
/********************************************************************
* Description: interp_write.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rs274ngc.hh"
#include "rs274ngc_return.hh"
#include "interp_internal.hh"
/****************************************************************************/
/*! write_g_codes
Returned Value: int (RS274NGC_OK)
Side effects:
The active_g_codes in the settings are updated.
Called by:
rs274ngc_execute
rs274ngc_init
The block may be NULL.
This writes active g_codes into the settings->active_g_codes array by
examining the interpreter settings. The array of actives is composed
of ints, so (to handle codes like 59.1) all g_codes are reported as
ints ten times the actual value. For example, 59.1 is reported as 591.
The correspondence between modal groups and array indexes is as follows
(no apparent logic to it).
The group 0 entry is taken from the block (if there is one), since its
codes are not modal.
group 0 - gez[2] g4, g10, g28, g30, g53, g92 g92.1, g92.2, g92.3 - misc
group 1 - gez[1] g0, g1, g2, g3, g38.2, g80, g81, g82, g83, g84, g85,
g86, g87, g88, g89 - motion
group 2 - gez[3] g17, g18, g19 - plane selection
group 3 - gez[6] g90, g91 - distance mode
group 4 - no such group
group 5 - gez[7] g93, g94 - feed rate mode
group 6 - gez[5] g20, g21 - units
group 7 - gez[4] g40, g41, g42 - cutter radius compensation
group 8 - gez[9] g43, g49 - tool length offse
group 9 - no such group
group 10 - gez[10] g98, g99 - return mode in canned cycles
group 11 - no such group
group 12 - gez[8] g54, g55, g56, g57, g58, g59, g59.1, g59.2, g59.3
- coordinate system
group 13 - gez[11] g61, g61.1, g64 - control mode
*/
int Interp::write_g_codes(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings) //!< pointer to machine settings
{
int *gez;
gez = settings->active_g_codes;
gez[0] = settings->sequence_number;
gez[1] = settings->motion_mode;
gez[2] = ((block == NULL) ? -1 : block->g_modes[0]);
gez[3] =
(settings->plane == CANON_PLANE_XY) ? G_17 :
(settings->plane == CANON_PLANE_XZ) ? G_18 : G_19;
gez[4] =
(settings->cutter_comp_side == RIGHT) ? G_42 :
(settings->cutter_comp_side == LEFT) ? G_41 : G_40;
gez[5] = (settings->length_units == CANON_UNITS_INCHES) ? G_20 : G_21;
gez[6] = (settings->distance_mode == MODE_ABSOLUTE) ? G_90 : G_91;
gez[7] = (settings->feed_mode == INVERSE_TIME) ? G_93 : G_94;
gez[8] =
(settings->origin_index <
7) ? (530 + (10 * settings->origin_index)) : (584 +
settings->origin_index);
gez[9] = (settings->tool_length_offset == 0.0) ? G_49 : G_43;
gez[10] = (settings->retract_mode == OLD_Z) ? G_98 : G_99;
gez[11] =
(settings->control_mode == CANON_CONTINUOUS) ? G_64 :
(settings->control_mode == CANON_EXACT_PATH) ? G_61 : G_61_1;
return RS274NGC_OK;
}
/****************************************************************************/
/*! write_m_codes
Returned Value: int (RS274NGC_OK)
Side effects:
The settings->active_m_codes are updated.
Called by:
rs274ngc_execute
rs274ngc_init
This is testing only the feed override to see if overrides is on.
Might add check of speed override.
*/
int Interp::write_m_codes(block_pointer block, //!< pointer to a block of RS274/NGC instructions
setup_pointer settings) //!< pointer to machine settings
{
int *emz;
emz = settings->active_m_codes;
emz[0] = settings->sequence_number; /* 0 seq number */
emz[1] = (block == NULL) ? -1 : block->m_modes[4]; /* 1 stopping */
emz[2] = (settings->spindle_turning == CANON_STOPPED) ? 5 : /* 2 spindle */
(settings->spindle_turning == CANON_CLOCKWISE) ? 3 : 4;
emz[3] = /* 3 tool change */
(block == NULL) ? -1 : block->m_modes[6];
emz[4] = /* 4 mist */
(settings->mist == ON) ? 7 : (settings->flood == ON) ? -1 : 9;
emz[5] = /* 5 flood */
(settings->flood == ON) ? 8 : -1;
emz[6] = /* 6 overrides */
(settings->feed_override == ON) ? 48 : 49;
return RS274NGC_OK;
}
/****************************************************************************/
/*! write_settings
Returned Value: int (RS274NGC_OK)
Side effects:
The settings->active_settings array of doubles is updated with the
sequence number, feed, and speed settings.
Called by:
rs274ngc_execute
rs274ngc_init
*/
int Interp::write_settings(setup_pointer settings) //!< pointer to machine settings
{
double *vals;
vals = settings->active_settings;
vals[0] = settings->sequence_number; /* 0 sequence number */
vals[1] = settings->feed_rate; /* 1 feed rate */
vals[2] = settings->speed; /* 2 spindle speed */
return RS274NGC_OK;
}
/****************************************************************************/

View file

@ -1,376 +1,376 @@
/********************************************************************
* Description: rs274ngc.hh
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef RS274NGC_HH
#define RS274NGC_HH
/**********************/
/* INCLUDE DIRECTIVES */
/**********************/
#include <stdio.h>
#include "emc.hh"
#include "canon.hh"
#include "interp_internal.hh"
#define DEBUG_EMC
class Interp {
public:
/* Interface functions to call to tell the interpreter what to do.
Return values indicate status of execution.
These functions may change the state of the interpreter. */
// close the currently open NC code file
int rs274ngc_close();
// execute a line of NC code
#ifndef NOT_OLD_EMC_INTERP_COMPATIBLE
int rs274ngc_execute(const char *command = 0);
#else
int rs274ngc_execute();
#endif
// stop running
int rs274ngc_exit();
// get ready to run
int rs274ngc_init();
// load a tool table
int rs274ngc_load_tool_table();
// open a file of NC code
int rs274ngc_open(const char *filename);
// read the mdi or the next line of the open NC code file
int rs274ngc_read(const char *mdi = 0);
// reset yourself
int rs274ngc_reset();
// restore interpreter variables from a file
int rs274ngc_restore_parameters(const char *filename);
// save interpreter variables to file
int rs274ngc_save_parameters(const char *filename,
const double parameters[]);
// synchronize your internal model with the external world
int rs274ngc_synch();
/* Interface functions to call to get information from the interpreter.
If a function has a return value, the return value contains the information.
If a function returns nothing, information is copied into one of the
arguments to the function. These functions do not change the state of
the interpreter. */
// copy active G codes into array [0]..[11]
void rs274ngc_active_g_codes(int *codes);
// copy active M codes into array [0]..[6]
void rs274ngc_active_m_codes(int *codes);
// copy active F, S settings into array [0]..[2]
void rs274ngc_active_settings(double *settings);
// copy the text of the error message whose number is error_code into the
// error_text array, but stop at max_size if the text is longer.
void rs274ngc_error_text(int error_code, char *error_text,
int max_size);
// copy the name of the currently open file into the file_name array,
// but stop at max_size if the name is longer
void rs274ngc_file_name(char *file_name, int max_size);
// return the length of the most recently read line
int rs274ngc_line_length();
// copy the text of the most recently read line into the line_text array,
// but stop at max_size if the text is longer
void rs274ngc_line_text(char *line_text, int max_size);
// return the current sequence number (how many lines read)
int rs274ngc_sequence_number();
// copy the function name from the stack_index'th position of the
// function call stack at the time of the most recent error into
// the function name string, but stop at max_size if the name is longer
void rs274ngc_stack_name(int stack_index, char *function_name,
int max_size);
// Get the parameter file name from the ini file.
int rs274ngc_ini_load(const char *filename);
int rs274ngc_line() { return rs274ngc_sequence_number(); }
char *rs274ngc_command(char *buf, int len) { rs274ngc_line_text(buf, len); return buf; }
char *rs274ngc_file(char *buf, int len) { rs274ngc_file_name(buf, len); return buf; }
private:
/* Function prototypes for all functions */
int arc_data_comp_ijk(int move, int side, double tool_radius,
double current_x, double current_y, double end_x,
double end_y, double i_number, double j_number,
double *center_x, double *center_y, int *turn,
double tolerance);
int arc_data_comp_r(int move, int side, double tool_radius,
double current_x, double current_y, double end_x,
double end_y, double big_radius, double *center_x,
double *center_y, int *turn);
int arc_data_ijk(int move, double current_x, double current_y,
double end_x, double end_y, double i_number,
double j_number, double *center_x, double *center_y,
int *turn, double tolerance);
int arc_data_r(int move, double current_x, double current_y,
double end_x, double end_y, double radius,
double *center_x, double *center_y, int *turn);
int check_g_codes(block_pointer block, setup_pointer settings);
int check_items(block_pointer block, setup_pointer settings);
int check_m_codes(block_pointer block);
int check_other_codes(block_pointer block);
int close_and_downcase(char *line);
int convert_arc(int move, block_pointer block, setup_pointer settings);
int convert_arc2(int move, block_pointer block,
setup_pointer settings, double *current1,
double *current2, double *current3, double end1,
double end2, double end3, double AA_end,
double BB_end, double CC_end, double offset1,
double offset2);
int convert_arc_comp1(int move, block_pointer block,
setup_pointer settings, double end_x,
double end_y, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_arc_comp2(int move, block_pointer block,
setup_pointer settings, double end_x,
double end_y, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_axis_offsets(int g_code, block_pointer block,
setup_pointer settings);
int convert_comment(char *comment);
int convert_control_mode(int g_code, setup_pointer settings);
int convert_coordinate_system(int g_code, setup_pointer settings);
int convert_cutter_compensation(int g_code, block_pointer block,
setup_pointer settings);
int convert_cutter_compensation_off(setup_pointer settings);
int convert_cutter_compensation_on(int side, block_pointer block,
setup_pointer settings);
int convert_cycle(int motion, block_pointer block,
setup_pointer settings);
int convert_cycle_g81(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z);
int convert_cycle_g82(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z, double dwell);
int convert_cycle_g83(CANON_PLANE plane, double x, double y,
double r, double clear_z, double bottom_z,
double delta);
int convert_cycle_g84(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z,
CANON_DIRECTION direction,
CANON_SPEED_FEED_MODE mode);
int convert_cycle_g85(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z);
int convert_cycle_g86(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z, double dwell,
CANON_DIRECTION direction);
int convert_cycle_g87(CANON_PLANE plane, double x, double offset_x,
double y, double offset_y, double r,
double clear_z, double middle_z, double bottom_z,
CANON_DIRECTION direction);
int convert_cycle_g88(CANON_PLANE plane, double x, double y,
double bottom_z, double dwell,
CANON_DIRECTION direction);
int convert_cycle_g89(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z, double dwell);
int convert_cycle_xy(int motion, block_pointer block,
setup_pointer settings);
int convert_cycle_yz(int motion, block_pointer block,
setup_pointer settings);
int convert_cycle_zx(int motion, block_pointer block,
setup_pointer settings);
int convert_distance_mode(int g_code, setup_pointer settings);
int convert_dwell(double time);
int convert_feed_mode(int g_code, setup_pointer settings);
int convert_feed_rate(block_pointer block, setup_pointer settings);
int convert_g(block_pointer block, setup_pointer settings);
int convert_home(int move, block_pointer block,
setup_pointer settings);
int convert_length_units(int g_code, setup_pointer settings);
int convert_m(block_pointer block, setup_pointer settings);
int convert_modal_0(int code, block_pointer block,
setup_pointer settings);
int convert_motion(int motion, block_pointer block,
setup_pointer settings);
int convert_probe(block_pointer block, setup_pointer settings);
int convert_retract_mode(int g_code, setup_pointer settings);
int convert_setup(block_pointer block, setup_pointer settings);
int convert_set_plane(int g_code, setup_pointer settings);
int convert_speed(block_pointer block, setup_pointer settings);
int convert_stop(block_pointer block, setup_pointer settings);
int convert_straight(int move, block_pointer block,
setup_pointer settings);
int convert_straight_comp1(int move, block_pointer block,
setup_pointer settings, double px,
double py, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_straight_comp2(int move, block_pointer block,
setup_pointer settings, double px,
double py, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_tool_change(setup_pointer settings);
int convert_tool_length_offset(int g_code, block_pointer block,
setup_pointer settings);
int convert_tool_select(block_pointer block, setup_pointer settings);
int cycle_feed(CANON_PLANE plane, double end1,
double end2, double end3);
int cycle_traverse(CANON_PLANE plane, double end1, double end2,
double end3);
int enhance_block(block_pointer block, setup_pointer settings);
int execute_binary(double *left, int operation, double *right);
int execute_binary1(double *left, int operation, double *right);
int execute_binary2(double *left, int operation, double *right);
int execute_block(block_pointer block, setup_pointer settings);
int execute_unary(double *double_ptr, int operation);
double find_arc_length(double x1, double y1, double z1,
double center_x, double center_y, int turn,
double x2, double y2, double z2);
int find_ends(block_pointer block, setup_pointer settings, double *px,
double *py, double *pz, double *AA_p, double *BB_p,
double *CC_p);
int find_relative(double x1, double y1, double z1, double AA_1,
double BB_1, double CC_1, double *x2, double *y2,
double *z2, double *AA_2, double *BB_2, double *CC_2,
setup_pointer settings);
double find_straight_length(double x2, double y2, double z2,
double AA_2, double BB_2, double CC_2,
double x1, double y1, double z1,
double AA_1, double BB_1, double CC_1);
double find_turn(double x1, double y1, double center_x,
double center_y, int turn, double x2, double y2);
int init_block(block_pointer block);
int inverse_time_rate_arc(double x1, double y1, double z1,
double cx, double cy, int turn, double x2,
double y2, double z2, block_pointer block,
setup_pointer settings);
int inverse_time_rate_arc2(double start_x, double start_y, int turn1,
double mid_x, double mid_y, double cx,
double cy, int turn2, double end_x,
double end_y, double end_z,
block_pointer block,
setup_pointer settings);
int inverse_time_rate_as(double start_x, double start_y, int turn,
double mid_x, double mid_y, double end_x,
double end_y, double end_z, double AA_end,
double BB_end, double CC_end,
block_pointer block, setup_pointer settings);
int inverse_time_rate_straight(double end_x, double end_y,
double end_z, double AA_end,
double BB_end, double CC_end,
block_pointer block,
setup_pointer settings);
int parse_line(char *line, block_pointer block,
setup_pointer settings);
int precedence(int an_operator);
int read_a(char *line, int *counter, block_pointer block,
double *parameters);
int read_atan(char *line, int *counter, double *double_ptr,
double *parameters);
int read_b(char *line, int *counter, block_pointer block,
double *parameters);
int read_c(char *line, int *counter, block_pointer block,
double *parameters);
int read_comment(char *line, int *counter, block_pointer block,
double *parameters);
int read_d(char *line, int *counter, block_pointer block,
double *parameters);
int read_f(char *line, int *counter, block_pointer block,
double *parameters);
int read_g(char *line, int *counter, block_pointer block,
double *parameters);
int read_h(char *line, int *counter, block_pointer block,
double *parameters);
int read_i(char *line, int *counter, block_pointer block,
double *parameters);
int read_integer_unsigned(char *line, int *counter, int *integer_ptr);
int read_integer_value(char *line, int *counter, int *integer_ptr,
double *parameters);
int read_items(block_pointer block, char *line, double *parameters);
int read_j(char *line, int *counter, block_pointer block,
double *parameters);
int read_k(char *line, int *counter, block_pointer block,
double *parameters);
int read_l(char *line, int *counter, block_pointer block,
double *parameters);
int read_line_number(char *line, int *counter, block_pointer block);
int read_m(char *line, int *counter, block_pointer block,
double *parameters);
int read_one_item(char *line, int *counter, block_pointer block,
double *parameters);
int read_operation(char *line, int *counter, int *operation);
int read_operation_unary(char *line, int *counter, int *operation);
int read_p(char *line, int *counter, block_pointer block,
double *parameters);
int read_parameter(char *line, int *counter, double *double_ptr,
double *parameters);
int read_parameter_setting(char *line, int *counter,
block_pointer block, double *parameters);
int read_q(char *line, int *counter, block_pointer block,
double *parameters);
int read_r(char *line, int *counter, block_pointer block,
double *parameters);
int read_real_expression(char *line, int *counter,
double *hold2, double *parameters);
int read_real_number(char *line, int *counter, double *double_ptr);
int read_real_value(char *line, int *counter, double *double_ptr,
double *parameters);
int read_s(char *line, int *counter, block_pointer block,
double *parameters);
int read_t(char *line, int *counter, block_pointer block,
double *parameters);
int read_text(const char *command, FILE * inport, char *raw_line,
char *line, int *length);
int read_unary(char *line, int *counter, double *double_ptr,
double *parameters);
int read_x(char *line, int *counter, block_pointer block,
double *parameters);
int read_y(char *line, int *counter, block_pointer block,
double *parameters);
int read_z(char *line, int *counter, block_pointer block,
double *parameters);
int set_probe_data(setup_pointer settings);
int write_g_codes(block_pointer block, setup_pointer settings);
int write_m_codes(block_pointer block, setup_pointer settings);
int write_settings(setup_pointer settings);
/* Internal arrays */
static const int _gees[];
static const int _ems[];
static const int _required_parameters[];
static const read_function_pointer _readers[];
static setup _setup;
};
#endif
/********************************************************************
* Description: rs274ngc.hh
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef RS274NGC_HH
#define RS274NGC_HH
/**********************/
/* INCLUDE DIRECTIVES */
/**********************/
#include <stdio.h>
#include "emc.hh"
#include "canon.hh"
#include "interp_internal.hh"
#define DEBUG_EMC
class Interp {
public:
/* Interface functions to call to tell the interpreter what to do.
Return values indicate status of execution.
These functions may change the state of the interpreter. */
// close the currently open NC code file
int rs274ngc_close();
// execute a line of NC code
#ifndef NOT_OLD_EMC_INTERP_COMPATIBLE
int rs274ngc_execute(const char *command = 0);
#else
int rs274ngc_execute();
#endif
// stop running
int rs274ngc_exit();
// get ready to run
int rs274ngc_init();
// load a tool table
int rs274ngc_load_tool_table();
// open a file of NC code
int rs274ngc_open(const char *filename);
// read the mdi or the next line of the open NC code file
int rs274ngc_read(const char *mdi = 0);
// reset yourself
int rs274ngc_reset();
// restore interpreter variables from a file
int rs274ngc_restore_parameters(const char *filename);
// save interpreter variables to file
int rs274ngc_save_parameters(const char *filename,
const double parameters[]);
// synchronize your internal model with the external world
int rs274ngc_synch();
/* Interface functions to call to get information from the interpreter.
If a function has a return value, the return value contains the information.
If a function returns nothing, information is copied into one of the
arguments to the function. These functions do not change the state of
the interpreter. */
// copy active G codes into array [0]..[11]
void rs274ngc_active_g_codes(int *codes);
// copy active M codes into array [0]..[6]
void rs274ngc_active_m_codes(int *codes);
// copy active F, S settings into array [0]..[2]
void rs274ngc_active_settings(double *settings);
// copy the text of the error message whose number is error_code into the
// error_text array, but stop at max_size if the text is longer.
void rs274ngc_error_text(int error_code, char *error_text,
int max_size);
// copy the name of the currently open file into the file_name array,
// but stop at max_size if the name is longer
void rs274ngc_file_name(char *file_name, int max_size);
// return the length of the most recently read line
int rs274ngc_line_length();
// copy the text of the most recently read line into the line_text array,
// but stop at max_size if the text is longer
void rs274ngc_line_text(char *line_text, int max_size);
// return the current sequence number (how many lines read)
int rs274ngc_sequence_number();
// copy the function name from the stack_index'th position of the
// function call stack at the time of the most recent error into
// the function name string, but stop at max_size if the name is longer
void rs274ngc_stack_name(int stack_index, char *function_name,
int max_size);
// Get the parameter file name from the ini file.
int rs274ngc_ini_load(const char *filename);
int rs274ngc_line() { return rs274ngc_sequence_number(); }
char *rs274ngc_command(char *buf, int len) { rs274ngc_line_text(buf, len); return buf; }
char *rs274ngc_file(char *buf, int len) { rs274ngc_file_name(buf, len); return buf; }
private:
/* Function prototypes for all functions */
int arc_data_comp_ijk(int move, int side, double tool_radius,
double current_x, double current_y, double end_x,
double end_y, double i_number, double j_number,
double *center_x, double *center_y, int *turn,
double tolerance);
int arc_data_comp_r(int move, int side, double tool_radius,
double current_x, double current_y, double end_x,
double end_y, double big_radius, double *center_x,
double *center_y, int *turn);
int arc_data_ijk(int move, double current_x, double current_y,
double end_x, double end_y, double i_number,
double j_number, double *center_x, double *center_y,
int *turn, double tolerance);
int arc_data_r(int move, double current_x, double current_y,
double end_x, double end_y, double radius,
double *center_x, double *center_y, int *turn);
int check_g_codes(block_pointer block, setup_pointer settings);
int check_items(block_pointer block, setup_pointer settings);
int check_m_codes(block_pointer block);
int check_other_codes(block_pointer block);
int close_and_downcase(char *line);
int convert_arc(int move, block_pointer block, setup_pointer settings);
int convert_arc2(int move, block_pointer block,
setup_pointer settings, double *current1,
double *current2, double *current3, double end1,
double end2, double end3, double AA_end,
double BB_end, double CC_end, double offset1,
double offset2);
int convert_arc_comp1(int move, block_pointer block,
setup_pointer settings, double end_x,
double end_y, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_arc_comp2(int move, block_pointer block,
setup_pointer settings, double end_x,
double end_y, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_axis_offsets(int g_code, block_pointer block,
setup_pointer settings);
int convert_comment(char *comment);
int convert_control_mode(int g_code, setup_pointer settings);
int convert_coordinate_system(int g_code, setup_pointer settings);
int convert_cutter_compensation(int g_code, block_pointer block,
setup_pointer settings);
int convert_cutter_compensation_off(setup_pointer settings);
int convert_cutter_compensation_on(int side, block_pointer block,
setup_pointer settings);
int convert_cycle(int motion, block_pointer block,
setup_pointer settings);
int convert_cycle_g81(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z);
int convert_cycle_g82(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z, double dwell);
int convert_cycle_g83(CANON_PLANE plane, double x, double y,
double r, double clear_z, double bottom_z,
double delta);
int convert_cycle_g84(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z,
CANON_DIRECTION direction,
CANON_SPEED_FEED_MODE mode);
int convert_cycle_g85(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z);
int convert_cycle_g86(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z, double dwell,
CANON_DIRECTION direction);
int convert_cycle_g87(CANON_PLANE plane, double x, double offset_x,
double y, double offset_y, double r,
double clear_z, double middle_z, double bottom_z,
CANON_DIRECTION direction);
int convert_cycle_g88(CANON_PLANE plane, double x, double y,
double bottom_z, double dwell,
CANON_DIRECTION direction);
int convert_cycle_g89(CANON_PLANE plane, double x, double y,
double clear_z, double bottom_z, double dwell);
int convert_cycle_xy(int motion, block_pointer block,
setup_pointer settings);
int convert_cycle_yz(int motion, block_pointer block,
setup_pointer settings);
int convert_cycle_zx(int motion, block_pointer block,
setup_pointer settings);
int convert_distance_mode(int g_code, setup_pointer settings);
int convert_dwell(double time);
int convert_feed_mode(int g_code, setup_pointer settings);
int convert_feed_rate(block_pointer block, setup_pointer settings);
int convert_g(block_pointer block, setup_pointer settings);
int convert_home(int move, block_pointer block,
setup_pointer settings);
int convert_length_units(int g_code, setup_pointer settings);
int convert_m(block_pointer block, setup_pointer settings);
int convert_modal_0(int code, block_pointer block,
setup_pointer settings);
int convert_motion(int motion, block_pointer block,
setup_pointer settings);
int convert_probe(block_pointer block, setup_pointer settings);
int convert_retract_mode(int g_code, setup_pointer settings);
int convert_setup(block_pointer block, setup_pointer settings);
int convert_set_plane(int g_code, setup_pointer settings);
int convert_speed(block_pointer block, setup_pointer settings);
int convert_stop(block_pointer block, setup_pointer settings);
int convert_straight(int move, block_pointer block,
setup_pointer settings);
int convert_straight_comp1(int move, block_pointer block,
setup_pointer settings, double px,
double py, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_straight_comp2(int move, block_pointer block,
setup_pointer settings, double px,
double py, double end_z, double AA_end,
double BB_end, double CC_end);
int convert_tool_change(setup_pointer settings);
int convert_tool_length_offset(int g_code, block_pointer block,
setup_pointer settings);
int convert_tool_select(block_pointer block, setup_pointer settings);
int cycle_feed(CANON_PLANE plane, double end1,
double end2, double end3);
int cycle_traverse(CANON_PLANE plane, double end1, double end2,
double end3);
int enhance_block(block_pointer block, setup_pointer settings);
int execute_binary(double *left, int operation, double *right);
int execute_binary1(double *left, int operation, double *right);
int execute_binary2(double *left, int operation, double *right);
int execute_block(block_pointer block, setup_pointer settings);
int execute_unary(double *double_ptr, int operation);
double find_arc_length(double x1, double y1, double z1,
double center_x, double center_y, int turn,
double x2, double y2, double z2);
int find_ends(block_pointer block, setup_pointer settings, double *px,
double *py, double *pz, double *AA_p, double *BB_p,
double *CC_p);
int find_relative(double x1, double y1, double z1, double AA_1,
double BB_1, double CC_1, double *x2, double *y2,
double *z2, double *AA_2, double *BB_2, double *CC_2,
setup_pointer settings);
double find_straight_length(double x2, double y2, double z2,
double AA_2, double BB_2, double CC_2,
double x1, double y1, double z1,
double AA_1, double BB_1, double CC_1);
double find_turn(double x1, double y1, double center_x,
double center_y, int turn, double x2, double y2);
int init_block(block_pointer block);
int inverse_time_rate_arc(double x1, double y1, double z1,
double cx, double cy, int turn, double x2,
double y2, double z2, block_pointer block,
setup_pointer settings);
int inverse_time_rate_arc2(double start_x, double start_y, int turn1,
double mid_x, double mid_y, double cx,
double cy, int turn2, double end_x,
double end_y, double end_z,
block_pointer block,
setup_pointer settings);
int inverse_time_rate_as(double start_x, double start_y, int turn,
double mid_x, double mid_y, double end_x,
double end_y, double end_z, double AA_end,
double BB_end, double CC_end,
block_pointer block, setup_pointer settings);
int inverse_time_rate_straight(double end_x, double end_y,
double end_z, double AA_end,
double BB_end, double CC_end,
block_pointer block,
setup_pointer settings);
int parse_line(char *line, block_pointer block,
setup_pointer settings);
int precedence(int an_operator);
int read_a(char *line, int *counter, block_pointer block,
double *parameters);
int read_atan(char *line, int *counter, double *double_ptr,
double *parameters);
int read_b(char *line, int *counter, block_pointer block,
double *parameters);
int read_c(char *line, int *counter, block_pointer block,
double *parameters);
int read_comment(char *line, int *counter, block_pointer block,
double *parameters);
int read_d(char *line, int *counter, block_pointer block,
double *parameters);
int read_f(char *line, int *counter, block_pointer block,
double *parameters);
int read_g(char *line, int *counter, block_pointer block,
double *parameters);
int read_h(char *line, int *counter, block_pointer block,
double *parameters);
int read_i(char *line, int *counter, block_pointer block,
double *parameters);
int read_integer_unsigned(char *line, int *counter, int *integer_ptr);
int read_integer_value(char *line, int *counter, int *integer_ptr,
double *parameters);
int read_items(block_pointer block, char *line, double *parameters);
int read_j(char *line, int *counter, block_pointer block,
double *parameters);
int read_k(char *line, int *counter, block_pointer block,
double *parameters);
int read_l(char *line, int *counter, block_pointer block,
double *parameters);
int read_line_number(char *line, int *counter, block_pointer block);
int read_m(char *line, int *counter, block_pointer block,
double *parameters);
int read_one_item(char *line, int *counter, block_pointer block,
double *parameters);
int read_operation(char *line, int *counter, int *operation);
int read_operation_unary(char *line, int *counter, int *operation);
int read_p(char *line, int *counter, block_pointer block,
double *parameters);
int read_parameter(char *line, int *counter, double *double_ptr,
double *parameters);
int read_parameter_setting(char *line, int *counter,
block_pointer block, double *parameters);
int read_q(char *line, int *counter, block_pointer block,
double *parameters);
int read_r(char *line, int *counter, block_pointer block,
double *parameters);
int read_real_expression(char *line, int *counter,
double *hold2, double *parameters);
int read_real_number(char *line, int *counter, double *double_ptr);
int read_real_value(char *line, int *counter, double *double_ptr,
double *parameters);
int read_s(char *line, int *counter, block_pointer block,
double *parameters);
int read_t(char *line, int *counter, block_pointer block,
double *parameters);
int read_text(const char *command, FILE * inport, char *raw_line,
char *line, int *length);
int read_unary(char *line, int *counter, double *double_ptr,
double *parameters);
int read_x(char *line, int *counter, block_pointer block,
double *parameters);
int read_y(char *line, int *counter, block_pointer block,
double *parameters);
int read_z(char *line, int *counter, block_pointer block,
double *parameters);
int set_probe_data(setup_pointer settings);
int write_g_codes(block_pointer block, setup_pointer settings);
int write_m_codes(block_pointer block, setup_pointer settings);
int write_settings(setup_pointer settings);
/* Internal arrays */
static const int _gees[];
static const int _ems[];
static const int _required_parameters[];
static const read_function_pointer _readers[];
static setup _setup;
};
#endif

View file

@ -1,231 +1,231 @@
/********************************************************************
* Description: rs274ngc_errors.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
// #INDENT-OFF*
#include <libintl.h>
#ifdef USE_NLS
#define _(string) gettext(string)
#else
#define _(string) (string)
#endif
char * _rs274ngc_errors[] = {
/* 0 */ _("No error"),
/* 1 */ _("No error"),
/* 2 */ _("No error"),
/* 3 */ _("No error"),
/* 4 */ _("A file is already open"), // rs274ngc_open
/* 5 */ _("All axes missing with g92"), // enhance_block
/* 6 */ _("All axes missing with motion code"), // enhance_block
/* 7 */ _("Arc radius too small to reach end point"), // arc_data_r
/* 8 */ _("Argument to acos out of range"), // execute_unary
/* 9 */ _("Argument to asin out of range"), // execute_unary
/* 10 */ _("Attempt to divide by zero"), // execute_binary1
/* 11 */ _("Attempt to raise negative to non integer power"), // execute_binary1
/* 12 */ _("Bad character used"), // read_one_item
/* 13 */ _("Bad format unsigned integer"), // read_integer_unsigned
/* 14 */ _("Bad number format"), // read_real_number
/* 15 */ _("Bug bad g code modal group 0"), // check_g_codes
/* 16 */ _("Bug code not g0 or g1"), // convert_straight, convert_straight_comp1, convert_straight_comp2
/* 17 */ _("Bug code not g17 g18 or g19"), // convert_set_plane
/* 18 */ _("Bug code not g20 or g21"), // convert_length_units
/* 19 */ _("Bug code not g28 or g30"), // convert_home
/* 20 */ _("Bug code not g2 or g3"), // arc_data_comp_ijk, arc_data_ijk
/* 21 */ _("Bug code not g40 g41 or g42"), // convert_cutter_compensation
/* 22 */ _("Bug code not g43 or g49"), // convert_tool_length_offset
/* 23 */ _("Bug code not g4 g10 g28 g30 g53 or g92 series"), // convert_modal_0
/* 24 */ _("Bug code not g61 g61 1 or g64"), // convert_control_mode
/* 25 */ _("Bug code not g90 or g91"), // convert_distance_mode
/* 26 */ _("Bug code not g93 or g94"), // convert_feed_mode
/* 27 */ _("Bug code not g98 or g99"), // convert_retract_mode
/* 28 */ _("Bug code not in g92 series"), // convert_axis_offsets
/* 29 */ _("Bug code not in range g54 to g593"), // convert_coordinate_system
/* 30 */ _("Bug code not m0 m1 m2 m30 m60"), // convert_stop
/* 31 */ _("Bug distance mode not g90 or g91"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 32 */ _("Bug function should not have been called"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx, read_a, read_b, read_c, read_comment, read_d, read_f, read_g, read_h, read_i, read_j, read_k, read_l, read_line_number, read_m, read_p, read_parameter, read_parameter_setting, read_q, read_r, read_real_expression, read_s, read_t, read_x, read_y, read_z
/* 33 */ _("Bug in tool radius comp"), // arc_data_comp_r
/* 34 */ _("Bug plane not xy yz or xz"), // convert_arc, convert_cycle
/* 35 */ _("Bug side not right or left"), // convert_straight_comp1, convert_straight_comp2
/* 36 */ _("Bug unknown motion code"), // convert_motion
/* 37 */ _("Bug unknown operation"), // execute_binary1, execute_binary2, execute_unary
/* 38 */ _("Cannot change axis offsets with cutter radius comp"), // convert_axis_offsets
/* 39 */ _("Cannot change units with cutter radius comp"), // convert_length_units
/* 40 */ _("Cannot create backup file"), // rs274ngc_save_parameters
/* 41 */ _("Cannot do g1 with zero feed rate"), // convert_straight
/* 42 */ _("Cannot do zero repeats of cycle"), // convert_cycle
/* 43 */ _("Cannot make arc with zero feed rate"), // convert_arc
/* 44 */ _("Cannot move rotary axes during probing"), // convert_probe
/* 45 */ _("Cannot open backup file"), // rs274ngc_save_parameters
/* 46 */ _("Cannot open variable file"), // rs274ngc_save_parameters
/* 47 */ _("Cannot probe in inverse time feed mode"), // convert_probe
/* 48 */ _("Cannot probe with cutter radius comp on"), // convert_probe
/* 49 */ _("Cannot probe with zero feed rate"), // convert_probe
/* 50 */ _("Cannot put a b in canned cycle"), // check_other_codes
/* 51 */ _("Cannot put a c in canned cycle"), // check_other_codes
/* 52 */ _("Cannot put an a in canned cycle"), // check_other_codes
/* 53 */ _("Cannot turn cutter radius comp on out of xy plane"), // convert_cutter_compensation_on
/* 54 */ _("Cannot turn cutter radius comp on when on"), // convert_cutter_compensation_on
/* 55 */ _("Cannot use a word"), // read_a
/* 56 */ _("Cannot use axis values with g80"), // enhance_block
/* 57 */ _("Cannot use axis values without a g code that uses them"), // enhance_block
/* 58 */ _("Cannot use b word"), // read_b
/* 59 */ _("Cannot use c word"), // read_c
/* 60 */ _("Cannot use g28 or g30 with cutter radius comp"), // convert_home
/* 61 */ _("Cannot use g53 incremental"), // check_g_codes
/* 62 */ _("Cannot use g53 with cutter radius comp"), // convert_straight
/* 63 */ _("Cannot use two g codes that both use axis values"), // enhance_block
/* 64 */ _("Cannot use xz plane with cutter radius comp"), // convert_set_plane
/* 65 */ _("Cannot use yz plane with cutter radius comp"), // convert_set_plane
/* 66 */ _("Command too long"), // read_text, rs274ngc_open
/* 67 */ _("Concave corner with cutter radius comp"), // convert_arc_comp2, convert_straight_comp2
/* 68 */ _("Coordinate system index parameter 5220 out of range"), // rs274ngc_init
/* 69 */ _("Current point same as end point of arc"), // arc_data_r
/* 70 */ _("Cutter gouging with cutter radius comp"), // convert_arc_comp1, convert_straight_comp1
/* 71 */ _("D word with no g41 or g42"), // check_other_codes
/* 72 */ _("Dwell time missing with g4"), // check_g_codes
/* 73 */ _("Dwell time p word missing with g82"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 74 */ _("Dwell time p word missing with g86"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 75 */ _("Dwell time p word missing with g88"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 76 */ _("Dwell time p word missing with g89"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 77 */ _("Equal sign missing in parameter setting"), // read_parameter_setting
/* 78 */ _("F word missing with inverse time arc move"), // convert_arc
/* 79 */ _("F word missing with inverse time g1 move"), // convert_straight
/* 80 */ _("File ended with no percent sign"), // read_text, rs274ngc_open
/* 81 */ _("File ended with no percent sign or program end"), // read_text
/* 82 */ _("File name too long"), // rs274ngc_open
/* 83 */ _("File not open"), // rs274ngc_read
/* 84 */ _("G code out of range"), // read_g
/* 85 */ _("H word with no g43"), // check_other_codes
/* 86 */ _("I word given for arc in yz plane"), // convert_arc
/* 87 */ _("I word missing with g87"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 88 */ _("I word with no g2, g3 or g87 to use it"), // check_other_codes
/* 89 */ _("J word given for arc in xz plane"), // convert_arc
/* 90 */ _("J word missing with g87"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 91 */ _("J word with no g2, g3 or g87 to use it"), // check_other_codes
/* 92 */ _("K word given for arc in xy plane"), // convert_arc
/* 93 */ _("K word missing with g87"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 94 */ _("K word with no g2, g3, g33, or g87 to use it"), // check_other_codes
/* 95 */ _("L word with no canned cycle or g10"), // check_other_codes
/* 96 */ _("Left bracket missing after slash with atan"), // read_atan
/* 97 */ _("Left bracket missing after unary operation name"), // read_unary
/* 98 */ _("Line number greater than 99999"), // read_line_number
/* 99 */ _("Line with g10 does not have l2"), // check_g_codes
/* 100 */ _("M code greater than 199"), // read_m
/* 101 */ _("Mixed radius ijk format for arc"), // convert_arc
/* 102 */ _("Multiple a words on one line"), // read_a
/* 103 */ _("Multiple b words on one line"), // read_b
/* 104 */ _("Multiple c words on one line"), // read_c
/* 105 */ _("Multiple d words on one line"), // read_d
/* 106 */ _("Multiple f words on one line"), // read_f
/* 107 */ _("Multiple h words on one line"), // read_h
/* 108 */ _("Multiple i words on one line"), // read_i
/* 109 */ _("Multiple j words on one line"), // read_j
/* 110 */ _("Multiple k words on one line"), // read_k
/* 111 */ _("Multiple l words on one line"), // read_l
/* 112 */ _("Multiple p words on one line"), // read_p
/* 113 */ _("Multiple q words on one line"), // read_q
/* 114 */ _("Multiple r words on one line"), // read_r
/* 115 */ _("Multiple s words on one line"), // read_s
/* 116 */ _("Multiple t words on one line"), // read_t
/* 117 */ _("Multiple x words on one line"), // read_x
/* 118 */ _("Multiple y words on one line"), // read_y
/* 119 */ _("Multiple z words on one line"), // read_z
/* 120 */ _("Must use g0 or g1 with g53"), // check_g_codes
/* 121 */ _("Negative argument to sqrt"), // execute_unary
/* 122 */ _("Negative d word tool radius index used"), // read_d
/* 123 */ _("Negative f word used"), // read_f
/* 124 */ _("Negative g code used"), // read_g
/* 125 */ _("Negative h word tool length offset index used"), // read_h
/* 126 */ _("Negative l word used"), // read_l
/* 127 */ _("Negative m code used"), // read_m
/* 128 */ _("Negative or zero q value used"), // read_q
/* 129 */ _("Negative p word used"), // read_p
/* 130 */ _("Negative spindle speed used"), // read_s
/* 131 */ _("Negative tool id used"), // read_t
/* 132 */ _("Nested comment found"), // close_and_downcase
/* 133 */ _("No characters found in reading real value"), // read_real_value
/* 134 */ _("No digits found where real number should be"), // read_real_number
/* 135 */ _("Non integer value for integer"), // read_integer_value
/* 136 */ _("Null missing after newline"), // close_and_downcase
/* 137 */ _("Offset index missing"), // convert_tool_length_offset
/* 138 */ _("P value not an integer with g10 l2"), // check_g_codes
/* 139 */ _("P value out of range with g10 l2"), // check_g_codes
/* 140 */ _("P word with no g4 g10 g82 g86 g88 g89"), // check_other_codes
/* 141 */ _("Parameter file out of order"), // rs274ngc_restore_parameters, rs274ngc_save_parameters
/* 142 */ _("Parameter number out of range"), // read_parameter, read_parameter_setting, rs274ngc_restore_parameters, rs274ngc_save_parameters
/* 143 */ _("Q word missing with g83"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 144 */ _("Q word with no g83"), // check_other_codes
/* 145 */ _("Queue is not empty after probing"), // rs274ngc_read
/* 146 */ _("R clearance plane unspecified in cycle"), // convert_cycle
/* 147 */ _("R i j k words all missing for arc"), // convert_arc
/* 148 */ _("R less than x in cycle in yz plane"), // convert_cycle_yz
/* 149 */ _("R less than y in cycle in xz plane"), // convert_cycle_zx
/* 150 */ _("R less than z in cycle in xy plane"), // convert_cycle_xy
/* 151 */ _("R word with no g code that uses it"), // check_other_codes
/* 152 */ _("Radius to end of arc differs from radius to start"), // arc_data_comp_ijk, arc_data_ijk
/* 153 */ _("Radius too small to reach end point"), // arc_data_comp_r
/* 154 */ _("Required parameter missing"), // rs274ngc_restore_parameters
/* 155 */ _("Selected tool slot number too large"), // convert_tool_select
/* 156 */ _("Slash missing after first atan argument"), // read_atan
/* 157 */ _("Spindle not turning clockwise in g84"), // convert_cycle_g84
/* 158 */ _("Spindle not turning in g86"), // convert_cycle_g86
/* 159 */ _("Spindle not turning in g87"), // convert_cycle_g87
/* 160 */ _("Spindle not turning in g88"), // convert_cycle_g88
/* 161 */ _("Sscanf failed"), // read_integer_unsigned, read_real_number
/* 162 */ _("Start point too close to probe point"), // convert_probe
/* 163 */ _("Too many m codes on line"), // check_m_codes
/* 164 */ _("Tool length offset index too big"), // read_h
/* 165 */ _("Tool max too large"), // rs274ngc_load_tool_table
/* 166 */ _("Tool radius index too big"), // read_d
/* 167 */ _("Tool radius not less than arc radius with comp"), // arc_data_comp_r, convert_arc_comp2
/* 168 */ _("Two g codes used from same modal group"), // read_g
/* 169 */ _("Two m codes used from same modal group"), // read_m
/* 170 */ _("Unable to open file"), // convert_stop, rs274ngc_open, rs274ngc_restore_parameters
/* 171 */ _("Unclosed comment found"), // close_and_downcase
/* 172 */ _("Unclosed expression"), // read_operation
/* 173 */ _("Unknown g code used"), // read_g
/* 174 */ _("Unknown m code used"), // read_m
/* 175 */ _("Unknown operation"), // read_operation
/* 176 */ _("Unknown operation name starting with a"), // read_operation
/* 177 */ _("Unknown operation name starting with m"), // read_operation
/* 178 */ _("Unknown operation name starting with o"), // read_operation
/* 179 */ _("Unknown operation name starting with x"), // read_operation
/* 180 */ _("Unknown word starting with a"), // read_operation_unary
/* 181 */ _("Unknown word starting with c"), // read_operation_unary
/* 182 */ _("Unknown word starting with e"), // read_operation_unary
/* 183 */ _("Unknown word starting with f"), // read_operation_unary
/* 184 */ _("Unknown word starting with l"), // read_operation_unary
/* 185 */ _("Unknown word starting with r"), // read_operation_unary
/* 186 */ _("Unknown word starting with s"), // read_operation_unary
/* 187 */ _("Unknown word starting with t"), // read_operation_unary
/* 188 */ _("Unknown word where unary operation could be"), // read_operation_unary
/* 189 */ _("X and y words missing for arc in xy plane"), // convert_arc
/* 190 */ _("X and z words missing for arc in xz plane"), // convert_arc
/* 191 */ _("X value unspecified in yz plane canned cycle"), // convert_cycle_yz
/* 192 */ _("X y and z words all missing with g38 2"), // convert_probe
/* 193 */ _("Y and z words missing for arc in yz plane"), // convert_arc
/* 194 */ _("Y value unspecified in xz plane canned cycle"), // convert_cycle_zx
/* 195 */ _("Z value unspecified in xy plane canned cycle"), // convert_cycle_xy
/* 196 */ _("Zero or negative argument to ln"), // execute_unary
/* 197 */ _("Zero radius arc"), // arc_data_ijk
/* 198 */ _("K word missing with g33"), // check_other_codes
/* 199 */ _("F word used with a g33"), // check_other_codes
/* 200 */ _("G33 not supported"), // convert_straight
/* 201 */ _("Canned cycles not supported"), // check_other_codes
/* 202 */ _("Unknown error"), // dummy
_("The End")};
// *INDENT-ON*
/********************************************************************
* Description: rs274ngc_errors.cc
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
// #INDENT-OFF*
#include <libintl.h>
#ifdef USE_NLS
#define _(string) gettext(string)
#else
#define _(string) (string)
#endif
char * _rs274ngc_errors[] = {
/* 0 */ _("No error"),
/* 1 */ _("No error"),
/* 2 */ _("No error"),
/* 3 */ _("No error"),
/* 4 */ _("A file is already open"), // rs274ngc_open
/* 5 */ _("All axes missing with g92"), // enhance_block
/* 6 */ _("All axes missing with motion code"), // enhance_block
/* 7 */ _("Arc radius too small to reach end point"), // arc_data_r
/* 8 */ _("Argument to acos out of range"), // execute_unary
/* 9 */ _("Argument to asin out of range"), // execute_unary
/* 10 */ _("Attempt to divide by zero"), // execute_binary1
/* 11 */ _("Attempt to raise negative to non integer power"), // execute_binary1
/* 12 */ _("Bad character used"), // read_one_item
/* 13 */ _("Bad format unsigned integer"), // read_integer_unsigned
/* 14 */ _("Bad number format"), // read_real_number
/* 15 */ _("Bug bad g code modal group 0"), // check_g_codes
/* 16 */ _("Bug code not g0 or g1"), // convert_straight, convert_straight_comp1, convert_straight_comp2
/* 17 */ _("Bug code not g17 g18 or g19"), // convert_set_plane
/* 18 */ _("Bug code not g20 or g21"), // convert_length_units
/* 19 */ _("Bug code not g28 or g30"), // convert_home
/* 20 */ _("Bug code not g2 or g3"), // arc_data_comp_ijk, arc_data_ijk
/* 21 */ _("Bug code not g40 g41 or g42"), // convert_cutter_compensation
/* 22 */ _("Bug code not g43 or g49"), // convert_tool_length_offset
/* 23 */ _("Bug code not g4 g10 g28 g30 g53 or g92 series"), // convert_modal_0
/* 24 */ _("Bug code not g61 g61 1 or g64"), // convert_control_mode
/* 25 */ _("Bug code not g90 or g91"), // convert_distance_mode
/* 26 */ _("Bug code not g93 or g94"), // convert_feed_mode
/* 27 */ _("Bug code not g98 or g99"), // convert_retract_mode
/* 28 */ _("Bug code not in g92 series"), // convert_axis_offsets
/* 29 */ _("Bug code not in range g54 to g593"), // convert_coordinate_system
/* 30 */ _("Bug code not m0 m1 m2 m30 m60"), // convert_stop
/* 31 */ _("Bug distance mode not g90 or g91"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 32 */ _("Bug function should not have been called"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx, read_a, read_b, read_c, read_comment, read_d, read_f, read_g, read_h, read_i, read_j, read_k, read_l, read_line_number, read_m, read_p, read_parameter, read_parameter_setting, read_q, read_r, read_real_expression, read_s, read_t, read_x, read_y, read_z
/* 33 */ _("Bug in tool radius comp"), // arc_data_comp_r
/* 34 */ _("Bug plane not xy yz or xz"), // convert_arc, convert_cycle
/* 35 */ _("Bug side not right or left"), // convert_straight_comp1, convert_straight_comp2
/* 36 */ _("Bug unknown motion code"), // convert_motion
/* 37 */ _("Bug unknown operation"), // execute_binary1, execute_binary2, execute_unary
/* 38 */ _("Cannot change axis offsets with cutter radius comp"), // convert_axis_offsets
/* 39 */ _("Cannot change units with cutter radius comp"), // convert_length_units
/* 40 */ _("Cannot create backup file"), // rs274ngc_save_parameters
/* 41 */ _("Cannot do g1 with zero feed rate"), // convert_straight
/* 42 */ _("Cannot do zero repeats of cycle"), // convert_cycle
/* 43 */ _("Cannot make arc with zero feed rate"), // convert_arc
/* 44 */ _("Cannot move rotary axes during probing"), // convert_probe
/* 45 */ _("Cannot open backup file"), // rs274ngc_save_parameters
/* 46 */ _("Cannot open variable file"), // rs274ngc_save_parameters
/* 47 */ _("Cannot probe in inverse time feed mode"), // convert_probe
/* 48 */ _("Cannot probe with cutter radius comp on"), // convert_probe
/* 49 */ _("Cannot probe with zero feed rate"), // convert_probe
/* 50 */ _("Cannot put a b in canned cycle"), // check_other_codes
/* 51 */ _("Cannot put a c in canned cycle"), // check_other_codes
/* 52 */ _("Cannot put an a in canned cycle"), // check_other_codes
/* 53 */ _("Cannot turn cutter radius comp on out of xy plane"), // convert_cutter_compensation_on
/* 54 */ _("Cannot turn cutter radius comp on when on"), // convert_cutter_compensation_on
/* 55 */ _("Cannot use a word"), // read_a
/* 56 */ _("Cannot use axis values with g80"), // enhance_block
/* 57 */ _("Cannot use axis values without a g code that uses them"), // enhance_block
/* 58 */ _("Cannot use b word"), // read_b
/* 59 */ _("Cannot use c word"), // read_c
/* 60 */ _("Cannot use g28 or g30 with cutter radius comp"), // convert_home
/* 61 */ _("Cannot use g53 incremental"), // check_g_codes
/* 62 */ _("Cannot use g53 with cutter radius comp"), // convert_straight
/* 63 */ _("Cannot use two g codes that both use axis values"), // enhance_block
/* 64 */ _("Cannot use xz plane with cutter radius comp"), // convert_set_plane
/* 65 */ _("Cannot use yz plane with cutter radius comp"), // convert_set_plane
/* 66 */ _("Command too long"), // read_text, rs274ngc_open
/* 67 */ _("Concave corner with cutter radius comp"), // convert_arc_comp2, convert_straight_comp2
/* 68 */ _("Coordinate system index parameter 5220 out of range"), // rs274ngc_init
/* 69 */ _("Current point same as end point of arc"), // arc_data_r
/* 70 */ _("Cutter gouging with cutter radius comp"), // convert_arc_comp1, convert_straight_comp1
/* 71 */ _("D word with no g41 or g42"), // check_other_codes
/* 72 */ _("Dwell time missing with g4"), // check_g_codes
/* 73 */ _("Dwell time p word missing with g82"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 74 */ _("Dwell time p word missing with g86"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 75 */ _("Dwell time p word missing with g88"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 76 */ _("Dwell time p word missing with g89"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 77 */ _("Equal sign missing in parameter setting"), // read_parameter_setting
/* 78 */ _("F word missing with inverse time arc move"), // convert_arc
/* 79 */ _("F word missing with inverse time g1 move"), // convert_straight
/* 80 */ _("File ended with no percent sign"), // read_text, rs274ngc_open
/* 81 */ _("File ended with no percent sign or program end"), // read_text
/* 82 */ _("File name too long"), // rs274ngc_open
/* 83 */ _("File not open"), // rs274ngc_read
/* 84 */ _("G code out of range"), // read_g
/* 85 */ _("H word with no g43"), // check_other_codes
/* 86 */ _("I word given for arc in yz plane"), // convert_arc
/* 87 */ _("I word missing with g87"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 88 */ _("I word with no g2, g3 or g87 to use it"), // check_other_codes
/* 89 */ _("J word given for arc in xz plane"), // convert_arc
/* 90 */ _("J word missing with g87"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 91 */ _("J word with no g2, g3 or g87 to use it"), // check_other_codes
/* 92 */ _("K word given for arc in xy plane"), // convert_arc
/* 93 */ _("K word missing with g87"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 94 */ _("K word with no g2, g3, g33, or g87 to use it"), // check_other_codes
/* 95 */ _("L word with no canned cycle or g10"), // check_other_codes
/* 96 */ _("Left bracket missing after slash with atan"), // read_atan
/* 97 */ _("Left bracket missing after unary operation name"), // read_unary
/* 98 */ _("Line number greater than 99999"), // read_line_number
/* 99 */ _("Line with g10 does not have l2"), // check_g_codes
/* 100 */ _("M code greater than 199"), // read_m
/* 101 */ _("Mixed radius ijk format for arc"), // convert_arc
/* 102 */ _("Multiple a words on one line"), // read_a
/* 103 */ _("Multiple b words on one line"), // read_b
/* 104 */ _("Multiple c words on one line"), // read_c
/* 105 */ _("Multiple d words on one line"), // read_d
/* 106 */ _("Multiple f words on one line"), // read_f
/* 107 */ _("Multiple h words on one line"), // read_h
/* 108 */ _("Multiple i words on one line"), // read_i
/* 109 */ _("Multiple j words on one line"), // read_j
/* 110 */ _("Multiple k words on one line"), // read_k
/* 111 */ _("Multiple l words on one line"), // read_l
/* 112 */ _("Multiple p words on one line"), // read_p
/* 113 */ _("Multiple q words on one line"), // read_q
/* 114 */ _("Multiple r words on one line"), // read_r
/* 115 */ _("Multiple s words on one line"), // read_s
/* 116 */ _("Multiple t words on one line"), // read_t
/* 117 */ _("Multiple x words on one line"), // read_x
/* 118 */ _("Multiple y words on one line"), // read_y
/* 119 */ _("Multiple z words on one line"), // read_z
/* 120 */ _("Must use g0 or g1 with g53"), // check_g_codes
/* 121 */ _("Negative argument to sqrt"), // execute_unary
/* 122 */ _("Negative d word tool radius index used"), // read_d
/* 123 */ _("Negative f word used"), // read_f
/* 124 */ _("Negative g code used"), // read_g
/* 125 */ _("Negative h word tool length offset index used"), // read_h
/* 126 */ _("Negative l word used"), // read_l
/* 127 */ _("Negative m code used"), // read_m
/* 128 */ _("Negative or zero q value used"), // read_q
/* 129 */ _("Negative p word used"), // read_p
/* 130 */ _("Negative spindle speed used"), // read_s
/* 131 */ _("Negative tool id used"), // read_t
/* 132 */ _("Nested comment found"), // close_and_downcase
/* 133 */ _("No characters found in reading real value"), // read_real_value
/* 134 */ _("No digits found where real number should be"), // read_real_number
/* 135 */ _("Non integer value for integer"), // read_integer_value
/* 136 */ _("Null missing after newline"), // close_and_downcase
/* 137 */ _("Offset index missing"), // convert_tool_length_offset
/* 138 */ _("P value not an integer with g10 l2"), // check_g_codes
/* 139 */ _("P value out of range with g10 l2"), // check_g_codes
/* 140 */ _("P word with no g4 g10 g82 g86 g88 g89"), // check_other_codes
/* 141 */ _("Parameter file out of order"), // rs274ngc_restore_parameters, rs274ngc_save_parameters
/* 142 */ _("Parameter number out of range"), // read_parameter, read_parameter_setting, rs274ngc_restore_parameters, rs274ngc_save_parameters
/* 143 */ _("Q word missing with g83"), // convert_cycle_xy, convert_cycle_yz, convert_cycle_zx
/* 144 */ _("Q word with no g83"), // check_other_codes
/* 145 */ _("Queue is not empty after probing"), // rs274ngc_read
/* 146 */ _("R clearance plane unspecified in cycle"), // convert_cycle
/* 147 */ _("R i j k words all missing for arc"), // convert_arc
/* 148 */ _("R less than x in cycle in yz plane"), // convert_cycle_yz
/* 149 */ _("R less than y in cycle in xz plane"), // convert_cycle_zx
/* 150 */ _("R less than z in cycle in xy plane"), // convert_cycle_xy
/* 151 */ _("R word with no g code that uses it"), // check_other_codes
/* 152 */ _("Radius to end of arc differs from radius to start"), // arc_data_comp_ijk, arc_data_ijk
/* 153 */ _("Radius too small to reach end point"), // arc_data_comp_r
/* 154 */ _("Required parameter missing"), // rs274ngc_restore_parameters
/* 155 */ _("Selected tool slot number too large"), // convert_tool_select
/* 156 */ _("Slash missing after first atan argument"), // read_atan
/* 157 */ _("Spindle not turning clockwise in g84"), // convert_cycle_g84
/* 158 */ _("Spindle not turning in g86"), // convert_cycle_g86
/* 159 */ _("Spindle not turning in g87"), // convert_cycle_g87
/* 160 */ _("Spindle not turning in g88"), // convert_cycle_g88
/* 161 */ _("Sscanf failed"), // read_integer_unsigned, read_real_number
/* 162 */ _("Start point too close to probe point"), // convert_probe
/* 163 */ _("Too many m codes on line"), // check_m_codes
/* 164 */ _("Tool length offset index too big"), // read_h
/* 165 */ _("Tool max too large"), // rs274ngc_load_tool_table
/* 166 */ _("Tool radius index too big"), // read_d
/* 167 */ _("Tool radius not less than arc radius with comp"), // arc_data_comp_r, convert_arc_comp2
/* 168 */ _("Two g codes used from same modal group"), // read_g
/* 169 */ _("Two m codes used from same modal group"), // read_m
/* 170 */ _("Unable to open file"), // convert_stop, rs274ngc_open, rs274ngc_restore_parameters
/* 171 */ _("Unclosed comment found"), // close_and_downcase
/* 172 */ _("Unclosed expression"), // read_operation
/* 173 */ _("Unknown g code used"), // read_g
/* 174 */ _("Unknown m code used"), // read_m
/* 175 */ _("Unknown operation"), // read_operation
/* 176 */ _("Unknown operation name starting with a"), // read_operation
/* 177 */ _("Unknown operation name starting with m"), // read_operation
/* 178 */ _("Unknown operation name starting with o"), // read_operation
/* 179 */ _("Unknown operation name starting with x"), // read_operation
/* 180 */ _("Unknown word starting with a"), // read_operation_unary
/* 181 */ _("Unknown word starting with c"), // read_operation_unary
/* 182 */ _("Unknown word starting with e"), // read_operation_unary
/* 183 */ _("Unknown word starting with f"), // read_operation_unary
/* 184 */ _("Unknown word starting with l"), // read_operation_unary
/* 185 */ _("Unknown word starting with r"), // read_operation_unary
/* 186 */ _("Unknown word starting with s"), // read_operation_unary
/* 187 */ _("Unknown word starting with t"), // read_operation_unary
/* 188 */ _("Unknown word where unary operation could be"), // read_operation_unary
/* 189 */ _("X and y words missing for arc in xy plane"), // convert_arc
/* 190 */ _("X and z words missing for arc in xz plane"), // convert_arc
/* 191 */ _("X value unspecified in yz plane canned cycle"), // convert_cycle_yz
/* 192 */ _("X y and z words all missing with g38 2"), // convert_probe
/* 193 */ _("Y and z words missing for arc in yz plane"), // convert_arc
/* 194 */ _("Y value unspecified in xz plane canned cycle"), // convert_cycle_zx
/* 195 */ _("Z value unspecified in xy plane canned cycle"), // convert_cycle_xy
/* 196 */ _("Zero or negative argument to ln"), // execute_unary
/* 197 */ _("Zero radius arc"), // arc_data_ijk
/* 198 */ _("K word missing with g33"), // check_other_codes
/* 199 */ _("F word used with a g33"), // check_other_codes
/* 200 */ _("G33 not supported"), // convert_straight
/* 201 */ _("Canned cycles not supported"), // check_other_codes
/* 202 */ _("Unknown error"), // dummy
_("The End")};
// *INDENT-ON*

File diff suppressed because it is too large Load diff

View file

@ -1,241 +1,244 @@
/********************************************************************
* Description: rs274ngc_return.hh
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef RS274NGC_RETURN_H
#define RS274NGC_RETURN_H
#define RS274NGC_OK 0
#define RS274NGC_EXIT 1
#define RS274NGC_EXECUTE_FINISH 2
#define RS274NGC_ENDFILE 3
#define NCE_A_FILE_IS_ALREADY_OPEN 4
#define NCE_ALL_AXES_MISSING_WITH_G92 5
#define NCE_ALL_AXES_MISSING_WITH_MOTION_CODE 6
#define NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT 7
#define NCE_ARGUMENT_TO_ACOS_OUT_OF_RANGE 8
#define NCE_ARGUMENT_TO_ASIN_OUT_OF_RANGE 9
#define NCE_ATTEMPT_TO_DIVIDE_BY_ZERO 10
#define NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER 11
#define NCE_BAD_CHARACTER_USED 12
#define NCE_BAD_FORMAT_UNSIGNED_INTEGER 13
#define NCE_BAD_NUMBER_FORMAT 14
#define NCE_BUG_BAD_G_CODE_MODAL_GROUP_0 15
#define NCE_BUG_CODE_NOT_G0_OR_G1 16
#define NCE_BUG_CODE_NOT_G17_G18_OR_G19 17
#define NCE_BUG_CODE_NOT_G20_OR_G21 18
#define NCE_BUG_CODE_NOT_G28_OR_G30 19
#define NCE_BUG_CODE_NOT_G2_OR_G3 20
#define NCE_BUG_CODE_NOT_G40_G41_OR_G42 21
#define NCE_BUG_CODE_NOT_G43_OR_G49 22
#define NCE_BUG_CODE_NOT_G4_G10_G28_G30_G53_OR_G92_SERIES 23
#define NCE_BUG_CODE_NOT_G61_G61_1_OR_G64 24
#define NCE_BUG_CODE_NOT_G90_OR_G91 25
#define NCE_BUG_CODE_NOT_G93_OR_G94 26
#define NCE_BUG_CODE_NOT_G98_OR_G99 27
#define NCE_BUG_CODE_NOT_IN_G92_SERIES 28
#define NCE_BUG_CODE_NOT_IN_RANGE_G54_TO_G593 29
#define NCE_BUG_CODE_NOT_M0_M1_M2_M30_M60 30
#define NCE_BUG_DISTANCE_MODE_NOT_G90_OR_G91 31
#define NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 32
#define NCE_BUG_IN_TOOL_RADIUS_COMP 33
#define NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ 34
#define NCE_BUG_SIDE_NOT_RIGHT_OR_LEFT 35
#define NCE_BUG_UNKNOWN_MOTION_CODE 36
#define NCE_BUG_UNKNOWN_OPERATION 37
#define NCE_CANNOT_CHANGE_AXIS_OFFSETS_WITH_CUTTER_RADIUS_COMP 38
#define NCE_CANNOT_CHANGE_UNITS_WITH_CUTTER_RADIUS_COMP 39
#define NCE_CANNOT_CREATE_BACKUP_FILE 40
#define NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE 41
#define NCE_CANNOT_DO_ZERO_REPEATS_OF_CYCLE 42
#define NCE_CANNOT_MAKE_ARC_WITH_ZERO_FEED_RATE 43
#define NCE_CANNOT_MOVE_ROTARY_AXES_DURING_PROBING 44
#define NCE_CANNOT_OPEN_BACKUP_FILE 45
#define NCE_CANNOT_OPEN_VARIABLE_FILE 46
#define NCE_CANNOT_PROBE_IN_INVERSE_TIME_FEED_MODE 47
#define NCE_CANNOT_PROBE_WITH_CUTTER_RADIUS_COMP_ON 48
#define NCE_CANNOT_PROBE_WITH_ZERO_FEED_RATE 49
#define NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE 50
#define NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE 51
#define NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE 52
#define NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_OUT_OF_XY_PLANE 53
#define NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_WHEN_ON 54
#define NCE_CANNOT_USE_A_WORD 55
#define NCE_CANNOT_USE_AXIS_VALUES_WITH_G80 56
#define NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM 57
#define NCE_CANNOT_USE_B_WORD 58
#define NCE_CANNOT_USE_C_WORD 59
#define NCE_CANNOT_USE_G28_OR_G30_WITH_CUTTER_RADIUS_COMP 60
#define NCE_CANNOT_USE_G53_INCREMENTAL 61
#define NCE_CANNOT_USE_G53_WITH_CUTTER_RADIUS_COMP 62
#define NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES 63
#define NCE_CANNOT_USE_XZ_PLANE_WITH_CUTTER_RADIUS_COMP 64
#define NCE_CANNOT_USE_YZ_PLANE_WITH_CUTTER_RADIUS_COMP 65
#define NCE_COMMAND_TOO_LONG 66
#define NCE_CONCAVE_CORNER_WITH_CUTTER_RADIUS_COMP 67
#define NCE_COORDINATE_SYSTEM_INDEX_PARAMETER_5220_OUT_OF_RANGE 68
#define NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC 69
#define NCE_CUTTER_GOUGING_WITH_CUTTER_RADIUS_COMP 70
#define NCE_D_WORD_WITH_NO_G41_OR_G42 71
#define NCE_DWELL_TIME_MISSING_WITH_G4 72
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G82 73
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G86 74
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G88 75
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G89 76
#define NCE_EQUAL_SIGN_MISSING_IN_PARAMETER_SETTING 77
#define NCE_F_WORD_MISSING_WITH_INVERSE_TIME_ARC_MOVE 78
#define NCE_F_WORD_MISSING_WITH_INVERSE_TIME_G1_MOVE 79
#define NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN 80
#define NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN_OR_PROGRAM_END 81
#define NCE_FILE_NAME_TOO_LONG 82
#define NCE_FILE_NOT_OPEN 83
#define NCE_G_CODE_OUT_OF_RANGE 84
#define NCE_H_WORD_WITH_NO_G43 85
#define NCE_I_WORD_GIVEN_FOR_ARC_IN_YZ_PLANE 86
#define NCE_I_WORD_MISSING_WITH_G87 87
#define NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT 88
#define NCE_J_WORD_GIVEN_FOR_ARC_IN_XZ_PLANE 89
#define NCE_J_WORD_MISSING_WITH_G87 90
#define NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT 91
#define NCE_K_WORD_GIVEN_FOR_ARC_IN_XY_PLANE 92
#define NCE_K_WORD_MISSING_WITH_G87 93
#define NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT 94
#define NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10 95
#define NCE_LEFT_BRACKET_MISSING_AFTER_SLASH_WITH_ATAN 96
#define NCE_LEFT_BRACKET_MISSING_AFTER_UNARY_OPERATION_NAME 97
#define NCE_LINE_NUMBER_GREATER_THAN_99999 98
#define NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2 99
#define NCE_M_CODE_GREATER_THAN_199 100
#define NCE_MIXED_RADIUS_IJK_FORMAT_FOR_ARC 101
#define NCE_MULTIPLE_A_WORDS_ON_ONE_LINE 102
#define NCE_MULTIPLE_B_WORDS_ON_ONE_LINE 103
#define NCE_MULTIPLE_C_WORDS_ON_ONE_LINE 104
#define NCE_MULTIPLE_D_WORDS_ON_ONE_LINE 105
#define NCE_MULTIPLE_F_WORDS_ON_ONE_LINE 106
#define NCE_MULTIPLE_H_WORDS_ON_ONE_LINE 107
#define NCE_MULTIPLE_I_WORDS_ON_ONE_LINE 108
#define NCE_MULTIPLE_J_WORDS_ON_ONE_LINE 109
#define NCE_MULTIPLE_K_WORDS_ON_ONE_LINE 110
#define NCE_MULTIPLE_L_WORDS_ON_ONE_LINE 111
#define NCE_MULTIPLE_P_WORDS_ON_ONE_LINE 112
#define NCE_MULTIPLE_Q_WORDS_ON_ONE_LINE 113
#define NCE_MULTIPLE_R_WORDS_ON_ONE_LINE 114
#define NCE_MULTIPLE_S_WORDS_ON_ONE_LINE 115
#define NCE_MULTIPLE_T_WORDS_ON_ONE_LINE 116
#define NCE_MULTIPLE_X_WORDS_ON_ONE_LINE 117
#define NCE_MULTIPLE_Y_WORDS_ON_ONE_LINE 118
#define NCE_MULTIPLE_Z_WORDS_ON_ONE_LINE 119
#define NCE_MUST_USE_G0_OR_G1_WITH_G53 120
#define NCE_NEGATIVE_ARGUMENT_TO_SQRT 121
#define NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED 122
#define NCE_NEGATIVE_F_WORD_USED 123
#define NCE_NEGATIVE_G_CODE_USED 124
#define NCE_NEGATIVE_H_WORD_TOOL_LENGTH_OFFSET_INDEX_USED 125
#define NCE_NEGATIVE_L_WORD_USED 126
#define NCE_NEGATIVE_M_CODE_USED 127
#define NCE_NEGATIVE_OR_ZERO_Q_VALUE_USED 128
#define NCE_NEGATIVE_P_WORD_USED 129
#define NCE_NEGATIVE_SPINDLE_SPEED_USED 130
#define NCE_NEGATIVE_TOOL_ID_USED 131
#define NCE_NESTED_COMMENT_FOUND 132
#define NCE_NO_CHARACTERS_FOUND_IN_READING_REAL_VALUE 133
#define NCE_NO_DIGITS_FOUND_WHERE_REAL_NUMBER_SHOULD_BE 134
#define NCE_NON_INTEGER_VALUE_FOR_INTEGER 135
#define NCE_NULL_MISSING_AFTER_NEWLINE 136
#define NCE_OFFSET_INDEX_MISSING 137
#define NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2 138
#define NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2 139
#define NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89 140
#define NCE_PARAMETER_FILE_OUT_OF_ORDER 141
#define NCE_PARAMETER_NUMBER_OUT_OF_RANGE 142
#define NCE_Q_WORD_MISSING_WITH_G83 143
#define NCE_Q_WORD_WITH_NO_G83 144
#define NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING 145
#define NCE_R_CLEARANCE_PLANE_UNSPECIFIED_IN_CYCLE 146
#define NCE_R_I_J_K_WORDS_ALL_MISSING_FOR_ARC 147
#define NCE_R_LESS_THAN_X_IN_CYCLE_IN_YZ_PLANE 148
#define NCE_R_LESS_THAN_Y_IN_CYCLE_IN_XZ_PLANE 149
#define NCE_R_LESS_THAN_Z_IN_CYCLE_IN_XY_PLANE 150
#define NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT 151
#define NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START 152
#define NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT 153
#define NCE_REQUIRED_PARAMETER_MISSING 154
#define NCE_SELECTED_TOOL_SLOT_NUMBER_TOO_LARGE 155
#define NCE_SLASH_MISSING_AFTER_FIRST_ATAN_ARGUMENT 156
#define NCE_SPINDLE_NOT_TURNING_CLOCKWISE_IN_G84 157
#define NCE_SPINDLE_NOT_TURNING_IN_G86 158
#define NCE_SPINDLE_NOT_TURNING_IN_G87 159
#define NCE_SPINDLE_NOT_TURNING_IN_G88 160
#define NCE_SSCANF_FAILED 161
#define NCE_START_POINT_TOO_CLOSE_TO_PROBE_POINT 162
#define NCE_TOO_MANY_M_CODES_ON_LINE 163
#define NCE_TOOL_LENGTH_OFFSET_INDEX_TOO_BIG 164
#define NCE_TOOL_MAX_TOO_LARGE 165
#define NCE_TOOL_RADIUS_INDEX_TOO_BIG 166
#define NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP 167
#define NCE_TWO_G_CODES_USED_FROM_SAME_MODAL_GROUP 168
#define NCE_TWO_M_CODES_USED_FROM_SAME_MODAL_GROUP 169
#define NCE_UNABLE_TO_OPEN_FILE 170
#define NCE_UNCLOSED_COMMENT_FOUND 171
#define NCE_UNCLOSED_EXPRESSION 172
#define NCE_UNKNOWN_G_CODE_USED 173
#define NCE_UNKNOWN_M_CODE_USED 174
#define NCE_UNKNOWN_OPERATION 175
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_A 176
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_M 177
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_O 178
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_X 179
#define NCE_UNKNOWN_WORD_STARTING_WITH_A 180
#define NCE_UNKNOWN_WORD_STARTING_WITH_C 181
#define NCE_UNKNOWN_WORD_STARTING_WITH_E 182
#define NCE_UNKNOWN_WORD_STARTING_WITH_F 183
#define NCE_UNKNOWN_WORD_STARTING_WITH_L 184
#define NCE_UNKNOWN_WORD_STARTING_WITH_R 185
#define NCE_UNKNOWN_WORD_STARTING_WITH_S 186
#define NCE_UNKNOWN_WORD_STARTING_WITH_T 187
#define NCE_UNKNOWN_WORD_WHERE_UNARY_OPERATION_COULD_BE 188
#define NCE_X_AND_Y_WORDS_MISSING_FOR_ARC_IN_XY_PLANE 189
#define NCE_X_AND_Z_WORDS_MISSING_FOR_ARC_IN_XZ_PLANE 190
#define NCE_X_VALUE_UNSPECIFIED_IN_YZ_PLANE_CANNED_CYCLE 191
#define NCE_X_Y_AND_Z_WORDS_ALL_MISSING_WITH_G38_2 192
#define NCE_Y_AND_Z_WORDS_MISSING_FOR_ARC_IN_YZ_PLANE 193
#define NCE_Y_VALUE_UNSPECIFIED_IN_XZ_PLANE_CANNED_CYCLE 194
#define NCE_Z_VALUE_UNSPECIFIED_IN_XY_PLANE_CANNED_CYCLE 195
#define NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN 196
#define NCE_ZERO_RADIUS_ARC 197
#define NCE_K_WORD_MISSING_WITH_G33 198
#define NCE_F_WORD_USED_WITH_G33 199
#define NCE_G33_NOT_SUPPORTED 200
#define NCE_CANNED_CYCLES_NOT_SUPPORTED 201
#define RS274NGC_MIN_ERROR 3
#define RS274NGC_MAX_ERROR 202
/*
Modification history:
/********************************************************************
* Description: rs274ngc_return.hh
*
* Derived from a work by Thomas Kramer
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#ifndef RS274NGC_RETURN_H
#define RS274NGC_RETURN_H
#define RS274NGC_OK 0
#define RS274NGC_EXIT 1
#define RS274NGC_EXECUTE_FINISH 2
#define RS274NGC_ENDFILE 3
#define NCE_A_FILE_IS_ALREADY_OPEN 4
#define NCE_ALL_AXES_MISSING_WITH_G92 5
#define NCE_ALL_AXES_MISSING_WITH_MOTION_CODE 6
#define NCE_ARC_RADIUS_TOO_SMALL_TO_REACH_END_POINT 7
#define NCE_ARGUMENT_TO_ACOS_OUT_OF_RANGE 8
#define NCE_ARGUMENT_TO_ASIN_OUT_OF_RANGE 9
#define NCE_ATTEMPT_TO_DIVIDE_BY_ZERO 10
#define NCE_ATTEMPT_TO_RAISE_NEGATIVE_TO_NON_INTEGER_POWER 11
#define NCE_BAD_CHARACTER_USED 12
#define NCE_BAD_FORMAT_UNSIGNED_INTEGER 13
#define NCE_BAD_NUMBER_FORMAT 14
#define NCE_BUG_BAD_G_CODE_MODAL_GROUP_0 15
#define NCE_BUG_CODE_NOT_G0_OR_G1 16
#define NCE_BUG_CODE_NOT_G17_G18_OR_G19 17
#define NCE_BUG_CODE_NOT_G20_OR_G21 18
#define NCE_BUG_CODE_NOT_G28_OR_G30 19
#define NCE_BUG_CODE_NOT_G2_OR_G3 20
#define NCE_BUG_CODE_NOT_G40_G41_OR_G42 21
#define NCE_BUG_CODE_NOT_G43_OR_G49 22
#define NCE_BUG_CODE_NOT_G4_G10_G28_G30_G53_OR_G92_SERIES 23
#define NCE_BUG_CODE_NOT_G61_G61_1_OR_G64 24
#define NCE_BUG_CODE_NOT_G90_OR_G91 25
#define NCE_BUG_CODE_NOT_G93_OR_G94 26
#define NCE_BUG_CODE_NOT_G98_OR_G99 27
#define NCE_BUG_CODE_NOT_IN_G92_SERIES 28
#define NCE_BUG_CODE_NOT_IN_RANGE_G54_TO_G593 29
#define NCE_BUG_CODE_NOT_M0_M1_M2_M30_M60 30
#define NCE_BUG_DISTANCE_MODE_NOT_G90_OR_G91 31
#define NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED 32
#define NCE_BUG_IN_TOOL_RADIUS_COMP 33
#define NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ 34
#define NCE_BUG_SIDE_NOT_RIGHT_OR_LEFT 35
#define NCE_BUG_UNKNOWN_MOTION_CODE 36
#define NCE_BUG_UNKNOWN_OPERATION 37
#define NCE_CANNOT_CHANGE_AXIS_OFFSETS_WITH_CUTTER_RADIUS_COMP 38
#define NCE_CANNOT_CHANGE_UNITS_WITH_CUTTER_RADIUS_COMP 39
#define NCE_CANNOT_CREATE_BACKUP_FILE 40
#define NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE 41
#define NCE_CANNOT_DO_ZERO_REPEATS_OF_CYCLE 42
#define NCE_CANNOT_MAKE_ARC_WITH_ZERO_FEED_RATE 43
#define NCE_CANNOT_MOVE_ROTARY_AXES_DURING_PROBING 44
#define NCE_CANNOT_OPEN_BACKUP_FILE 45
#define NCE_CANNOT_OPEN_VARIABLE_FILE 46
#define NCE_CANNOT_PROBE_IN_INVERSE_TIME_FEED_MODE 47
#define NCE_CANNOT_PROBE_WITH_CUTTER_RADIUS_COMP_ON 48
#define NCE_CANNOT_PROBE_WITH_ZERO_FEED_RATE 49
#define NCE_CANNOT_PUT_A_B_IN_CANNED_CYCLE 50
#define NCE_CANNOT_PUT_A_C_IN_CANNED_CYCLE 51
#define NCE_CANNOT_PUT_AN_A_IN_CANNED_CYCLE 52
#define NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_OUT_OF_XY_PLANE 53
#define NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_WHEN_ON 54
#define NCE_CANNOT_USE_A_WORD 55
#define NCE_CANNOT_USE_AXIS_VALUES_WITH_G80 56
#define NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM 57
#define NCE_CANNOT_USE_B_WORD 58
#define NCE_CANNOT_USE_C_WORD 59
#define NCE_CANNOT_USE_G28_OR_G30_WITH_CUTTER_RADIUS_COMP 60
#define NCE_CANNOT_USE_G53_INCREMENTAL 61
#define NCE_CANNOT_USE_G53_WITH_CUTTER_RADIUS_COMP 62
#define NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES 63
#define NCE_CANNOT_USE_XZ_PLANE_WITH_CUTTER_RADIUS_COMP 64
#define NCE_CANNOT_USE_YZ_PLANE_WITH_CUTTER_RADIUS_COMP 65
#define NCE_COMMAND_TOO_LONG 66
#define NCE_CONCAVE_CORNER_WITH_CUTTER_RADIUS_COMP 67
#define NCE_COORDINATE_SYSTEM_INDEX_PARAMETER_5220_OUT_OF_RANGE 68
#define NCE_CURRENT_POINT_SAME_AS_END_POINT_OF_ARC 69
#define NCE_CUTTER_GOUGING_WITH_CUTTER_RADIUS_COMP 70
#define NCE_D_WORD_WITH_NO_G41_OR_G42 71
#define NCE_DWELL_TIME_MISSING_WITH_G4 72
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G82 73
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G86 74
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G88 75
#define NCE_DWELL_TIME_P_WORD_MISSING_WITH_G89 76
#define NCE_EQUAL_SIGN_MISSING_IN_PARAMETER_SETTING 77
#define NCE_F_WORD_MISSING_WITH_INVERSE_TIME_ARC_MOVE 78
#define NCE_F_WORD_MISSING_WITH_INVERSE_TIME_G1_MOVE 79
#define NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN 80
#define NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN_OR_PROGRAM_END 81
#define NCE_FILE_NAME_TOO_LONG 82
#define NCE_FILE_NOT_OPEN 83
#define NCE_G_CODE_OUT_OF_RANGE 84
#define NCE_H_WORD_WITH_NO_G43 85
#define NCE_I_WORD_GIVEN_FOR_ARC_IN_YZ_PLANE 86
#define NCE_I_WORD_MISSING_WITH_G87 87
#define NCE_I_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT 88
#define NCE_J_WORD_GIVEN_FOR_ARC_IN_XZ_PLANE 89
#define NCE_J_WORD_MISSING_WITH_G87 90
#define NCE_J_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT 91
#define NCE_K_WORD_GIVEN_FOR_ARC_IN_XY_PLANE 92
#define NCE_K_WORD_MISSING_WITH_G87 93
#define NCE_K_WORD_WITH_NO_G2_OR_G3_OR_G87_TO_USE_IT 94
#define NCE_L_WORD_WITH_NO_CANNED_CYCLE_OR_G10 95
#define NCE_LEFT_BRACKET_MISSING_AFTER_SLASH_WITH_ATAN 96
#define NCE_LEFT_BRACKET_MISSING_AFTER_UNARY_OPERATION_NAME 97
#define NCE_LINE_NUMBER_GREATER_THAN_99999 98
#define NCE_LINE_WITH_G10_DOES_NOT_HAVE_L2 99
#define NCE_M_CODE_GREATER_THAN_199 100
#define NCE_MIXED_RADIUS_IJK_FORMAT_FOR_ARC 101
#define NCE_MULTIPLE_A_WORDS_ON_ONE_LINE 102
#define NCE_MULTIPLE_B_WORDS_ON_ONE_LINE 103
#define NCE_MULTIPLE_C_WORDS_ON_ONE_LINE 104
#define NCE_MULTIPLE_D_WORDS_ON_ONE_LINE 105
#define NCE_MULTIPLE_F_WORDS_ON_ONE_LINE 106
#define NCE_MULTIPLE_H_WORDS_ON_ONE_LINE 107
#define NCE_MULTIPLE_I_WORDS_ON_ONE_LINE 108
#define NCE_MULTIPLE_J_WORDS_ON_ONE_LINE 109
#define NCE_MULTIPLE_K_WORDS_ON_ONE_LINE 110
#define NCE_MULTIPLE_L_WORDS_ON_ONE_LINE 111
#define NCE_MULTIPLE_P_WORDS_ON_ONE_LINE 112
#define NCE_MULTIPLE_Q_WORDS_ON_ONE_LINE 113
#define NCE_MULTIPLE_R_WORDS_ON_ONE_LINE 114
#define NCE_MULTIPLE_S_WORDS_ON_ONE_LINE 115
#define NCE_MULTIPLE_T_WORDS_ON_ONE_LINE 116
#define NCE_MULTIPLE_X_WORDS_ON_ONE_LINE 117
#define NCE_MULTIPLE_Y_WORDS_ON_ONE_LINE 118
#define NCE_MULTIPLE_Z_WORDS_ON_ONE_LINE 119
#define NCE_MUST_USE_G0_OR_G1_WITH_G53 120
#define NCE_NEGATIVE_ARGUMENT_TO_SQRT 121
#define NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED 122
#define NCE_NEGATIVE_F_WORD_USED 123
#define NCE_NEGATIVE_G_CODE_USED 124
#define NCE_NEGATIVE_H_WORD_TOOL_LENGTH_OFFSET_INDEX_USED 125
#define NCE_NEGATIVE_L_WORD_USED 126
#define NCE_NEGATIVE_M_CODE_USED 127
#define NCE_NEGATIVE_OR_ZERO_Q_VALUE_USED 128
#define NCE_NEGATIVE_P_WORD_USED 129
#define NCE_NEGATIVE_SPINDLE_SPEED_USED 130
#define NCE_NEGATIVE_TOOL_ID_USED 131
#define NCE_NESTED_COMMENT_FOUND 132
#define NCE_NO_CHARACTERS_FOUND_IN_READING_REAL_VALUE 133
#define NCE_NO_DIGITS_FOUND_WHERE_REAL_NUMBER_SHOULD_BE 134
#define NCE_NON_INTEGER_VALUE_FOR_INTEGER 135
#define NCE_NULL_MISSING_AFTER_NEWLINE 136
#define NCE_OFFSET_INDEX_MISSING 137
#define NCE_P_VALUE_NOT_AN_INTEGER_WITH_G10_L2 138
#define NCE_P_VALUE_OUT_OF_RANGE_WITH_G10_L2 139
#define NCE_P_WORD_WITH_NO_G4_G10_G82_G86_G88_G89 140
#define NCE_PARAMETER_FILE_OUT_OF_ORDER 141
#define NCE_PARAMETER_NUMBER_OUT_OF_RANGE 142
#define NCE_Q_WORD_MISSING_WITH_G83 143
#define NCE_Q_WORD_WITH_NO_G83 144
#define NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING 145
#define NCE_R_CLEARANCE_PLANE_UNSPECIFIED_IN_CYCLE 146
#define NCE_R_I_J_K_WORDS_ALL_MISSING_FOR_ARC 147
#define NCE_R_LESS_THAN_X_IN_CYCLE_IN_YZ_PLANE 148
#define NCE_R_LESS_THAN_Y_IN_CYCLE_IN_XZ_PLANE 149
#define NCE_R_LESS_THAN_Z_IN_CYCLE_IN_XY_PLANE 150
#define NCE_R_WORD_WITH_NO_G_CODE_THAT_USES_IT 151
#define NCE_RADIUS_TO_END_OF_ARC_DIFFERS_FROM_RADIUS_TO_START 152
#define NCE_RADIUS_TOO_SMALL_TO_REACH_END_POINT 153
#define NCE_REQUIRED_PARAMETER_MISSING 154
#define NCE_SELECTED_TOOL_SLOT_NUMBER_TOO_LARGE 155
#define NCE_SLASH_MISSING_AFTER_FIRST_ATAN_ARGUMENT 156
#define NCE_SPINDLE_NOT_TURNING_CLOCKWISE_IN_G84 157
#define NCE_SPINDLE_NOT_TURNING_IN_G86 158
#define NCE_SPINDLE_NOT_TURNING_IN_G87 159
#define NCE_SPINDLE_NOT_TURNING_IN_G88 160
#define NCE_SSCANF_FAILED 161
#define NCE_START_POINT_TOO_CLOSE_TO_PROBE_POINT 162
#define NCE_TOO_MANY_M_CODES_ON_LINE 163
#define NCE_TOOL_LENGTH_OFFSET_INDEX_TOO_BIG 164
#define NCE_TOOL_MAX_TOO_LARGE 165
#define NCE_TOOL_RADIUS_INDEX_TOO_BIG 166
#define NCE_TOOL_RADIUS_NOT_LESS_THAN_ARC_RADIUS_WITH_COMP 167
#define NCE_TWO_G_CODES_USED_FROM_SAME_MODAL_GROUP 168
#define NCE_TWO_M_CODES_USED_FROM_SAME_MODAL_GROUP 169
#define NCE_UNABLE_TO_OPEN_FILE 170
#define NCE_UNCLOSED_COMMENT_FOUND 171
#define NCE_UNCLOSED_EXPRESSION 172
#define NCE_UNKNOWN_G_CODE_USED 173
#define NCE_UNKNOWN_M_CODE_USED 174
#define NCE_UNKNOWN_OPERATION 175
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_A 176
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_M 177
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_O 178
#define NCE_UNKNOWN_OPERATION_NAME_STARTING_WITH_X 179
#define NCE_UNKNOWN_WORD_STARTING_WITH_A 180
#define NCE_UNKNOWN_WORD_STARTING_WITH_C 181
#define NCE_UNKNOWN_WORD_STARTING_WITH_E 182
#define NCE_UNKNOWN_WORD_STARTING_WITH_F 183
#define NCE_UNKNOWN_WORD_STARTING_WITH_L 184
#define NCE_UNKNOWN_WORD_STARTING_WITH_R 185
#define NCE_UNKNOWN_WORD_STARTING_WITH_S 186
#define NCE_UNKNOWN_WORD_STARTING_WITH_T 187
#define NCE_UNKNOWN_WORD_WHERE_UNARY_OPERATION_COULD_BE 188
#define NCE_X_AND_Y_WORDS_MISSING_FOR_ARC_IN_XY_PLANE 189
#define NCE_X_AND_Z_WORDS_MISSING_FOR_ARC_IN_XZ_PLANE 190
#define NCE_X_VALUE_UNSPECIFIED_IN_YZ_PLANE_CANNED_CYCLE 191
#define NCE_X_Y_AND_Z_WORDS_ALL_MISSING_WITH_G38_2 192
#define NCE_Y_AND_Z_WORDS_MISSING_FOR_ARC_IN_YZ_PLANE 193
#define NCE_Y_VALUE_UNSPECIFIED_IN_XZ_PLANE_CANNED_CYCLE 194
#define NCE_Z_VALUE_UNSPECIFIED_IN_XY_PLANE_CANNED_CYCLE 195
#define NCE_ZERO_OR_NEGATIVE_ARGUMENT_TO_LN 196
#define NCE_ZERO_RADIUS_ARC 197
#define NCE_K_WORD_MISSING_WITH_G33 198
#define NCE_F_WORD_USED_WITH_G33 199
#define NCE_G33_NOT_SUPPORTED 200
#define NCE_CANNED_CYCLES_NOT_SUPPORTED 201
#define RS274NGC_MIN_ERROR 3
#define RS274NGC_MAX_ERROR 202
/*
Modification history:
$Log$
Revision 1.6 2005/05/23 01:54:49 paul_c
Missed a few files in the last effort....
Revision 1.5 2005/05/23 00:29:12 paul_c
Remove any last trace of those M$ line terminators
Revision 1.4 2005/05/04 04:50:37 jmkasunich
Merged Pauls work from the lathe_fork branch. Compiles cleanly but completely untested. Changes include: G33 parsing, breaking interp into smaller files, using a C++ class for the interp, using LINELEN instead of many #defines for buffer lengths, and more
Revision 1.3 2005/04/27 20:03:13 proctor
Changed NCE_M_CODE_GREATER_THAN_99 to NCE_M_CODE_GREATER_THAN_199
*/
#endif /* RS274NGC_RETURN_H */
Revision 1.4 2005/05/04 04:50:37 jmkasunich
Merged Pauls work from the lathe_fork branch. Compiles cleanly but completely untested. Changes include: G33 parsing, breaking interp into smaller files, using a C++ class for the interp, using LINELEN instead of many #defines for buffer lengths, and more
Revision 1.3 2005/04/27 20:03:13 proctor
Changed NCE_M_CODE_GREATER_THAN_99 to NCE_M_CODE_GREATER_THAN_199
*/
#endif /* RS274NGC_RETURN_H */

File diff suppressed because it is too large Load diff

View file

@ -1,286 +1,286 @@
/********************************************************************
* Description: emcsvr.cc
* Network server for EMC NML
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <stdio.h> // sscanf()
#include <math.h> // fabs()
#include <stdlib.h> // exit()
#include <string.h> // strncpy()
#include "rcs.hh" // EMC NML
#include "emc.hh" // EMC NML
#include "emcglb.h" // emcGetArgs(), EMC_NMLFILE
static int iniLoad(const char *filename)
{
INIFILE inifile;
const char *inistring;
// open it
if (inifile.open(filename) != 0) {
return -1;
}
if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {
// copy to global
if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {
EMC_DEBUG = 0;
}
} else {
// not found, use default
EMC_DEBUG = 0;
}
if (EMC_DEBUG & EMC_DEBUG_RCS) {
// set_rcs_print_flag(PRINT_EVERYTHING);
max_rcs_errors_to_print = -1;
}
if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
// copy to global
strcpy(EMC_NMLFILE, inistring);
} else {
// not found, use default
}
// close it
inifile.close();
return 0;
}
static RCS_CMD_CHANNEL *emcCommandChannel = NULL;
static RCS_STAT_CHANNEL *emcStatusChannel = NULL;
static NML *emcErrorChannel = NULL;
static RCS_CMD_CHANNEL *toolCommandChannel = NULL;
static RCS_STAT_CHANNEL *toolStatusChannel = NULL;
static RCS_CMD_CHANNEL *auxCommandChannel = NULL;
static RCS_STAT_CHANNEL *auxStatusChannel = NULL;
static RCS_CMD_CHANNEL *lubeCommandChannel = NULL;
static RCS_STAT_CHANNEL *lubeStatusChannel = NULL;
static RCS_CMD_CHANNEL *spindleCommandChannel = NULL;
static RCS_STAT_CHANNEL *spindleStatusChannel = NULL;
static RCS_CMD_CHANNEL *coolantCommandChannel = NULL;
static RCS_STAT_CHANNEL *coolantStatusChannel = NULL;
int main(int argc, char *argv[])
{
double start_time;
// process command line args
if (0 != emcGetArgs(argc, argv)) {
rcs_print_error("Error in argument list\n");
exit(1);
}
// get configuration information
iniLoad(EMC_INIFILE);
set_rcs_print_destination(RCS_PRINT_TO_NULL);
start_time = etime();
while (fabs(etime() - start_time) < 10.0 &&
(emcCommandChannel == NULL || emcStatusChannel == NULL
|| toolCommandChannel == NULL || toolStatusChannel == NULL
|| emcErrorChannel == NULL)
) {
if (NULL == emcCommandChannel) {
emcCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcStatusChannel) {
emcStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcErrorChannel) {
emcErrorChannel =
new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
}
if (NULL == toolCommandChannel) {
toolCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == toolStatusChannel) {
toolStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == spindleCommandChannel) {
spindleCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "spindleCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == spindleStatusChannel) {
spindleStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "spindleSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == auxCommandChannel) {
auxCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == auxStatusChannel) {
auxStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "auxSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == coolantCommandChannel) {
coolantCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "coolantCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == coolantStatusChannel) {
coolantStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "coolantSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == lubeCommandChannel) {
lubeCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "lubeCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == lubeStatusChannel) {
lubeStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "lubeSts", "emcsvr",
EMC_NMLFILE);
}
if (!emcCommandChannel->valid()) {
delete emcCommandChannel;
emcCommandChannel = NULL;
}
if (!emcStatusChannel->valid()) {
delete emcStatusChannel;
emcStatusChannel = NULL;
}
if (!emcErrorChannel->valid()) {
delete emcErrorChannel;
emcErrorChannel = NULL;
}
if (!toolCommandChannel->valid()) {
delete toolCommandChannel;
toolCommandChannel = NULL;
}
if (!toolStatusChannel->valid()) {
delete toolStatusChannel;
toolStatusChannel = NULL;
}
if (!auxCommandChannel->valid()) {
delete auxCommandChannel;
auxCommandChannel = NULL;
}
if (!auxStatusChannel->valid()) {
delete auxStatusChannel;
auxStatusChannel = NULL;
}
if (!coolantCommandChannel->valid()) {
delete coolantCommandChannel;
coolantCommandChannel = NULL;
}
if (!coolantStatusChannel->valid()) {
delete coolantStatusChannel;
coolantStatusChannel = NULL;
}
if (!lubeCommandChannel->valid()) {
delete lubeCommandChannel;
lubeCommandChannel = NULL;
}
if (!lubeStatusChannel->valid()) {
delete lubeStatusChannel;
lubeStatusChannel = NULL;
}
if (!spindleCommandChannel->valid()) {
delete spindleCommandChannel;
spindleCommandChannel = NULL;
}
if (!spindleStatusChannel->valid()) {
delete spindleStatusChannel;
spindleStatusChannel = NULL;
}
esleep(0.200);
}
set_rcs_print_destination(RCS_PRINT_TO_STDERR);
if (NULL == emcCommandChannel) {
emcCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcStatusChannel) {
emcStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcErrorChannel) {
emcErrorChannel =
new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
}
if (NULL == toolCommandChannel) {
toolCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
}
if (NULL == toolStatusChannel) {
toolStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr", EMC_NMLFILE);
}
if (NULL == spindleCommandChannel) {
spindleCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "spindleCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == spindleStatusChannel) {
spindleStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "spindleSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == auxCommandChannel) {
auxCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "emcsvr", EMC_NMLFILE);
}
if (NULL == auxStatusChannel) {
auxStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "auxSts", "emcsvr", EMC_NMLFILE);
}
if (NULL == coolantCommandChannel) {
coolantCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "coolantCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == coolantStatusChannel) {
coolantStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "coolantSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == lubeCommandChannel) {
lubeCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "lubeCmd", "emcsvr", EMC_NMLFILE);
}
if (NULL == lubeStatusChannel) {
lubeStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "lubeSts", "emcsvr", EMC_NMLFILE);
}
run_nml_servers();
return 0;
}
/********************************************************************
* Description: emcsvr.cc
* Network server for EMC NML
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <stdio.h> // sscanf()
#include <math.h> // fabs()
#include <stdlib.h> // exit()
#include <string.h> // strncpy()
#include "rcs.hh" // EMC NML
#include "emc.hh" // EMC NML
#include "emcglb.h" // emcGetArgs(), EMC_NMLFILE
static int iniLoad(const char *filename)
{
INIFILE inifile;
const char *inistring;
// open it
if (inifile.open(filename) != 0) {
return -1;
}
if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {
// copy to global
if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {
EMC_DEBUG = 0;
}
} else {
// not found, use default
EMC_DEBUG = 0;
}
if (EMC_DEBUG & EMC_DEBUG_RCS) {
// set_rcs_print_flag(PRINT_EVERYTHING);
max_rcs_errors_to_print = -1;
}
if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
// copy to global
strcpy(EMC_NMLFILE, inistring);
} else {
// not found, use default
}
// close it
inifile.close();
return 0;
}
static RCS_CMD_CHANNEL *emcCommandChannel = NULL;
static RCS_STAT_CHANNEL *emcStatusChannel = NULL;
static NML *emcErrorChannel = NULL;
static RCS_CMD_CHANNEL *toolCommandChannel = NULL;
static RCS_STAT_CHANNEL *toolStatusChannel = NULL;
static RCS_CMD_CHANNEL *auxCommandChannel = NULL;
static RCS_STAT_CHANNEL *auxStatusChannel = NULL;
static RCS_CMD_CHANNEL *lubeCommandChannel = NULL;
static RCS_STAT_CHANNEL *lubeStatusChannel = NULL;
static RCS_CMD_CHANNEL *spindleCommandChannel = NULL;
static RCS_STAT_CHANNEL *spindleStatusChannel = NULL;
static RCS_CMD_CHANNEL *coolantCommandChannel = NULL;
static RCS_STAT_CHANNEL *coolantStatusChannel = NULL;
int main(int argc, char *argv[])
{
double start_time;
// process command line args
if (0 != emcGetArgs(argc, argv)) {
rcs_print_error("Error in argument list\n");
exit(1);
}
// get configuration information
iniLoad(EMC_INIFILE);
set_rcs_print_destination(RCS_PRINT_TO_NULL);
start_time = etime();
while (fabs(etime() - start_time) < 10.0 &&
(emcCommandChannel == NULL || emcStatusChannel == NULL
|| toolCommandChannel == NULL || toolStatusChannel == NULL
|| emcErrorChannel == NULL)
) {
if (NULL == emcCommandChannel) {
emcCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcStatusChannel) {
emcStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcErrorChannel) {
emcErrorChannel =
new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
}
if (NULL == toolCommandChannel) {
toolCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == toolStatusChannel) {
toolStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == spindleCommandChannel) {
spindleCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "spindleCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == spindleStatusChannel) {
spindleStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "spindleSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == auxCommandChannel) {
auxCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == auxStatusChannel) {
auxStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "auxSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == coolantCommandChannel) {
coolantCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "coolantCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == coolantStatusChannel) {
coolantStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "coolantSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == lubeCommandChannel) {
lubeCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "lubeCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == lubeStatusChannel) {
lubeStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "lubeSts", "emcsvr",
EMC_NMLFILE);
}
if (!emcCommandChannel->valid()) {
delete emcCommandChannel;
emcCommandChannel = NULL;
}
if (!emcStatusChannel->valid()) {
delete emcStatusChannel;
emcStatusChannel = NULL;
}
if (!emcErrorChannel->valid()) {
delete emcErrorChannel;
emcErrorChannel = NULL;
}
if (!toolCommandChannel->valid()) {
delete toolCommandChannel;
toolCommandChannel = NULL;
}
if (!toolStatusChannel->valid()) {
delete toolStatusChannel;
toolStatusChannel = NULL;
}
if (!auxCommandChannel->valid()) {
delete auxCommandChannel;
auxCommandChannel = NULL;
}
if (!auxStatusChannel->valid()) {
delete auxStatusChannel;
auxStatusChannel = NULL;
}
if (!coolantCommandChannel->valid()) {
delete coolantCommandChannel;
coolantCommandChannel = NULL;
}
if (!coolantStatusChannel->valid()) {
delete coolantStatusChannel;
coolantStatusChannel = NULL;
}
if (!lubeCommandChannel->valid()) {
delete lubeCommandChannel;
lubeCommandChannel = NULL;
}
if (!lubeStatusChannel->valid()) {
delete lubeStatusChannel;
lubeStatusChannel = NULL;
}
if (!spindleCommandChannel->valid()) {
delete spindleCommandChannel;
spindleCommandChannel = NULL;
}
if (!spindleStatusChannel->valid()) {
delete spindleStatusChannel;
spindleStatusChannel = NULL;
}
esleep(0.200);
}
set_rcs_print_destination(RCS_PRINT_TO_STDERR);
if (NULL == emcCommandChannel) {
emcCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcStatusChannel) {
emcStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr",
EMC_NMLFILE);
}
if (NULL == emcErrorChannel) {
emcErrorChannel =
new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
}
if (NULL == toolCommandChannel) {
toolCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
}
if (NULL == toolStatusChannel) {
toolStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr", EMC_NMLFILE);
}
if (NULL == spindleCommandChannel) {
spindleCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "spindleCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == spindleStatusChannel) {
spindleStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "spindleSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == auxCommandChannel) {
auxCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "emcsvr", EMC_NMLFILE);
}
if (NULL == auxStatusChannel) {
auxStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "auxSts", "emcsvr", EMC_NMLFILE);
}
if (NULL == coolantCommandChannel) {
coolantCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "coolantCmd", "emcsvr",
EMC_NMLFILE);
}
if (NULL == coolantStatusChannel) {
coolantStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "coolantSts", "emcsvr",
EMC_NMLFILE);
}
if (NULL == lubeCommandChannel) {
lubeCommandChannel =
new RCS_CMD_CHANNEL(emcFormat, "lubeCmd", "emcsvr", EMC_NMLFILE);
}
if (NULL == lubeStatusChannel) {
lubeStatusChannel =
new RCS_STAT_CHANNEL(emcFormat, "lubeSts", "emcsvr", EMC_NMLFILE);
}
run_nml_servers();
return 0;
}

View file

@ -1,457 +1,460 @@
/********************************************************************
* Description: emctask.cc
* Mode and state management for EMC_TASK class
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <stdlib.h>
#include <string.h> // strncpy()
#include <sys/stat.h> // struct stat
#include <unistd.h> // stat()
#include "rcs.hh" // INIFILE
#include "emc.hh" // EMC NML
#include "emcglb.h" // EMC_INIFILE
#include "interpl.hh" // NML_INTERP_LIST, interp_list
#include "canon.hh" // CANON_VECTOR, GET_PROGRAM_ORIGIN()
#include "rs274ngc.hh" // the interpreter
#include "rs274ngc_return.hh" // NCE_FILE_NOT_OPEN
/* flag for how we want to interpret traj coord mode, as mdi or auto */
static int mdiOrAuto = EMC_TASK_MODE_AUTO;
Interp interp;
// EMC_TASK interface
/*
format string for user-defined programs, e.g., "programs/M1%02d" means
user-defined programs are in the programs/ directory and are named
M1XX, where XX is a two-digit string.
*/
static char user_defined_fmt[EMC_SYSTEM_CMD_LEN] = "nc_files/M1%02d";
static void user_defined_add_m_code(int num, double arg1, double arg2)
{
char fmt[EMC_SYSTEM_CMD_LEN];
EMC_SYSTEM_CMD system_cmd;
strcpy(fmt, user_defined_fmt);
strcat(fmt, " %f %f");
sprintf(system_cmd.string, fmt, num, arg1, arg2);
interp_list.append(system_cmd);
}
int emcTaskInit()
{
int index;
char path[EMC_SYSTEM_CMD_LEN];
struct stat buf;
INIFILE inifile;
const char * inistring;
// read out directory where programs are located
inifile.open(EMC_INIFILE);
inistring = inifile.find("PROGRAM_PREFIX", "DISPLAY");
inifile.close();
// if we have a program prefix, override the default user_defined_fmt
// string with program prefix, then "M1%02d", e.g.
// nc_files/M101, where the %%02d means 2 digits after the M code
// and we need two % to get the literal %
if (NULL != inistring) {
sprintf(user_defined_fmt, "%sM1%%02d", inistring);
}
/* check for programs named programs/M100 .. programs/M199 and add
any to the user defined functions list */
for (index = 0; index < USER_DEFINED_FUNCTION_NUM; index++) {
sprintf(path, user_defined_fmt, index);
if (0 == stat(path, &buf)) {
if (buf.st_mode & S_IXUSR) {
USER_DEFINED_FUNCTION_ADD(user_defined_add_m_code, index);
if (EMC_DEBUG & EMC_DEBUG_CONFIG) {
rcs_print("emcTaskInit: adding user-defined function %s\n", path);
}
} else {
if (EMC_DEBUG & EMC_DEBUG_CONFIG) {
rcs_print("emcTaskInit: user-defined function %s found, but not executable, so ignoring\n", path);
}
}
}
}
return 0;
}
int emcTaskHalt()
{
return 0;
}
int emcTaskAbort()
{
emcMotionAbort();
emcIoAbort();
return 0;
}
int emcTaskSetMode(int mode)
{
int retval = 0;
switch (mode) {
case EMC_TASK_MODE_MANUAL:
// go to manual mode
emcTrajSetMode(EMC_TRAJ_MODE_FREE);
mdiOrAuto = EMC_TASK_MODE_AUTO; // we'll default back to here
break;
case EMC_TASK_MODE_MDI:
// go to mdi mode
emcTrajSetMode(EMC_TRAJ_MODE_COORD);
emcTaskPlanSynch();
mdiOrAuto = EMC_TASK_MODE_MDI;
break;
case EMC_TASK_MODE_AUTO:
// go to auto mode
emcTrajSetMode(EMC_TRAJ_MODE_COORD);
emcTaskPlanSynch();
mdiOrAuto = EMC_TASK_MODE_AUTO;
break;
default:
retval = -1;
break;
}
return retval;
}
int emcTaskSetState(int state)
{
int t;
int retval = 0;
switch (state) {
case EMC_TASK_STATE_OFF:
// turn the machine servos off-- go into ESTOP_RESET state
for (t = 0; t < emcStatus->motion.traj.axes; t++) {
emcAxisDisable(t);
}
emcTrajDisable();
emcLubeOff();
break;
case EMC_TASK_STATE_ON:
// turn the machine servos on
emcTrajEnable();
for (t = 0; t < emcStatus->motion.traj.axes; t++) {
emcAxisEnable(t);
}
emcLubeOn();
break;
case EMC_TASK_STATE_ESTOP_RESET:
// reset the estop
if (emcStatus->io.aux.estopIn) {
rcs_print
("Can't come out of estop while the estop button is in.");
}
emcAuxEstopOff();
emcLubeOff();
break;
case EMC_TASK_STATE_ESTOP:
// go into estop-- do both IO estop and machine servos off
emcAuxEstopOn();
for (t = 0; t < emcStatus->motion.traj.axes; t++) {
emcAxisDisable(t);
}
emcTrajDisable();
emcLubeOff();
break;
default:
retval = -1;
break;
}
return retval;
}
// WM access functions
/*
determineMode()
Looks at mode of subsystems, and returns associated mode
Depends on traj mode, and mdiOrAuto flag
traj mode mdiOrAuto mode
--------- --------- ----
FREE XXX MANUAL
COORD MDI MDI
COORD AUTO AUTO
*/
static int determineMode()
{
// if traj is in free mode, then we're in manual mode
if (emcStatus->motion.traj.mode == EMC_TRAJ_MODE_FREE ||
emcStatus->motion.traj.mode == EMC_TRAJ_MODE_TELEOP) {
return EMC_TASK_MODE_MANUAL;
}
// else traj is in coord mode-- we can be in either mdi or auto
return mdiOrAuto;
}
/*
determineState()
Looks at state of subsystems, and returns associated state
Depends on traj enabled, io estop, and desired task state
traj enabled io estop state
------------ -------- -----
DISABLED ESTOP ESTOP
ENABLED ESTOP ESTOP
DISABLED OUT OF ESTOP ESTOP_RESET
ENABLED OUT OF ESTOP ON
*/
static int determineState()
{
if (emcStatus->io.aux.estop) {
return EMC_TASK_STATE_ESTOP;
}
if (!emcStatus->motion.traj.enabled) {
return EMC_TASK_STATE_ESTOP_RESET;
}
return EMC_TASK_STATE_ON;
}
static int waitFlag = 0;
static char rs274ngc_error_text_buf[LINELEN];
static char rs274ngc_stack_buf[LINELEN];
static void print_rs274ngc_error(int retval)
{
int index = 0;
if (retval == 0) {
return;
}
if (0 != emcStatus) {
emcStatus->task.interpreter_errcode = retval;
}
rs274ngc_error_text_buf[0] = 0;
interp.rs274ngc_error_text(retval, rs274ngc_error_text_buf, LINELEN);
if (0 != rs274ngc_error_text_buf[0]) {
rcs_print_error("rs274ngc_error: %s\n", rs274ngc_error_text_buf);
}
emcOperatorError(0, rs274ngc_error_text_buf);
index = 0;
if (EMC_DEBUG & EMC_DEBUG_INTERP) {
rcs_print("rs274ngc_stack: \t");
while (index < 5) {
rs274ngc_stack_buf[0] = 0;
interp.rs274ngc_stack_name(index, rs274ngc_stack_buf, LINELEN);
if (0 == rs274ngc_stack_buf[0]) {
break;
}
rcs_print(" - %s ", rs274ngc_stack_buf);
index++;
}
rcs_print("\n");
}
}
int emcTaskPlanInit()
{
interp.rs274ngc_ini_load(EMC_INIFILE);
waitFlag = 0;
int retval = interp.rs274ngc_init();
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
} else {
if (0 != RS274NGC_STARTUP_CODE[0]) {
retval = interp.rs274ngc_execute(RS274NGC_STARTUP_CODE);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
}
}
return retval;
}
int emcTaskPlanSetWait()
{
waitFlag = 1;
return 0;
}
int emcTaskPlanIsWait()
{
return waitFlag;
}
int emcTaskPlanClearWait()
{
waitFlag = 0;
return 0;
}
int emcTaskPlanSynch()
{
return interp.rs274ngc_synch();
}
int emcTaskPlanExit()
{
return interp.rs274ngc_exit();
}
int emcTaskPlanOpen(const char *file)
{
if (emcStatus != 0) {
emcStatus->task.motionLine = 0;
emcStatus->task.currentLine = 0;
emcStatus->task.readLine = 0;
}
int retval = interp.rs274ngc_open(file);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
return retval;
}
taskplanopen = 1;
return retval;
}
int emcTaskPlanRead()
{
int retval = interp.rs274ngc_read();
if (retval == NCE_FILE_NOT_OPEN) {
if (emcStatus->task.file[0] != 0) {
retval = interp.rs274ngc_open(emcStatus->task.file);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
retval = interp.rs274ngc_read();
}
}
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
return retval;
}
int emcTaskPlanExecute(const char *command)
{
int inpos = emcStatus->motion.traj.inpos; // 1 if in position, 0 if not.
if(command != 0){ // Command is 0 if in AUTO mode, non-null if in MDI mode.
// Don't sync if not in position.
if ((*command != 0) && (inpos)){
interp.rs274ngc_synch();
}
}
int retval = interp.rs274ngc_execute(command);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
return retval;
}
int emcTaskPlanClose()
{
int retval = interp.rs274ngc_close();
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
taskplanopen = 0;
return retval;
}
int emcTaskPlanLine()
{
return interp.rs274ngc_line();
}
int emcTaskPlanCommand(char *cmd)
{
char buf[LINELEN];
strcpy(cmd, interp.rs274ngc_command(buf, LINELEN));
return 0;
}
int emcTaskUpdate(EMC_TASK_STAT * stat)
{
stat->mode = (enum EMC_TASK_MODE_ENUM) determineMode();
stat->state = (enum EMC_TASK_STATE_ENUM) determineState();
// execState set in main
// interpState set in main
if (emcStatus->motion.traj.id > 0) {
stat->motionLine = emcStatus->motion.traj.id;
}
// currentLine set in main
// readLine set in main
char buf[LINELEN];
strcpy(stat->file, interp.rs274ngc_file(buf, LINELEN));
// command set in main
// update active G and M codes
interp.rs274ngc_active_g_codes(&stat->activeGCodes[0]);
interp.rs274ngc_active_m_codes(&stat->activeMCodes[0]);
interp.rs274ngc_active_settings(&stat->activeSettings[0]);
stat->heartbeat++;
return 0;
}
/*
Modification history:
/********************************************************************
* Description: emctask.cc
* Mode and state management for EMC_TASK class
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
* $Revision$
* $Author$
* $Date$
********************************************************************/
#include <stdlib.h>
#include <string.h> // strncpy()
#include <sys/stat.h> // struct stat
#include <unistd.h> // stat()
#include "rcs.hh" // INIFILE
#include "emc.hh" // EMC NML
#include "emcglb.h" // EMC_INIFILE
#include "interpl.hh" // NML_INTERP_LIST, interp_list
#include "canon.hh" // CANON_VECTOR, GET_PROGRAM_ORIGIN()
#include "rs274ngc.hh" // the interpreter
#include "rs274ngc_return.hh" // NCE_FILE_NOT_OPEN
/* flag for how we want to interpret traj coord mode, as mdi or auto */
static int mdiOrAuto = EMC_TASK_MODE_AUTO;
Interp interp;
// EMC_TASK interface
/*
format string for user-defined programs, e.g., "programs/M1%02d" means
user-defined programs are in the programs/ directory and are named
M1XX, where XX is a two-digit string.
*/
static char user_defined_fmt[EMC_SYSTEM_CMD_LEN] = "nc_files/M1%02d";
static void user_defined_add_m_code(int num, double arg1, double arg2)
{
char fmt[EMC_SYSTEM_CMD_LEN];
EMC_SYSTEM_CMD system_cmd;
strcpy(fmt, user_defined_fmt);
strcat(fmt, " %f %f");
sprintf(system_cmd.string, fmt, num, arg1, arg2);
interp_list.append(system_cmd);
}
int emcTaskInit()
{
int index;
char path[EMC_SYSTEM_CMD_LEN];
struct stat buf;
INIFILE inifile;
const char * inistring;
// read out directory where programs are located
inifile.open(EMC_INIFILE);
inistring = inifile.find("PROGRAM_PREFIX", "DISPLAY");
inifile.close();
// if we have a program prefix, override the default user_defined_fmt
// string with program prefix, then "M1%02d", e.g.
// nc_files/M101, where the %%02d means 2 digits after the M code
// and we need two % to get the literal %
if (NULL != inistring) {
sprintf(user_defined_fmt, "%sM1%%02d", inistring);
}
/* check for programs named programs/M100 .. programs/M199 and add
any to the user defined functions list */
for (index = 0; index < USER_DEFINED_FUNCTION_NUM; index++) {
sprintf(path, user_defined_fmt, index);
if (0 == stat(path, &buf)) {
if (buf.st_mode & S_IXUSR) {
USER_DEFINED_FUNCTION_ADD(user_defined_add_m_code, index);
if (EMC_DEBUG & EMC_DEBUG_CONFIG) {
rcs_print("emcTaskInit: adding user-defined function %s\n", path);
}
} else {
if (EMC_DEBUG & EMC_DEBUG_CONFIG) {
rcs_print("emcTaskInit: user-defined function %s found, but not executable, so ignoring\n", path);
}
}
}
}
return 0;
}
int emcTaskHalt()
{
return 0;
}
int emcTaskAbort()
{
emcMotionAbort();
emcIoAbort();
return 0;
}
int emcTaskSetMode(int mode)
{
int retval = 0;
switch (mode) {
case EMC_TASK_MODE_MANUAL:
// go to manual mode
emcTrajSetMode(EMC_TRAJ_MODE_FREE);
mdiOrAuto = EMC_TASK_MODE_AUTO; // we'll default back to here
break;
case EMC_TASK_MODE_MDI:
// go to mdi mode
emcTrajSetMode(EMC_TRAJ_MODE_COORD);
emcTaskPlanSynch();
mdiOrAuto = EMC_TASK_MODE_MDI;
break;
case EMC_TASK_MODE_AUTO:
// go to auto mode
emcTrajSetMode(EMC_TRAJ_MODE_COORD);
emcTaskPlanSynch();
mdiOrAuto = EMC_TASK_MODE_AUTO;
break;
default:
retval = -1;
break;
}
return retval;
}
int emcTaskSetState(int state)
{
int t;
int retval = 0;
switch (state) {
case EMC_TASK_STATE_OFF:
// turn the machine servos off-- go into ESTOP_RESET state
for (t = 0; t < emcStatus->motion.traj.axes; t++) {
emcAxisDisable(t);
}
emcTrajDisable();
emcLubeOff();
break;
case EMC_TASK_STATE_ON:
// turn the machine servos on
emcTrajEnable();
for (t = 0; t < emcStatus->motion.traj.axes; t++) {
emcAxisEnable(t);
}
emcLubeOn();
break;
case EMC_TASK_STATE_ESTOP_RESET:
// reset the estop
if (emcStatus->io.aux.estopIn) {
rcs_print
("Can't come out of estop while the estop button is in.");
}
emcAuxEstopOff();
emcLubeOff();
break;
case EMC_TASK_STATE_ESTOP:
// go into estop-- do both IO estop and machine servos off
emcAuxEstopOn();
for (t = 0; t < emcStatus->motion.traj.axes; t++) {
emcAxisDisable(t);
}
emcTrajDisable();
emcLubeOff();
break;
default:
retval = -1;
break;
}
return retval;
}
// WM access functions
/*
determineMode()
Looks at mode of subsystems, and returns associated mode
Depends on traj mode, and mdiOrAuto flag
traj mode mdiOrAuto mode
--------- --------- ----
FREE XXX MANUAL
COORD MDI MDI
COORD AUTO AUTO
*/
static int determineMode()
{
// if traj is in free mode, then we're in manual mode
if (emcStatus->motion.traj.mode == EMC_TRAJ_MODE_FREE ||
emcStatus->motion.traj.mode == EMC_TRAJ_MODE_TELEOP) {
return EMC_TASK_MODE_MANUAL;
}
// else traj is in coord mode-- we can be in either mdi or auto
return mdiOrAuto;
}
/*
determineState()
Looks at state of subsystems, and returns associated state
Depends on traj enabled, io estop, and desired task state
traj enabled io estop state
------------ -------- -----
DISABLED ESTOP ESTOP
ENABLED ESTOP ESTOP
DISABLED OUT OF ESTOP ESTOP_RESET
ENABLED OUT OF ESTOP ON
*/
static int determineState()
{
if (emcStatus->io.aux.estop) {
return EMC_TASK_STATE_ESTOP;
}
if (!emcStatus->motion.traj.enabled) {
return EMC_TASK_STATE_ESTOP_RESET;
}
return EMC_TASK_STATE_ON;
}
static int waitFlag = 0;
static char rs274ngc_error_text_buf[LINELEN];
static char rs274ngc_stack_buf[LINELEN];
static void print_rs274ngc_error(int retval)
{
int index = 0;
if (retval == 0) {
return;
}
if (0 != emcStatus) {
emcStatus->task.interpreter_errcode = retval;
}
rs274ngc_error_text_buf[0] = 0;
interp.rs274ngc_error_text(retval, rs274ngc_error_text_buf, LINELEN);
if (0 != rs274ngc_error_text_buf[0]) {
rcs_print_error("rs274ngc_error: %s\n", rs274ngc_error_text_buf);
}
emcOperatorError(0, rs274ngc_error_text_buf);
index = 0;
if (EMC_DEBUG & EMC_DEBUG_INTERP) {
rcs_print("rs274ngc_stack: \t");
while (index < 5) {
rs274ngc_stack_buf[0] = 0;
interp.rs274ngc_stack_name(index, rs274ngc_stack_buf, LINELEN);
if (0 == rs274ngc_stack_buf[0]) {
break;
}
rcs_print(" - %s ", rs274ngc_stack_buf);
index++;
}
rcs_print("\n");
}
}
int emcTaskPlanInit()
{
interp.rs274ngc_ini_load(EMC_INIFILE);
waitFlag = 0;
int retval = interp.rs274ngc_init();
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
} else {
if (0 != RS274NGC_STARTUP_CODE[0]) {
retval = interp.rs274ngc_execute(RS274NGC_STARTUP_CODE);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
}
}
return retval;
}
int emcTaskPlanSetWait()
{
waitFlag = 1;
return 0;
}
int emcTaskPlanIsWait()
{
return waitFlag;
}
int emcTaskPlanClearWait()
{
waitFlag = 0;
return 0;
}
int emcTaskPlanSynch()
{
return interp.rs274ngc_synch();
}
int emcTaskPlanExit()
{
return interp.rs274ngc_exit();
}
int emcTaskPlanOpen(const char *file)
{
if (emcStatus != 0) {
emcStatus->task.motionLine = 0;
emcStatus->task.currentLine = 0;
emcStatus->task.readLine = 0;
}
int retval = interp.rs274ngc_open(file);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
return retval;
}
taskplanopen = 1;
return retval;
}
int emcTaskPlanRead()
{
int retval = interp.rs274ngc_read();
if (retval == NCE_FILE_NOT_OPEN) {
if (emcStatus->task.file[0] != 0) {
retval = interp.rs274ngc_open(emcStatus->task.file);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
retval = interp.rs274ngc_read();
}
}
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
return retval;
}
int emcTaskPlanExecute(const char *command)
{
int inpos = emcStatus->motion.traj.inpos; // 1 if in position, 0 if not.
if(command != 0){ // Command is 0 if in AUTO mode, non-null if in MDI mode.
// Don't sync if not in position.
if ((*command != 0) && (inpos)){
interp.rs274ngc_synch();
}
}
int retval = interp.rs274ngc_execute(command);
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
return retval;
}
int emcTaskPlanClose()
{
int retval = interp.rs274ngc_close();
if (retval > RS274NGC_MIN_ERROR) {
print_rs274ngc_error(retval);
}
taskplanopen = 0;
return retval;
}
int emcTaskPlanLine()
{
return interp.rs274ngc_line();
}
int emcTaskPlanCommand(char *cmd)
{
char buf[LINELEN];
strcpy(cmd, interp.rs274ngc_command(buf, LINELEN));
return 0;
}
int emcTaskUpdate(EMC_TASK_STAT * stat)
{
stat->mode = (enum EMC_TASK_MODE_ENUM) determineMode();
stat->state = (enum EMC_TASK_STATE_ENUM) determineState();
// execState set in main
// interpState set in main
if (emcStatus->motion.traj.id > 0) {
stat->motionLine = emcStatus->motion.traj.id;
}
// currentLine set in main
// readLine set in main
char buf[LINELEN];
strcpy(stat->file, interp.rs274ngc_file(buf, LINELEN));
// command set in main
// update active G and M codes
interp.rs274ngc_active_g_codes(&stat->activeGCodes[0]);
interp.rs274ngc_active_m_codes(&stat->activeMCodes[0]);
interp.rs274ngc_active_settings(&stat->activeSettings[0]);
stat->heartbeat++;
return 0;
}
/*
Modification history:
$Log$
Revision 1.8 2005/05/23 01:54:51 paul_c
Missed a few files in the last effort....
Revision 1.7 2005/05/23 00:29:13 paul_c
Remove any last trace of those M$ line terminators
Revision 1.6 2005/05/18 22:48:59 rumley
Fix for Bug 1171692, Odd behavoir in MDI mode.
Caused by rs274ngc_synch call when axis not 'inpos'
Revision 1.5 2005/05/04 04:50:38 jmkasunich
Merged Pauls work from the lathe_fork branch. Compiles cleanly but completely untested. Changes include: G33 parsing, breaking interp into smaller files, using a C++ class for the interp, using LINELEN instead of many #defines for buffer lengths, and more
Revision 1.4 2005/04/27 20:05:47 proctor
Added user-defined M codes, from BDI-4
*/
Revision 1.6 2005/05/18 22:48:59 rumley
Fix for Bug 1171692, Odd behavoir in MDI mode.
Caused by rs274ngc_synch call when axis not 'inpos'
Revision 1.5 2005/05/04 04:50:38 jmkasunich
Merged Pauls work from the lathe_fork branch. Compiles cleanly but completely untested. Changes include: G33 parsing, breaking interp into smaller files, using a C++ class for the interp, using LINELEN instead of many #defines for buffer lengths, and more
Revision 1.4 2005/04/27 20:05:47 proctor
Added user-defined M codes, from BDI-4
*/

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff