A PLCopen motion control function block interaction method and system based on shared memory
By creating a shared memory area between the PLC control unit and the motion control unit, efficient and reliable interaction of the PLCopen standard motion control function block is achieved, and the problem of insufficient support for the PLCopen standard is solved, and the system response speed and stability are improved .
Patent Information
- Application Number
- CN202411164727.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-08-23
AI Technical Summary
The existing PLC products have poor support for PLCopen standard motion control function blocks, resulting in a lack of efficient and reliable interaction between logic control and motion control, which is difficult to meet the high-speed and high-reliability needs of modern control systems.
By creating five shared memory areas between the PLC control unit and the motion control unit, the input area, the instruction area, the axis state area, the output area and the response area, the semaphore is used to ensure mutual exclusion, and the PLCopen standard motion control function block is realized Efficient and reliable interaction.
It provides an efficient and reliable collaborative working mechanism, realizes the PLCopen standard motion control function block, improves the system response speed, data processing capability and operation efficiency, simplifies the system architecture, and enhances operation coordination and stability.
Smart Images

Figure CN118672203B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of motion control, and in particular relates to a PLCopen motion control function block interaction method and system based on shared memory. Background Art
[0002] In the field of automation control, logic control and motion control are two key technologies, which generally use independent controllers and programming languages. Logic control uses PLC, the programming language is ladder diagram, and motion control uses motion control card, the programming language is C++ / C# and other high-level languages. The difference in programming environment and programming language has brought great inconvenience to the programming and debugging work of on-site engineers. At the same time, there is a lack of efficient and reliable communication methods between the two independent controllers, which makes it difficult to meet the high-speed and high-reliability requirements of modern control systems.
[0003] In the field of motion control, the PLCopen Association has standardized the functions and interfaces of various motion forms and encapsulated them in the IEC61131-3 standard function block language, making the development of motion control programs consistent with the development of PLC programs, and enabling mixed programming of logic control and motion control in the same integrated development environment using the same programming language. However, existing PLC products still have poor support for PLCopen standard motion control function blocks.
[0004] The invention patent with application number CN202210618926.1 proposes a robot control system that combines logic control and motion control based on shared memory. The PLC control unit completes the logic control of I / O, and the motion control unit completes the motion control of the robot. The two control units work together through shared memory. The patent proposes to combine logic control functions and motion control functions on a hardware platform, but fails to implement standard motion control function blocks according to PLCopen.
[0005] The invention patent with application number CN201410157410.7 proposes a logic and motion integrated controller, in which the DSP chip parses and executes the logic and motion control program, and the FPGA chip implements the configurable hardware interface and axis control module, processes the input and output signals, and the two communicate through the bus module. This patent uses the bus module communication method to realize the interaction between logic control and motion control, which is inferior to the shared memory method in terms of real-time performance and reliability.
[0006] In view of this, it is necessary to propose a PLCopen motion control function block interaction method based on shared memory. Summary of the invention
[0007] The purpose of the present invention is to provide a PLCopen motion control function block interaction method based on shared memory, by creating five shared memory areas, namely, input area, instruction area, axis status area, output area and response area, and providing an efficient and reliable collaborative working mechanism for a PLC control unit and a motion control unit based on the interaction method of the shared memory area, thereby realizing the PLCopen standard motion control function block.
[0008] A PLCopen motion control function block interaction method based on shared memory provided by the present invention is applicable to a PLCopen motion control function block interaction system based on shared memory, wherein the PLCopen motion control function block interaction system based on shared memory comprises a PLC control unit, a shared memory and a motion control unit.
[0009] The interactive method includes the following steps:
[0010] Execute the logic control program through the PLC control unit and interact with the PLC control unit through the interface of the PLCopen standard motion control function block, and run cyclically according to input sampling, IEC61131-3 program execution, axis state synchronization, output refresh and execution response callback function;
[0011] Establish EtherCAT communication and execute motion instructions through the motion control unit, and run in a loop according to EtherCAT communication, motion instruction queue entry, motion instruction execution and axis status update;
[0012] Information interaction between the PLC control unit and the motion control unit is established through shared memory to achieve collaborative work between the PLC control unit and the motion control unit.
[0013] Preferably, the shared memory is respectively configured as an input area, a command area, an axis status area, an output area and a response area, wherein:
[0014] The input area and the output area are configured to synchronously input process data and output process data, and the data length is fixedly set;
[0015] The axis status area is configured as the status information of the synchronous axis, wherein the number of axes and the length of the status data of each axis are fixedly set and arranged in sequence according to the axis number;
[0016] The instruction area is configured to store motion instructions dynamically generated during the operation of the PLC control unit and the motion control unit, and when the header of the instruction area is the instruction total length field, it is configured to indicate the total length of the current motion instruction data, and then the instruction data is discharged in sequence;
[0017] The response area is configured to store response events dynamically generated during the operation of the PLC control unit and the motion control unit, and when the header of the response area is a response total length field, it is configured to indicate the total length of the current response event data, and then the response data is discharged in sequence;
[0018] The access of the PLC control unit and the motion control unit to the above-mentioned shared memory area is configured to use semaphores to ensure mutual exclusion.
[0019] Preferably, the PLC control unit cycle operation steps include:
[0020] Input sampling: copy the shared memory input area data to the local I area;
[0021] IEC61131-3 program execution: Execute the IEC61131-3 program including the logic control unit and the PLCopen motion control unit. For the PLCopen motion control function block that needs to control the axis to perform the corresponding action, if the PLCopen motion control function block is in the enabled / triggered state, write the motion instruction to the shared memory instruction area; for the PLCopen motion control function block that does not need to control the axis to perform the action and only needs to read the axis status, if the PLCopen motion control function block is in the enabled / triggered state, read directly from the local axis status data;
[0022] Axis status synchronization: synchronize the shared memory axis status area data to the local axis status data;
[0023] Output refresh: copy the local Q area data to the output area of the shared memory;
[0024] Execute the response callback function: read all response events in the shared memory response area, clear the shared memory response area, execute the corresponding response callback function according to the axis number, function block index and event type of the response event, and update the output pin of the corresponding function block.
[0025] Preferably, the motion control unit cycle operation steps include:
[0026] EtherCAT communication: Integrate the EtherCAT master program, copy the data in the shared memory output area to the local EtherCAT output process data area, perform EtherCAT real-time communication, send local process data to the EtherCAT slave, receive input process data from the EtherCAT slave, and then copy the local EtherCAT input process data to the shared memory input area;
[0027] Motion instruction queue: read all motion instructions in the shared memory instruction area, clear the shared memory instruction area, and add the motion instructions to the execution queue;
[0028] Motion instruction execution: executes the motion instructions in the queue, performs trajectory planning and interpolation operations based on the motion instruction content and the current state of the axis, obtains the target position / speed / torque of the axis, and sends the control command to the physical axis through EtherCAT communication;
[0029] Axis status update: write the axis status information to the shared memory axis status area, the axis status information includes at least the axis number, status code, fault status, error code, origin position, enable status, actual position, actual speed, actual acceleration and actual torque.
[0030] Preferably, during the execution of the logic program, the PLC control unit detects that the motion control function block is triggered and writes the motion instruction according to the following steps:
[0031] Determine whether the PLCopen motion control function block is triggered, and if the PLCopen motion control function block is triggered, perform the following steps in sequence;
[0032] Wait for the command area to be accessible: If no program is currently locking the command area, there is no need to wait, otherwise you need to wait for the current program to unlock the command area;
[0033] Lock the instruction area: When the instruction area is accessible, it needs to be locked to prevent different programs from accessing it at the same time;
[0034] Write motion instructions: According to the instruction total length field, write a new motion instruction directly after the last instruction;
[0035] Update the total length of the instruction: obtain the total length of the original instruction and the data length of the motion instruction currently written, and calculate the new total length of the instruction = the total length of the original instruction + the data length of the motion instruction currently written;
[0036] Unlock the instruction area: After the access to the instruction area is completed, unlock the instruction area to allow the instruction area to be accessed by subsequent programs;
[0037] Update the function block output pins: According to the PLCopen specification, set the Busy pin and Active pin of the function block to true.
[0038] Preferably, the motion control unit checks the instruction area and reads the motion instruction in each cycle according to the following steps:
[0039] Check whether the instruction area is accessible: if the current instruction area is locked, skip it and wait for the next cycle to read it;
[0040] Lock instruction area: If the current instruction area is accessible, lock the current instruction area to prevent different programs from accessing it at the same time;
[0041] Get the total length of the instruction: read the value of the total length field of the instruction;
[0042] Read motion instructions: Read motion instructions in sequence, calculate the length of the instructions that have been taken out, and compare it with the total length of the instructions to determine whether the instruction reading is completed;
[0043] Set the total length of the instruction to 0: When all motion instructions are read, the total length of the instruction is set to 0;
[0044] Unlock the instruction area: After the access to the instruction area is completed, unlock the instruction area to allow the instruction area to be accessed by different programs;
[0045] Motion instruction queue: add the read motion instruction to the execution queue of the motion control unit.
[0046] Preferably, the steps of interacting the PLC control unit and the motion control unit with respect to the shared memory response area include:
[0047] When the motion control unit generates a response event during the execution of a motion instruction, follow the steps below to write to the response area:
[0048] Waiting for the answering area to be accessible: If no program is currently locking the answering area, there is no need to wait, otherwise you need to wait for the current program to unlock the answering area;
[0049] Lock the answer area: When the answer area is accessible, you need to lock the answer area to prevent different programs from accessing it at the same time;
[0050] Write response event: According to the total response length field, write a new response event directly after the last response;
[0051] Update total response length: obtain the total length of the original response and the data length of the currently written response event, and calculate the new total response length = the total length of the original response + the data length of the written response event;
[0052] Unlock the response area: When the access to the response area is completed, unlock the response area to allow it to be accessed by subsequent programs.
[0053] Preferably, the PLC control unit checks the response area and reads the response event in each cycle according to the following steps:
[0054] Check whether the response area is accessible: If the current response area is locked, skip it and wait for the next cycle to read it;
[0055] Lock the answer area: If the current answer area is accessible, lock the current answer area to prevent different programs from accessing it at the same time;
[0056] Get the total length of the response: read the value of the total length field of the response;
[0057] Read response events: read response events one by one, calculate the length of the response that has been retrieved, and compare it with the total length of the response to determine whether the response reading is completed;
[0058] Set the total length of the response to 0: When all response events are read, the total length of the response field is set to 0;
[0059] Unlock the response area: When the access to the response area is completed, unlock the response area to allow it to be accessed by different programs;
[0060] Execute the response callback function and update the output pins of the function block: according to the type of the response event, execute the corresponding callback function, and according to the PLCopen specification, update the output pins corresponding to the function block. The output pins include at least Busy pin, Active pin, Done pin, Error pin, ErrorID pin, and CommandAborted pin.
[0061] The present invention also provides a PLCopen motion control function block interactive system based on shared memory, characterized in that it includes a PLC control unit, a shared memory and a motion control unit.
[0062] The PLC control unit is used to execute the logic control program and interact with the PLC control unit through the interface of the PLCopen standard motion control function block, and run cyclically according to input sampling, IEC61131-3 program execution, axis state synchronization, output refresh and execution response callback function;
[0063] The motion control unit is used to establish EtherCAT communication and execute motion instructions, and operates in a cycle according to EtherCAT communication, motion instruction queue entry, motion instruction execution and axis status update;
[0064] The shared memory is used to establish information interaction between the PLC control unit and the motion control unit to achieve collaborative work between the PLC control unit and the motion control unit.
[0065] Preferably, the shared memory includes an input area, a command area, an axis status area, an output area and a response area, wherein:
[0066] The input area and the output area are used to synchronously input process data and output process data, and the data length is fixedly set;
[0067] The axis status area is used to synchronize the status information of the axis, wherein the number of axes and the length of the status data of each axis are fixed and arranged in sequence according to the axis number;
[0068] The instruction area is used to store motion instructions dynamically generated during the operation of the PLC control unit and the motion control unit. When the header of the instruction area is the instruction total length field, it is used to indicate the total length of the current motion instruction data, and then the instruction data is discharged in sequence;
[0069] The response area is used to store response events dynamically generated during the operation of the PLC control unit and the motion control unit. When the header of the response area is the total response length field, it is used to indicate the total length of the current response event data, and then the response data is discharged in sequence;
[0070] The PLC control unit and the motion control unit use semaphores to ensure mutual exclusion when accessing the above shared memory area.
[0071] Due to the adoption of the above technical solution, the present invention has the following advantages and positive effects compared with the prior art:
[0072] The present invention provides a PLCopen motion control function block interaction method and system based on shared memory, provides an efficient and reliable technical solution for PLC integration of PLCopen standard motion control function blocks, creates five shared memory areas, namely, input area, instruction area, axis state area, output area and response area, and designs an interaction method for the shared memory areas, provides an efficient and reliable collaborative working mechanism for the PLC control unit and the motion control unit, thereby realizing the PLCopen standard motion control function block. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Figure 1 A block diagram of a PLCopen motion control function block interaction system based on shared memory according to an embodiment of the present invention;
[0074] Figure 2 A schematic diagram of the division of shared memory areas in an embodiment of the present invention;
[0075] Figure 3 A schematic diagram of the interaction logic of the shared memory instruction area in an embodiment of the present invention;
[0076] Figure 4 This is a schematic diagram of the shared memory response area interaction logic in an embodiment of the present invention. DETAILED DESCRIPTION
[0077] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0078] The system block diagram provided by the embodiment of the present invention is as follows Figure 1 As shown, a PLCopen motion control function block interactive system based on shared memory provided by the present invention includes a PLC control unit, a shared memory and a motion control unit. That is to say, the PLC control unit and the motion control unit here refer to the PLC runtime software and the motion control software respectively.
[0079] The PLC control unit is used to execute the logic control program and interact with the PLC control unit through the interface of the PLCopen standard motion control function block, and run cyclically according to input sampling, IEC61131-3 program execution, axis state synchronization, output refresh and execution response callback function;
[0080] The motion control unit is used to establish EtherCAT communication and execute motion instructions, and operates in a cycle according to EtherCAT communication, motion instruction queue entry, motion instruction execution and axis status update;
[0081] The shared memory is used to establish information interaction between the PLC control unit and the motion control unit to achieve collaborative work between the PLC control unit and the motion control unit.
[0082] The fast data exchange mechanism implemented by the shared memory in this embodiment makes the communication between the PLC control unit and the motion control unit more efficient, reduces the delay of data processing and transmission, and thus improves the response speed of the whole system; the PLC control unit and the motion control unit focus on the execution of logic control and motion instructions respectively, with clear division of labor, and can process the corresponding tasks more efficiently. This separate processing method improves the data processing capability and operation efficiency of the system; the shared memory, as an intermediate layer, ensures the real-time synchronization and consistency of information between the PLC control unit and the motion control unit. This collaborative working mechanism improves the overall operation coordination and stability of the system; the use of standardized PLCopen function blocks and shared memory mechanisms simplifies the system architecture, making the development and maintenance of the system easier, and developers can focus more on the implementation of application logic rather than the underlying communication and data exchange details; the design based on shared memory makes it easier to add or modify functions without affecting the operation of the existing system. This flexibility is essential for adapting to rapidly changing automation needs; the system efficiently manages data access through shared memory, reduces the processing and storage of redundant data, optimizes the use of resources, and improves system performance; the components of the system work closely together through shared memory, and can identify and respond to error conditions more quickly, improving the efficiency of error handling and the reliability of the system.
[0083] In this embodiment, the shared memory area is divided as follows: Figure 2 As shown, the shared memory includes an input area, a command area, an axis status area, an output area and a response area, wherein:
[0084] The input area and the output area are used to synchronously input and output process data, and the data length is fixed;
[0085] The axis status area is used to synchronize the status information of the axis, wherein the number of axes and the length of the status data of each axis are fixed and arranged in sequence according to the axis number;
[0086] The instruction area is used to store motion instructions dynamically generated during the operation of the PLC control unit and the motion control unit. The header of the instruction area is the instruction total length field, which is used to indicate the total length of the current motion instruction data, followed by the instruction data being discharged in sequence;
[0087] The response area is used to store response events dynamically generated during the operation of the PLC control unit and the motion control unit. The header of the response area is a total response length field, which is used to indicate the total length of the current response event data, followed by the response data being discharged in sequence;
[0088] The PLC control unit and the motion control unit use semaphores to ensure mutual exclusion when accessing the above shared memory area.
[0089] By distinguishing the input area and the output area, the above embodiment enables the system to quickly and accurately synchronize input and output process data, thereby ensuring timely transmission of control instructions and rapid feedback of execution results. This partition design reduces data processing time and improves system operation efficiency; the structured design of the axis status area, such as the fixed number of axes and the length of the status data of each axis, and the mechanism of arranging data in sequence according to the axis number, simplifies the reading, writing and management of the axis status data. This orderly data structure improves the readability and manageability of the data, and also facilitates the monitoring and maintenance of the system; in the design of the instruction area and the response area, the total length field is added to the header to dynamically process motion instructions and response events of different lengths, which increases the flexibility of data processing. At the same time, this design also helps to avoid data errors and overflows and ensure the accuracy of data processing; through the careful planning and design of shared memory, the system can use memory resources more efficiently and reduce resource waste. At the same time, semaphores and other means are used to ensure that access to shared memory is mutually exclusive, which avoids data competition and conflicts and improves the concurrency performance and stability of the system; the clear division and structured design of the shared memory area make the system easy to expand and modify. For example, new axes can be easily added or the structure of the axis status data can be modified without affecting the normal operation of other parts. This design also enhances the applicability and versatility of the system in different applications and environments.
[0090] In this embodiment, the PLC control unit cycle operation step is to execute the program and operate the shared memory according to the following steps in the cycle of the PLC control unit:
[0091] Step 1: Input sampling. Copy the shared memory input area data to the local I area. The local I area is usually called the input image register or simply the input zone (Input Zone), and its address identifier is "I". It is used to receive level signals from external devices. These external devices include various buttons, switches, sensors, etc. When these external devices are activated, they will send signals to the input end of the PLC, and these signals are then stored in the input image register. The input image register is updated at the beginning of each scan cycle of the PLC to reflect the current status of the external device. This status information is then used in the logical operation and decision-making process of the PLC.
[0092] Step 2: IEC61131-3 program execution. Execute the IEC61131-3 program written by the PLC user, including the logic control program and the PLCopen motion control program. For the function blocks that need to control the axis to perform the corresponding action (such as MC_MoveAbsolute), if the function block is in the enabled / triggered state, write the motion instruction to the shared memory instruction area; for the function blocks that do not need to control the axis to perform the action, but only read the axis status (such as MC_ReadActualPosition), if the function block is in the enabled / triggered state, read directly from the local axis status data. When executing IEC61131-3 programs and motion control instructions, the accuracy of data processing and motion control is ensured through precise timing control and data synchronization mechanisms.
[0093] Step 3: Axis status synchronization: Synchronize the shared memory axis status area data to the local axis status data. Through the axis status synchronization and output refresh steps, the system resources are effectively managed, the waste of resources is avoided, and the system performance is improved.
[0094] Step 4: Output refresh. Copy the local Q zone data to the shared memory output zone. The local Q zone is usually called the output image register or simply the output zone (Output Zone). Its address identifier is "Q". It is used to send level signals to external devices to control their operations. For example, the PLC can control the on and off of indicator lights, the energization and release of relays, etc. through the output image register. The status value in the output image register is set during the execution of the PLC program, and is copied to the digital output module after all instructions are executed to drive the external device to act.
[0095] Step 5: Execute the response callback function. Read all response events in the shared memory response area, clear the shared memory response area, execute the corresponding response callback function according to the axis number, function block index and event type of the response event, update the output pin of the corresponding function block, and execute the response callback function step. By reading and processing the response event, the system can respond to the error in time, enhancing the error handling capability of the system. The above process ensures the timely acquisition of input signals and the rapid refresh of output signals through optimized cycle steps, thereby improving the system's response speed to external events and the real-time performance of the entire system.
[0096] In this embodiment, the motion control unit cycle operation step is to execute the program and operate the shared memory according to the following steps in the motion control unit cycle:
[0097] Step 1: EtherCAT communication. The motion control unit integrates the EtherCAT master program, copies the data in the shared memory output area to the local EtherCAT output process data area, executes EtherCAT real-time communication, sends the local process data to the EtherCAT slave, receives the input process data from the EtherCAT slave, and then copies the local EtherCAT input process data to the shared memory input area. By integrating the EtherCAT master program, efficient real-time communication is achieved, allowing the motion control unit to quickly exchange data with the EtherCAT slave, improving the communication efficiency and real-time response capability of the entire system.
[0098] Step 2: Add motion instructions to the queue. Read all motion instructions in the shared memory instruction area, clear the shared memory instruction area, and add the motion instructions to the execution queue.
[0099] Step 3: Execution of motion instructions. The motion instructions in the execution queue are used to perform trajectory planning and interpolation operations based on the instruction content and the current state of the axis to obtain the target position / speed / torque of the axis. The control command is sent to the physical axis through EtherCAT communication. The queueing and execution mechanism of motion instructions ensures that the motion instructions can be effectively managed and accurately executed. Through trajectory planning and interpolation operations, precise motion control is achieved, which improves the motion control performance of the system.
[0100] Step 4: Axis status update. Write the axis status information to the shared memory axis status area, including axis number, status code, fault status, error code, origin position, enable status, actual position, actual speed, actual acceleration, actual torque, etc. The timely update of the axis status ensures that the system can monitor and manage the axis status in real time, including the rapid detection and processing of fault and error status, which enhances the stability and reliability of the system.
[0101] Based on the above division of shared memory and the use of mutexes to protect access to each single area, efficient and reliable information exchange between the PLC control unit and the motion control unit can be guaranteed.
[0102] The following is a further explanation of the interaction logic between the shared memory instruction area and the response area.
[0103] The interaction logic between the PLC control unit and the motion control unit to the shared memory instruction area is as follows Figure 3 As shown. That is, during the execution of the logic program, the PLC control unit detects that the motion control function block is triggered and writes the motion instruction according to the following steps:
[0104] Step 1: Wait for the instruction area to be accessible. The specific implementation here can be a semaphore. If no other program locks the instruction area, there is no need to wait. Otherwise, you need to wait for other programs to unlock the instruction area. Since the logic program needs to be executed in a fixed cycle, the waiting time here cannot be too long. Therefore, the access lock time of the PLC control unit and the motion control unit to the instruction area should be as short as possible. The introduction of the semaphore mechanism allows the PLC control unit to quickly determine whether the shared memory is accessible, reducing the waiting time and improving the response speed of the system.
[0105] Step 2: Lock the command area. After the command area is accessible, you need to lock the command area to prevent other programs from accessing it at the same time.
[0106] Step 3: Write motion instructions. According to the total length field of the instruction, the PLC control unit can write a new motion instruction directly after the last instruction.
[0107] Step 4: Update the total length of the instruction. The new total length of the instruction = the total length of the original instruction + the data length of the motion instruction written.
[0108] Step 5: Unlock the instruction area. After access to the instruction area is completed, unlock the instruction area to allow it to be accessed by other programs.
[0109] Step 6: Update the function block output pins. According to the PLCopen specification, set the Busy and Active pins of the function block to true. The above steps use a locking mechanism to ensure data consistency when accessing the shared memory instruction area, prevent data competition and conflict, and ensure data synchronization between the PLC control unit and the motion control unit; if an error occurs during access to the shared memory, it can be quickly recovered through the exception handling mechanism, which improves the system's error handling capabilities; this design pattern facilitates system expansion, such as adding new motion control instructions or function blocks, without affecting the stability of the existing system.
[0110] In this embodiment, the motion control unit checks the instruction area and reads the motion instruction in each cycle according to the following steps:
[0111] Step 1: Check whether the instruction area is accessible. Since there is a delay in reading and executing motion instructions, if the instruction area is locked at this time, it will be skipped directly and read again in the next cycle. By checking the accessibility of the instruction area in the cycle, the motion control unit can efficiently decide whether to read the motion instruction, avoiding unnecessary waiting time and improving the response efficiency of the system.
[0112] Step 2: Lock the instruction area. If the instruction area is accessible, lock the instruction area to prevent other programs from accessing it at the same time. The mechanism of locking the instruction area ensures data consistency when reading motion instructions, prevents data competition and conflicts, and ensures data synchronization between the PLC control unit and the motion control unit.
[0113] Step 3: Get the total length of the instruction. Read the value of the total length field of the instruction, and then read the motion instructions in sequence. This process improves the efficiency and accuracy of data processing.
[0114] Step 4: Read motion instructions. Read the motion instructions one by one, calculate the length of the instructions that have been taken out, and compare it with the total length of the instructions to determine whether the instruction reading is completed.
[0115] Step 5: Set the total length of the instruction to 0. After all motion instructions are read, set the total length of the instruction to 0.
[0116] Step 6: Unlock the instruction area. After access to the instruction area is completed, unlock the instruction area to allow it to be accessed by other programs.
[0117] Step 7: Add motion instructions to the queue. Add the read motion instructions to the execution queue of the motion control unit.
[0118] In this embodiment, the interaction logic between the PLC control unit and the motion control unit for the shared memory response area is as follows: Figure 4 As shown. During the execution of the motion instruction, the motion control unit generates a response event, which is written into the response area according to the following steps:
[0119] Step 1: Wait for the response area to be accessible. The specific implementation here can be a semaphore. If no other program locks the instruction area, there is no need to wait. Otherwise, you need to wait for other programs to unlock the response area. In order to prevent the waiting time from being too long, the PLC control unit and the motion control unit should lock the access to the response area as short as possible. The locking mechanism ensures data consistency when accessing the shared memory response area, prevents data competition and conflicts, and ensures data synchronization between the PLC control unit and the motion control unit. The introduction of the semaphore mechanism allows the motion control unit to quickly determine whether the shared memory is accessible, reducing the waiting time and improving the response speed of the system.
[0120] Step 2: Lock the response area. After the response area is accessible, you need to lock the response area to prevent other programs from accessing it at the same time. Clear locking and unlocking steps reduce potential problems caused by concurrent access and enhance the stability and reliability of system operation.
[0121] Step 3: Write the response event. According to the total response length field, the motion control unit can write a new response event directly after the last response.
[0122] Step 4: Update the total length of the response. The new total length of the response = the total length of the original response + the data length of the written response event. The method of directly appending a new response after the last response and dynamically updating the total length field of the response improves the efficiency and flexibility of data processing.
[0123] Step 5: Unlock the response area. After access to the response area is completed, unlock the response area to allow it to be accessed by other programs.
[0124] In this embodiment, the PLC control unit checks the response area and reads the response event in each cycle according to the following steps:
[0125] Step 1: Check whether the response area is accessible. Since there is a delay in reading and processing the response event, if the response area is locked at this time, it will be skipped directly and read again in the next cycle. By checking the accessibility of the response area in the cycle, the PLC control unit can efficiently decide whether to read the response event, avoiding unnecessary waiting time and improving the response efficiency of the system.
[0126] Step 2: Lock the response area. If the response area is accessible, lock the response area to prevent other programs from accessing it at the same time. The mechanism of locking the response area ensures data consistency when reading response events, prevents data competition and conflicts, and ensures data synchronization between the PLC control unit and the motion control unit.
[0127] Step 3: Get the total length of the response. Read the value of the total length field of the response.
[0128] Step 4: Read the response event. Read the response events one by one, calculate the length of the response that has been taken out, and compare it with the total length of the response to determine whether the response reading is completed.
[0129] Step 5: Set the total length of the response to 0. After all response events are read, set the total length of the response to 0.
[0130] Step 6: Unlock the response area. After the access to the response area is completed, unlock the response area to allow it to be accessed by other programs. The clear locking and unlocking steps reduce potential problems caused by concurrent access and enhance the stability and reliability of system operation.
[0131] Step 7: Execute the response callback function and update the function block output pins. According to the type of response event, execute the corresponding callback function and update the function block Busy, Active, Done, Error, ErrorID, CommandAborted and other output pins according to the PLCopen specification.
[0132] Embodiment 2
[0133] Based on the same inventive concept, the present invention provides a PLCopen motion control function block interaction method based on shared memory, which is applied to the above-mentioned PLCopen motion control function block interaction system based on shared memory, and includes the following steps:
[0134] Execute the logic control program through the PLC control unit and interact with the PLC control unit through the interface of the PLCopen standard motion control function block, and run cyclically according to input sampling, IEC61131-3 program execution, axis state synchronization, output refresh and execution response callback function;
[0135] Establish EtherCAT communication and execute motion instructions through the motion control unit, and run in a loop according to EtherCAT communication, motion instruction queue entry, motion instruction execution and axis status update;
[0136] Information interaction between the PLC control unit and the motion control unit is established through shared memory to achieve collaborative work between the PLC control unit and the motion control unit. Other interaction methods can be found in the logical methods in the above system and will not be repeated here.
[0137] Embodiment 3
[0138] Based on the same inventive concept, the present invention also provides a PLCopen motion control function block interaction device based on shared memory, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the PLCopen motion control function block interaction method based on shared memory in one embodiment of the present invention is implemented.
[0139] The PLCopen motion control function block interactive device based on shared memory may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) and memories, and one or more storage media (such as one or more mass storage devices) for storing application programs or data. The memories and storage media may be short-term storage or permanent storage. The program stored in the storage medium may include one or more modules, and each module may include a series of instruction operations in the PLCopen motion control function block interactive device based on shared memory.
[0140] Furthermore, the processor may be configured to communicate with the storage medium and execute a series of instruction operations in the storage medium on a PLCopen motion control function block interactive device based on a shared memory.
[0141] The shared memory-based PLCopen motion control function block interactive device may also include one or more power supplies, one or more wired or wireless network interfaces, one or more input and output interfaces, and / or one or more operating systems, such as Windows Serve, Vista, etc.
[0142] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by one or more processors, the PLCopen motion control function block interaction method based on shared memory in one embodiment of the present invention is implemented. If the module in the second embodiment is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of software, and the computer-readable storage medium can be a non-volatile computer-readable storage medium, and the computer-readable storage medium can also be a volatile computer-readable storage medium. The computer-readable storage medium stores instructions, and when the instructions are executed on a computer, the computer executes the steps of the PLCopen motion control function block interaction method based on shared memory in the first embodiment.
[0143] Those skilled in the art can understand that the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of software, and the computer software is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0144] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A PLCopen motion control function block interaction method based on shared memory, applicable to a PLCopen motion control function block interaction system based on shared memory, wherein the PLCopen motion control function block interaction system based on shared memory comprises a PLC control unit, a shared memory and a motion control unit, It is characterized in that The interactive method includes the following steps: Execute the logic control program through the PLC control unit and interact with the PLC control unit through the interface of the PLCopen standard motion control function block, and run cyclically according to input sampling, IEC61131-3 program execution, axis state synchronization, output refresh and execution response callback function; Establish EtherCAT communication and execute motion instructions through the motion control unit, and run in a loop according to EtherCAT communication, motion instruction queue entry, motion instruction execution and axis status update; Establishing information interaction between the PLC control unit and the motion control unit through a shared memory to achieve collaborative work between the PLC control unit and the motion control unit; The shared memory is respectively configured as an input area, a command area, an axis status area, an output area and a response area, wherein: The input area and the output area are configured to synchronously input process data and output process data, and the data length is fixedly set; The axis status area is configured as the status information of the synchronous axis, wherein the number of axes and the length of the status data of each axis are fixedly set and arranged in sequence according to the axis number; The instruction area is configured to store motion instructions dynamically generated during the operation of the PLC control unit and the motion control unit, and when the header of the instruction area is the instruction total length field, it is configured to indicate the total length of the current motion instruction data, and then the instruction data is discharged in sequence; The response area is configured to store response events dynamically generated during the operation of the PLC control unit and the motion control unit, and when the header of the response area is a response total length field, it is configured to indicate the total length of the current response event data, and then the response data is discharged in sequence; The access of the PLC control unit and the motion control unit to the above-mentioned shared memory area is configured to use semaphores to ensure mutual exclusion.
2. The PLCopen motion control function block interaction method based on shared memory according to claim 1, It is characterized in that The PLC control unit cycle operation steps include: Input sampling: copy the shared memory input area data to the local I area; IEC61131-3 program execution: Execute the IEC61131-3 program including the logic control unit and the PLCopen motion control unit. For the PLCopen motion control function block that needs to control the axis to perform the corresponding action, if the PLCopen motion control function block is in the enabled / triggered state, write the motion instruction to the shared memory instruction area; for the PLCopen motion control function block that does not need to control the axis to perform the action and only needs to read the axis status, if the PLCopen motion control function block is in the enabled / triggered state, read directly from the local axis status data; Axis status synchronization: synchronize the shared memory axis status area data to the local axis status data; Output refresh: copy the local Q area data to the output area of the shared memory; Execute the response callback function: read all response events in the shared memory response area, clear the shared memory response area, execute the corresponding response callback function according to the axis number, function block index and event type of the response event, and update the output pin of the corresponding function block.
3. The PLCopen motion control function block interaction method based on shared memory according to claim 1, It is characterized in that The motion control unit cycle operation steps include: EtherCAT communication: Integrate the EtherCAT master program, copy the data in the shared memory output area to the local EtherCAT output process data area, perform EtherCAT real-time communication, send local process data to the EtherCAT slave, receive input process data from the EtherCAT slave, and then copy the local EtherCAT input process data to the shared memory input area; Motion instruction queue: read all motion instructions in the shared memory instruction area, clear the shared memory instruction area, and add the motion instructions to the execution queue; Motion instruction execution: executes the motion instructions in the queue, performs trajectory planning and interpolation operations based on the motion instruction content and the current state of the axis, obtains the target position / speed / torque of the axis, and sends the control command to the physical axis through EtherCAT communication; Axis status update: write the axis status information to the shared memory axis status area, the axis status information includes at least the axis number, status code, fault status, error code, origin position, enable status, actual position, actual speed, actual acceleration and actual torque.
4. The PLCopen motion control function block interaction method based on shared memory according to claim 1, It is characterized in that During the execution of the logic program, the PLC control unit detects that the motion control function block is triggered and writes the motion instruction according to the following steps: Determine whether the PLCopen motion control function block is triggered, and if the PLCopen motion control function block is triggered, perform the following steps in sequence; Wait for the command area to be accessible: If no program is currently locking the command area, there is no need to wait, otherwise you need to wait for the current program to unlock the command area; Lock the instruction area: When the instruction area is accessible, it needs to be locked to prevent different programs from accessing it at the same time; Write motion instructions: According to the instruction total length field, write a new motion instruction directly after the last instruction; Update the total length of the instruction: obtain the total length of the original instruction and the data length of the motion instruction currently written, and calculate the new total length of the instruction = the total length of the original instruction + the data length of the motion instruction currently written; Unlock the instruction area: After the access to the instruction area is completed, unlock the instruction area to allow the instruction area to be accessed by subsequent programs; Update the function block output pins: According to the PLCopen specification, set the Busy pin and Active pin of the function block to true.
5. The PLCopen motion control function block interaction method based on shared memory according to claim 1, It is characterized in that In each cycle, the motion control unit checks the instruction area and reads the motion instruction according to the following steps: Check whether the instruction area is accessible: if the current instruction area is locked, skip it and wait for the next cycle to read it; Lock instruction area: If the current instruction area is accessible, lock the current instruction area to prevent different programs from accessing it at the same time; Get the total length of the instruction: read the value of the total length field of the instruction; Read motion instructions: Read motion instructions in sequence, calculate the length of the instructions that have been taken out, and compare it with the total length of the instructions to determine whether the instruction reading is completed; Set the total length of the instruction to 0: When all motion instructions are read, the total length of the instruction is set to 0; Unlock the instruction area: After the access to the instruction area is completed, unlock the instruction area to allow the instruction area to be accessed by different programs; Motion instruction queue: add the read motion instruction to the execution queue of the motion control unit.
6. The PLCopen motion control function block interaction method based on shared memory according to claim 1, It is characterized in that The steps for the PLC control unit and the motion control unit to interact with the shared memory response area include: When the motion control unit generates a response event during the execution of a motion instruction, follow the steps below to write to the response area: Waiting for the answering area to be accessible: If no program is currently locking the answering area, there is no need to wait, otherwise you need to wait for the current program to unlock the answering area; Lock the answer area: When the answer area is accessible, you need to lock the answer area to prevent different programs from accessing it at the same time; Write response event: According to the total response length field, write a new response event directly after the last response; Update the total length of the response: obtain the total length of the original response and the data length of the currently written response event, and calculate the new total length of the response = the total length of the original response + the data length of the written response event; Unlock the response area: When the access to the response area is completed, unlock the response area to allow it to be accessed by subsequent programs.
7. The PLCopen motion control function block interaction method based on shared memory according to claim 1, It is characterized in that In each cycle, the PLC control unit checks the response area and reads the response event according to the following steps: Check whether the response area is accessible: If the current response area is locked, skip it and wait for the next cycle to read it; Lock the answer area: If the current answer area is accessible, lock the current answer area to prevent different programs from accessing it at the same time; Get the total length of the response: read the value of the total length field of the response; Read response events: read response events one by one, calculate the length of the response that has been retrieved, and compare it with the total length of the response to determine whether the response reading is completed; Set the total length of the response to 0: When all response events are read, the total length of the response field is set to 0; Unlock the response area: When the access to the response area is completed, unlock the response area to allow it to be accessed by different programs; Execute the response callback function and update the output pins of the function block: according to the type of the response event, execute the corresponding callback function, and according to the PLCopen specification, update the output pins corresponding to the function block. The output pins include at least Busy pin, Active pin, Done pin, Error pin, ErrorID pin, and CommandAborted pin.
8. A PLCopen motion control function block interactive system based on shared memory, It is characterized in that Including PLC control unit, shared memory and motion control unit, The PLC control unit is used to execute the logic control program and interact with the PLC control unit through the interface of the PLCopen standard motion control function block, and run cyclically according to input sampling, IEC61131-3 program execution, axis state synchronization, output refresh and execution response callback function; The motion control unit is used to establish EtherCAT communication and execute motion instructions, and operates in a cycle according to EtherCAT communication, motion instruction queue entry, motion instruction execution and axis status update; The shared memory is used to establish information interaction between the PLC control unit and the motion control unit to achieve collaborative work between the PLC control unit and the motion control unit; The shared memory includes an input area, a command area, an axis status area, an output area and a response area, wherein: The input area and the output area are used to synchronously input process data and output process data, and the data length is fixedly set; The axis status area is used to synchronize the status information of the axis, wherein the number of axes and the length of the status data of each axis are fixed and arranged in sequence according to the axis number; The instruction area is used to store motion instructions dynamically generated during the operation of the PLC control unit and the motion control unit. When the header of the instruction area is the instruction total length field, it is used to indicate the total length of the current motion instruction data, and then the instruction data is discharged in sequence; The response area is used to store response events dynamically generated during the operation of the PLC control unit and the motion control unit. When the header of the response area is the total response length field, it is used to indicate the total length of the current response event data, and then the response data is discharged in sequence; The PLC control unit and the motion control unit use semaphores to ensure mutual exclusion when accessing the above shared memory area.
