Disclosure of Invention
The invention aims to provide an industrial motion control system and method based on an API (application program interface) to reduce communication data redundancy and improve communication speed.
In order to achieve the purpose, the invention adopts the technical scheme that the industrial motion control system based on the API comprises an industrial personal PC control subsystem and a P L C control subsystem, wherein the industrial PC control subsystem comprises a control module and an API library, the P L C control subsystem comprises a P L C motion controller and a plurality of servo drivers, and the industrial motion control system comprises:
the control module is used for generating a motion control instruction and processing feedback data from a P L C control subsystem;
the API library is used for caching the motion control commands from the control module, sending a plurality of motion control commands to the P L C control subsystem at one time and reading feedback data of the P L C control subsystem to the industrial PC control subsystem at one time;
the P L C motion controller for controlling the plurality of servo drives according to the plurality of motion control commands and generating feedback data;
and the plurality of servo drivers are used for controlling the corresponding motor motion under the control of the P L C motion controller.
Preferably, the industrial PC control subsystem and the P L C control subsystem communicate with each other via an extended Modbus TCP protocol, where the extended Modbus TCP protocol includes a batch read function code and a batch write function code.
Preferably, the P L C motion controller comprises a plurality of data storage units for storing feedback data of the P L C control subsystem, wherein the feedback data of the P L C control subsystem comprises execution result data and motor state data of the plurality of servo drivers for controlling the motor motion;
the plurality of servo drivers are further configured to return the execution result data and the motor state data to the plurality of data storage units.
Preferably, the API library includes a dynamic link library, a processing unit, and an instruction storage unit, wherein:
the dynamic link library is used for providing an API interface function for the control module so that the control module can store a plurality of motion control instructions to the instruction storage unit in sequence by calling the API interface function;
the processing unit is used for sending the motion control commands stored in the command storage unit to the P L C control subsystem at one time, and reading the execution result data and the motor state data at one time;
the instruction storage unit is used for temporarily storing the plurality of motion control instructions.
Preferably, the processing unit is further configured to:
and when the instruction storage unit is empty, the motor state data is read to the industrial PC control subsystem at one time.
Correspondingly, the invention also provides an industrial motion control method based on the API, which comprises the following steps:
step S1, generating a motion control command and sending a plurality of motion control commands to the P L C control subsystem at one time;
step S2, the P L C motion controller controls a plurality of servo drivers according to the motion control commands;
step S3: the servo drivers control the corresponding motors to move;
and step S4, reading the feedback data of the P L C control subsystem to the industrial PC control subsystem at one time.
Preferably, the industrial PC control subsystem and the P L C control subsystem communicate with each other via an extended Modbus TCP protocol, where the extended Modbus TCP protocol includes a batch read function code and a batch write function code.
Preferably, the feedback data of the P L C control subsystem includes execution result data and motor state data of the plurality of servo drivers controlling the motor motion;
in the step S4, the P L C control subsystem simultaneously transmits the execution result data and the motor state data to the industrial PC control subsystem.
Preferably, the step S1 includes:
step S11: a control module of the industrial PC control subsystem generates a motion control instruction;
step S12: calling an API interface function of an API library to sequentially store the motion control instructions into an instruction storage unit;
step S13, the motion control commands stored in the command storage unit are sent to the P L C control subsystem at a time.
Preferably, the API-based industrial motion control method further comprises:
and when the instruction storage unit is empty, the motor state data is read to the industrial PC control subsystem at one time.
The API-based industrial motion control system and the API-based industrial motion control method have the advantages that the industrial PC control subsystem sends a plurality of motion control instructions to the P L C control subsystem at one time through the API library, the P L C control subsystem controls the motor shaft to complete corresponding motion according to the motion control instructions and then reads feedback data of the P L C control subsystem at one time, therefore, the industrial PC control subsystem can provide a visualization function and control the motor shaft by using the stability of the P L C, meanwhile, the industrial PC control subsystem can send a plurality of motion control instructions to the P L C control subsystem at one time and simultaneously read the feedback data of the P L C control subsystem at one time, and therefore, communication data redundancy is greatly reduced, the purpose of improving communication speed and meeting system requirements is achieved.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
FIG. 1 is a schematic diagram of an API-based industrial motion control system according to an embodiment of the present invention, and as shown in FIG. 1, the API-based industrial motion control system of the present invention includes an industrial PC control subsystem 10 and a P L C control subsystem 20. the industrial PC control subsystem 10 includes a control module 110 and an API library 120, and the P L C control subsystem 20 includes a P L C motion controller 210 and a plurality of servo drivers 220.
In an embodiment of the present invention, the industrial PC control subsystem 10 and the P L C control subsystem 20 communicate with each other via an extended Modbus TCP protocol, where the extended Modbus TCP protocol includes a batch read function code and a batch write function code, the host computer can read discrete register data at a time via the batch read function code 0x61, and write a plurality of discrete registers at a time via the batch write function code 0x 62.
Specifically, in an embodiment of the present invention, the motion control command refers to a command for controlling rotation of a motor shaft, such as a start motor shaft command, a stop command, an acceleration command, a deceleration command, and the like, when the system needs to control a certain motor shaft to move in a certain manner, a plurality of corresponding motion control commands are simultaneously sent to the P L C control subsystem through the control module 110 at one time, instead of sending the control commands one by one.
The API library 120 is used for caching the motion control commands from the control module 110, sending a plurality of motion control commands to the P L C control subsystem 20 at one time, and reading the feedback data of the P L C control subsystem 20 to the industrial PC control subsystem 10 at one time, specifically, the API library 120 provides data buffering for the control module 110, is responsible for transmitting the commands of the control module 110 to the P L C control subsystem and feeding back the execution results to a service layer, and the control module 110 can realize the starting, stopping, accelerating and decelerating of the shaft, and obtaining various states of the shaft and the like only by calling interface functions provided by the API library 120.
The P L C motion controller 210 is used for controlling the servo drivers 220 according to the motion control commands and generating feedback data, the servo drivers 220 are used for controlling corresponding motor motion under the control of the P L C motion controller 210, specifically, the P L C motion controller 210 is connected with the servo drivers 220 through an EtherCAT (Ethernet control automation Technology) bus to form a P L C control subsystem 20. the P L C motion controller 210 is programmed with function modules corresponding to different motion control commands in advance through P L C programming languages such as ladder diagram, ST (structured text) and the like according to control requirements, the P L C motion controller 210 calls corresponding function modules according to the motion control commands sent by the industrial PC control subsystem 10, and controls the corresponding servo drivers 220 through the EtherCAT bus, thereby realizing the motion control of corresponding motor shafts.
Further, in an embodiment of the present invention, the P L C motion controller 210 includes a plurality of data storage units for storing feedback data of the P L C control subsystem 20, the feedback data of the P L C control subsystem 20 includes execution result data and motor status data of the plurality of servo drivers 220 for controlling the motor motion, the plurality of servo drivers 220 are further used for returning the execution result data and the motor status data to the plurality of data storage units, specifically, the servo drivers need to return to the data storage units of the P L C motion controller according to an execution result after controlling the motor shaft motion, and the motor also updates its own status data (e.g., the data of the rotation speed, position, etc. of the motor at that time) to the data storage units through the servo drivers in real time.
Further, as shown in fig. 2, in an embodiment of the present invention, the API library 120 includes a dynamic link library 122, an instruction storage unit 124, and a processing unit 126, where the dynamic link library 122 is configured to provide an API interface function for the control module 110, so that the control module 110 sequentially stores a plurality of motion control instructions to the instruction storage unit 124 by calling the API interface function, the processing unit 126 is configured to send the plurality of motion control instructions stored in the instruction storage unit 124 to the P L C control subsystem 20 at one time, and read the execution result data and the motor state data at one time, and the instruction storage unit 124 is configured to temporarily store the plurality of motion control instructions.
Therefore, when the control module 110 needs to send a plurality of motion control instructions to the P L C control subsystem 20, the motion control instructions can be sequentially read to the instruction storage unit 124 by calling the API interface function, the processing unit 126 polls the instruction storage unit 124, when the instruction storage unit 124 is not empty (i.e., there is a motion control instruction), the processing unit 126 reads the instruction storage unit 124 and simultaneously issues a plurality of instructions to the P L C control subsystem through batch write function codes, and when the P L C control subsystem responds, the processing unit not only needs to read execution result data, but also needs to read motor state data together, i.e., the data stored in a plurality of discrete registers of the P L C control subsystem is updated to the memory of the industrial PC at one time through batch read function codes.
Further, in an embodiment of the present invention, the processing unit 126 is further configured to read the motor status data to the industrial PC control subsystem 10 once when the instruction storage unit 124 is empty (i.e. when there is no motion control instruction), specifically, when the instruction storage unit 124 is empty (i.e. when there is no motion control instruction), the processing unit 126 reads the feedback data of the P L C control subsystem to the industrial PC control subsystem to the memory once through a 0x61 function code.
Advantageously, in the API-based industrial motion control system provided by this embodiment, the industrial PC control subsystem sends a plurality of motion control commands to the P L C control subsystem at a time through the API library, the P L C control subsystem controls the motor shaft to complete corresponding motions according to the plurality of motion control commands, and then the industrial PC control subsystem reads the feedback data of the P L C control subsystem at a time, so that the industrial PC control subsystem can provide a visualization function through the industrial PC control subsystem, and can also control the motor shaft by using the stability of the P L C, and meanwhile, the industrial PC control subsystem and the P L C control subsystem communicate through the extended Modbus TCP protocol, and the industrial PC control subsystem can simultaneously send a plurality of motion control commands to the P L C control subsystem at a time by writing function codes in batches, and read the feedback data of the P L C control subsystem at a time by writing function codes in batches, thereby greatly reducing communication data redundancy, achieving the purpose of increasing communication speed and satisfying system requirements.
It should be noted that, in the embodiment of the present invention, a plurality of motion control commands and feedback data may be sent and read at one time, or may be sent and read in multiple times according to an application scenario, which is not limited herein.
Fig. 3 is a flowchart illustrating an API-based industrial motion control method according to an embodiment of the present invention. As shown in fig. 3, the API-based industrial motion control method includes the steps of:
step S1, generating a motion control command and sending a plurality of motion control commands to the P L C control subsystem at one time;
when the system needs to control a certain motor shaft to move in a certain mode, a plurality of corresponding motion control commands are simultaneously sent to the P L C control subsystem through the control module at one time instead of sending the control commands one by one.
Step S2, the P L C motion controller controls a plurality of servo drivers according to the motion control commands;
step S3: the servo drivers control the corresponding motors to move;
the P L C motion controller is programmed with function modules corresponding to different motion control instructions in advance through P L C programming languages such as ladder diagram and ST (Structured Text) according to control requirements, the P L C motion controller calls corresponding function modules according to the motion control instructions sent by the industrial PC control subsystem, and controls the corresponding servo drivers through the EtherCAT bus, thereby realizing the motion control of corresponding motor shafts
And step S4, reading the feedback data of the P L C control subsystem to the industrial PC control subsystem at one time.
Further, in an embodiment of the present invention, the feedback data of the P L C control subsystem includes the execution result data and the motor status data of the plurality of servo drivers controlling the motor motion, and in the step S4, the P L C control subsystem simultaneously transmits the execution result data and the motor status data to the industrial PC control subsystem, the plurality of servo drivers return the execution result data and the motor status data to the plurality of data storage units of the P L C motion controller.
In an embodiment of the present invention, the industrial PC control subsystem 10 and the P L C control subsystem 20 communicate with each other via an extended Modbus TCP protocol, where the extended Modbus TCP protocol includes a batch read function code and a batch write function code, the host computer can read the discrete register data at one time via the new function code via the batch read function code 0x61, and the other function is a batch write function 0x62, i.e. the host computer can write a plurality of discrete registers at one time via the function code.
Further, as shown in fig. 4, the step S1 includes the following steps:
step S11: a control module of the industrial PC control subsystem generates a motion control instruction;
step S12:
calling an API interface function of an API library to sequentially store the motion control instructions into an instruction storage unit;
step S13, the motion control commands stored in the command storage unit are sent to the P L C control subsystem at a time.
The industrial PC control subsystem and the P L C control subsystem are communicated through an extended Modbus TCP protocol, therefore, when a control module needs to send a plurality of motion control commands to the P L C control subsystem, the motion control commands can be sequentially stored in the command storage unit by calling the API interface function, the processing unit polls the command storage unit, when the command storage unit is not empty (namely, when the motion control commands exist), the processing unit reads the command storage unit and simultaneously issues the commands to the P L C control subsystem through batch writing function codes, and when the P L C control subsystem responds, the processing unit not only needs to read execution result data, but also needs to read motor state data together, namely, the data stored in a plurality of discrete registers of the P L C control subsystem are updated to the memory of the industrial PC control subsystem at one time through the batch reading function codes.
Further, in this embodiment, the API-based industrial motion control method further includes:
and when the instruction storage unit is empty, the motor state data is read to the industrial PC control subsystem at one time.
Specifically, when the instruction storage unit is empty (namely when no motion control instruction exists), the processing unit reads the feedback data of the P L C control subsystem into the industrial PC control subsystem to be stored into the memory at one time through the 0x61 function code.
Advantageously, according to the API-based industrial motion control method provided by the embodiment, the industrial PC control subsystem sends a plurality of motion control commands to the P L C control subsystem at one time through the API library, the P L C control subsystem controls the motor shaft to complete corresponding motion according to the motion control commands, and then the industrial PC control subsystem reads feedback data of the P L C control subsystem at one time, so that a visualization function can be provided through the industrial PC control subsystem, control over the motor shaft can be achieved by using the stability performance of the P L C, meanwhile, the industrial PC control subsystem and the P L C control subsystem communicate through an expanded Modbus TCP protocol, the industrial PC control subsystem can simultaneously send a plurality of motion control commands to the P L C control subsystem at one time through batch writing of function codes, and read feedback data of the P L C control subsystem at one time through batch writing of function codes, and therefore communication data redundancy can be greatly reduced, communication speed can be improved, and the purpose of meeting system requirements can be achieved.
While the invention has been described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.