📄 rs274ngc_pre.cc
字号:
/* rs274ngc.cc This rs274ngc.cc file contains the source code for (1) the kernel ofseveral rs274ngc interpreters and (2) two of the four sets of interfacefunctions declared in canon.hh:1. interface functions to call to tell the interpreter what to do. These all return a status value.2. interface functions to call to get information from the interpreter.Kernel functions call each other. A few kernel functions are called byinterface functions.Interface function names all begin with "rs274ngc_".Error handling is by returning a status value of either a non-errorcode (RS274NGC_OK, RS274NGC_EXIT, etc.) or some specific error codefrom each function where there is a possibility of error. If an erroroccurs, processing is always stopped, and control is passed back upthrough the function call hierarchy to an interface function; theerror code is also passed back up. The stack of functions called isalso recorded. The external program calling an interface function maythen handle the error further as it sees fit.Since returned values are usually used as just described to handle thepossibility of errors, an alternative method of passing calculatedvalues is required. In general, if function A needs a value forvariable V calculated by function B, this is handled by passing apointer to V from A to B, and B calculates and sets V.There are a lot of functions named read_XXXX. All such functions readcharacters from a string using a counter. They all reset the counterto point at the character in the string following the last one used bythe function. The counter is passed around from function to functionby using pointers to it. The first character read by each of thesefunctions is expected to be a member of some set of characters (oftena specific character), and each function checks the first character.This version of the interpreter not saving input lines. A list of alllines will be needed in future versions to implement loops, andprobably for other purposes.This version does not use any additional memory as it runs. Nomemory is allocated by the source code.This version does not suppress superfluous commands, such as a commandto start the spindle when the spindle is already turning, or a commandto turn on flood coolant, when flood coolant is already on. When theinterpreter is being used for direct control of the machining center,suppressing superfluous commands might confuse the user and could bedangerous, but when it is used to translate from one file to another,suppression can produce more concise output. Future versions mightinclude an option for suppressing superfluous commands.This file has been arranged typographically so that it may be usedfor compiling fifteen different executables. The file may be compiledas is for a six-axis interpreter. The file may be pre-preprocessedinto "pre.cc" by "prepre" (a lex-based pre-processor). Allfifteen executables may be compiled from the pre.cc file. The specialtypography items are:1. Any line with the comment /^AA^/, /^BB^/, or /^CC^/ at the end(where ^ is replaced by *).2. Calls to the canonical functions STRAIGHT_FEED, STRAIGHT_TRAVERSE,STRAIGHT_PROBE, and ARC_FEED. These are always set on two lineswith the rotary axes on the second line:3. Calls to the canonical function SET_ORIGIN_OFFSETS. These arealways set on six lines, with one argument per line.4. Anywhere else AA, BB, or CC appears followed by an underscore.The pre-preprocessor looks for these items of typography and, in the outputfile (pre.cc), resets them appropriately marked with #ifdef and #endif.The rest of the text is put into the output file unchanged.The compiler flags are:1. -DAA to have an A-axis2. -DBB to have a B-axis3. -DCC to have a C-axis4. -DALL_AXES to have a 3-, 4-, or 5-axis interpreter use all threerotary axes in canonical function calls. In those calls, the valuefor a rotary axis not compiled into an interpreter is always zero.5. -DAXIS_ERROR to have a 3-, 4-, or 5-axis interpreter signal an errorif the input RS274 code has a value for an axis not compiled in. Ifthis flag is not used, the interpreter will read and ignore values foraxes not compiled in.*//* comment added by wpin on 2003-04-14modified G02,G03,for helix L number G02(03) X... Y... Z... L...:L number is a integer,1 means 0~360,2 means 360~720,so on.added G code for G11,g12,g13,G14,g25 G11: X... Y... Z...: coordinate of each axis will be multiplied by the x(y,z) number G12: canel all axis mirror G25 jumping_line_number: none condition jump G25 loop_begin_line.loop_end_line: loop from beging_line to end_line once. also the loop_begin_line will be execute G25 loop_begin_line.loop_end_line.loop_times:loop from beging_line to end_line loop_time timesstatic int fSyncLine(FILE * fileFp , int syncLine)static int read_g25(char * line,int * counter, block_pointer block, SysParmeter * parameters)static int pre_compile(char * line)fSyncLine : while on file explantion mode,and when wanting jump to a labeled line, these function will rewind the file pointer and then seek the pointer at the exact line which line sequence number is syncLine.read_g25 : inprete the N25 code,for none condition jumping and loopingpre_complie : called by rs274ngc_read. explain G11,G12,G13,G14,G25 codes . otherwise,G11--G14 was explained in convert_g function and work in read_* function*//****************************************************************************///#define LATHE#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <ctype.h>#include "rs274ngc.hh"#include "rs274ngc_return.hh"#include "rs274ngc_errors.cc"#include "rcs.hh" // RCS_LINKED_LIST#include "interpl.hh" // NML_INTERP_LIST, interp_list#ifdef LATHE_FLAG#include "profdata.hh"#endif#include "gmcode.hh"#include "message.hh"#include "Compensation.hh"//#define DEBUG_EMC#ifdef DEBUG_EMC#include <stdarg.h>#include <sys/types.h>#include <sys/time.h>#include <time.h>#include <unistd.h>#define LOG(level, fmt, args...) \ doLog("%02d(%d):%s:%d -- " fmt "\n", \ level, getpid(), __FILE__, __LINE__ , ## args)#define logDebug(fmt, args...) LOG(0, fmt, ## args)static FILE *log_file;#define LOG_FILE "log/cnc_log"void doLog(char *fmt, ...){ struct timeval tv; struct tm *tm; va_list ap; va_start(ap, fmt); if(log_file == NULL) { log_file = fopen(LOG_FILE, "a"); } if(log_file == NULL) { fprintf(stderr, "(%d)Unable to open log file:%s\n", getpid(), LOG_FILE); exit(1); } gettimeofday(&tv, NULL); tm = localtime(&tv.tv_sec); fprintf(log_file, "%04d%02d%02d-%02d:%02d:%02d.%03d ", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec/1000); vfprintf(log_file, fmt, ap); fflush(log_file); va_end(ap);}#else#define logDebug(fmt, args...) if(0)#endif#define TEMP_QUEUE_LEN 20static inline int IS_QUEUE_FULL() { if ((temp_list.len()) >= TEMP_QUEUE_LEN) { return NCE_COMPENSATION_QUEUE_FULL; } //printf ("add queue\n"); return RS274NGC_OK;} /*The _setup model includes a stack array for the names of functioncalls. This stack is written into if an error occurs. Just before eachfunction returns an error code, it writes its name in the nextavailable string, initializes the following string, and incrementsthe array index. The following four macros do the work.The size of the stack array is 50. An error in the middle of a verycomplex expression would cause the ERP and CHP macros to write past thebounds of the array if a check were not provided. No real programwould contain such a thing, but the check is included to make themacros totally crash-proof. If the function call stack is deeper than49, the top of the stack will be missing.*/static int fSyncLine(FILE * fileFp , int syncLine);static int GetFilePosFormNumber(FILE * fileFp , int syncLine,FilePosition fpos);static int read_g25(char * line,int * counter, block_pointer block, SysParmeter * parameters) ;static int pre_compile(char * line);static int interp_reset();static int init_system_parameters(SysParmeter *pars);static int get_system_parameters(int index,double *value);static int write_system_parameters(int index,double value);#ifdef LATHE_FLAGstatic void cncLatheCompensation (setup_pointer settings);int CNC_MainProgOfSpeCylce(setup_pointer settings,Special_Cycle *pSpeCycle);int read_sequence_number(setup_pointer settings, Special_Cycle *pSpeCycle);static int convert_profile_arc(int move, block_pointer block, setup_pointer settings);static int convert_paralle_cycle(int motion, block_pointer block, setup_pointer settings);static int InitSpeCycleArg(int motion, block_pointer block, setup_pointer settings);static int G70init(int motion, block_pointer block, setup_pointer settings);static int convert_profile(int motion, block_pointer block, setup_pointer settings);static int execute_Parallel_axis(int motion, block_pointer block, setup_pointer settings);static int execute_Parallel_prof(block_pointer block, setup_pointer settings); static int convert_profile_straight(int move, block_pointer block, setup_pointer settings);static int pre_block(block_pointer block, setup_pointer settings);static int BuildArgOfProfile(Special_Cycle *pSpeCycle,int move);#endif/*Function prototypes for all static functions*/static 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);static 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);static 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);static 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);static int check_g_codes(block_pointer block, setup_pointer settings);static int check_items(block_pointer block, setup_pointer settings);static int check_m_codes(block_pointer block);static int check_other_codes(block_pointer block);static int close_and_downcase(block_pointer block, char * line);static int convert_arc(int move, block_pointer block, setup_pointer settings);static int convert_arc2(int move, block_pointer block, setup_pointer settings, double * current1, double * current2, double * current3, double end1, double end2, double end3#ifdef AA, double AA_end#endif#ifdef BB, double BB_end#endif#ifdef CC, double CC_end#endif, double offset1, double offset2);static int convert_arc_comp1(int move, block_pointer block, setup_pointer settings, double end_x, double end_y, double end_z#ifdef AA, double AA_end#endif#ifdef BB, double BB_end#endif#ifdef CC, double CC_end#endif);static int convert_arc_comp2(int move, block_pointer block, setup_pointer settings, double end_x, double end_y, double end_z#ifdef AA, double AA_end#endif#ifdef BB, double BB_end#endif#ifdef CC, double CC_end#endif);static int convert_axis_offsets(int g_code, block_pointer block, setup_pointer settings);static int convert_comment(char * comment);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -