Research and Development of CNC System Software Chips
2026-04-06 04:46:39··#1
Numerical control (NC) technology is undoubtedly the most important technological foundation in modern advanced manufacturing technology. In a sense, the level of NC technology has become one of the important indicators for measuring the level of a country's manufacturing industry. Due to technological monopoly and market monopoly, the NC systems produced by various manufacturers are mostly closed in terms of architecture, and cannot be expanded with high reliability software. In recent years, many NC software developers at home and abroad have been repeatedly researching and developing the same or similar NC systems and repeatedly designing several basic modules, resulting in a huge waste of human, material and financial resources. Moreover, due to the lack of unified standards, the software developed by different NC software developers cannot be interchanged, lacks compatibility, hinders the upgrading of NC software, and also hinders the ability of NC machine tool manufacturers to respond quickly to the market and users. Through the analysis of the NC system software architecture, we envision that if the same or similar parts of the NC system software are made into software chips (Software IC, SIC) similar to hardware electronic chips [1,2], each software chip has high functional independence, portability, ease of assembly and easy expansion. In this way, when building a new CNC system, we only need to retrieve the required chips from the chip library and combine them, expanding as needed to enable the reuse of the CNC system without having to develop the entire software system from scratch. This changes the current closed design of CNC systems, laying a solid foundation for adapting to the task- and order-oriented production organization model of future workshops, making the integration of the underlying production control system simpler and more effective, thereby greatly improving the productivity and reliability of CNC software, and reducing production costs and development cycles. This is an inevitable path to enhance the rapid response capability of CNC systems to the market and promote the rapid and efficient development of the CNC industry. 1. Division of CNC System Software Chips Reasonable chip division is the first step in developing software chips. Each chip in the CNC system software chip library is open via an interface. Through interface parameters and information prompts, users can understand the chip's startup, shutdown, and operation. Different chips are internally black-box packaged, with open external interfaces, and new systems are built upon this foundation. Therefore, defining a reasonable CNC system software chip, making the external interface of the chip easy to standardize and normalize, and the internal black box encapsulation easy to perform, is the key step in our development of CNC system software chip library. At present, although CNC systems vary greatly in terms of system design methods and system implementation, their basic principles and software composition are similar. Based on a careful and comprehensive analysis of existing CNC systems [3] and user requirements, and based on summarizing the common characteristics of existing system control structures and appropriately classifying and abstracting them, the CNC system is divided into the following basic functional modules. (1) Human-machine interface module This module mainly completes the modification and setting of system parameters before and during system operation, such as setting the system working mode (automatic, manual, jog, etc.), graphic display mode, system initialization setting, coordinate offset setting, G-code program editing, etc. (2) The part code interpretation module is responsible for performing syntax checks on the user-written part program according to the user's system configuration and the syntax rules of the part program, and interpreting and decoding it. It separates and extracts various information given in the source code instructions, turns them into various states and data, and provides the preprocessing chip with grammatically correct intermediate code for the part program. (3) The tool compensation preprocessing module is responsible for preprocessing the interpreted data and preparing for interpolation. (4) The trajectory interpolation module is responsible for acceleration and deceleration control, interpolation, endpoint discrimination, etc., and outputs the feed amount after trajectory calculation to the position controller. (5) With the help of information obtained from I/O and interpolation calculation, the axis servo control module controls the machine tool actuator to move according to the path and speed specified by the NC instruction through fine interpolation. (6) The I/O module is responsible for the input and output of the controller (including the input of machine tool detection signals and position and related feedback information, the output of control instructions, etc.). The above modules have interoperability, portability and scalability, and can therefore be used as the basic chip division of the CNC software chip library. 2 Construction and Working Principle of CNC System Software Chip The concept of software chip is a milestone in the development of software reuse. Developing a software chip involves using object-oriented technology to make some common modules in a specific class into independent, reusable object classes. Because object-oriented programming has valuable features such as encapsulation, classification, message response, and inheritance, the coupling between the software chip and other parts of the system is reduced as much as possible, which provides a reliable guarantee for the development and use of the software chip. At the same time, since chips are implemented by encapsulating relatively mature technologies, they have been verified in practice. That is to say, a mature chip has reduced the error rate to a minimum. Therefore, the reliability of the system can be maximized by using CNC software chips to construct new CNC systems. The construction of the software chip involves encapsulating the main body of the functional modules in a black box, making its input and output interfaces as simple and standardized as possible. Because C++ has good object-oriented features and encapsulation [4], VC is used as the programming environment to construct the chip body in this system. The entire chip is created based on a static library, and finally a Lib library file is generated. The implementation of all functions is encapsulated in the Lib library file. When using the chip, users don't need to know how its internal functions (such as initialization, error handling, and data separation) are implemented. They only need to add the corresponding .Lib and .H files to their system and then call the corresponding methods through the interface parameters according to the interface requirements specified in the chip's documentation. The interface parameters and methods are defined in the Lib file, allowing users to interact with the chip from the outside, just like using the pins of a hardware IC to access its internal functions. The following section uses a part program to explain the chip as an example to briefly describe the construction process of a CNC system software chip. First, the chip's core functions are analyzed, and suitable interfaces are defined. Generally, a complete CNC machining program for a part consists of several program segments, each segment consisting of several code words, ending with a semicolon (;). Each code word consists of text characters and numeric characters, separated by spaces. Based on the top-down principle, this part can be further divided into the following sections: (1) Lexical checking: the spelling and bit depth of the source program data are checked; (2) Syntax checking: the format of G codes and other function codes in the program segment is checked, such as G code compatibility check; (3) Semantic checking: context-related errors are checked, such as I, J, K and R cannot appear in the same line of code; (4) Decoding: the information of the program segment is extracted and converted into corresponding state variables and data variables, which are stored in the output buffer. Based on a comprehensive consideration of the internal logic relationship of the CNC system interpreter and the motion control of the CNC system, the input port data of the interpreter chip is defined as a line of CNC code segment (char* LineStr) input in string form; the output port data is defined as a structure containing various information variables. Output data structure: typedef struct { int Gp01; // Group 1 G code ... int Gp15; // Group 15 G codes int N, // Program segment number G, // Preparation function M, // Auxiliary function P, Q, L, D, H; // Other parameter characters long T; // Tool selection double F; // Feed rate double S; // Spindle speed double D; // Tool radius double X, Y, Z, A, B, C, I, J, K, R, U, V, W; // Dimension characters ... BOOL bLastCmnd; Last line indicator } NCcode To interpret and decode a line of code, first declare an instance: CCode code; // CCode is the class generated by the Lib file. Then call its member function, code.InterCode(char * LineStr) to complete the lexical, syntactic, and semantic checks and data separation of the code segment in LineStr. During the interpretation process, if any syntax or semantic errors are found in the code segment, InterCode will provide corresponding prompts and return to the editing state for re-editing. Similarly, to initialize flags in the structure, you can call code.FlagINI(). Additionally, you can terminate the entire chip's operation by assigning a value to the code.ENDED variable externally. The various states and data information after interpretation are stored in the previously defined data structure. Users can retrieve the corresponding data using the general structure reading method, such as NCcode.G; NCcode.M, or use the entire data structure as the entry point for the next chip to achieve data transfer between chips. To prevent errors caused by external operations on the data structure during chip decoding, this chip uses a critical section method. When the InterCode() method is called, the Lock member function of CcriticalSection is used to lock the data being updated, preventing external access to the data and avoiding the error of reading both old and new data simultaneously. After interpretation, Unlock is used to unlock the data, allowing users to access the updated data. 3. Synchronization and Coordination Between Chips When several chips are combined into a practical system, the synchronization between them becomes particularly important, especially in systems with high real-time requirements, such as CNC systems. When building a CNC system using software chips, each chip with a specific function, such as decoding or interpolation, is a separate thread. Communication between threads is achieved using event objects. Since this system was developed in the VC environment, the CEvent class and its member functions in the MFC library can be used. Each event object can have two states: semaphore and non-semaphore. Events can monitor whether a thread is in the semaphore state and thus determine when to run the appropriate thread. Another reason for using event objects for thread communication is that declaring event objects is very easy, as simple as declaring a global variable. For example, `CEvent InterCodedStart;` After the event object is created, it is in the non-semaphore state. To make the event object in the semaphore state, simply call the event object's member function `SetEvent()`, i.e., `InterCodeStart.SetEvent();` After executing the above statement, the event object `InterCodeStart` is in the semaphore state. The following Windows API function can be used to monitor whether an event is in a semaphore state: `WaitForSingleObject(InterCodeStart.mhObject, 0)`. In this case, if the function returns `WAITOBJECT0`, the event is in a semaphore state; otherwise, the event remains in a non-semaphore state. Through these messages and methods, we can achieve communication between threads in the system, and we can also control the communication between these event objects to "glue" several chips together into an organic and practical system. 4. Conclusion This system was developed entirely in the VC environment under Windows NT, so it utilizes many basic classes from MFC, which greatly improves the flexibility and functionality of the entire system. For example, the CNC code editor is based on the `CEditView` class, so it can utilize the editing functions built into the `CEditView` class, such as `New`, `Open`, `Save`, `Copy`, `Cut`, and `Paste`, making the editing and management of CNC programs as convenient and easy as file management in Windows. At the same time, the use of various controls in VC not only increases the ease of operation of the system control but also makes the control interface more aesthetically pleasing and user-friendly. These are all areas worthy of further in-depth exploration. The idea of using reusable component technology to develop software chips and using them to build new CNC systems has been applied to the research of the National Natural Science Foundation of China project "Software Chip Library and Operating Environment of High Reliability CNC System". It has achieved good results. It not only realizes the open design and resource reuse of CNC systems, but also has good development prospects for upgrading CNC systems and responding to the market in a timely manner because it is developed based on general environments such as Windows NT and IPC. References 1 Wang Fuqing. Object-Oriented Programming. Beijing: Peking University Press, 1992: 56-57, 88-107, 142-159 2 Lenz ManFred. IEEE SOFTWARE, 1987, 4(4): 34-42 3 Bi Chengen. Modern CNC Machine Tools. Beijing: Machinery Industry Press, 1991: 1-50 4 Kate Gregory, translated by Kangbo Studio. Visual C++ 5 Development and User Manual. Beijing: Machinery Industry Press, 1998: 543-563