Embedded numerical control system based on heterogeneous multiple cores
By adopting heterogeneous multi-core processors in embedded CNC systems, the development system and operation system are deployed, and the heterogeneous characteristics of Cortex-A7 and Cortex-M4 cores are used to solve the shortcomings of existing systems in processor performance and soft PLC technology, and the support of efficient real-time performance and complex logic control is achieved.
Patent Information
- Application Number
- CN202510158769.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-13
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2045-02-13
AI Technical Summary
The existing embedded CNC systems have shortcomings in processor performance, power consumption and real-time performance, and the development of embedded soft PLC technology in domestic CNC systems is hysteresis, making it difficult to meet the needs of complex logic control.
Using an embedded CNC system based on heterogeneous multi-core, the development system and operation system are deployed on the same processor, and the heterogeneous characteristics of the Cortex-A7 and Cortex-M4 cores are used to achieve efficient real-time performance, and data interaction is carried out through shared memory and inter-core interrupt mechanisms.
It improves the real-time performance and integration of embedded CNC systems, reduces the complexity and maintenance costs of the system, and enhances the ability to support complex logic control.
Smart Images

Figure CN120010383A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded numerical control systems, and in particular to an embedded numerical control system based on heterogeneous multi-cores. Background Art
[0002] CNC systems are developing towards multi-axis linkage, intelligence, and greenness. Embedded CNC has an increasing demand for processor performance, power consumption, real-time performance, and other indicators. Single-core processors can no longer meet the increasing real-time computing performance requirements of embedded CNC systems. Although the multi-processor separation architecture has alleviated the problem of insufficient performance to a certain extent, it still has defects such as complex system structure, high maintenance cost, high delay and instability in physical communication between processors. In addition, PLC plays an important role in CNC machine tool control. The embedded soft PLC technology in domestic CNC systems has been slow to develop, and the control function is relatively closed. It can only provide basic components and functional instructions, which is difficult to meet the needs of complex logic control. The control program editing mostly relies on the PC platform, which is not very flexible, and the program compilation process is cumbersome, the algorithm is highly complex, and the large amount of calculations involved in the execution process leads to high CPU load, affecting system performance and response speed. Summary of the invention
[0003] The present invention aims to at least solve the technical problems existing in the prior art, and in particular innovatively proposes an embedded CNC system based on heterogeneous multi-core.
[0004] In order to achieve the above-mentioned object of the present invention, the present invention provides an embedded CNC system based on heterogeneous multi-core, comprising a development system, an operating system and a bus servo drive unit, wherein a data output end of the development system is connected to a data input end of the operating system, and a data transmission end of the operating system is connected to a data transmission end of the bus servo drive unit;
[0005] The development system is similar to the host computer in traditional PLC, which is used for programming and monitoring tasks. The operation system is similar to the slave computer in traditional PLC, which is used to execute control logic and control external devices. It receives the compiled control program from the development system and controls the input and output devices on site according to the instructions in the program to realize industrial automation control. Its working method is that the user first writes and debugs the control program in the development system, and then calls the compilation module to convert the user program into an intermediate code that can be recognized by the operation system. The development system transmits the intermediate code to the operation system through shared memory. The operation system interprets and executes the intermediate code and outputs the results of the logical operation to the remote I / O module through EtherCAT, thereby realizing the control of the field equipment. In this process, the operating status of the external device will also be fed back to the development system through the bus through the operation system and inter-core communication for the user to view.
[0006] Preferably, the development system and the operating system are respectively run on two different cores of the same processor. Through this deployment mode, the development system and the operating system can each focus on their own tasks, and while achieving efficient real-time performance, the integration of the soft PLC system is improved. The development system and the operating system exchange data through shared memory to ensure the reliability and response speed of the entire system. The development system adopts the Cortex-A7 core, and the operating system adopts the Cortex-M4 core. The operating system may also include a lower computer chip, or only the Cortex-M4 core may be used.
[0007] Preferably, the Cortex-A7 core is used for human-computer interaction tasks, code preprocessing, G code parsing, tool compensation processing, file management, parameter setting and other task modules, which have low real-time requirements and are related to graphic display, so these task modules are divided into a task set and assigned to run under the Cortex-A7 core;
[0008] The Cortex-M4 core is used to divide real-time periodic tasks such as interpolation calculations, position control, bus drive, PLC tasks, etc. into a task set and assign them to run under the Cortex-M4 core. For real-time burst tasks such as handwheel control and keyboard response, they are also assigned to the Cortex-M4 core to ensure the system's real-time response to this type of task.
[0009] Preferably, the Cortex-A7 core and the Cortex-M4 core realize inter-core data interaction through shared memory and inter-core interrupt mechanism. Specifically, communication is realized through OpenAMP, a software framework for communication between Linux and RTOS, the inter-core communication driver module is loaded in the Linux kernel and the inter-core communication driver is loaded in the M4 kernel, and the applications on the two cores can realize data transmission by calling the API interface provided by the communication component.
[0010] Based on the above software architecture, the system adopts a mechanism of synchronous interpolation operation and bus drive. In the interpolation interrupt service function of the M4 end, the program directly sends the position control instruction to the servo drive unit through the bus, and sends the position and I / O data to the A7 end in the communication service program. The two cores work together to give full play to their respective advantages, achieve a balance between high performance and real-time performance, and meet various complex and real-time application requirements of the CNC system.
[0011] Preferably, in the development system, the ladder diagram is mapped into a plurality of structure arrays through an intermediate code conversion unit, wherein one structure array is used to store information of a rung of the ladder diagram; finally, these structure arrays are packaged into data frames and sent to the running system;
[0012] After the operating system receives the data frame, the storage management module of the operating system obtains all the information of the ladder diagram by identifying the data frame of the intermediate code. In order to achieve efficient interpretation and execution of the intermediate code, the storage management module records the first address of each data frame storage unit while saving the intermediate code.
[0013] Preferably, the ladder diagram is mapped into multiple structure arrays through an intermediate code conversion unit, including: starting from the first graphic element of the main road, scanning horizontally from left to right, and saving its information in the form of a structure into the array according to the position and type of the graphic element; when encountering a branch at a certain node, a depth-first search method is used for scanning, and each branch is scanned vertically according to the vertical connecting lines, and the graphic element information structure is saved in the array in order.
[0014] Preferably, it includes:
[0015] (1) Scan and convert from left to right starting from the main line of the ladder. Once a branch node is encountered, it will switch to the next line for judgment to determine whether the vertical line of the current branch node is a left vertical line or a right vertical line;
[0016] (2) If it is a left vertical line, determine whether the right side is an output element. If so, perform a conversion and then return to the previous branch node to scan right for conversion. If not, directly return to the branch node and scan right.
[0017] (3) If it is a right vertical line, scan to the left until it encounters a left vertical line or a left busbar. The graphic element between the two vertical lines is a parallel module. Scan and convert the parallel branch from left to right, record the number of graphic elements in the branch, and determine whether there is a branch node in the branch. If there is, continue to perform operation (3). If not, after completing the branch conversion, return to the branch node and continue to scan to the right until the last column of the trunk is converted.
[0018] Among them, the left vertical line indicates that the right angle formed by the lines opens to the left, and the right vertical line indicates that the right angle formed by the lines opens to the right.
[0019] During the above scanning process, we can calculate the depth of the current rung by the number of branch nodes, so as to determine the number of rows of the rung. After completing the scan conversion of the rung, we can directly jump to the row where the main road of the next rung is located according to the number of rows occupied by the rung, and start the scan conversion of the next rung. Repeat the above steps until the conversion of all runs is completed.
[0020] In the above manner, the ladder diagram compilation module (the ladder diagram compilation module is mainly composed of two parts: the logic check unit and the intermediate code conversion unit) converts each rung into a structure array and packs it into a data frame and sends it to the operating system. When packing the data of each rung, the total number of conditional elements and the total number of execution elements of the rung must also be added to the data frame so that the operating system can parse and execute. The packaged byte stream information is regarded as the intermediate code. The data frame format of a rung includes the frame header, data type, number of conditional elements, and number of output elements.
[0021] Preferably, before the ladder diagram is mapped into a plurality of structure arrays by the intermediate code conversion unit, a logic check is performed by the logic check unit:
[0022] (1) Short circuit: Use the sequential scanning ladder diagram program to find two parallel vertical lines based on the downward cascade mark of the graphics element, and then count the number of graphics elements between the two parallel straight lines. If it is zero, it means there is a short circuit error;
[0023] (2) Open circuit: A open circuit refers to a situation where a main circuit or branch of the ladder diagram is missing a graphic element. Scan the ladder diagram sequentially and record the positions where the graphic elements are empty. If there are graphic elements on both the left and right sides, it indicates that a open circuit error exists.
[0024] (3) Constant output: A constant output error refers to the situation where there is only an output coil but no normally open or normally closed contacts on the main circuit of a ladder step in the ladder diagram. Scan each element sequentially and determine its component type. If only an output coil is scanned but no contacts are found, it means there is a constant output error.
[0025] (4) Function block missing parameters: For function blocks such as timers or logic operation modules, users are required to manually set instructions or parameters. Determine whether the parameters of the function block are default values. If so, this indicates that this error exists.
[0026] Preferably, the storage management module of the operating system obtains all the information of the ladder diagram by identifying the data frame of the intermediate code, including:
[0027] First, read the number of ladder condition elements and the number of execution elements from the data frame according to the specified communication protocol, use pointer offset to read the storage structure of each graphic element, and obtain its type, name, address, whether it is cascaded downward, and other information. Then read the status of the corresponding register to obtain the on-off status of each condition element, judge the on-off status of each condition element one by one according to the number of condition elements, and perform logical operations with the results of the previous level operation. Finally, judge whether the output condition is met based on the logical operation results of all condition elements. If the output condition is met, call the corresponding function function in sequence according to the number of output elements (the corresponding function function is: call according to the element status (on or off) in the ladder diagram and the set function (set to 1 for on, set to 0 for off, and parallel and series connection), so that these elements can participate in logical operations in the code, and the output condition can be judged based on the operation results) to modify the value of the software register. If the output condition is not met, the ladder diagram Figure 1 The process of interpreting and executing the ladder is now completed.
[0028] In summary, due to the adoption of the above-mentioned technical scheme, the present invention divides the embedded soft PLC into a development subsystem and an operation subsystem and deploys them on different cores of a multi-core embedded processor, thereby realizing an embedded soft PLC that runs independently of a PC. A method for directly interpreting and executing a ladder diagram is proposed and implemented, without the need to convert the ladder diagram into an instruction table program, thereby reducing the algorithm complexity of ladder diagram compilation and interpretation and execution, and improving the execution efficiency of the CNC PLC.
[0029] A direct interpretation and execution method of ladder diagram primitive mapping matching is proposed, which simplifies the ladder diagram compilation and interpretation and execution process and improves the system operation efficiency.
[0030] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0032] Figure 1 It is a schematic diagram of task division of the multi-core numerical control system of the present invention.
[0033] Figure 2 It is a system software architecture block diagram of the present invention.
[0034] Figure 3 It is a hierarchical diagram of the human-computer interaction functional structure of the present invention.
[0035] Figure 4 This is the main page of the human-machine interface coordinates of the present invention.
[0036] Figure 5 It is a flow chart of the interface refresh program of the present invention.
[0037] Figure 6 It is a schematic diagram of the program directory interface of the present invention.
[0038] Figure 7 It is a schematic diagram of the program editing interface of the present invention.
[0039] Figure 8 This is the tool length compensation page diagram of the present invention.
[0040] Fig. 9 It is a schematic diagram of the tool length compensation value modification window of the present invention.
[0041] Fig.10 The present invention is a schematic diagram of the G code parsing process of the present invention.
[0042] Fig.11 It is the flow chart of lexical checking of the present invention.
[0043] Fig.12 It is a grammar checking flow chart of the present invention.
[0044] Fig.13 It is a schematic diagram of the storage structure of G and M instructions of the present invention.
[0045] Fig.14 It is a schematic diagram of the tool radius compensation model of the present invention.
[0046] Fig.15 It is a schematic diagram of the linear tool radius compensation of the present invention.
[0047] Fig.16 It is a schematic diagram of arc tool radius compensation of the present invention.
[0048] Fig.17 It is a schematic diagram of tool radius compensation for straight-line to straight-line conversion according to the present invention.
[0049] Fig.18 It is a schematic diagram of the tool radius compensation for the straight line to circular arc conversion of the present invention.
[0050] Fig.19 It is a schematic diagram of the radius compensation of the circular arc conversion tool of the present invention.
[0051] Fig. 20 It is the flow chart of the tool radius compensation program of the present invention.
[0052] Fig.21 This is the embedded soft PLC system structure of the present invention.
[0053] Fig. 22 It is a schematic diagram of the logical structure model of the development system of the present invention.
[0054] Fig.23 It is the ladder diagram editing interface of the present invention.
[0055] Fig.24 It is a ladder diagram drawing flow chart of the present invention.
[0056] Fig.25 It is a ladder diagram preservation flow chart of the present invention.
[0057] Fig.26 It is a schematic diagram of a short-circuit error of a ladder diagram of the present invention.
[0058] Fig. 27 It is a schematic diagram of a ladder diagram circuit breaker error of the present invention.
[0059] Fig.28 It is a schematic diagram of the ladder diagram constant output error of the present invention.
[0060] Fig.29 This is a schematic diagram of an error in which a function block of the present invention is not configured with parameters.
[0061] Fig.30 It is a schematic diagram of the ladder diagram traversal and storage structure of the present invention.
[0062] Fig.31 It is a schematic diagram of the ladder diagram data frame format of the present invention.
[0063] Fig.32 It is the operating system structure of the present invention.
[0064] Fig.33 It is a schematic diagram of the assembly line operation of the operating system of the present invention.
[0065] Fig.34 It is a ladder diagram rung interpretation execution flow chart of the present invention.
[0066] Fig.35 It is an example of ladder diagram rungs of the present invention.
[0067] Fig.36 It is a flow chart of the inter-core communication program of the present invention.
[0068] Fig.37 It is a schematic diagram of the data frame of the inter-core communication program of the present invention.
[0069] Fig.38 It is a schematic diagram of the inter-core communication control command data frame of the present invention. DETAILED DESCRIPTION
[0070] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0071] 1. System software architecture design
[0072] Different cores in heterogeneous multi-core processors have different architectures and performance characteristics. Different types of tasks in the CNC system can be assigned to cores of different processor architectures according to certain strategies, so as to provide the most optimized processing effect for different types of tasks. By assigning various tasks in the CNC system to these cores of different architectures according to certain strategies, each core can independently execute its assigned tasks, which can greatly improve the parallel processing capability of the CNC system, which means that the system can process more tasks at the same time without being restricted by the performance bottleneck of a single-core processor. It not only improves the operating efficiency of system tasks, but also ensures the real-time performance of key tasks. A reasonable task allocation strategy is crucial for CNC systems based on heterogeneous multi-core processors. When allocating tasks, it is necessary to comprehensively consider the characteristics and requirements of the tasks, as well as the architecture and performance characteristics of different cores in the heterogeneous multi-core processor.
[0073] The heterogeneous multi-core processor STM32MP157 used in this paper integrates two cores with different architectures, Cortex-A7 and Cortex-M4. As a high-performance application processor, the Cortex-A7 core has demonstrated excellent capabilities in processing complex transactions and user interface customization. The Cortex-M4 core is known for its strict requirements for real-time performance and low power consumption characteristics, and is mainly used to execute real-time tasks and optimize power consumption performance. This paper uses the heterogeneous multi-core characteristics of the STM32MP157 to deploy the embedded Linux operating system on the Cortex-A7 core to give full play to its powerful transaction processing capabilities and user interface customization advantages; and runs the FreeRTOS real-time operating system on the Cortex-M4 core to meet the real-time task's requirements for precise response and low latency, while optimizing system power consumption.
[0074] When allocating tasks, this paper adopts an allocation strategy that prioritizes task characteristics: ① Divide the CNC system tasks into multiple subsets according to real-time requirements, and allocate different task sets to cores with corresponding performance characteristics; ② Divide tasks that communicate frequently into a subset and allocate them to the same core to ensure that the data exchange overhead between cores is as small as possible; ③ Assign high-priority tasks to cores with better real-time performance to ensure that the system can respond to task requests and process them in a timely manner; ④ Balance the loads of different cores of the processor as much as possible. Based on the previous analysis of the CNC system task characteristics and the task allocation strategy of this paper, the task division diagram is as follows: Figure 1 shown.
[0075] Task modules such as human-computer interaction tasks, code preprocessing, file management, parameter setting, etc. have low real-time requirements and are related to graphic display, so these task modules are divided into a task set and assigned to the Cortex-A7 core for operation. Real-time periodic tasks such as interpolation calculations, position control, and PLC tasks are divided into a task set and assigned to the Cortex-M4 core for operation. For real-time burst tasks such as handwheel control and keyboard response, they are also assigned to the Cortex-M4 core to ensure the system's real-time response to this type of task. In summary, the system software architecture block diagram is as follows: Figure 2 shown.
[0076] In the software architecture of the CNC system in this paper, the Cortex-A7 core runs the embedded Linux 5.4.31 kernel, establishes multi-tasks based on Linux, and uses a time slice round-robin scheduling algorithm to be responsible for human-machine interaction, G code parsing, tool compensation processing, and data management tasks. The open source real-time operating system FreeRTOS is transplanted on the Cortex-M4 core, and a fixed priority preemptive scheduling mechanism is used to execute bus driving, interpolation operations, position control, and PLC execution tasks. The two cores use shared memory and inter-core interrupt mechanisms to achieve inter-core data interaction. Specifically, communication is achieved through OpenAMP, a software framework for communication between Linux and RTOS. The inter-core communication driver module is loaded in the Linux kernel and the inter-core communication driver is installed in the M4 kernel. The applications on the two cores can realize data transmission by calling the API interface provided by the communication component.
[0077] Based on the above software architecture, the system adopts a mechanism of synchronous interpolation operation and bus drive. In the interpolation interrupt service function of the M4 end, the program directly sends the position control instruction to the servo drive unit through the bus, and sends the position and I / O data to the A7 end in the communication service program. The two cores work together to give full play to their respective advantages, achieve a balance between high performance and real-time performance, and meet various complex and real-time application requirements of the CNC system.
[0078] 2. System function module implementation
[0079] 2.1 Design and development of human-computer interaction functions
[0080] In the construction of embedded CNC systems, a good human-machine interaction interface design is crucial to the stability and usability of the CNC system. The human-machine interaction interface is responsible for providing users with real-time operating status information, processing data, and error alarm information of the system, while ensuring that users can complete all operations of the machine tool through the human-machine interface.
[0081] The human-computer interaction interface of the CNC system designed in this paper is developed based on the Qt framework. It adopts a multi-level menu. According to the system software modules and functions, the entire system interface is divided into five first-level function menus: position, program, tool compensation, parameter, and diagnosis. Each menu has a second-level or third-level submenu with corresponding functions. The human-computer interaction function structure hierarchy of the CNC system designed in this paper is as follows: Figure 3 shown.
[0082] The overall human-computer interaction function can be divided into four key functional modules: status monitoring, NC program editing management, tool information management and soft PLC subsystem.
[0083] 2.1.1 Status Monitoring
[0084] The main interface after the system is started is the coordinate interface. This interface mainly serves the purpose of display and feedback. It will return in real time the absolute coordinate values of each coordinate axis motor on the machine tool, the current tool information, the effective status of commonly used M codes, etc. At the same time, the user can select and establish the coordinate system through the menu button at the bottom of the page. After the workpiece coordinate system is established, the interface will also display the relative coordinate value of the coordinate axis relative to this workpiece coordinate system. In addition, the interface will also display the current spindle speed information and feed speed information, that is, the current spindle speed (S value) and feed rate (F value). When performing actual processing operations, this interface will also provide real-time feedback on the current processing code line, which is convenient for users to determine which processing instruction is currently being executed. The coordinate main interface is as follows: Figure 4 shown.
[0085] The initialization of the human-machine interface program will call the relevant driver function to start the M4 kernel and load the application firmware. After the M4 kernel program starts running, the timed interrupt task is used to collect the absolute encoder value of the motor, the port status of the remote I / O, and the operating parameters such as the spindle speed and feed rate through the EtherCAT bus, and save this information in a fixed data structure, which is transmitted to the human-machine interface program running on the A7 kernel through the virtual serial port. The human-machine interaction program receives the data frame from the M4 end in real time through the virtual serial port, parses it according to the communication protocol, and updates the data structure variables of the buffer.
[0086] For window refresh, this article uses QTimer under the Qt framework to implement timed refresh of various types of information. By connecting the timeout() of the QTimer object to the corresponding slot function, reading the updated structure variable in the buffer in the slot function and reassigning the information display control, the timed refresh of the window can be achieved. The specific program flow is as follows Figure 5 shown.
[0087] 2.1.2NC program editing management
[0088] The human-machine interface program designed in this paper supports two ways to obtain NC program code. The first is to download the code pre-written on the PC to the CNC system through a USB flash drive or serial port transmission. The second is to manually write the code directly on the human-machine interface by using the keyboard.
[0089] In order to facilitate the management and operation of code files in the operating system, this paper designs a file resource management system based on the Qt framework. Users can access and edit files through the program menu interface. The interface is mainly divided into a file display area and a program path area. The file display area presents program files and folders in the system directory in a list form. The QDir class and QFileInfoList class provided by the Qt framework are used to distinguish the files and folders in the system storage path, and the entryInfoList() function is used to filter the file type. Only the machining program files and folders with NC, nc and txt as suffixes are displayed in the program directory. The running effect of the program directory interface is as follows Figure 6 shown.
[0090] By rewriting the double-click event function of the QListView control class, the function of double-clicking to open the NC program file is realized. When the user double-clicks the NC directory list option, the program will determine whether the current item is a file or a folder. If it is a folder, it will advance to the folder directory. If it is a program file, the directory list control will be hidden, and the QPlainTextEdit control will be instantiated in this area, and the program content will be loaded into it. The user can use the keyboard to edit and modify it. The program editing page is as follows: Figure 7 shown.
[0091] 2.1.3 Tool information management
[0092] In low-end CNC systems, due to functional limitations, they usually only support the use of a single tool. However, with the development of CNC technology and the increase in application needs, mid-to-high-end CNC systems are generally equipped with a power tool magazine to achieve automatic replacement of multiple tools, thereby improving processing efficiency and flexibility. The embedded CNC system studied in this project is applied to a multi-axis machining center with a power tool changer, so the possibility of supporting multiple tools must be considered.
[0093] In the application of machining centers and CNC milling machines, tool information mainly includes length compensation value and radius compensation value. Taking into account the different number of tools equipped in different machining centers, this system allows users to set the number of tools. Each tool can be set with four tool length compensation values and four radius compensation values. The radius compensation value and length compensation value of the corresponding tool are called through H1-H4 and D1-D4 in the machining program. When the tool length and radius are worn during the machining process, the user can set and modify these compensation values.
[0094] The tool information of the system is saved in the system storage in the form of text files. When the user switches to the tool compensation interface, the program will call the corresponding page initialization function, load and extract the compensation information of all tools from the tool compensation information file, and display the compensation value of each tool to the user in a table form through the QTableWidget control. When the number of props changes, you only need to modify the number of rows in the table control and add the compensation value data of the initialized tool according to the row number index. The running effect of the tool length compensation page is as follows: Figure 8 shown.
[0095] By adding a mouse double-click event capture to the QTableWidget control, the user can modify the compensation value by double-clicking to call the parameter setting window. The compensation value modification window is as follows: Fig. 9 As shown, the user can select the compensation value number to be modified through the ComBox control, and click OK to update the compensation value. At the same time, the program will save the updated compensation value in the table in the form of a text file to the system storage.
[0096] 2.2 NC program analysis
[0097] CNC machining programs are usually generated by CAD / CAM systems or written manually by engineers and then imported into the control system of CNC machine tools. Machining programs usually consist of a series of numerical control instructions that describe the workpiece geometry, machining path, cutting speed, feed speed, tool selection and other information. These program instructions cannot be executed directly by the machine tool and need to be interpreted and converted into a data structure that can be recognized by the system's operation and control module before subsequent path planning and interpolation operations can be performed.
[0098] The program interpretation of this system is completed on the Cortex-A7 side of the processor. After being processed by the code parsing module, the NC program is saved in the buffer in the form of a structure linked list, and then enters the tool compensation processing unit to correct the data in the buffer. The resulting instruction set is then sent to the Cortex-M4 side through the shared memory. When processing starts, the application on the Cortex-M4 side decodes these instruction sets and performs speed planning and interpolation operations to control machine tool processing.
[0099] 2.2.1 Analysis of NC program code structure
[0100] A complete CNC machining program consists of multiple lines of different program segments, each of which contains a series of G instructions, M instructions and other instructions. These instructions guide the machine tool to perform corresponding actions and operations to complete the processing of the workpiece. Each line of the program segment contains the machining coordinates of the workpiece contour, and also contains some auxiliary operations to ensure that the workpiece can be processed smoothly. The general expression format of the program segment is
[0101] Nxx G__X__Y__Z__I__J__K__R__F__S__T__M__H__D__
[0102] The meaning of each part of the program segment is as follows:
[0103] Nxx: Line number, used to identify each line in the program. Although it can be omitted in some simple cases, in practical applications, line numbers help to find, debug, and modify programs.
[0104] G__: G command, indicating a motion mode or function. Each G command corresponds to a machine tool motion or function. For example, G00 indicates rapid positioning, G01 indicates linear interpolation, G02 and G03 indicate circular interpolation, etc.
[0105] M__: M command, indicating auxiliary function or program control. M command includes functions such as starting / stopping the spindle, tool changing, and coolant opening. For example, M03 indicates spindle forward rotation, and M05 indicates spindle stop.
[0106] X__Y__Z__: represents the coordinate value of the workpiece in the direction of the corresponding coordinate axis. These coordinate values define the position of the point on the workpiece, thereby determining the path of the machining tool.
[0107] F__: Feed rate, which defines the speed at which the tool moves along the trajectory during machining.
[0108] S__: Spindle speed, defines the rotation speed of the spindle.
[0109] T__: Tool number for tool change. When the system includes the tool change function, it defines the tool number used to select the replacement.
[0110] I__J__K__: The offset of circular interpolation, which defines the position of the center of the arc relative to the starting point.
[0111] R__: defines the radius of the arc.
[0112] H__D__: Tool length and radius compensation value number
[0113] Among them, G and M code function instruction words include two types: modal and non-modal. Non-modal instructions refer to instructions whose functions are only valid in the current program line, while modal instructions retain their functions in the program line where they are located and the subsequent program lines until they are replaced by other modal instructions in the same group. The same operation type may contain multiple modal instructions, such as M03 (spindle forward), M04 (spindle reverse), and M05 (spindle stop), all of which are modal instructions. The instruction system divides modal instructions of the same type into a modal group, and only one of them can be selected for execution at any time. Modal codes are mainly used to set the motion state, working mode and some parameters of the machine tool for use in subsequent instructions, thereby simplifying program writing and improving efficiency.
[0114] 2.2.2G code analysis research
[0115] CNC code parsing is one of the important tasks in CNC systems. The code parsing module identifies the instructions, parameters and other information in the G-code file and converts them into a format that the motion control module can recognize, providing correct instructions and parameters for subsequent processing operations to ensure that the CNC system processes as expected. Its main task is to identify different types of instructions in the G-code file, such as motion instructions (G code), auxiliary functions (M code), tool compensation, etc., and then extract the parameter values in the instructions, including coordinates, speed, compensation values, etc., and verify the extracted instructions and parameters to ensure that they meet the working range and requirements of the machine tool and avoid unreasonable instructions or parameters. The G-code parsing process designed in this paper mainly includes three steps: lexical checking, syntax checking, and data extraction of G-code.
[0116] Lexical checking refers to the lexical analysis of the G code file, which divides the character sequence in the file into lexical units, such as instructions, parameters, etc. During the lexical analysis process, it is necessary to identify various instructions and parameters and convert them into internal representations for subsequent syntax analysis and processing. Syntax checking is the grammatical analysis of lexical units to check whether they conform to the syntax rules of the G code. During the syntax checking process, it is necessary to verify whether the relationship between instructions and parameters is correct, and whether there are grammatical errors or unreasonable parts. If syntax errors are found, corresponding error prompts need to be given; data extraction is the extraction of instructions and data from the G code, and saving them to specific structure variables to facilitate the motion control system to obtain processing parameter information. The G code parsing process is as follows: Fig.10 shown.
[0117] The code parsing module designed in this paper scans and processes the program file line by line. Each line of code must go through the above three steps to be processed, stored in the structure and inserted into the structure linked list of the buffer. This cycle continues until the entire program is parsed. The parsed instruction set is then transmitted to the tool compensation module for processing. Finally, the processed instruction set is sent to the M4 end in the form of a byte stream, and is called by the motion control module program for interpolation processing.
[0118] 2.2.3 NC program analysis software design
[0119] (I) Lexical Analysis
[0120] In the entire code parsing process, lexical checking is a crucial link. Its role is to decompose the G code string into lexical units and verify whether the instructions, parameters and structures in the code meet the standard requirements of the G code language. For example, the instructions in the G code usually start with the letter G or M, followed by one or more numbers to represent different functions or operations. The syntax checker verifies whether the instructions meet this format requirement to ensure that they are correctly recognized and parsed.
[0121] Regular expressions can help us find specific characters or substrings in a string accurately. Given that G code has strict programming specifications and standards, regular expressions can be used to quickly and easily extract key information such as instructions and parameters in G code. Therefore, this article uses the regular expression QRegExp class under the Qt framework to implement the programming of G code preprocessing. The workflow diagram of lexical checking is as follows: Fig.11 shown.
[0122] First, a regular expression pattern table is established according to the G code programming specifications, and then a line of code is read from the program file separated by line breaks. Each phrase is checked according to the lexical character matching table. If there are unmatched phrases, it means that the program uses instructions that the CNC machine tool cannot recognize, and a relevant error message will be displayed in a pop-up window on the human-machine interface. If all phrases in the entire line of code pass the match, the line of code is saved in a string as the source code for the next stage of syntax checking.
[0123] The phrase of G code is usually composed of an address character and a numerical value. The address character refers to a letter with a specific meaning, such as the preparation function word (G function word), dimension word (X, Y, Z), feed function word (F), etc. The numerical value is the number following the address. The numerical value following different function words has different meanings and value ranges [51-52]. The lexical analysis regular expression designed based on this rule is as follows:
[0124] QRegExp gCodePattern1("[GM]\\d{1,2}"); / / G, M code function word
[0125] QRegExp gCodePattern2("[XYZIJKR][+-]?\\d{1,4}([.]\\d{0,3})?"); / / Size character
[0126] QRegExp gCodePattern3("[NFST]\\d{1,4}"); / / auxiliary function word
[0127] QRegExp gCodePattern4("^%\\s*$"); / / beginning and end of program segment
[0128] gCodePattern1 is used to match G and M code function words, followed by two integers, ranging from 00 to 99. gCodePattern2 is used to match coordinate related information, and the size function word can be followed by an integer or decimal, ranging from -0000.000 to +9999.999. gCodePattern3 is used to match program segment number, feed rate, command speed and other function words, and the function word can be followed by an unsigned one to four-digit integer. gCodePattern4 is used to match the beginning and end of the program.
[0129] (ii) Grammar check
[0130] After a line of code is obtained from the program file, it is analyzed by lexical analysis and then enters the syntax check. The syntax check includes whether the function code of the same modal group appears only once, whether all the function codes that appear in the same line are legal, such as whether G00 and G01 appear in the same line, whether there is coordinate instruction data after G00 and G01, whether the tool compensation is canceled when changing tools, etc. The syntax check is also implemented using regular expressions. Similar to the lexical check stage, if the line of code passes the syntax check, the program segment that passes the check is saved in a string for data extraction. If it fails the check, a pop-up window will display the relevant error message on the human-machine interface to prompt the user to correct the program segment. The syntax check process is as follows: Fig.12 Shown
[0131] (III) Data extraction
[0132] If there are errors in the lexical analysis or syntax checking of the program segment, the user should make necessary modifications to the program according to the error message prompted. If there are no errors, the code parser will extract the instructions and data in the program segment, including identifying functional instructions and extracting parameter values related to these instructions. The extracted instructions and data are then stored in structure variables and stored in a structure linked list until the entire program is parsed. The linked list is then sent to the M4 end in the form of a byte stream. When the system needs to perform processing operations, the decoding unit of the motion control module reads the variables in these data structures to obtain the required processing motion parameter information, and controls the machine tool for processing accordingly.
[0133] After the extraction is completed, the data storage structure of a line of NC code is as follows:
[0134]
[0135] For G and M instructions, this article uses the flag form to store them. The char data type can represent an 8-bit binary number. The value of one or several binary numbers represents the effective state of an instruction function word. This definition method greatly reduces the amount of data and can greatly reduce the storage space of the buffer. The storage structure of G and M instructions is shown in the figure below. Fig.13 shown.
[0136] 2.3 Tool radius compensation
[0137] 2.3.1 Concept of tool radius compensation
[0138] The CNC system processes the workpiece according to the motion trajectory analyzed by the NC program. The CNC machining code generated by the software is generally designed according to the contour and size of the workpiece. However, in the actual machining process, the tool has a certain radius length. At the same time, as the tool wears during the machining process, the radius value will also change. Therefore, there will be an offset between the motion trajectory of the tool center and the actual contour trajectory of the workpiece. Therefore, we need to correct the trajectory of the tool center according to this offset to make the actual machined parts consistent with the shape and size of the parts expected during programming.
[0139] Tool compensation is divided into left compensation (G41 command) and right compensation (G42 command). When the G41 command is used, the tool automatically shifts to the left by a set compensation amount during the cutting process. In contrast, the G42 command will automatically shift the tool to the right by a set compensation amount during the cutting process. When the workpiece is processed clockwise or when the tool is on the left side of the workpiece, left compensation is usually used, and when processing in the counterclockwise direction or when the tool is on the right side of the workpiece, right compensation is usually used. The schematic diagram of the tool radius compensation model is shown below. Fig.14 shown.
[0140] 2.3.2 Research on tool radius compensation
[0141] The essence of radius compensation is to use the coordinate difference between the actual position of the tool and the programmed position, and use coordinate transformation to correct the tool's motion trajectory. According to the different types of machining contours, it can be divided into linear tool compensation and arc tool compensation. According to the different connection transition methods between two segments of the trajectory, it can be divided into three types: straight line connecting straight line, straight line connecting arc, and arc connecting arc.
[0142] 1. Calculation of linear tool radius compensation
[0143] like Fig.15 As shown, point P0 (X0, Y0) is the starting point of the workpiece straight line contour trajectory, point P e (X e ,Y e ) is the end point of the straight line trajectory, the tool radius is r, assuming that the system is performing tool right compensation, then the compensated straight line trajectory is P'0P' e , so we need to calculate the starting coordinates P0'(X0',Y0') and the end coordinates P e '(X e ',Y e ').
[0144] Assume vector The coordinates of P′0 are (ΔX, ΔY), then the coordinates of P′0 can be expressed as (3.1):
[0145]
[0146] Also because there is
[0147]
[0148] Therefore, the starting point coordinates of the new straight line trajectory after tool right compensation are calculated as follows:
[0149]
[0150] Just replace the coordinates of point P0 with P e The coordinates of the point can be used to calculate the end point coordinates of the new trajectory after compensation. The above calculation is based on the assumption that the tool is compensated on the right side of the straight line segment. If the tool is on the left side, the direction of compensation will be opposite, and the coordinates of the left tool compensation starting point P″0 are calculated as shown in formula (3.4):
[0151]
[0152] 2. Arc tool radius compensation calculation
[0153] like Fig.16 As shown, point A(X a ,Y a ) is the starting point of the workpiece arc trajectory, point B (X b ,Y b ) is the end point of the arc trajectory, the coordinate origin O is the center of the arc trajectory, the arc radius is R, and the tool radius is r. Assuming that the system performs right tool compensation, the starting point and end point of the arc trajectory after compensation are A′(X′ a ,Y′ a ) and B′(X′ b ,Y′ b ), their coordinates are calculated as follows:
[0154] Let vector The projection on the X-axis is ΔX, and the projection on the Y-axis is ΔY, so we have
[0155]
[0156] From the geometric relationship, we can get formula (3.6):
[0157]
[0158] Therefore, the coordinates of the starting point of the new arc trajectory after tool right compensation are calculated as follows:
[0159]
[0160] Similar to linear compensation, the coordinates of the new arc trajectory end point can be obtained by simply substituting the coordinates of point B. If left tool compensation is performed, the coordinates of the new arc trajectory start point are calculated as shown in formula (3.8):
[0161]
[0162] 3. Inter-segment transition calculation
[0163] During continuous machining, in order to connect the previous and next machining paths, it is necessary to calculate the coordinates of the tool compensation connection point to ensure that the tool can smoothly transition from one path segment to another and avoid unnecessary pauses or jumps at the connection.
[0164] (a) Straight-line to straight-line transition
[0165] In CNC machining, when two straight line segments are connected, their transfer point is the common endpoint of the two straight lines. When performing tool compensation calculations, for the case of a straight line connecting to a straight line, the coordinates of the transfer point are still determined by the common endpoint of the two straight lines, such as Fig.17 As shown:
[0166] The two segments before and after the continuous machining program are both straight line trajectories. The new trajectory of the first segment AB after adding tool compensation is A1B1, and the new trajectory of the second segment BC after adding tool compensation is B2C1. Let us assume that the trajectory function of A1B1 is y=k1x+b1, and the trajectory function of B2C1 is y=k2x+b2. By combining the two trajectory functions, the intersection point X of the two trajectories can be obtained. This intersection point is the transition point of the two straight line tool compensation trajectories. The calculation process is shown in formula (3.9).
[0167]
[0168] (b) Straight line and circular arc transition
[0169] The schematic diagram of the straight line transition to the arc is as follows Fig.18 Shown
[0170] The workpiece trajectory is the transition from straight line AB to arc BC, and the intersection point between the two trajectories is B(X b ,Y b ), the new trajectory of the first straight line trajectory AB after adding tool compensation is A1B1, and the new trajectory of the second arc trajectory BC after adding tool compensation is B2C1. Let's assume that the trajectory function of A1B1 is y=kx+b, and the trajectory function of B2C1 is (xm) 2 +(yn) 2 =R 2 , combined two trajectory functions
[0171]
[0172] The solution is to obtain the coordinate value of the intersection point M of the two trajectories:
[0173]
[0174] There are two solutions to the equation group. It can be clearly seen from the figure that the point closer to point B is the actual tool compensation intersection point M. Substituting the horizontal coordinate of M into the trajectory function can obtain the coordinate value of M.
[0175] (c) Arc to Arc Transition
[0176] The schematic diagram of arc transition is as follows: Fig.19 As shown:
[0177] The workpiece trajectory is arc AB to arc BC. The new trajectory after adding tool compensation to the first segment AB is A1B1, and the new trajectory after adding tool compensation to the second segment BC is B1C1. Let's assume that the trajectory function of A1B1 is (x-m1) 2 +(y-n1) 2 =R1 2 , the trajectory function of B1C1 is (x-m2) 2 +(y-n2) 2 =R2 2 , combining the two trajectory functions:
[0178]
[0179] Solving equation (3.13) yields:
[0180]
[0181] make
[0182]
[0183] Substituting k and t, the horizontal coordinate of the transfer point M can be calculated. Similar to the transition from a straight line to an arc, there are also two solutions. The point closer to point B is the actual tool compensation intersection point M. Substituting the horizontal coordinate of M into the trajectory function can obtain the coordinate value of M.
[0184] In the tool compensation implementation, the transition (transfer) mode of the tool center trajectory from one programming segment to another is further subdivided into three types: extension type, shortening type and insertion type. Taking into account the vector angle between the two programming trajectories (the angle between the two programming trajectories on the non-machining side at the intersection) and the tool compensation direction, there are as many as 54 types of transfers, which need to be fully considered when designing the tool compensation algorithm. However, they are all based on the above three basic transfer types. Due to space limitations, this article will not give a detailed introduction here.
[0185] 2.3.3 Design and implementation of tool radius compensation
[0186] The key to tool radius compensation is to determine the connection relationship between the two tool trajectories through the program processing module. In the design of the NC code preprocessing module in the previous section, data has been extracted from the program segments that have passed the lexical analysis and syntax check, and the processing data in the NC program segments are saved in the buffer according to a certain data structure. Tool radius compensation processing is to convert the processing path data in the buffer according to the tool center offset. In this process, the data storage structure will not change. The tool radius compensation processing program flow chart is as follows: Fig. 20 shown.
[0187] In order to accurately determine the type of transition between two trajectories in the NC program code, when implementing tool radius compensation processing, we first need to continuously read two segments of machining path information from the buffer, which are marked as Current_Buffer and Next_Buffer respectively. Next, we parse the G instructions in Next_Buffer. If it does not contain G41 or G42 (that is, it does not contain tool radius compensation instructions), there is no need to perform special processing on the data in Current_Buffer, and it can be directly written into the intermediate file.
[0188] If Next_Buffer contains G41 or G42 instructions, the new tool trajectory coordinates need to be calculated based on the current tool radius and compensation direction (left or right). Then, by analyzing the function words in the two code segments, the trajectory transfer type can be determined. Based on the transfer type, the transfer point coordinates of the two trajectories are calculated, and the end point coordinates in Current_Buffer and Next_Buffer are updated accordingly, thereby achieving accurate correction of the actual tool trajectory.
[0189] After processing the current two code segments, we need to update the Current_Buffer and Next_Buffer. The data in Next_Buffer is passed to Current_Buffer as the first code segment of the next processing, and the next code segment is read from the buffer as the new Next_Buffer. This process will continue until the entire NC program is processed. If the G40 instruction (cancel tool radius compensation) is encountered in the subsequent reading of Next_Buffer, the tool compensation processing will no longer be executed.
[0190] 2.4 Research and implementation of inter-core collaboration
[0191] The Cortex-A7 core of this system runs the embedded Linux operating system to perform non-real-time tasks such as human-machine interface, code analysis, and parameter management. The Cortex-M4 core runs the FreeRTOS real-time operating system to complete real-time tasks such as interpolation operations and bus driving. The two cores communicate through shared memory to achieve coordinated processing between various tasks of the CNC system. The data exchanged between the cores is stored in the shared memory space. After the sending core sends the data, it notifies the receiving core in the form of an inter-core interrupt. The application of the receiving core reads the data from the shared memory through the interrupt service program and processes it.
[0192] 2.4.1 Inter-core communication mechanism design
[0193] For STM32MP157, A7 is called the main processor and M4 is called the coprocessor or remote processor. According to the previous introduction, the user programs of A7 and M4 can send data by calling the API provided by RPMsg, but they need to specify the RPMsg endpoint, the user data to be sent, the length of the data (in bytes), and the source address or destination address, etc., which is not convenient and flexible to use. Therefore, when designing the program, this article adopts the virtual serial port provided by the OpenAMP library to implement it, encapsulate the communication mechanism of RPMsg into an interface similar to a serial port, and the creation, configuration and management process of the RPMsg channel is encapsulated into an API similar to a serial port. The applications on the A7 and M4 ends can send and receive data in the manner of serial port operations, but the transmitted data is still stored in shared memory. The program flow chart of this system that uses a virtual serial port to implement data interaction between cores is shown below. Fig.36 shown.
[0194] The A7-side human-machine interface application of the system is developed based on Qt. After the A7 kernel is started, the human-machine interaction program calls the Linux command line through the QProcess class to load and run the M4 firmware in the storage unit. In the M4 application, the RPMsg endpoint is created by calling the virtual serial port initialization function VIRT_UART_Init() in the OpenAMP library. When the service name of the endpoint is consistent with the name attribute in rpmsg_driver_tty_id_table[] under the Linux kernel source code, the A7 kernel will establish an RPMsg channel to achieve communication between the two kernels. In the applications of the two cores, the corresponding callback functions are bound to the virtual serial ports respectively. When the virtual serial port receives data, the bound callback function will be executed.
[0195] In this system, there are two main types of data that are exchanged between the two cores. One is the bulk data such as pre-processed processing program data or compiled PLC program. Its data frame format is as follows: Fig.37 The other is a simple data frame such as system mode switching or processing control command information, and its data frame format is as follows Fig.38 To avoid the time overhead caused by frequent communication between cores, for large batches of data such as the former, A7 sends them to M4 through the virtual serial port, and M4 writes them into the dedicated memory. When executing workpiece processing, the data is read from the M4 dedicated memory, thereby avoiding frequent interruptions affecting the execution of motion control tasks. For control commands, the M4 application calls the corresponding function module function according to the corresponding command number.
[0196] 3. Research and implementation of soft PLC subsystem
[0197] 3.1 Soft PLC structure and working principle
[0198] The soft PLC has many similarities with the traditional PLC in terms of system structure. The overall system is divided into two parts: the development system and the operation system. The functions of these two parts correspond to the upper computer and the lower computer in the traditional PLC. Fig.21 shown.
[0199] The development system is similar to the host computer in traditional PLC, which is mainly responsible for programming and monitoring tasks, allowing users to create and edit the control logic of PLC through the ladder diagram editor. The operation system is similar to the slave computer in traditional PLC, which is mainly responsible for executing control logic and controlling external devices. It receives the compiled control program from the development system and controls the input and output devices on site according to the instructions in the program to realize industrial automation control.
[0200] The development system and operation system designed in this paper run on two different cores of the same processor respectively. Through this deployment method, the development system and the operation system can each focus on their own tasks, achieving efficient real-time performance while improving the integration of the soft PLC system. The development system and the operation system exchange data through shared memory to ensure the overall reliability and response speed of the system.
[0201] The embedded soft PLC implemented in this paper uses an embedded microprocessor to implement PLC data and program storage, logical operations and control, and collects data from field input devices and controls signals of output devices through remote I / O modules based on the EtherCAT bus. Its working method is that the user first writes and debugs the control program in the development system, and then calls the compilation module to convert the user program into an intermediate code that can be recognized by the running system. The development system transmits the intermediate code to the running system through shared memory, and the running system interprets and executes the intermediate code, and outputs the results of the logical operation to the remote I / O module through EtherCAT, thereby realizing the control of field devices. In this process, the operating status of the external device will also be fed back to the development system through the bus through the running system and inter-core communication for the user to view.
[0202] 3.2 Soft PLC development system design
[0203] 3.2.1Soft PLC Development System Framework
[0204] PLC has a variety of programming languages, including ladder diagram, function block, statement list, sequential function chart, etc.
[57] . Among them, ladder diagram programming is favored by many electrical engineers because it is highly similar to the circuit diagram of traditional relay control system. It uses the terms such as contacts, coils, and series and parallel of traditional relays, which makes it easier for electrical personnel with relay control background to understand and apply it intuitively. In daily PLC use, ladder diagram programming is also the most widely used. Therefore, this paper adopts ladder diagram that complies with IEC61131-3 standard as the programming language of soft PLC function.
[0205] The development system includes an editing module and a compiling module. The editing module allows the user to write and edit the control program in the form of a ladder diagram on the human-machine interface. After the user completes the ladder diagram program editing, the compiling module converts the ladder diagram program written by the user into an intermediate code that can be recognized by the running system, and performs a logic check on the program in the process. If the check is correct, the intermediate code is sent to the running system through the shared memory, and the running system interprets and executes it. If the check is wrong, the user is prompted through the human-machine interface. The logical structure model of the development system is as follows: Fig. 22 As shown:
[0206] 3.2.2 Ladder Diagram Editing Area Design
[0207] The soft PLC designed in this paper is a soft PLC subsystem embedded in the CNC system, so its development system software is also developed based on Qt. The ladder diagram editing function is embedded in the human-machine interface program of the CNC system and serves as one of the function menus. Click the "ladder diagram editing" button under the diagnostic first-level menu to enter the PLC ladder diagram editing interface. When the system enters the ladder diagram editing interface, the function buttons at the bottom of the page will also become graphic element buttons. Different graphic element buttons correspond to different PLC component types. The ">>" button can be used to turn the graphic element button area. The ladder diagram editing interface is as follows Fig.23 shown.
[0208] The editing and display area of the ladder diagram is implemented using Qt's predefined drawing device class QWidget. In order to ensure the orderliness and readability of the ladder diagram program, the ladder diagram drawing area is laid out in a grid format, stipulating that each ladder diagram element occupies a grid, and each grid has fixed coordinates in the drawing area, so that it can be mapped to the row and column positions of the ladder diagram element in the drawing area.
[0209] By re-implementing the mouse press event function mousePressEvent(QMouseEvent*event) of the QWidget class, you can get the coordinate information of the mouse click in the ladder diagram drawing area. When the user clicks the position where the component is to be placed in the drawing area, the program will obtain the coordinate information of the position, convert it into row and column position information, and highlight the grid area at that position. By clicking the PLC component button on the menu bar, you can add the corresponding component to the grid at the mouse click position. This system sets a 1000*10 grid in the ladder diagram editing area, which means that each ladder diagram program can write up to 1000 lines, and each line contains up to 10 graphics elements.
[0210] The above design idea enables each ladder diagram component to be assigned specific row and column position information, allowing users to edit and modify the ladder diagram program intuitively and conveniently, while reducing the difficulty of storing and converting the ladder diagram program. By obtaining the row and column position information of the component, all components of the entire ladder diagram can be easily saved and converted.
[0211] 3.2.3 Ladder diagram element design
[0212] In order to realize the ladder diagram drawing, this paper abstracts the ladder diagram elements involved in the system into visual elements in the software, namely ladder diagram primitives. These primitives represent the elements in the PLC (Programmable Logic Controller) with graphical symbols and attributes. Each primitive corresponds to a specific graphic symbol.
[0213] Taking into account the diversity of graphics elements, the graphics elements of the CNC system soft PLC designed in this paper are divided into basic instruction graphics elements and functional instruction graphics elements according to the instruction functions. Adopting the object-oriented design method, the common properties of all graphics elements are abstracted and a base class of graphics elements is created. This base class is built based on Qt's window widget class QWidget. By deriving specific classes from the base class, their unique properties and methods can be defined according to the characteristics of different graphics elements. By creating a PLCElement class to describe the common properties of all graphics elements, the common properties of components such as component name, component type, component number, and drawing methods are defined in the graphics element base class. The code is as follows:
[0214]
[0215] In the above base class design, the tool_Type variable represents the component type, the tool_Name variable represents the component name, the tool_Num variable represents the component number, and the tool_Branch variable represents the branch status of the component. Different values of the member variables correspond to different definitions. The comparison between the class member variable values and definitions is shown in Table 4.1.
[0216] Table 4.1 Comparison table of values and definitions of element class member variables
[0217]
[0218] The primitive base class PLCElementBase defines the name, type and number of the element, which are the common attributes of ladder diagram primitives. According to the specific ladder diagram element type (such as input relay, output relay, etc.), specific subclasses can be derived from PLCElement, and the attributes of different primitive types can be added to the subclasses. Each subclass inherits the common attributes of PLCElement and can add its own unique attributes. By re-implementing the drawing event processing function paintEvent (QPaintEvent*event) contained in each subclass, the drawing of graphic symbols corresponding to different primitives can be realized.
[0219] This article divides the graphics in the system into simple graphics and complex graphics. Simple graphics refer to graphics without parameters or with fewer parameter types. These graphics usually have simpler structures and functions, and usually only perform single bit operations during interpretation and execution, such as horizontal connections, vertical connections, normally open and normally closed contacts, direct output coils, and set and reset coils. These simple graphics inherit from the graphics base class, thereby inheriting its common properties and methods. For simple graphics, the internal parameter types are not much different from the graphics base class, and only its unique drawing methods need to be paid attention to, so they are not introduced here.
[0220] Complex primitive classes refer to those primitives with more parameter types or used to implement specific logic operations or control functions, such as timers, counters, data comparisons, data shifts, etc. These primitives often have more parameters and more complex logic processing requirements, so their data structures need to be designed separately to meet these specific requirements. Because there are many types of primitives, here we only take the logic operation function block as an example to introduce its class design.
[0221] The logic operation function block is used to process and control input signals and generate output signals according to logical relationships. Through the logic operation function block, the soft PLC can realize complex logic operation control such as data comparison, data shift, addition, subtraction, multiplication and division, etc. The class design code of the logic operation function block is as follows:
[0222] class logic_Operation:publicPLCElement
[0223] {
[0224] public:
[0225] logicOperation();
[0226] unsigned char logic_Type;
[0227] unsigned char ctrl_Condition;
[0228] unsigned int Para_A;
[0229] unsigned int Para_B;
[0230] unsigned int Para_C;
[0231] virtual~PLCElementBase();
[0232] }
[0233] The variable logic_Type is the type of logic operation. Different values correspond to different types of logic operations. The variable ctrl_Condition represents the control condition. Different control conditions correspond to different operation rules. Para_A, Para_B, and Para_C are the parameters of the function block. Parameter C is always an address. The types of parameters A and B can be addresses or constants, depending on the value of the control condition variable. The two variables, the type of logic operation and the control condition, jointly determine the specific operation rules of the logic operation. The comparison of the values and definitions of the logic operation type variables is shown in Table 4.2.
[0234] Table 4.2 Logical operation type parameter value and definition comparison table
[0235]
[0236] 3.2.4 Ladder diagram editing and drawing
[0237] When editing a ladder diagram, first click on the area where you want to place the component. The program will capture this event, calculate the row and column information of the location in the ladder diagram editing area based on the clicked position, and select and highlight the corresponding grid. You can draw the component in the grid by clicking the component button at the bottom of the page. If you want to configure and change the properties of the component, just double-click on the original and the component property configuration window will pop up. Users can change and configure the component properties through this window, and the corresponding primitive property display in the grid will also be updated. For the convenience of editing, when a component is edited, the pointer will automatically move to the next grid, that is, the column will be automatically added by one. If the added component is an output type, then horizontal connecting lines will be added from the current column to the ninth column of the current row, and the output component will be added in the last column. When the column exceeds the maximum limit, the pointer will move to the next row.
[0238] The user can edit and modify the ladder diagram through the above steps. After editing, the user needs to click the Save button at the bottom of the page. The system will prompt whether to save. The user can decide whether to save the changes according to the actual situation. Fig.24 As shown:
[0239] When designing the primitives, each primitive class contains the corresponding drawing method and double-click response function. When each user clicks the corresponding component button in the menu bar at the bottom of the page, the program will call the drawing function of the corresponding primitive class according to the button ID, thereby realizing the drawing of the ladder diagram components in the grid. For the attribute configuration of the primitive, the program designs the primitive attribute editing dialog box. When the component is double-clicked, the double-click response function will be called and the attribute value set in the dialog box will be updated to the primitive.
[0240] To facilitate program modification, the system has set up component deletion and row deletion buttons in the menu bar at the bottom of the page. The logic is the same as adding components. First, click the element to be deleted, and then select the Delete button. The program will delete the element instance at the current position according to the current cursor position and refresh the window. The same is true when deleting a row. The program will delete all element instances in the current row according to the current cursor position.
[0241] 3.2.5 Saving and loading ladder diagrams
[0242] In actual applications, users do not often change ladder diagram programs, and usually reuse ladder diagrams that have been edited and saved in the system. Therefore, in order to improve the convenience of operation, this system can save the ladder diagram code edited and modified by the user in the form of a binary file in the system memory. The file contains all relevant information of the ladder diagram program, including the structure of the ladder diagram, the location and attributes of each graphic element, and the logical relationship between the graphic elements. When the system is initialized, all ladder diagram data is loaded from the above binary file, and then the corresponding graphic element objects are rebuilt based on these data and filled into the corresponding positions, so that the previously stored ladder diagram program is accurately redrawn into the editing area for users to continue editing or using.
[0243] In ladder diagram programming, there are usually multiple rungs, and each rung contains a series of graphic elements, such as contacts, coils, function blocks, etc. In order to save the entire ladder diagram program completely and accurately, we need to store and process each rung separately. For a single rung, we need to record and store all the graphic element information it contains, as well as the logical relationship between these graphic elements. Considering that each graphic element has similar attributes, including type, name, number, and parameter information, in order to facilitate program design, this article uses a unified data structure to store graphic element attributes. The graphic element storage data structure is defined as follows:
[0244] typedef struct
[0245] {
[0246] short row_Num; / / row number where the component is located
[0247] short col_Num; / / column number where the component is located
[0248] char m_Type; / / component type
[0249] char m_Name; / / component name
[0250] short m_Number; / / component address
[0251] char m_Branch; / / Branch status
[0252] int params[3]; / / Storage component parameter information
[0253] short param_Count; / / Number of parameters
[0254] }LadderElement
[0255] The above defined primitive storage data structure clearly and completely reflects the primitive information. The m_Type member is used to store the component type, m_Name is used to store the component name, m_Number indicates the component number, the params member is used to store various parameter information related to the component, the paramCount member indicates the number of parameters, which is used to indicate the size of the parameter list, and the row_Num and col_Num members respectively indicate the row number and column number of the component in the ladder diagram editing area. These two variables are crucial for the position layout when rebuilding the ladder diagram. The above structure can be used to store an instance of each primitive class in the ladder diagram.
[0256] In order to save all the graphics elements in the ladder diagram, additional data structures are required to store these graphics element structures. This article chooses to use a simple data structure such as an array to save all the graphics element information in the ladder diagram. When the user completes the ladder diagram and clicks Save, the program will create a structure array LadderElementArray, and then start from the first row and first column of the ladder diagram, and scan each grid in order from left to right and from top to bottom. If there is an instance of the graphics element class in the grid, the graphics element information will be saved to the structure instance, and the structure instance will be added to the LadderElementArray array until the entire ladder diagram editing area is scanned. The ladder diagram saving program flow chart is as follows Fig.25 shown.
[0257] In order to restore the ladder diagram when the system is restarted and initialized, the above structure array needs to be saved in the form of a binary file. When the system is initialized, the program can read the ladder diagram information from the file and reconstruct the primitives. Thanks to the convenience of the Qt framework, Qt provides the QDataStream class to serialize and deserialize data, so we can use QDataStream to write the structure array that saves the ladder diagram program information into a byte stream, thereby realizing serialization and writing it to the file. When the ladder diagram is to be loaded, the program will read the structure array from the above binary file through deserialization, and then restore all primitives in sequence according to the structure information in the array.
[0258] 3.2.6 Ladder diagram compilation module
[0259] The ladder diagram compilation module is the core part of the development system. The ladder diagram compilation module designed in this paper is mainly composed of two parts: the logic check unit and the intermediate code conversion unit. The logic check unit is mainly responsible for the logic check of the ladder diagram written by the user to ensure the correctness and rationality of the ladder diagram. In this process, the logic check unit will analyze each element in the ladder diagram and the connection relationship between them to determine whether there are logical conflicts and errors. If problems are found, the logic check unit will pop up a window to prompt relevant error information to help users locate and fix these problems. After the ladder diagram passes the logic check, it will enter the intermediate code conversion unit, which will convert the ladder diagram that passes the logic check into the intermediate code that the running system can recognize. During the conversion process, the program will generate the corresponding intermediate code according to the element type and connection relationship of the ladder diagram.
[0260] (I) Logic Check Unit
[0261] In the process of ladder diagram editing, some errors are inevitable, such as short circuit, open circuit and other syntax and logic errors or function block parameters are not set. These errors may not only cause abnormal operation of PLC, but also damage hardware equipment in serious cases. Therefore, the compilation module will carefully check the ladder diagram before converting it to ensure its accuracy. The following are common error types of ladder diagrams and the inspection methods in this article.
[0262] Short circuit: A short circuit condition refers to the current passing directly through the ladder diagram without logic processing, which may cause the program logic to fail, such as Fig.26 As shown, for short-circuit errors, the inspection method in this article is to sequentially scan the ladder diagram program, find two parallel vertical lines according to the downward cascade mark of the primitive, and then count the number of primitives between the two parallel straight lines. If it is zero, it means there is a short-circuit error.
[0263] Open circuit: Open circuit means that a main circuit or branch circuit of the ladder diagram lacks a graphic element, such as Fig. 27 As shown, the inspection method for circuit breaks in this article is to sequentially scan the ladder diagram and record the positions where the graphics elements are empty. If there are graphics elements on both the left and right sides, it means that there is a circuit break error.
[0264] Constant output: A constant output error refers to a situation where there is only an output coil but no normally open or normally closed contacts on the main circuit of a ladder diagram. Fig.28 As shown, the method for checking constant output is to scan each graphic element in sequence and determine its component type. If only the output coil is scanned but there is no contact, it means that there is a constant output error.
[0265] Function blocks are missing parameters: For function blocks such as timers or logic operation modules, users are required to manually set instructions or parameters. If the user does not configure them, it will affect the execution of the ladder diagram. Take the comparison module as an example. If there is no configuration parameter, the primitive will display the parameter default value (invalid value). Fig.29 As shown, the method to detect this error is to determine whether its parameter is the default value. If so, it means that this error exists.
[0266] (II) Intermediate Code Conversion Unit
[0267] The ladder diagram program is composed of several rungs, each of which can be used to implement an independent task or function, such as input detection, logical judgment, output control, etc. The basis for the division of the rungs is whether there is a parallel relationship between two rows of components in the program, that is, if there is no parallel relationship between two rows of components in the ladder diagram, they can be classified as two different rungs. For each rung, the trunk of the rung is the center to connect the various branches.
[0268] This paper does not use the instruction list language as the intermediate code, but based on the ladder diagram storage structure introduced in the previous article, proposes a ladder diagram direct interpretation and execution method based on primitive mapping matching. The so-called primitive mapping matching is to map the ladder diagram into a structure array in the intermediate code conversion unit, with the ladder level as the conversion unit, starting from the first primitive of the main road and scanning horizontally from left to right. When encountering a branch at a node, scan each branch vertically according to the vertical connecting line, and save the primitive information structure into the array in a certain order.
[0269] According to the above idea, each rung of the ladder diagram is stored in a structure array. Each element of the array is a pointer to the LadderElement structure. The LadderElement structure instance pointed to by the pointer contains the attribute information of a grid element in the rung. The ladder diagram traversal and storage data structure example is as follows Fig.30 shown.
[0270] When converting the ladder diagram, for the rungs without parallel branches, we only need to scan the trunk from left to right, and save its information in the form of a structure into an array according to the position and type of the primitive. For the rungs with parallel branches, the depth-first search method is used for scanning, which can be divided into the following steps:
[0271] (1) Scan and convert from left to right starting from the main line of the ladder. Once a branch node is encountered, it will go to the next line to determine whether the vertical line of the current branch node is a left vertical line or a right vertical line.
[0272] (2) If it is a left vertical line, determine whether the right side is an output element. If so, convert it and then return to the previous branch node to scan right for conversion. If it is not an output element, directly return to the branch node and scan right.
[0273] (3) If it is a right vertical line, scan to the left until encountering a left vertical line or a left busbar. The graphic element between the two vertical lines is the parallel module. Scan and convert the parallel branch from left to right, record the number of graphic elements in the branch, and determine whether there is a branch node in the branch. If so, continue to perform operation (3). If not, after completing the branch conversion, return to the branch node and continue to scan to the right until the last column of the main line is converted.
[0274] Specifically: Fig.30 In the figure, the ones on the X side are all left vertical lines, because the right angle is to the left, and the ones on the Y side are all right vertical lines, because the right angle is to the right. In the figure, first enter (1), walk X1, X2, encounter a branch connected to the next row, enter the next row according to the rule, walk X5 and encounter a branch connected to the next row, enter the next row, walk X7, there is no branch connected to the next row, judge that the branch encountered after walking X7 is a left vertical line, enter rule (2), the right side of X7 is not an output element, then return to the previous level branch (second row), scan to the right, encounter a branch after walking X6, judge it is a left vertical line, and the right side of X6 is not an output element, return to the previous level branch (first row), scan to the right, walk X3, X4, encounter a left vertical line, judge that the right side is an output element, convert to (1), once you encounter a branch connected to the next The branch node of the row enters the next row, encounters a branch, enters the second row, encounters another branch, enters the third row, and there is no branch node connected to the next row. It is determined that the branch of the third row is a right vertical line, and enters (3). The third row is scanned to the left until the left main line (trunk). The graphics elements between the two vertical lines are connected in parallel, which means that the output graphics element on the right side of the right vertical line of the third row is connected in parallel with the output graphics element of the first row. The right side of the right vertical line of the third row is scanned to obtain Y3, and then return to the second row branch node, continue to perform operation (3), scan out Y2, and then return to the first row branch node, perform operation (3), obtain Y1, and complete the conversion of the last column of the trunk (the last column refers to the rightmost). The number of branch nodes can be used to determine how many rows of the rung just scanned, and according to the number of rows, enter the next rung and repeat the above scanning process.
[0275] During the above scanning process, we can calculate the depth of the current rung by the number of branch nodes, so as to determine the number of rows of the rung. After completing the scan conversion of the rung, we can directly jump to the row where the main road of the next rung is located according to the number of rows occupied by the rung, and start the scan conversion of the next rung. Repeat the above steps until the conversion of all runs is completed.
[0276] In the above way, the compilation module converts each rung into a structure array and packages it into a data frame and sends it to the running system. When packaging the data of each rung, the total number of conditional elements and the total number of execution elements of the rung must be added to the data frame so that the running system can parse and execute. The packaged byte stream information is regarded as the intermediate code. The data frame format of a rung is as follows: Fig.31 shown.
[0277] The operating system can read the number of conditional elements and output elements contained in a rung and the attributes of all the primitives contained in the rung by parsing the data frame, thereby realizing the direct interpretation and execution of the ladder diagram, which makes it easier to track and locate errors, because the processing of each primitive is independent, so when a problem occurs in a primitive, it is easier to find the problem. In addition, this type of primitive type allows customization of higher integration, because all information of the primitive will be saved in the data structure in the intermediate code conversion link, so the data structure can be designed to adapt to different types of primitives.
[0278] In contrast, as a more abstract way of expression, the instruction table needs to simplify or approximate the behavior of some graphics elements, which may lose some details or specific functions. Therefore, by directly saving the graphics element information, the richness of the graphics element types can be expanded, thereby reducing the complexity of ladder diagram programming and enabling developers to understand and implement control logic more quickly. More importantly, this method of directly interpreting and executing the ladder diagram can improve the efficiency of logical operations, and can terminate the execution of certain branches in advance according to logical conditions, or skip unnecessary calculations according to the input status, thereby improving the execution efficiency of the system.
[0279] 3.3 Design of soft PLC operation system
[0280] The soft PLC operation system designed in this paper consists of a storage management module and an interpretation operation module. The storage management module is responsible for receiving the intermediate code transmitted from the development system and saving it in the dedicated storage of the M4 kernel. When the PLC system starts running, the storage management module will read the corresponding intermediate code from the memory and pass it to the interpretation operation module. The interpretation operation module restores the intermediate code to graphic element information, performs logical operations according to the values of the corresponding software registers, and updates the input and output registers of the PLC according to the results of the logical operations, thereby realizing the control of external devices. The operation system structure is as follows Fig.32 Shown
[0281] 3.3.1 Storage Management Module
[0282] The storage management module mainly completes the data interaction with the development system. After the user completes the program editing in the development system, the intermediate code needs to be downloaded to the development system. During the operation of the soft PLC, the status of each relay also needs to be transmitted to the running system in real time. The data interaction between the development system and the running system is realized through shared memory. When the user completes the editing of the ladder diagram in the editing interface of the development system and clicks the compile button, the development system will send a program transmission request to the running system. After receiving this request, the running system will send a response signal to the development system, indicating that it is ready to receive the program. Subsequently, the development system will convert the intermediate code converted from the ladder diagram into a unit of rungs and send it to the running system frame by frame according to the pre-set communication protocol. Each data frame not only contains all the primitive information of the rung, but also indicates the number of conditional elements and execution elements in the rung.
[0283] In order to achieve efficient interpretation and execution of the intermediate code, the storage management module will record the first address of each data frame storage unit while saving the intermediate code. When the operating system needs to read the program instruction, it can quickly locate the corresponding storage location. When all the program instructions are received, the operating system will generate an instruction address table in the program storage area. This address table records the location of each ladder intermediate code in the storage area. When the program execution module is running, it can quickly retrieve the intermediate code through pointers according to this address table for interpretation and execution.
[0284] After the soft PLC starts running, the running system needs to feed back the effective status of each relay to the development system in real time. These data are also transmitted through shared memory. The running system adopts a periodic sending mechanism, which is responsible for the task scheduling unit of the M4 kernel application. It sends the data of the current input and output image storage area to the development system every 10ms. After receiving the status information, the running system parses it and reflects the results on the human-machine interface.
[0285] 3.3.2 Data Exchange Area
[0286] In order to ensure that the soft PLC operating system can accurately parse the logical relationship of the intermediate code, the consistency of the input data needs to be ensured within a single scan cycle. In the input sampling stage, all input status data received through bus acquisition are saved in the memory unit. In the rest of the scan cycle, no matter how the input status changes, the data in the memory should not be modified until the next sampling cycle starts. At the same time, since the status of the output relay and auxiliary relay will change during program execution, a dedicated memory space is also required to record these states. Therefore, this article defines a data storage area in the memory to store these status data, which is mainly divided into input register area, output register area, intermediate register area, and the intermediate register area includes auxiliary register area, timer and counter data register area.
[0287] 3.3.3 Explanation of running modules
[0288] The interpretation and operation module is the core of the operation system, and its main function is to restore the intermediate code to graphic element information and perform logical operations. When a scan cycle begins, the ladder diagram storage management module will read the PLC program data frame of each rung from the program storage area in turn according to the instruction address table mentioned above and perform parsing and logical operations. The operation system adopts the classic five-stage pipeline working mode when interpreting the intermediate code: instruction fetch, instruction decoding, register access, execution and write back. These five-stage pipelines work in parallel, that is, when one stage is processing a certain instruction, the next stage is ready to process the next instruction. This greatly reduces the waiting time between instruction executions and improves the throughput and execution efficiency of the entire system. The operation system pipeline working diagram is shown below. Fig.33 as shown.
[0289] For a rung of a PLC program, the process of interpretation and execution is a process of performing logical operations based on the state of conditional components and judging whether the output conditions are met. Since the soft PLC system designed in this paper does not use the instruction table as the intermediate code, the ladder diagram is directly interpreted and executed according to the idea of "element matching judgment" during decoding and logical operations. The so-called "element matching judgment" is to match the element attributes of each element in a rung, call the corresponding function to judge the state of the conditional element, and then judge whether the output condition is met through bit logic operations. If it is met, all the output conditions of the rung are executed in sequence. If not, the interpretation and execution of the next rung will start directly.
[0290] As mentioned above, when converting the intermediate code of the ladder diagram, all types of graphics elements use a unified data structure, so the memory space occupied by each graphics element is the same. Therefore, after the running system extracts a PLC program data frame of a ladder, it first reads the number of conditional elements and the number of execution elements of the ladder from the data frame according to the specified communication protocol, and uses pointer offset to read the storage structure of each graphics element to obtain its type, name, address, and whether it is cascaded downward. Then read the status of the corresponding register to obtain the on-off status of each conditional element, judge the on-off status of each conditional element one by one according to the number of conditional elements, and perform logical operations with the results of the previous level operation. Finally, judge whether the output condition is met based on the logical operation results of all conditional elements. If the output condition is met, the corresponding function function is called in sequence according to the number of output elements to modify the value of the software register. If the output condition is not met, the ladder diagram Figure 1The process of interpreting and executing a rung ends here. After the interpreting and running module completes the interpretation and execution of a rung, the running system will read the data frame of the next rung from the program storage area for parsing and execution, and repeat this cycle until the system stops running. Figure 1 The explanation and execution process of each ladder is as follows Fig.34 shown.
[0291] When performing logical operations on conditional elements, the idea of depth-first scanning is adopted. First, the logical operation results Res of all conditional elements are initialized to 1 and Res is used as the first-level logical operation result, that is, the default output condition is met, and then the matching judgment is performed one by one from the first element of the ladder. During the entire matching and operation process, the logical operation result of each element without a branch is always "AND" operated with the result of the previous element. In the process of matching and judging the ladder trunk conditional elements one by one, if a branch node is encountered, the current operation result is pushed onto the stack and the trunk scan is terminated, and the next row of branches is entered to start a new scan and matching judgment. If a branch point is encountered in the branch, the backward scan is also stopped and the operation result of the current row is pushed onto the stack. When the scan of the current branch is completed, the result of the branch is "OR" operated with the operation result at the top of the stack and the stack pop operation is performed, and then the result of the conditional element is judged backward from the previous branch point and the logical operation is performed. The above process will continue until all input elements are judged and calculated, and the final logic operation result is obtained. If it is 1, it means that the output condition is met, and if it is 0, it means that the output condition is not met.
[0292] In order to explain the process of running the system logic operation more specifically, the following is a ladder diagram rung example for detailed explanation. Fig.35 As shown: After completing the extraction of graphic element information and input state sampling, the logic operation process of the ladder diagram shown in the figure is as follows.
[0293] 1) Read the values corresponding to X1 and X2 in the input registers in turn, perform AND operations, and push the result Res into the simulation stack. The X2 cascade flag is 1, so the logical value of the cascade branch must be calculated first;
[0294] 2) Read the value corresponding to X5 in the input register, save it to ConcaLogic1 and push it into the simulation stack. The X5 cascade flag is 1, so the logic value of the cascade branch must be calculated first.
[0295] 3) Read the value of X7 in the register. There is no element on the right side of X7, so the cascade branch judgment is completed. Pop ConcaLogic1 in the simulation stack, perform an OR operation on the two, and save the result to ConcaLogic1;
[0296] 4) Read the value corresponding to register X6 and perform AND operation with ConcaLogic1 and save the result in ConcaLogic1;
[0297] 5) Pop Res from the simulation stack, perform an OR operation with the variable ConcaLogic1, and save the result to Res. At this point, the logic value of the cascade branch has been calculated;
[0298] 6) Read the values of X3 and X4 in the input register in turn and perform AND operation with Res, and save the result in Res;
[0299] 7) Complete the logical operation and output the value of Res to the output register mapped by Y1.
[0300] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. An embedded CNC system based on heterogeneous multi-core, characterized in that: It includes a development system, an operating system and a bus servo drive unit, wherein the data output end of the development system is connected to the data input end of the operating system, and the data transmission end of the operating system is connected to the data transmission end of the bus servo drive unit; Among them, the development system is used for programming and monitoring tasks; The running system is used to execute control logic and control external devices, receive the compiled control program from the development system, and control the input and output devices on site according to the instructions in the program to realize industrial automation control.
2. The heterogeneous multi-core embedded numerical control system according to claim 1, characterized in that: The development system and the operating system respectively run on two different cores of the same processor. The development system adopts the Cortex-A7 core, and the operating system adopts the Cortex-M4 core.
3. The heterogeneous multi-core embedded numerical control system according to claim 2, characterized in that: The Cortex-A7 core is used for human-computer interaction tasks, code preprocessing, G-code parsing, tool compensation processing, file management, and parameter setting; The Cortex-M4 core is used for interpolation operations, position control, bus driving, and PLC tasks.
4. The heterogeneous multi-core embedded numerical control system according to claim 2, characterized in that: The Cortex-A7 core and the Cortex-M4 core realize inter-core data interaction through shared memory and inter-core interrupt mechanism.
5. The heterogeneous multi-core embedded numerical control system according to claim 1, characterized in that: In the development system, the ladder diagram is mapped into a plurality of structure arrays through an intermediate code conversion unit, wherein one structure array is used to store information of a rung of the ladder diagram; finally, these structure arrays are packaged into data frames and sent to the running system; After the operating system receives the data frame, the storage management module of the operating system obtains all the information of the ladder diagram by identifying the data frame of the intermediate code. While saving the intermediate code, the storage management module records the first address of each data frame storage unit.
6. The heterogeneous multi-core embedded numerical control system according to claim 5, characterized in that: The ladder diagram is mapped into multiple structure arrays through an intermediate code conversion unit, including: starting from the first graphic element of the main road, scanning horizontally from left to right, and saving its information in the form of a structure into an array according to the position and type of the graphic element; when encountering a branch at a certain node, a depth-first search method is used for scanning, and each branch is scanned vertically according to the vertical connecting line, and the graphic element information structure is saved in the array in order.
7. The heterogeneous multi-core embedded numerical control system according to claim 6, characterized in that: include: (1) Scan and convert from left to right starting from the main line of the ladder. Once a branch node is encountered, it will switch to the next line for judgment to determine whether the vertical line of the current branch node is a left vertical line or a right vertical line; (2) If it is a left vertical line, determine whether the right side is an output element. If so, perform a conversion and then return to the previous branch node to scan right for conversion. If not, directly return to the branch node and scan right. (3) If it is a right vertical line, scan to the left until it encounters a left vertical line or a left busbar. The graphic element between the two vertical lines is a parallel module. Scan and convert the parallel branch from left to right, record the number of graphic elements in the branch, and determine whether there is a branch node in the branch. If there is, continue to perform operation (3). If not, after completing the branch conversion, return to the branch node and continue to scan to the right until the last column of the trunk is converted. Among them, the left vertical line indicates that the right angle formed by the lines opens to the left, and the right vertical line indicates that the right angle formed by the lines opens to the right.
8. The heterogeneous multi-core embedded numerical control system according to claim 5, characterized in that: Before the ladder diagram is mapped into multiple structure arrays by the intermediate code conversion unit, a logic check is performed by the logic check unit: (1) Short circuit: Use the sequential scanning ladder diagram program to find two parallel vertical lines based on the downward cascade mark of the graphics element, and then count the number of graphics elements between the two parallel straight lines. If it is zero, it means there is a short circuit error; (2) Circuit break: Scan the ladder diagram sequentially and record the position where the element is empty. If there are elements on both the left and right sides, it means there is a circuit break error. (3) Constant output: Scan each graphic element sequentially and determine its component type. If only the output coil is scanned without the contact, it means that there is a constant output error; (4) Function block is missing parameters: Determine whether the parameters of the function block are default values. If so, this indicates that this error exists.
9. The heterogeneous multi-core embedded numerical control system according to claim 5, characterized in that: The storage management module of the operating system obtains all the information of the ladder diagram by identifying the data frame of the intermediate code, including: First, the number of conditional elements and the number of execution elements of the ladder are read from the data frame according to the prescribed communication protocol, and the storage structure of each graphic element is read by pointer offset to obtain its type, name, address, whether it is cascaded downward, and other information. Then, the state of the corresponding register is read to obtain the on-off state of each conditional element. The on-off state of each conditional element is judged one by one according to the number of conditional elements, and a logical operation is performed with the result of the previous operation. Finally, whether the output condition is met is judged according to the logical operation results of all conditional elements. If the output condition is met, the corresponding function function is called in sequence according to the number of output elements to modify the value of the software register. If the output condition is not met, the process of interpreting and executing a ladder of the ladder diagram ends.
Citation Information
Patent Citations
Embedded digital control system based on ARM7 and FPGA
CN101382788A
Ladder diagram matrix compiling and interpreting method based on PLC
CN104820393A
Numerical control interpolation system with PCIe control function
CN107783501A
Multi-axis linkage embedded type digital control system and development method thereof
CN108549330A
Handling value types
US20150331681A1
Cited By
Software architecture for numerical control system, software control method and application
CN120686729A
Software architecture, software control method for numerical control system and application
CN120686729B
Soft PLC programming debugging system
CN121918482A