Share this

Research on Code Compiler for CNC Machining Virtual Simulation System

2026-04-06 03:30:34 · · #1
Abstract: This paper analyzes the advantages and disadvantages of CNC machining code decoding methods. Based on this, a new implementation algorithm for the NC code compiler of a CNC machining virtual simulation system—the interpretation-compilation method—is proposed. The paper also discusses how to develop an NC code compiler for a CNC machining virtual simulation system using computer compiler principles and object-oriented technology in the Visual C++ environment. 1 Introduction With the widespread application of CNC technology in the machinery manufacturing industry, CNC machining virtual simulation systems have also developed rapidly and are widely used in the teaching and training of CNC programming operations. This is of great significance for reducing the financial investment of higher education institutions and training organizations, shortening the production preparation cycle of enterprises, reducing production costs, and improving enterprise production efficiency. As the pre-processing part of the CNC machining virtual simulation system—the NC code compiler—serves as a bridge for communicating and transmitting information between the CNC machining virtual simulation system and other parts of the CAD/CAM system, and has also developed rapidly. In the CNC machining virtual simulation process, correctly and quickly extracting machining information from the input machining program and effectively organizing it into the default representation form within the simulation system are prerequisites for dynamic simulation and guarantees for the smooth progress of the simulation process. Looking at the development of NC code compilation technology in CNC machining virtual simulation systems at home and abroad, foreign research in this area is relatively mature, while domestic research has made great progress and reached a considerable level, but there are still some shortcomings: (1) Insufficient universality, such as the fact that some NC code compilers for CNC systems are only applicable to the compilation of code for a certain system; (2) Further research is needed on how to handle the relationship between computer memory resource utilization and running speed; (3) Limited NC code can be processed, especially since most domestic NC code compilers can only translate some commonly used C code (such as GOO-G04, etc.) and basic code such as M code, while the processing of some important code (such as tool compensation code), fixed loops and subroutines is very limited; (4) Insufficient language error checking for NC code programs, most NC code compilers only display the line number where the error occurred. In the research and implementation of NC code translators, if the aforementioned shortcomings can be improved—namely, by enhancing versatility, perfecting code processing functions, and truly realizing the optimization of machining information through virtual simulation of CNC machining—then the realism of virtual simulation can be further improved. This will lay a solid foundation for improving the production efficiency of CNC machining, shortening the production preparation cycle, reducing production costs, and enabling enterprises to produce high-quality products with optimal allocation and utilization of production time, processing costs, and resources. Therefore, the authors of this paper will focus on the research of key technologies for realizing a NC code translator with certain versatility, so that the CNC machining virtual simulation system can meet the needs of CAD/CAM systems developing towards integration, intelligence, and networking. 2. Decoding Methods Used in the Compilation System Traditional CNC system code compilation methods include interpretation, compilation, and object code compilation. Each of these three compilation methods has its advantages and disadvantages. The disadvantages of the first two are that they waste computer memory resources, and there may be pauses between program segments during program execution, affecting the machining accuracy of parts. Moreover, both of these decoding methods have a drawback: when machining different parts of the same type, the program needs to be recompiled every time it runs, which takes up a certain amount of machining time. While using object code for compilation improves the speed of CNC machining programs by requiring only one decoding run when machining similar parts, and the object code's simple format and fast reading speed greatly enhance the efficiency of repeated program execution, the compiled object code occupies a significant amount of memory when the CNC machining program is long. Furthermore, users must fully understand the code's design principles to extend its functionality. Therefore, this decoding method has poor versatility and portability. Based on this, and according to the principle of time-overlapping pipelined processing, this paper proposes a method for decoding CNC machining code using an interpretation-compilation approach, the workflow of which is shown in Figure 1. Figure 1. Flowchart of the interpret-compile decoding method. The interpret-compile decoding method involves the compiler performing two scans, each targeting a different object. The first scan examines various address symbols in the CNC machining program, performing lexical, syntactic, and simple semantic analysis, and accumulating the number of program segments. Simultaneously, the compiler extracts key machining information from the CNC machining program, such as G00, G01, G02, and G03, and stores this information sequentially in the compilation result buffer `m_CurveList`, setting the interpolation type flag: `enum locustype {point, line, cwarc, antiticwarc} locustp`, for use in the second scan. If errors are found, the compiler exits with an error message, and the buffer `m_Cu~eHst` is cleared. If the first scan is error-free, the second scan is performed. At this point, the second scan targets the interpolation flags in the compilation result buffer. By identifying each interpolation flag, tool position data is read from the m_CurveList dimension list in the compilation result buffer, and this tool position data drives the corresponding interpolation module to complete the dynamic simulation of the CNC machining process. Clearly, the second scan takes less time and requires less storage space than the first scan. This interpret-compile decoding method, which scans different objects in stages, overcomes the drawbacks of both interpretive and compile methods that waste computer memory resources. It also overcomes the drawback of sequential processing methods where the time interval between the outputs of two program segments causes intermittent motor operation, leading to a decrease in workpiece machining quality. Furthermore, because the objects scanned in the two scans are different, and the content of the second scan is less complex than the first, this interpret-compile method significantly improves the utilization of computer memory resources and shortens compilation time, greatly increasing the efficiency of the compilation software. 3. Implementation of CNC Machining Program Decoding Algorithm The CNC machining virtual simulation system undertakes two main tasks: first, it scans the CNC machining program and performs lexical, syntactic, and semantic recognition, outputting the recognition results to the user; second, after confirming the machining program is error-free through scanning and recognition, it extracts the machining information of the moving parts of the machine tool for machining simulation. The CNC machining virtual simulation system compiler is mainly used to verify the correctness of the CNC machining program and extract the tool position information for driving machining. Therefore, the main task of developing a CNC machining program compiler in the Visual C++ environment is to complete the scanning of the part program, recognize the lexical and syntactic properties, and store the recognition results in a linked list in the cache. Figure 2 shows the flowchart of the decoding method used by the author for lexical and syntactic recognition of the NC code program. Figure 2 Flowchart of NC Code Lexical and Syntactic Recognition Algorithm 3.1 Reading the CNC Machining Program The CNC machining virtual simulation system reads the CNC machining program stored in *.txt format from the floppy disk or hard disk. Therefore, the simulation system first calls the open function to open a text-format machining program file, and the Read function reads the NC program segment by segment into the m_strFileAll object of the CString class in sequence; then the corresponding addresses are stored in the m_FileLineList linked list of the CStringList class. This process is repeated until the end of the file. In this way, the m_FileLineList linked list of the CStringList type will record the information of the entire NC program line by line in sequence. 3.2 NC code lexical check The main task of lexical check is to check the address characters in the machining program of the part, especially the G function words and M function words; to identify whether they conform to the G and M function library of the CNC system. If a violation of the lexical rules is found, the error is pointed out; if the lexical check is correct, the next step of syntax analysis check is performed. Otherwise, the compiler exits. For this purpose, the compiler mainly follows the following steps: (1) Establish the G and M function library. In the CSkDoc class, define the G and M function rule chain list CStringListm_WrodRuleList; // Store the CNC system G and M function rule library. (2) Create the BOOL CSkDoc::IsThereChar(CStringstrLine, TCHAR c) function to identify address characters such as N, G, M, X, Y, Z, I, J, K, R, U, V, W, S, T, F. (3) Create the LexicalParser(const CStringList & LineWdLs, int nlinenumber) function to perform lexical checking. 3.3 NC Code Syntax Check After the lexical check of the CNC machining program by the compiler system is successful, the next step is to perform a syntax check to determine whether the NC program conforms to the syntax rules of the CNC system. For example: function words G90 and G91 cannot coexist in the same file; function words in the same modal group cannot appear simultaneously in the same program segment; function words G00 and F cannot appear simultaneously in the same program segment; and G function words such as G00, G01, G02/G03 may lack correctly matched dimension words, etc. To this end, the compiler system establishes the following functions: First, in the SkDoc class, a function GetWordOrder(const CStringList & 1wlist) is defined to obtain the order of words in the program segment. Then, in the SkDoc class, a syntax check function SyntaxParser() is defined. If the NC machining program syntax check of the part is correct, the compilation system simultaneously extracts the tool position information such as G00, G01, G02, G03, etc., from the NC code program segment linked list m_FileLineList buffer and stores it in the trajectory linked list m_CurveList buffer of the driving simulation system. If a syntax error exists, the compilation system exits and the trajectory linked list m_CurveList buffer is cleared. 4. Conclusion NC machining virtual simulation systems are mainly used in higher education institutions and training organizations for teaching NC programming and machine tool operation. Their purpose is twofold: to deepen and reinforce students' understanding of NC programming knowledge and to reduce investment in expensive equipment. Therefore, in addition to realistically simulating the NC machining process, NC machining virtual simulation systems must consider recognizing as much NC system code as possible and also consider the speed of the simulation system's code compilation to improve the utilization rate of computer memory resources. This is of great significance for improving the realism of the NC machining simulation system and the utilization rate of computer resources. This paper analyzes the current development status of compiler technology for CNC simulation systems and the advantages and disadvantages of various decoding methods. It proposes a new NC code decoding method for CNC machining virtual simulation systems—the interpretation-compilation method. This method not only reduces the waste of system resources but also shortens compilation time and improves the overall efficiency of the compilation system. This paper addresses only one fundamental problem in CNC machining virtual simulation systems—the compilation problem—laying a solid foundation for further research and development of CNC machining virtual simulation systems.
Read next

CATDOLL 136CM Mila

Height: 136cm Weight: 23.3kg Shoulder Width: 31cm Bust/Waist/Hip: 60/54/68cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22