Implementation Method of a Dual CANopen Motion Control PLC

A dual-CANopen motion control PLC solution with a two-interface CPU module and prioritized thread structure enhances motion control capabilities and communication efficiency, addressing limitations of single-interface PLCs by supporting twice the number of motion axes and simplifying user programming.

CN115993799BActive Publication Date: 2025-07-15NANDA AUTOMATION TECH JIANGSU CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211630240.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-19
Publication Date
2025-07-15
Estimated Expiration
2042-12-19

Smart Images

  • Figure CN115993799B_ABST
    Figure CN115993799B_ABST
Patent Text Reader

Abstract

The present invention provides a method for implementing a dual CANopen motion control PLC. By using a CPU module with two CAN interfaces on the main body, it can run two CANopen master stations and support motion control of two CANopen master stations. At the bottom layer of the CPU module, a 1ms time-base thread, a CANopen master station thread, and a motion control thread are established, with the highest priority for the time-base thread and the lowest priority for the motion control thread. Users can flexibly and independently map the servo axis Mc_Axis[] interface to the %MW shared area without caring about which CANopen interface the servo axis is connected to, and all axis numbers are continuous and unified, facilitating user programming.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for implementing a dual CANopen motion control PLC. Background Art

[0002] With the significant improvement in processor performance, the performance of Programmable Logic Controllers (PLCs) has also been greatly enhanced, and motion control functions have become popular in PLCs. CANopen is an international standard application layer protocol, and its underlying layer uses CAN to communicate with slave stations such as servo systems. Since the CANopen protocol stack is open source and CAN communication does not require a dedicated interface chip like EtherCAT in terms of hardware, CANopen is one of the most common communication protocols for PLC motion control. CAN is the abbreviation of Controller Area Network, which was developed by the German company BOSCH, well-known for researching and producing automotive electronic products, and finally became an international standard (ISO 11898), and is one of the most widely used fieldbuses in the world.

[0003] A motion control PLC generally only has one CANopen motion control. Limited by the rate of CAN communication and the fact that the effective data of one CAN message frame is 8 bytes, in application scenarios with a large number of motion control axes, the CANopen communication data volume is large, and CAN can no longer meet the communication requirements.

[0004] Existing CANopen motion control PLC products only have one CANopen interface on the CPU module, so they cannot connect too many slave stations. Summary of the Invention

[0005] Object of the Invention: The technical problem to be solved by the present invention is to provide a method for implementing a dual CANopen motion control PLC in view of the deficiencies of the prior art, including: adopting a CPU module with two CAN interfaces on the body, which can run two CANopen master stations and support the motion control of two CANopen master stations; at the bottom layer of the CPU module, establishing a time base thread, a CANopen master station thread, and a motion control thread with a 1 ms time base, where the priority of the time base thread is the highest and the priority of the motion control thread is the lowest; the programs of the two CANopen master stations run in the CANopen master station thread; the two CANopen master stations are respectively denoted as the first CANopen master station and the second CANopen master station;

[0006] Complete the design of the motion control of the two CANopen master stations at the user PLC end.

[0007] The design of completing the motion control of two CANopen master stations at the user's PLC side specifically includes the following steps:

[0008] Step 1: Establish a motion control task mc_task and a motion control program mc_pou in the PLC programming environment;

[0009] Step 2: Allocate the starting address and size of the %MW mapping area of the first CANopen master station in the PLC programming environment. The addresses of the input area and the output area cannot overlap;

[0010] Step 3: Allocate the starting address and size of the %MW mapping area of the second CANopen master station in the PLC programming environment. The addresses of the input area and the output area cannot overlap, and it also does not overlap with the mapping area of the first CANopen master station;

[0011] Step 4: Define the SDO_Tx and SDO_Rx structure types in the PLC programming environment, and use the SDO_Tx and SDO_Rx structure types to define global variables. Each CANopen master station has its own variables of the SDO_Tx and SDO_Rx structure types, and adjust the soft element addresses corresponding to the variables to be the same as the starting addresses of the SDO reception-related and SDO transmission-related areas in the %MW mapping area of their respective CANopen master stations. The content of the SDO reception-related and SDO transmission-related areas is the same as the SDO_Tx and SDO_Rx structure types;

[0012] Step 5: Define the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types that are the same as the content of the RxPDO and TxPDO actually used under the two CANopen master stations in the PLC programming environment, and use the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types to define variables with the same number as the actual PDOs. And in the programming border, adjust the soft element addresses corresponding to the variables to be the same as the starting addresses of the RxPDO and TxPDO areas of each servo slave station in the %MW soft element area of the two CANopen master stations; The content of the RxPDO and TxPDO areas of each servo slave station is the same as the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types;

[0013] Step 6: Define the MC_AXIS_T structure type in the PLC programming environment, and define a corresponding axis structure variable array MC_Axis[N] according to the number N of servo slave stations driven by the two actual CANopen master stations. N corresponds to the number of servo axes configured in the actual configuration, and N < 127;

[0014] Step 7, write the code for the motion control program mc_pou of the PLC, and use the serial number of the MC_Axis[N] of the servo axis to be controlled as the input of the INPUT pin [AXIS] of the motion control function block; when the motion control function block is executed, it will access the corresponding variable MC_Axis[N] according to the incoming axis serial number;

[0015] Step 8, in the motion control task mc_task, first read the relevant data in the two-channel CANopen master station %MW mapped input area and write it into the corresponding axis variable MC_Axis[N], then call the motion control program mc_pou. The operation results of the motion control function blocks of each axis in the motion control program mc_pou will be written into the corresponding axis variable MC_Axis[N]; at the end of the execution of the mc_task task, write the operation results of each axis in the MC_Axis[N] into the %MW mapped output area of each CANopen master station;

[0016] Step 9, download the compiled program to the PLC for operation.

[0017] The present invention further includes: at the bottom layer of the CPU module, establish semaphore 1 and semaphore 2 in the time-based thread, and send semaphore 1 and 2 to the CANopen master station thread and the motion control thread in sequence through the system call interface in the operating system every time the thread executes a cycle, to ensure the synchronization of thread execution.

[0018] The present invention further includes: when the CANopen master station thread runs at the bottom layer of the CPU module, first block and wait for semaphore 1 through the system call interface. If it receives semaphore 1 sent by the time-based thread, it starts to send the synchronization frames of the two-channel CANopen master station, ensuring the accuracy of the synchronous frame periodic transmission, and enabling the servos on the two CANopen buses to act synchronously; after sending the synchronization frames, the CANopen master station thread sends the RxPDO messages of the two-channel CANopen master station and processes the SDO messages, and finally receives the TxPDO messages sent by each servo slave station in the thread.

[0019] The present invention further includes: when the motion control thread runs at the bottom layer of the CPU module, first block and wait for semaphore 2 through the system call interface. If it receives semaphore 2 sent by the time-based thread, it starts to execute the motion control task mc_task downloaded by the user to the PLC.

[0020] In the present invention, when the user programs and calls the motion control function block, there is no need to input which CANopen interface to use, only the axis number of the motion control function block needs to be passed in, and this axis number is continuous;

[0021] Establish a 1ms time-based task with the highest priority in the PLC;

[0022] An integer multiple period of the unified time base is used as the execution period of the motion control task;

[0023] An integer multiple period of the unified time base is used as the transmission period of the CANopen synchronization frame, and the CANopen synchronization frame is transmitted first at the beginning of the period;

[0024] The interaction between the user motion control program and the CANopen master station uses the %MW soft element area;

[0025] A separate %MW soft element is allocated for each CANopen master station, and the %MW soft element area of each CANopen master station is defined;

[0026] The MC_Axis[N] servo axis abstract structure type is established as a bridge for the interaction between the motion control task and the %MW soft element area, and the consecutive serial numbers of the array MC_Axis[N] are passed as input parameters to the input pin [AXIS] of the motion control function block.

[0027] The present invention has the following beneficial effects:

[0028] The present invention proposes an implementation method of a dual CANopen motion control PLC. Two CANopen interfaces are designed on the CPU module body. The two interfaces can simultaneously control servo slave stations for motion control, or can control slave stations such as sensors and I / O. The number of slave stations driven reaches twice that of existing CANopen motion control PLC products. Compared with existing CANopen motion control PLC products, the number of servo axes driven is greatly increased;

[0029] When the user writes a motion control program, there is no need to target a specific CANopen. The programming usage method is as convenient as that of a single CANopen interface;

[0030] The user can flexibly and independently map the servo axis Mc_Axis[] interface to the %MW shared area without caring about which CANopen interface the servo axis is connected to. All axis numbers are continuously unified, which facilitates user programming. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The following further specifically describes the present invention in conjunction with the drawings and specific embodiments. The above and / or other advantages of the present invention will become clearer.

[0032] Figure 1 It is a schematic diagram of the running process of the 1ms time base thread.

[0033] Figure 2 It is a schematic diagram of the interaction mechanism between the motion control task and the CANopen master station.

[0034] Figure 3 It is a schematic diagram of the operation process of the CANopen master station thread.

[0035] Figure 4 It is a schematic diagram of the operation process of the motion control thread and the motion control task.

[0036] Figure 5 It is a schematic diagram of the MC_Axis[] data structure.

[0037] Figure 6 It is a schematic diagram of the SDO and PDO data structures. Specific implementation mode

[0038] The present invention provides a method for implementing a dual CANopen motion control PLC. This solution uses a CPU module with two CAN interfaces in the main body. The CPU module uses the LinuxRT real-time operating system (not limited to LinuxRT, such as real-time operating systems like Vxworks, Xenomai, SyLixOS, INtime, etc.), and at the bottom layer, a high-precision timer is used to establish a time-base thread, a motion control thread, and a CANopen master station thread with a period of 1 ms. The priority of the CANopen master station thread is higher than that of the motion control thread. The time-base thread has the highest priority and serves as the common time base for the operation of the motion control thread and the CANopen master station thread. In this way, the synchronization of the motion control thread and the CANopen master station thread can be ensured. The operation process of the time-base thread is as Figure 1 shown.

[0039] The general way of rapid data communication between a large number of operating system tasks is usually through shared memory, but this method is invisible to the programming users of the PLC and cannot be accessed. In this method, the %MW soft element area of the PLC itself is used as the bridge for data interaction between the motion control task and the CANopen master station task. The size of this soft element area can be set according to the actual communication needs. The advantage of using the %MW soft element area is that users can directly access it when writing the PLC program, and can flexibly implement the input information required by the motion control function blocks of each axis in the motion control program, as well as the mapping of the calculated output data of the function blocks and the PDO data objects of each servo slave station on the actual CANopen bus. Each CANopen master station has its own %MW input and output soft element areas. The %MW input soft element area stores the data uploaded by each servo slave station on this CANopen bus, and the %MW output soft element area stores the control data output by the motion control program to each servo slave station on this CANopen bus. The storage content of the %MW soft element area is defined in format as Figure 2 shown.

[0040] The CANopen master station thread has a priority only lower than that of the time-base thread. The synchronization frame sending period of the CANopen master station is the same as the period of the motion control task, and the two CANopen master stations run in this thread. At the beginning of each period, the synchronization frames of the two CANopen are sent first to ensure the synchronization of the two-channel CANopen motion control. The CANopen master station reads the data written by the motion control task in the %MW soft element output area and sends it to each servo axis (i.e., the servo slave station) via the CAN bus through NMT, RxPDO or SDO messages. The CANopen master station also reads the feedback messages of each servo axis and writes the data therein into the %MW soft element input area. The running process of the CANopen master station thread is as Figure 3 shown.

[0041] The running period of the motion control task established in the programming interface is an integer multiple of the time-base thread period. The motion control task reads the input data in the %MW soft element area of the CANopen master station at the beginning of the running period, then executes the user-written motion control program, and writes the execution result into the output area of the %MW soft element area. After the program of the motion control task is downloaded to the PLC, the motion control thread periodically calls the program of the motion control task. The running processes of the motion control task and the motion control thread are as Figure 4 shown.

[0042] In the motion control program, MC_Axis[N] is an abstract data structure for the servo axis. For each servo axis connected to the CANopen bus, a data structure variable corresponding to this axis is required. The user's motion control program interacts with the %MW soft element area of the CANopen master station through the MC_Axis[N] variable corresponding to the servo axis. The content of the corresponding structure type data structure is as Figure 5 shown.

[0043] By designing the CANopen communication mapping area in %MW, the underlying information is shielded from the user. Through MC_Axis[N], the servo slave stations carried by different CANopen master stations can be regarded as servo slave stations under the same CANopen master station during user programming, that is, continuous and unified axis numbers are used for programming (for example, axis 0, 1, 2,..., N; the label of the Mc_Axis[N] array is the corresponding axis number, where axes 0-5 are the servo axes on the first CANopen slave station, and axes after 6 are the servo axes on the second CANopen slave station), which facilitates user programming.

[0044] Embodiment

[0045] I. Software (User PLC Programming Environment)

[0046] Step 1: Establish a motion control task mc_task and a motion control program mc_pou in the PLC programming environment;

[0047] Step 2: Allocate the starting address and size of the %MW mapping area of the first CANopen master station in the PLC programming environment. The addresses of the input area and the output area cannot overlap;

[0048] Step 3: Allocate the starting address and size of the %MW mapping area of the second CANopen master station in the PLC programming environment. The addresses of the input area and the output area cannot overlap, and they also do not overlap with the mapping area of CANopen_1;

[0049] Step 4: Define the SDO_Tx and SDO_Rx structure types in the PLC programming environment, as Figure 6 shown. Define global variables using the SDO_Tx and SDO_Rx structure types. Each CANopen master station has its own variables of the SDO_Tx and SDO_Rx types. Adjust the soft element addresses corresponding to the variables to be the same as the starting addresses of the "SDO reception related" and "SDO transmission related" areas in the %MW mapping area of their respective CANopen master stations. The content of the "SDO reception related" and "SDO transmission related" areas is the same as the SDO_Tx and SDO_Rx structure types;

[0050] Step 5: Define the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types in the PLC programming environment, which are the same as the content of the actual RxPDO and TxPDO used in the two CANopen master station buses, as Figure 6 shown. Define variables with the same number as the actual PDOs using the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types, and adjust the soft element addresses corresponding to the variables to be the same as the starting addresses of the RxPDO and TxPDO areas of each servo slave station in the %MW soft element area of the two CANopen master stations. The content of the RxPDO and TxPDO areas of each servo slave station is the same as the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types;

[0051] Step 6: Define the MC_AXIS_T structure type in the PLC programming environment, and define an array of axis structure variables MC_Axis[N] according to the number N of servo slave stations on the two actual CANopen master stations. N corresponds to the number of servo axes configured in the actual configuration, and N < 127;

[0052] Step 7, write the code of the PLC motion control program mc_pou, either ladder diagram or ST can be used, and the serial number of the MC_Axis[N] of the controlled servo axis is used as the input of the INPUT pin [AXIS] of the motion control function block, so that continuous axis serial numbers can be used to pass to the motion control function block without paying attention to which CANopen bus the axis serial number is located on. When the motion control function block is executed, it will access the corresponding variable MC_Axis[N] according to the passed axis serial number;

[0053] Step 8, in the motion control task mc_task, first read the relevant data of the %MW mapping input area of each CANopen master station and write it to the MC_Axis[N] variable of the corresponding axis, then call the motion control program mc_pou, and the running results of the motion control function blocks of each axis in the motion control program mc_pou will be written to the MC_Axis[N] variable of the corresponding axis. At the end of the mc_task task execution, write the running results of each axis in MC_Axis[N] to the %MW mapping output area of each CANopen master station;

[0054] Step 9, download the compiled program to the PLC and run it.

[0055] 2. Software (CPU module bottom layer, taking Linux RT operating system as an example)

[0056] Establish a 1ms time base thread, a CANopen master station thread and a motion control thread, with the time base thread having the highest priority and the motion control thread having the lowest priority. The programs of the two CANopen master stations run in the CANopen master station thread;

[0057] Semaphore 1 and semaphore 2 are established in the time base thread, and semaphore 1 and semaphore 2 are sent to the CANopen master thread and motion control thread in turn through the system call interface sem_post in Linux (taking Linux RT as an example) when the thread is executed every cycle. This way, the synchronization of the execution of the two threads is ensured;

[0058] The CANopen master thread operation process is as follows Figure 3 As shown, first, the system calls the interface to block and wait for semaphore 1. If the semaphore 1 sent by the time base thread is received, the synchronization frame of the two CANopen master stations will be sent. This can ensure the accuracy of the synchronization frame period and enable the servos on the two CANopen buses to act synchronously. After sending the synchronization frame, the CANopen master station thread sends the RxPDO messages of the two CANopen master stations and processes the SDO messages. At the end of the thread, the TxPDO messages sent by each servo slave station are received;

[0059] The operation control thread running process is as follows Figure 4 shown. First, it blocks and waits for Semaphore 2 through the system call interface. If it receives Semaphore 2 sent by the time-base thread, it starts to execute the motion control task mc_task downloaded by the user to the PLC.

[0060] In the specific implementation, the present application provides a computer storage medium and a corresponding data processing unit. Among them, the computer storage medium can store a computer program, and when the computer program is executed by the data processing unit, it can run the inventive content of a method for implementing a dual-CANopen motion control PLC provided by the present invention and some or all of the steps in each embodiment. The storage medium can be a magnetic disk, an optical disc, a read-only memory (ROM), or a random access memory (RAM), etc.

[0061] Those skilled in the art can clearly understand that the technical solutions in the embodiments of the present invention can be implemented by means of a computer program and its corresponding general hardware platform. Based on such an understanding, the technical solutions in the embodiments of the present invention, in essence, or the part that contributes to the prior art can be embodied in the form of a computer program, that is, a software product. The computer program software product can be stored in the storage medium and includes several instructions for causing a device (which can be a personal computer, a server, a single-chip microcomputer, a MUU, or a network device, etc.) including a data processing unit to execute the methods described in each embodiment or some parts of the embodiments of the present invention.

[0062] The present invention provides a method for implementing a dual-CANopen motion control PLC. There are many methods and ways to specifically implement this technical solution. The above is only the preferred implementation mode of the present invention. It should be noted that for those of ordinary skill in the art in this technical field, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention. Each component not clearly defined in this embodiment can be implemented by the prior art.

Claims

1. A method for implementing a dual CANopen motion control PLC, characterized in that, Including: A CPU module with two CAN interfaces in the main body, capable of running two CANopen masters, and supporting motion control of two CANopen masters; At the bottom layer of the CPU module, a 1ms time-base thread, a CANopen master thread, and a motion control thread are established. The priority of the time-base thread is the highest and that of the motion control thread is the lowest; the programs of the two CANopen masters run in the CANopen master thread; the two CANopen masters are respectively denoted as the first CANopen master and the second CANopen master; Complete the design of motion control for two CANopen masters at the user PLC side; The design of completing the motion control of two CANopen masters at the user PLC side specifically includes the following steps: Step 1, establish a motion control task mc_task and a motion control program mc_pou in the PLC programming environment; Step 2, allocate the starting address and size of the %MW mapping area of the first CANopen master in the PLC programming environment, and the addresses of the input area and the output area cannot overlap; Step 3, allocate the starting address and size of the %MW mapping area of the second CANopen master in the PLC programming environment, the addresses of the input area and the output area cannot overlap, and it does not overlap with the mapping area of the first CANopen master either; Step 4, define the SDO_Tx and SDO_Rx structure types in the PLC programming environment, and use the SDO_Tx and SDO_Rx structure types to define global variables. Each CANopen master has its own variables of the SDO_Tx and SDO_Rx structure types, and adjust the soft device addresses corresponding to the variables to be the same as the starting addresses of the SDO reception-related and SDO transmission-related areas in the %MW mapping area of their respective CANopen masters. The content of the SDO reception-related and SDO transmission-related areas is the same as the SDO_Tx and SDO_Rx structure types; Step 5, define the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types that are the same as the content of the RxPDO and TxPDO actually used under the two CANopen masters in the PLC programming environment, and use the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types to define variables with the same number as the actual PDOs. And in the programming border, adjust the soft device addresses corresponding to the variables to be the same as the starting addresses of the RxPDO and TxPDO areas of each servo slave station in the %MW soft device area of the two CANopen masters; the content of the RxPDO and TxPDO areas of each servo slave station is the same as the AXIS_RXPDO_POS_T and AXIS_TXPDO_POS_T structure types; Step 6: In the PLC programming environment, define the MC_AXIS_T structure type and define the corresponding axis structure variable array MC_Axis[N] according to the number N of servo slave stations carried by the two actual CANopen master stations. N corresponds to the number of servo axes configured in the actual configuration, and N < 127; Step 7: Write the code of the motion control program mc_pou of the PLC, and use the serial number of MC_Axis[N] of the servo axis to be controlled as the input of the INPUT pin [AXIS] of the motion control function block; when the motion control function block is executed, it will access the corresponding variable MC_Axis[N] according to the incoming axis serial number; Step 8: In the motion control task mc_task, first read the relevant data in the %MW mapping input area of the two CANopen master stations and write them into the MC_Axis[N] variables of the corresponding axes, and then call the motion control program mc_pou. The operation results of the motion control function blocks of each axis in the motion control program mc_pou will be written into the MC_Axis[N] variables of the corresponding axes; at the end of the execution of the mc_task task, write the operation results of each axis in MC_Axis[N] into the %MW mapping output area of each CANopen master station; Step 9: Download the compiled program to the PLC for operation.

2. The method according to claim 1, characterized in that It also includes: At the bottom layer of the CPU module, semaphore 1 and semaphore 2 are established in the time-base thread, and semaphore 1 and 2 are sent to the CANopen master station thread and the motion control thread in turn through the system call interface in the operating system every time the thread executes, ensuring the synchronization of thread execution.

3. The method according to claim 2, wherein It also includes: At the bottom layer of the CPU module, when the CANopen master station thread runs, it first blocks and waits for semaphore 1 through the system call interface. If it receives semaphore 1 sent by the time-base thread, it starts to send the synchronization frames of the two CANopen master stations, ensuring the accuracy of the synchronization frame periodic transmission and enabling the servos on the two CANopen buses to move synchronously; After sending the synchronization frames, the CANopen master station thread sends the RxPDO messages of the two CANopen master stations and processes the SDO messages, and finally receives the TxPDO messages sent by each servo slave station in the thread.

4. The method according to claim 3, characterized in that, It also includes: At the bottom layer of the CPU module, when the motion control thread runs, it first blocks and waits for semaphore 2 through the system call interface. If it receives semaphore 2 sent by the time-base thread, it starts to execute the motion control task mc_task downloaded by the user to the PLC.

Citation Information

Patent Citations

  • PLC becomes oar controller with servo driver integration

    CN205605358U