saicanon.cc

来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 1,223 行 · 第 1/3 页

CC
1,223
字号
/********************************************************************* Description: saicanon.cc** This file contains two sets of functions:* 1. functions for the interpreter to call to tell the rest of the world to* do something. These all return nothing.* 2. functions for the interpreter to call to get information from the rest* of the world. These all return some type of information.* These functions implement the interface between the RS274NGC interpreter* and some external environment.** This version of canon.cc also includes a third set of stuff: a dummy* model of the external world. The dummy model is used by the second set* of interface functions.** Modification history:** 22-Mar-2004  FMP added USER_DEFINED_FUNCTION(), SET_MOTION_OUTPUT_BIT()* and related* 16-Mar-2004  FMP added SYSTEM()* Early March 2007 MGS adapted this to emc2**   Derived from a work by Tom Kramer** Author:* License: GPL Version 2* System: Linux** Copyright (c) 2007 All rights reserved.** Last change:* $Revision: 1.13.2.1 $* $Author: jepler $* $Date: 2008/04/21 13:13:51 $*********************************************************************/#include "canon.hh"#include "rs274ngc.hh"#include <math.h>#include <stdio.h>#include <string.h>/* where to print *///extern FILE * _outfile;FILE * _outfile=NULL;      /* where to print, set in main *//* Dummy world model */static CANON_PLANE       _active_plane = CANON_PLANE_XY;static int               _active_slot = 1;static int               _feed_mode = 0;static double            _feed_rate = 0.0;static int               _flood = 0;static double            _length_unit_factor = 1; /* 1 for MM 25.4 for inch */static CANON_UNITS       _length_unit_type = CANON_UNITS_MM;static int               _line_number = 1;static int               _mist = 0;static CANON_MOTION_MODE _motion_mode = CANON_CONTINUOUS;char                     _parameter_file_name[PARAMETER_FILE_NAME_LENGTH];/*Not static.Driver writes*/#ifdef AAstatic double            _probe_position_a = 0; /*AA*/#endif#ifdef BBstatic double            _probe_position_b = 0; /*BB*/#endif#ifdef CCstatic double            _probe_position_c = 0; /*CC*/#endifstatic double            _probe_position_x = 0;static double            _probe_position_y = 0;static double            _probe_position_z = 0;#ifdef AAstatic double            _program_origin_a = 0; /*AA*/#endif#ifdef BBstatic double            _program_origin_b = 0; /*BB*/#endif#ifdef CCstatic double            _program_origin_c = 0; /*CC*/#endifstatic double            _program_origin_x = 0;static double            _program_origin_y = 0;static double            _program_origin_z = 0;#ifdef AAstatic double            _program_position_a = 0; /*AA*/#endif#ifdef BBstatic double            _program_position_b = 0; /*BB*/#endif#ifdef CCstatic double            _program_position_c = 0; /*CC*/#endifstatic double            _program_position_x = 0;static double            _program_position_y = 0;static double            _program_position_z = 0;static double            _spindle_speed;static CANON_DIRECTION   _spindle_turning;int                      _tool_max = CANON_TOOL_MAX; /*Not static. Driver reads  */CANON_TOOL_TABLE         _tools[CANON_TOOL_MAX]; /*Not static. Driver writes *//* optional program stop */static bool optional_program_stop = ON; //set enabled by default (previous EMC behaviour)/* optional block delete */static bool block_delete = ON; //set enabled by default (previous EMC behaviour)/* Dummy status variables */static double            _traverse_rate;static double _tool_xoffset, _tool_zoffset;/************************************************************************//* Canonical "Do it" functionsThis is a set of dummy definitions for the canonical machining functionsgiven in canon.hh. These functions just print themselves and, if necessary,update the dummy world model. On each output line is printed:1. an output line number (sequential, starting with 1).2. an input line number read from the input (or ... if not provided).3. a printed representation of the function call which was made.If an interpreter which makes these calls is compiled with this set ofdefinitions, it can be used as a translator by redirecting output fromstdout to a file.*///extern void rs274ngc_line_text(char * line_text, int max_size);extern Interp interp_new;void print_nc_line_number(){  char text[256];  int k;  int m;  if(NULL == _outfile)    {      _outfile = stdout;    }  interp_new.line_text(text, 256);  for (k = 0;       ((k < 256) &&        ((text[k] == '\t') || (text[k] == ' ') || (text[k] == '/')));       k++);  if ((k < 256) && ((text[k] == 'n') || (text[k] == 'N')))    {      fputc('N', _outfile);      for (k++, m = 0;           ((k < 256) && (text[k] >= '0') && (text[k] <= '9'));           k++, m++)        fputc(text[k], _outfile);      for (; m < 6; m++)        fputc(' ', _outfile);    }  else if (k < 256)    fprintf(_outfile, "N..... ");}#define PRINT0(control) if (1)                        \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++); \           print_nc_line_number();                    \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control);                \          } else#define PRINT1(control, arg1) if (1)                  \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++); \           print_nc_line_number();                    \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control, arg1);          \          } else#define PRINT2(control, arg1, arg2) if (1)            \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++); \           print_nc_line_number();                    \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control, arg1, arg2);    \          } else#define PRINT3(control, arg1, arg2, arg3) if (1)         \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++);    \           print_nc_line_number();                       \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control, arg1, arg2, arg3); \          } else#define PRINT4(control, arg1, arg2, arg3, arg4) if (1)         \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++);          \           print_nc_line_number();                             \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control, arg1, arg2, arg3, arg4); \          } else#define PRINT5(control, arg1, arg2, arg3, arg4, arg5) if (1)         \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++);                \           print_nc_line_number();                                   \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control, arg1, arg2, arg3, arg4, arg5); \          } else#define PRINT6(control, arg1, arg2, arg3, arg4, arg5, arg6) if (1)         \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++);                      \           print_nc_line_number();                                         \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control, arg1, arg2, arg3, arg4, arg5, arg6); \          } else#define PRINT7(control, arg1, arg2, arg3, arg4, arg5, arg6, arg7) if (1) \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++);                    \           print_nc_line_number();                                       \           {if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  control,                                    \                           arg1, arg2, arg3, arg4, arg5, arg6, arg7);    \          } else#define PRINT10(control,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) \          if (1)                                                            \          {{if(_outfile==NULL){_outfile=stdout;}} fprintf(_outfile,  "%5d ", _line_number++);                       \           print_nc_line_number();                                          \           fprintf(_outfile, control,                                       \                   arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10);     \          } else/* Representation */void SET_ORIGIN_OFFSETS( double x, double y, double z#ifdef AA , double a  /*AA*/#endif#ifdef BB , double b  /*BB*/#endif#ifdef CC , double c  /*CC*/#endif , double u, double v, double w){  fprintf(_outfile, "%5d ", _line_number++);  print_nc_line_number();  fprintf(_outfile, "SET_ORIGIN_OFFSETS(%.4f, %.4f, %.4f"#ifdef AA         ", %.4f"  /*AA*/#endif#ifdef BB         ", %.4f"  /*BB*/#endif#ifdef CC         ", %.4f"  /*CC*/#endif         ")\n", x, y, z#ifdef AA         , a  /*AA*/#endif#ifdef BB         , b  /*BB*/#endif#ifdef CC         , c  /*CC*/#endif         );  _program_position_x = _program_position_x + _program_origin_x - x;  _program_position_y = _program_position_y + _program_origin_y - y;  _program_position_z = _program_position_z + _program_origin_z - z;#ifdef AA  _program_position_a = _program_position_a + _program_origin_a - a;/*AA*/#endif#ifdef BB  _program_position_b = _program_position_b + _program_origin_b - b;/*BB*/#endif#ifdef CC  _program_position_c = _program_position_c + _program_origin_c - c;/*CC*/#endif  _program_origin_x = x;  _program_origin_y = y;  _program_origin_z = z;#ifdef AA  _program_origin_a = a;  /*AA*/#endif#ifdef BB  _program_origin_b = b;  /*BB*/#endif#ifdef CC  _program_origin_c = c;  /*CC*/#endif}void USE_LENGTH_UNITS(CANON_UNITS in_unit){  if (in_unit == CANON_UNITS_INCHES)    {      PRINT0("USE_LENGTH_UNITS(CANON_UNITS_INCHES)\n");      if (_length_unit_type == CANON_UNITS_MM)        {          _length_unit_type = CANON_UNITS_INCHES;          _length_unit_factor = 25.4;          _program_origin_x = (_program_origin_x / 25.4);          _program_origin_y = (_program_origin_y / 25.4);          _program_origin_z = (_program_origin_z / 25.4);          _program_position_x = (_program_position_x / 25.4);          _program_position_y = (_program_position_y / 25.4);          _program_position_z = (_program_position_z / 25.4);        }    }  else if (in_unit == CANON_UNITS_MM)    {      PRINT0("USE_LENGTH_UNITS(CANON_UNITS_MM)\n");      if (_length_unit_type == CANON_UNITS_INCHES)        {          _length_unit_type = CANON_UNITS_MM;          _length_unit_factor = 1.0;          _program_origin_x = (_program_origin_x * 25.4);          _program_origin_y = (_program_origin_y * 25.4);          _program_origin_z = (_program_origin_z * 25.4);          _program_position_x = (_program_position_x * 25.4);          _program_position_y = (_program_position_y * 25.4);          _program_position_z = (_program_position_z * 25.4);        }    }  else    PRINT0("USE_LENGTH_UNITS(UNKNOWN)\n");}/* Free Space Motion */void SET_TRAVERSE_RATE(double rate){  PRINT1("SET_TRAVERSE_RATE(%.4f)\n", rate);  _traverse_rate = rate;}void STRAIGHT_TRAVERSE( double x, double y, double z#ifdef AA , double a /*AA*/#endif#ifdef BB , double b /*BB*/#endif#ifdef CC , double c /*CC*/#endif , double u, double v, double w){  fprintf(_outfile, "%5d ", _line_number++);  print_nc_line_number();  fprintf(_outfile, "STRAIGHT_TRAVERSE(%.4f, %.4f, %.4f"#ifdef AA         ", %.4f" /*AA*/#endif#ifdef BB         ", %.4f" /*BB*/#endif#ifdef CC         ", %.4f" /*CC*/#endif         ")\n", x, y, z#ifdef AA         , a /*AA*/#endif#ifdef BB         , b /*BB*/#endif#ifdef CC         , c /*CC*/#endif         );  _program_position_x = x;  _program_position_y = y;  _program_position_z = z;#ifdef AA  _program_position_a = a; /*AA*/#endif#ifdef BB  _program_position_b = b; /*BB*/#endif#ifdef CC  _program_position_c = c; /*CC*/#endif}/* Machining Attributes */void SET_FEED_MODE(int mode){  PRINT1("SET_FEED_MODE(%d)\n", mode);  _feed_mode = mode;}void SET_FEED_RATE(double rate){  PRINT1("SET_FEED_RATE(%.4f)\n", rate);  _feed_rate = rate;}void SET_FEED_REFERENCE(CANON_FEED_REFERENCE reference){  PRINT1("SET_FEED_REFERENCE(%s)\n",         (reference == CANON_WORKPIECE) ? "CANON_WORKPIECE" : "CANON_XYZ");}extern void SET_MOTION_CONTROL_MODE(CANON_MOTION_MODE mode){  if (mode == CANON_EXACT_STOP)    {      PRINT0("SET_MOTION_CONTROL_MODE(CANON_EXACT_STOP)\n");      _motion_mode = CANON_EXACT_STOP;    }  else if (mode == CANON_EXACT_PATH)    {      PRINT0("SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH)\n");      _motion_mode = CANON_EXACT_PATH;    }  else if (mode == CANON_CONTINUOUS)    {      PRINT0("SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS)\n");      _motion_mode = CANON_CONTINUOUS;    }  else    PRINT0("SET_MOTION_CONTROL_MODE(UNKNOWN)\n");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?