Task execution method and device, electronic equipment and readable storage medium
By deploying real-time operating programs and task scheduling strategies in the servo drive, the problem of inflexible task scheduling of servo drives is solved, and task execution efficiency and processor resource utilization are improved.
Patent Information
- Application Number
- CN202411683859.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-04-08
AI Technical Summary
When servo drives perform tasks, task scheduling lacks flexibility, resulting in low task execution efficiency.
Deploy real-time operating programs in the servo drive, set task scheduling policies, obtain tasks to be executed and execute according to the policy, including the priority and time slice length management of initialized tasks, handshake tasks and other tasks to be executed.
Through flexible task scheduling strategies, the task execution efficiency of servo drives is improved, and higher processor resource utilization and network communication quality are achieved.
Smart Images

Figure CN119781912A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular, to a task execution method, a task execution device, an electronic device, and a computer-readable storage medium. Background Art
[0002] Servo drive is an important part of modern motion control. It is a controller used to control servo motors. It is currently widely used in automation equipment such as industrial robots and CNC machining centers.
[0003] However, currently, when executing tasks, the servo drive can only execute the received tasks one by one, and the task scheduling lacks flexibility, resulting in low task execution efficiency. Summary of the invention
[0004] The embodiments of the present invention provide a task execution method, device, electronic device and computer-readable storage medium to solve the problem that task scheduling lacks flexibility, resulting in low efficiency of servo drive task execution.
[0005] The embodiment of the present invention discloses a task execution method, which is applied to a servo drive, wherein the servo drive is connected to a debugging device, the servo drive is installed with a real-time operation program, and a task scheduling strategy is set in the real-time operation program. The method comprises:
[0006] Acquire at least one task to be executed; wherein the task to be executed includes a task sent by the debugging device and a task inside the servo driver;
[0007] The to-be-executed tasks are executed according to the task scheduling strategy.
[0008] In one embodiment of the present invention, obtaining at least one task to be executed includes:
[0009] When the servo drive is powered on, obtaining an initialization task of the servo drive;
[0010] The initialization task is used as a task to be executed.
[0011] In one embodiment of the present invention, the initialization task at least includes: opening the communication network port between the servo drive and the debugging device; enabling the interface chip of the servo drive, the interface chip transmitting data between the debugging device; initializing the memory space of the servo drive, the memory space being used to cache data; configuring the Ethernet protocol stack, the Ethernet protocol stack being used to transmit data packets between the debugging device.
[0012] In an embodiment of the present invention, the priorities of the initialization tasks are the same.
[0013] In one embodiment of the present invention, the method further comprises:
[0014] When the initialization task is successfully executed, obtaining a handshake task for communication connection with the debugging device as a task to be executed;
[0015] When the handshake task is successfully executed, the servo driver is communicatively connected with the debugging device, so that the servo driver receives the data message sent by the debugging device and generates a task to be executed according to the data message.
[0016] In one embodiment of the present invention, executing the to-be-executed task according to the task scheduling strategy includes:
[0017] Determining the priority of the task to be performed;
[0018] When the priorities of the tasks to be executed are different, the tasks to be executed are executed according to their priorities.
[0019] In one embodiment of the present invention, executing the tasks to be executed according to their priorities includes:
[0020] When the handshake task fails to execute, suspending the handshake task;
[0021] When the time for suspending the execution of the handshake task reaches the preset delay waiting time, the handshake task is executed again.
[0022] In an embodiment of the present invention, the priority of the handshake task is the highest priority.
[0023] In one embodiment of the present invention, executing the to-be-executed task according to the task scheduling strategy includes:
[0024] When the priorities of the tasks to be executed are the same, obtaining the time slice length;
[0025] Determine the current task to be executed from the tasks to be executed and execute it;
[0026] When the execution time of the current task to be executed exceeds the length of the time slice, return to the step of determining the current task to be executed from the tasks to be executed and executing it.
[0027] The embodiment of the present invention further discloses a task execution device, which is applied to a servo drive, wherein the servo drive is connected to a debugging device, the servo drive is installed with a real-time operation program, and a task scheduling strategy is set in the real-time operation program. The device comprises:
[0028] A task acquisition module to be executed, used to acquire at least one task to be executed; wherein the task to be executed includes a task sent by the debugging device and a task inside the servo driver;
[0029] The to-be-executed task execution module is used to execute the to-be-executed task according to the task scheduling strategy.
[0030] In one embodiment of the present invention, the initialization task at least includes: opening the communication network port between the servo drive and the debugging device; enabling the interface chip of the servo drive, the interface chip transmitting data between the debugging device; initializing the memory space of the servo drive, the memory space being used to cache data; configuring the Ethernet protocol stack, the Ethernet protocol stack being used to transmit data packets between the debugging device.
[0031] In an embodiment of the present invention, the priorities of the initialization tasks are the same.
[0032] In one embodiment of the present invention, the device further comprises: a handshake communication module, configured to:
[0033] When the initialization task is successfully executed, obtaining a handshake task for communication connection with the debugging device as a task to be executed;
[0034] When the handshake task is successfully executed, the servo driver is communicatively connected with the debugging device, so that the servo driver receives the data message sent by the debugging device and generates a task to be executed according to the data message.
[0035] In one embodiment of the present invention, the to-be-executed task execution module is used to:
[0036] Determining the priority of the task to be performed;
[0037] When the priorities of the tasks to be executed are different, the tasks to be executed are executed according to their priorities.
[0038] In one embodiment of the present invention, the to-be-executed task execution module is used to:
[0039] When the handshake task fails to execute, suspending the handshake task;
[0040] When the time for suspending the execution of the handshake task reaches the preset delay waiting time, the handshake task is executed again.
[0041] In an embodiment of the present invention, the priority of the handshake task is the highest priority.
[0042] In one embodiment of the present invention, the to-be-executed task execution module is used to:
[0043] When the priorities of the tasks to be executed are the same, obtaining the time slice length;
[0044] Determine the current task to be executed from the tasks to be executed and execute it;
[0045] When the execution time of the current task to be executed exceeds the length of the time slice, return to the step of determining the current task to be executed from the tasks to be executed and executing it.
[0046] The embodiment of the present invention further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0047] The memory is used to store computer programs;
[0048] The processor is used to implement the method described in the embodiment of the present invention when executing the program stored in the memory.
[0049] The embodiment of the present invention further discloses a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the embodiment of the present invention.
[0050] The embodiment of the present invention further discloses a computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the method described in the embodiment of the present invention.
[0051] The embodiments of the present invention include the following advantages:
[0052] In an embodiment of the present invention, a servo drive is connected to a debugging device, a real-time operating program is installed in the servo drive, a task scheduling strategy is set in the real-time operating program, and when the servo drive needs to execute a task, at least one task to be executed is obtained, wherein the task to be executed includes tasks sent by the debugging device and tasks inside the servo drive, and then the task to be executed is executed according to the task scheduling strategy. The embodiment of the present invention executes the acquired tasks based on the task scheduling strategy deployed in the servo drive, so that the task scheduling is flexible and the task execution efficiency of the servo drive is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 is a step flow chart of a task execution method provided in an embodiment of the present invention;
[0054] Figure 2 It is a schematic diagram of the physical connection between a servo drive and a PC dedicated debugging interface provided in an embodiment of the present invention;
[0055] Figure 3 It is a schematic diagram of a flow chart of a servo drive and a PC dedicated debugging interface communicating and connecting in an embodiment of the present invention;
[0056] Figure 4 is a structural block diagram of a task execution device provided in an embodiment of the present invention;
[0057] Figure 5 It is a schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention. DETAILED DESCRIPTION
[0058] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0059] Reference Figure 1 , shows a flowchart of the steps of a task execution method provided in an embodiment of the present invention, which is applied to a servo drive, the servo drive is connected to a debugging device, the servo drive is installed with a real-time operation program, and the real-time operation program is provided with a task scheduling strategy. The method may specifically include the following steps:
[0060] Step 101, obtaining at least one task to be executed; wherein the task to be executed includes a task sent by the debugging device and a task inside the servo driver.
[0061] Step 102: Execute the task to be executed according to the task scheduling strategy.
[0062] In the specific implementation, the servo drive has a network communication function and can be connected to the debugging device (debugging computer) through a network cable. In this way, the staff can send operating instructions or monitor data to the servo drive through the dedicated debugging interface provided for the servo drive on the debugging computer, such as checking the driving parameters of various servo drives, the operating status of the servo drive, the motor speed, the motor operating status, the current error code, etc. At the same time, according to the online upgrade function of the servo drive and the dedicated debugging interface, the servo drive driver can be upgraded online.
[0063] However, in the related technical solutions, the MCU (Microcontroller Unit) of the servo drive does not have an operating system, and of course does not have an RTOS (Real Time Operate System). Therefore, when the servo drive is currently executing tasks, it can only execute the received tasks one by one, and the task scheduling lacks flexibility, resulting in low efficiency in task execution. Specifically, RTOS is a real-time operating system, such as RTX, RT-Thread, etc. Most of the real-time operating systems are free and open source embedded real-time operating systems. When external events or data are generated, the real-time operating system RTOS can accept and process them at a fast enough speed. The processing results can control the production process or respond quickly to the processing system within the specified time, dispatch all available resources to complete real-time tasks, and control all real-time tasks to run in a coordinated manner. Since the servo drive does not have a real-time operating system, when the servo drive obtains a function (task) to execute, another function can only wait for the current function to finish execution before it can start execution. If it is necessary to stop the current function to execute another function, the only way is to use the interrupt method, that is, set an interrupt flag in the function. According to the interrupt flag, when the interrupt flag is generated, stop the currently executing function and execute the interrupted function, while the other function is in a waiting state, wasting the CPU (Central Processing Unit) and MCU resources of the servo drive, and the real-time performance is poor. Therefore, for applications with high real-time requirements, such as applications where the servo drive performs network debugging operations, problems such as slow network transmission speed and data packet loss will occur, causing inconvenience to the staff.
[0064] In an embodiment of the present invention, a real-time operating program (RTOS system plug-in) is installed in the servo driver, wherein the real-time operating program is written according to the real-time operating system, and the resources such as the algorithm code of the real-time operating system are completely open source and free, and there will be no conflict of interest. The R&D personnel write the algorithm code for the servo driver by themselves to obtain the real-time operating program, and the task scheduling strategy is deployed in the real-time operating program. The real-time operating program performs task scheduling according to the task scheduling strategy, realizes the real-time network communication between the servo driver and the dedicated debugging interface, improves the quality of network communication, and increases the data transmission speed and other purposes. In addition, the open source operating system can not only be used in the network communication function, but also can use the operating system for the development of other functions of the MCU micro control unit in the servo driver that does not have an operating system, and realizes the simultaneous operation of multiple tasks, etc.
[0065] In a specific implementation, task scheduling means that a processor (such as a CPU or MCU) can only execute one task at a time. If it switches quickly between tasks, it is equivalent to multiple tasks running at the same time for the user. The responsibility of the real-time operation program in the servo driver of the embodiment of the present invention is to use the relevant task scheduling strategy to decide which task to execute at the current moment. Among them, task scheduling can be divided into a variety of task scheduling methods such as preemptive and time slice. Preemptive means that according to the priority of the task, high priority tasks are executed first, and low priority tasks are executed later. Time slice means that each task has the same priority, and tasks are executed according to the length of the CPU time slice, that is, the fixed running time. When a task completes a time slice length, the next task will be executed. The time slice length is usually the same, but of course it can be different.
[0066] In an embodiment of the present invention, the servo driver can obtain and execute tasks to be executed, wherein the tasks to be executed may be tasks corresponding to operation instructions issued by the debugging interface, and may also be tasks generated by the servo driver itself, for example, the initialization task of the servo driver. Specifically, the initialization task of the servo driver is usually used to ensure that the servo driver can operate normally after power-on, and to prepare for subsequent operations and task scheduling, so that the servo driver can communicate normally with the debugging device, and then obtain tasks normally and process tasks normally. In the process of communication between the servo driver and the debugging computer's dedicated debugging interface, the two communicate and transmit data through the international standard communication protocol TCP (Transmission Control Protocol) / UDP (User Datagram Protocol). For example, the debugging computer issues operation instructions to the servo driver through the dedicated debugging interface, and the servo driver performs the corresponding operation after receiving it.
[0067] For example, refer to Figure 2 , is a schematic diagram of a physical connection between a servo drive and a PC dedicated debugging interface provided in an embodiment of the present invention. The servo drive has a network communication function and is directly connected to a debugging computer (PC) through a network cable. The staff can use the application of the servo drive's dedicated debugging interface. After the debugging interface and the servo drive successfully establish a communication connection, they can issue operation instructions (such as operation instructions for controlling the servo drive to start, stop, set parameters, adjust speed or position, etc.) through the dedicated debugging interface. The operation instructions are sent to the servo drive through a network communication protocol, such as the TCP / UDP protocol. After receiving the operation instructions, the servo drive takes the operation instructions as a task to be executed and performs corresponding operations based on the task.
[0068] In the embodiment of the present invention, an RTOS real-time operating system file package is added to the MCU single-chip engineering file of the servo drive to install a real-time operating program, so that the servo drive can perform task scheduling based on the real-time operating program. In this way, even if the servo drive itself does not have an operating system, various functions can be implemented. Exemplarily, the real-time operating program of the embodiment of the present invention can be specifically applied in the network communication scenario of the servo drive MCU to write a lightweight TCP protocol stack, including protocols of the physical layer, link layer, and network layer, to achieve TCP network communication with low latency.
[0069] In the above-mentioned task execution method, the servo drive is connected to the debugging device, the servo drive is installed with a real-time operation program, and a task scheduling strategy is set in the real-time operation program. When the servo drive needs to execute a task, at least one task to be executed is obtained, wherein the task to be executed includes the task sent by the debugging device and the task inside the servo drive, and then the task to be executed is executed according to the task scheduling strategy. The embodiment of the present invention executes the acquired task based on the task scheduling strategy deployed in the servo drive, so that the task scheduling is flexible and the task execution efficiency of the servo drive is improved.
[0070] In one embodiment of the present invention, obtaining at least one task to be executed may include:
[0071] When the servo drive is powered on, obtaining an initialization task of the servo drive;
[0072] The initialization task is used as a task to be executed.
[0073] In the embodiment of the present invention, when the servo drive is powered on, an initialization task can be acquired and executed, and the initialization task can be used as a task to be executed, and the task to be executed can be executed accordingly according to a task scheduling strategy.
[0074] In some specific examples, the initialization task of the servo drive may at least include: opening the communication network port between the servo drive and the debugging device; enabling the interface chip of the servo drive, the interface chip transmitting data with the debugging device; initializing the memory space of the servo drive, the memory space being used to cache data; configuring the Ethernet protocol stack, the Ethernet protocol stack being used to transmit data packets with the debugging device. The initialization tasks have the same priority.
[0075] Specifically, when the servo drive is powered on, it obtains and executes initialization tasks such as MCU peripherals, enables network communication interface functions, such as opening the RJ45 network port (communication network port) to connect to the RJ45 network port of the debugging device; enables the interface chip of the servo drive, such as the PHY (Physical Layer Interface) chip, which is responsible for the physical transmission of data, including the sending and receiving of operation instructions; initializes the memory space of the servo drive, such as DMA (Direct Memory Access), to access and send buffer data; initializes the Ethernet TCP / IP protocol stack (EtherNet network protocol stack), which is used to receive and send Ethernet messages.
[0076] In the above embodiment, when the servo drive is powered on, an initialization task can be acquired and executed as a task to be executed. After the initialization task is executed, the servo drive can run normally and prepare for subsequent normal communication with the debugging device.
[0077] In one embodiment of the present invention, the method may further include:
[0078] When the initialization task is successfully executed, obtaining a handshake task for communication connection with the debugging device as a task to be executed;
[0079] When the handshake task is successfully executed, the servo driver is communicatively connected with the debugging device, so that the servo driver receives the data message sent by the debugging device and generates a task to be executed according to the data message.
[0080] In an embodiment of the present invention, when the servo drive is powered on and after the execution of the task is successfully initialized, the servo drive can operate normally and be ready for normal communication with the debugging device. At this time, the servo drive can obtain a handshake task for communicating with the debugging device as a task to be executed. When the handshake task is successfully executed, the servo drive is communicated with the debugging device. At this time, the servo drive can start to receive data messages (operation instructions) sent by the debugging device, generate tasks to be executed based on the data messages, and then execute the tasks to be executed according to the task scheduling strategy.
[0081] In the above embodiment, after the servo drive is powered on and successfully executes the initialization task, a handshake task for communicating with the debugging device can be obtained as a task to be executed. In this way, when the handshake task is executed successfully, the servo drive and the debugging device can communicate normally, and the servo drive can receive the operation instructions sent by the debugging device through the dedicated debugging interface to generate tasks to be executed.
[0082] In one embodiment of the present invention, executing the to-be-executed task according to the task scheduling strategy includes:
[0083] Determining the priority of the task to be performed;
[0084] When the priorities of the tasks to be executed are different, the tasks to be executed are executed according to their priorities.
[0085] In a specific implementation, the tasks to be executed have different priorities, and the priorities represent the importance and urgency of the tasks to be executed in the servo drive, wherein the priorities may be fixed or may change according to the task status. In some specific examples, the priorities of the tasks to be executed may be divided into three levels: high, medium, and low, or may be represented by numerical values, where a larger numerical value represents a higher priority.
[0086] In the embodiment of the present invention, when the servo driver obtains multiple tasks to be executed at the same time, first, the execution order is determined according to the priority of the tasks to be executed. Specifically, the tasks to be executed with high priority are executed first, and the tasks to be executed with low priority are executed after the tasks with high priority are completed or blocked. In addition, when the servo driver is executing the tasks to be executed with low priority, if a task to be executed with high priority is obtained, the execution of the low priority task can be interrupted to execute the task to be executed with high priority.
[0087] In the above embodiment, the servo drive executes tasks sequentially based on the priority of the tasks to be executed. When there are multiple tasks to be executed, important and urgent tasks are processed first, thereby improving the performance and response time of the servo drive.
[0088] In an embodiment of the present invention, executing the to-be-executed tasks according to the priorities of the to-be-executed tasks may include:
[0089] When the handshake task fails to execute, suspending the handshake task;
[0090] When the time for suspending the execution of the handshake task reaches the preset delay waiting time, the handshake task is executed again.
[0091] In some embodiments, the handshake task has the highest priority. After the handshake task is completed, the servo driver can communicate with the debugging device, and then receive and execute the operation instructions sent by the debugging device through the dedicated debugging interface.
[0092] In an embodiment of the present invention, after completing the initialization task, the servo driver first executes the handshake task and attempts to establish a communication connection with the debugging device. If the handshake task fails, the servo driver will suspend the handshake task and wait for a preset delay time before re-executing the handshake task until the handshake task is successfully executed.
[0093] In the above embodiment, after the servo driver completes the initialization task, the handshake task is executed to realize the real-time network communication between the servo driver and the dedicated debugging interface of the debugging computer. During the data transmission process between the servo driver and the dedicated debugging interface of the debugging computer, the servo driver has good real-time performance and network stability. The servo driver and the dedicated debugging interface can have real-time network communication, and the speed is improved during data transmission, and the data of the servo driver is observed in real time.
[0094] In an embodiment of the present invention, executing the to-be-executed task according to the task scheduling strategy may include:
[0095] When the priorities of the tasks to be executed are the same, obtaining the time slice length;
[0096] Determine the current task to be executed from the tasks to be executed and execute it;
[0097] When the execution time of the current task to be executed exceeds the length of the time slice, return to the step of determining the current task to be executed from the tasks to be executed and executing it.
[0098] In a specific implementation, the tasks to be executed have different priorities. The priorities indicate the importance and urgency of the tasks to be executed in the servo drive. In some application scenarios, the priorities of the tasks to be executed obtained by the servo drive may be the same or different. When the priorities of the tasks to be executed are different, the tasks to be executed may be executed according to the priorities. When the priorities of the tasks to be executed are the same, the servo drive may allocate processor resources by rotating time slices. Specifically, the servo drive divides the processor time into multiple time slices of fixed lengths. Each task to be executed is executed within a time slice. If the task to be executed fails to be completed within a time slice, the servo drive saves the status of the current task and switches to the next task to be executed so that it continues to execute within the next time slice. Exemplarily, the time slice length can be 1ms (millisecond). Assume that the servo drive obtains three tasks to be executed with the same priority, namely Task A, Task B and Task C. Task A is executed first. If Task A is not completed within 1ms, the servo drive saves the status of Task A and switches to executing Task B. If Task B is not completed within 1ms, the servo drive saves the status of Task B and switches to executing Task C. Assuming that Task C is not completed within 1ms, the servo drive saves the status of Task C and switches back to executing Task A, and so on, until Task A, Task B and Task C are all executed or stopped.
[0099] In the above embodiment, when the priorities of the tasks to be executed are the same, the servo drive can execute the tasks to be executed according to the preset time slice length, thereby fairly allocating the processor resources of the servo drive so that each task to be executed can be scheduled for execution, thereby improving the overall performance and response time of the servo drive.
[0100] In summary, the embodiment of the present invention sets the priority of tasks according to different task properties. If the tasks to be executed have different priorities, preemptive task scheduling is performed. In the task scheduling process, if a communication task (such as a handshake task) contains a delay wait, for example, after the communication connection fails, there will be a delay wait. The servo drive will switch tasks to perform other low-priority tasks to be executed. After the delay wait ends, it will switch back to the high-priority tasks to be executed. For the tasks to be executed with the same priority, such as the initialization task, time slice scheduling is performed and they are executed sequentially, so that the processor resources of the servo drive are fully utilized.
[0101] In order to enable those skilled in the art to better understand the embodiments of the present invention, specific examples are used below for illustration. Figure 3 , is a schematic diagram of a flow chart of a servo drive and a PC dedicated debugging interface communication connection completion process provided in an embodiment of the present invention,
[0102] Step 301: The servo drive is powered on and starts loading the real-time operating program (including the RTOS system plug-in); the RTOS system plug-in is started and starts scheduling tasks according to task priorities.
[0103] Step 302: Execute initialization tasks of the servo driver MCU peripherals, etc., to initialize the servo driver.
[0104] Step 303: determine whether the servo driver is initialized successfully. If not, the servo driver is initialized again.
[0105] Step 304, if the servo drive is successfully initialized, the next task (handshake task) is performed to establish a communication connection with the debugging computer, namely, a TCP three-way handshake, which is used to ensure that the debugging computer and the servo drive can communicate data normally. If the three-way handshake is successful, the communication connection is successful.
[0106] Step 305, determine whether the communication connection is successful, if not, enter the delay waiting, and return to the communication connection task after a period of time. During this process, the CPU of the servo drive can perform other tasks. If the communication connection is successful, execute step 306.
[0107] Step 306: If the MCU currently acts as a network server, responsible for processing the client's (e.g., debugging device) request and feeding back data, it will enter the delayed waiting state again, waiting for the client to send a request message. During this process, the MCU can process other tasks. If the MCU acts as a client to send a request message, it will immediately execute the sending request task.
[0108] Step 307, communicating with the servo driver;
[0109] Step 308: The PC dedicated debugging interface determines whether the communication connection is successful. If not, return to step 307 to repeat the connection; if yes, the connection is completed and step 309 is executed;
[0110] Step 309: After the connection is completed, the dedicated debugging interface can send operation instructions or receive data and other communication processes.
[0111] After the above operations, the servo drive can complete the network data communication process by connecting to the PC-side dedicated debugging interface through the network port. At the same time, due to the use of RTOS plug-ins for task switching, if the MCU receives a new request while sending data, since the sending task and the receiving task have the same priority, the MCU will perform time slice scheduling (only one task is executed for one time slice length), and then use a fixed time as a time slice length. For example, the time slice length can be 1ms, and another task is performed every 1ms, switching between the sending task and the receiving task. Since the two tasks are executed in sequence, but because the 1ms time is very short, it is impossible for the user to distinguish, so the user's perception of the task is concurrent execution, running at the same time, so there is no task to wait for the completion of the data sending task before receiving the data, which improves the real-time performance of the network communication between the servo drive and the debugging device, and the data efficiency of data sending and receiving is also improved, and the servo drive processor resource utilization is also improved.
[0112] In addition, the embodiment of the present invention proposes a task scheduling strategy for adaptive scheduling of tasks based on the preemptive and time-slice task scheduling strategies for the servo drive. Specifically, the task scheduling strategy refers to the servo drive being able to dynamically execute tasks according to the system load and task characteristics to improve the performance and response time of the servo drive. Specifically, in the servo drive, the adaptive scheduling task scheduling strategy can dynamically adjust the execution order and time slice length of tasks according to the real-time load conditions and task priorities to ensure that key tasks can be executed in a timely manner. For example, assume that the servo drive obtains three tasks to be executed in a cycle, namely task A, task B and task C, among which task A has a higher priority than task B, and task B has a higher priority than task C. First, the servo drive executes task A with the highest priority according to the priority of the task. Assume that task A is completed within 10ms. During the execution of task A, the servo drive monitors the load in real time. If it is found that the load is low, the task can be completed normally in 10ms. After task A is completed, the servo drive switches to task B with the second highest priority. Assume that task B takes 20ms to complete. However, during the execution of task B, the load of the servo drive suddenly increases. After detecting the increase in load, the servo drive dynamically adjusts the time slice length of task B to reduce its execution time to cope with the increase in load. Assume that the time slice length of task B is adjusted from 20ms to 10ms. Assume that after task B is executed within 10ms, the servo drive switches to task C with the lowest priority. Assume that task C takes 15ms to complete. During the execution of Task C, the load of the servo drive gradually returns to normal levels. After the servo drive detects the load recovery, it restores the time slice length of Task C. After Task C is completed within 15ms, the servo drive switches to execute Task A in a cycle, and so on. The servo drive continues to dynamically adjust the execution order and time slice length of tasks according to task priority and load conditions, so that the critical tasks (tasks with higher priority) of the servo drive can be executed in time, while optimizing the use of the servo drive's system resources.
[0113] In other embodiments, the embodiments of the present invention, based on the task scheduling strategies such as preemptive, time slice, and adaptive scheduling for the servo drive, also propose to adjust the execution order based on the task execution history scheduling data of the task. Specifically, the embodiments of the present invention predict the execution behavior of the task by analyzing the historical execution time, load conditions, resource usage, etc. of the tasks of the servo drive, and adjust the scheduling strategy accordingly based on this to improve the performance and response time of the servo drive. For example, assume that the servo drive obtains three tasks to be executed in a cycle, namely task A, task B and task C, among which task A has a higher priority than task B, and task B has a higher priority than task C. First, the historical execution time and historical load status data of tasks A, task B and task C are obtained to calculate the average execution time of tasks A, task B and task C, so as to analyze the historical load trend of the system and then predict future load changes and predict the future execution time of tasks A, task B and task C. Assuming that the future execution time of task A is 10ms, the average future execution time of task B is 20ms, and the future execution time of task C is 15ms, and assuming that the future load will gradually increase, the execution order and time slice length of the tasks can be dynamically adjusted according to the prediction results, so that the critical tasks (tasks with higher priority) of the servo drive can be executed in time, while optimizing the use of system resources of the servo drive.
[0114] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0115] Reference Figure 4 , shows a structural block diagram of a task execution device provided in an embodiment of the present invention, which is applied to a servo drive, the servo drive is connected to a debugging device, the servo drive is installed with a real-time operation program, and the real-time operation program is provided with a task scheduling strategy. The device may specifically include the following modules:
[0116] The to-be-executed task acquisition module 401 is used to acquire at least one to-be-executed task; wherein the to-be-executed task includes the task sent by the debugging device and the task inside the servo drive;
[0117] The pending task execution module 402 is used to execute the pending task according to the task scheduling strategy.
[0118] In one embodiment of the present invention, the to-be-executed task acquisition module 401:
[0119] When the servo drive is powered on, obtaining an initialization task of the servo drive;
[0120] The initialization task is used as a task to be executed.
[0121] In one embodiment of the present invention, the initialization task at least includes: opening the communication network port between the servo drive and the debugging device; enabling the interface chip of the servo drive, the interface chip transmitting data between the debugging device; initializing the memory space of the servo drive, the memory space being used to cache data; configuring the Ethernet protocol stack, the Ethernet protocol stack being used to transmit data packets between the debugging device.
[0122] In an embodiment of the present invention, the priorities of the initialization tasks are the same.
[0123] In one embodiment of the present invention, the device further comprises: a handshake communication module, configured to:
[0124] When the initialization task is successfully executed, obtaining a handshake task for communication connection with the debugging device as a task to be executed;
[0125] When the handshake task is successfully executed, the servo driver is communicatively connected with the debugging device, so that the servo driver receives the data message sent by the debugging device and generates a task to be executed according to the data message.
[0126] In one embodiment of the present invention, the to-be-executed task execution module 402 is used to:
[0127] Determining the priority of the task to be performed;
[0128] When the priorities of the tasks to be executed are different, the tasks to be executed are executed according to their priorities.
[0129] In one embodiment of the present invention, the to-be-executed task execution module 402 is used to:
[0130] When the handshake task fails to execute, suspending the handshake task;
[0131] When the time for suspending the execution of the handshake task reaches the preset delay waiting time, the handshake task is executed again.
[0132] In an embodiment of the present invention, the priority of the handshake task is the highest priority.
[0133] In one embodiment of the present invention, the to-be-executed task execution module 402 is used to:
[0134] When the priorities of the tasks to be executed are the same, obtaining the time slice length;
[0135] Determine the current task to be executed from the tasks to be executed and execute it;
[0136] When the execution time of the current task to be executed exceeds the length of the time slice, return to the step of determining the current task to be executed from the tasks to be executed and executing it.
[0137] In an embodiment of the present invention, a servo drive is connected to a debugging device, a real-time operating program is installed in the servo drive, a task scheduling strategy is set in the real-time operating program, and when the servo drive needs to execute a task, at least one task to be executed is obtained, wherein the task to be executed includes tasks sent by the debugging device and tasks inside the servo drive, and then the task to be executed is executed according to the task scheduling strategy. The embodiment of the present invention executes the acquired tasks based on the task scheduling strategy deployed in the servo drive, so that the task scheduling is flexible and the task execution efficiency of the servo drive is improved.
[0138] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0139] In addition, an embodiment of the present invention further provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned task execution method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0140] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above-mentioned task execution method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0141] An embodiment of the present invention also provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned task execution method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0142] Figure 5 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0143] The electronic device 500 includes but is not limited to: a radio frequency unit 501, a network module 502, an audio output unit 503, an input unit 504, a sensor 505, a display unit 506, a user input unit 507, an interface unit 508, a memory 509, a processor 510, and a power supply 511. Those skilled in the art will appreciate that Figure 5 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. In the embodiments of the present invention, the electronic device includes but is not limited to a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted terminal, a wearable device, and a pedometer.
[0144] It should be understood that in the embodiment of the present invention, the radio frequency unit 501 can be used for receiving and sending signals during information transmission or communication. Specifically, after receiving downlink data from the base station, it is sent to the processor 510 for processing; in addition, uplink data is sent to the base station. Generally, the radio frequency unit 501 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, etc. In addition, the radio frequency unit 501 can also communicate with the network and other devices through a wireless communication system.
[0145] The electronic device provides users with wireless broadband Internet access through the network module 502, such as helping users to send and receive emails, browse web pages, and access streaming media.
[0146] The audio output unit 503 can convert the audio data received by the RF unit 501 or the network module 502 or stored in the memory 509 into an audio signal and output it as sound. Moreover, the audio output unit 503 can also provide audio output related to a specific function performed by the electronic device 500 (for example, a call signal reception sound, a message reception sound, etc.). The audio output unit 503 includes a speaker, a buzzer, a receiver, etc.
[0147] The input unit 504 is used to receive audio or video signals. The input unit 504 may include a graphics processor (GPU) 5041 and a microphone 5042. The graphics processor 5041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 506. The image frame processed by the graphics processor 5041 can be stored in the memory 509 (or other storage medium) or sent via the radio frequency unit 501 or the network module 502. The microphone 5042 can receive sound and can process such sound into audio data. The processed audio data can be converted into a format output that can be sent to a mobile communication base station via the radio frequency unit 501 in the case of a telephone call mode.
[0148] The electronic device 500 also includes at least one sensor 505, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 5061 according to the brightness of the ambient light, and the proximity sensor can turn off the display panel 5061 and / or the backlight when the electronic device 500 is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; the sensor 505 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be repeated here.
[0149] The display unit 506 is used to display information input by the user or information provided to the user. The display unit 506 may include a display panel 5061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0150] The user input unit 507 can be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the electronic device. Specifically, the user input unit 507 includes a touch panel 5071 and other input devices 5072. The touch panel 5071, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 5071 or near the touch panel 5071 using any suitable object or accessory such as a finger, stylus, etc.). The touch panel 5071 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the contact point coordinates, and then sends it to the processor 510, receives the command sent by the processor 510 and executes it. In addition, the touch panel 5071 can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic waves. In addition to the touch panel 5071, the user input unit 507 may also include other input devices 5072. Specifically, other input devices 5072 may include but are not limited to a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which are not described in detail here.
[0151] Furthermore, the touch panel 5071 may be overlaid on the display panel 5061. When the touch panel 5071 detects a touch operation on or near it, it transmits the information to the processor 510 to determine the type of the touch event. Then, the processor 510 provides a corresponding visual output on the display panel 5061 according to the type of the touch event. Figure 5 In the figure, the touch panel 5071 and the display panel 5061 are used as two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 5071 and the display panel 5061 can be integrated to realize the input and output functions of the electronic device, which is not limited here.
[0152] The interface unit 508 is an interface for connecting an external device to the electronic device 500. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, etc. The interface unit 508 may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic device 500 or may be used to transmit data between the electronic device 500 and an external device.
[0153] The memory 509 can be used to store software programs and various data. The memory 509 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 509 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0154] The processor 510 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 509 and calling data stored in the memory 509, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 510 may include one or more processing units; preferably, the processor 510 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 510.
[0155] The electronic device 500 may also include a power supply 511 (such as a battery) for supplying power to each component. Preferably, the power supply 511 may be logically connected to the processor 510 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system.
[0156] In addition, the electronic device 500 includes some functional modules not shown, which will not be described in detail here.
[0157] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0158] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0159] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
[0160] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0161] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0162] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0163] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0164] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0165] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical disks.
[0166] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A task execution method, characterized in that: Applied to a servo drive, the servo drive is connected to a debugging device, the servo drive is installed with a real-time operation program, and the real-time operation program is provided with a task scheduling strategy, the method comprises: Acquire at least one task to be executed; wherein the task to be executed includes a task sent by the debugging device and a task inside the servo driver; The to-be-executed tasks are executed according to the task scheduling strategy.
2. The method according to claim 1, characterized in that: Get at least one task to be executed, including: When the servo drive is powered on, obtaining an initialization task of the servo drive; The initialization task is used as a task to be executed.
3. The method according to claim 2, characterized in that The initialization task at least includes: opening the communication network port between the servo drive and the debugging device; enabling the interface chip of the servo drive, the interface chip transmitting data between the debugging device; initializing the memory space of the servo drive, the memory space being used to cache data; configuring the Ethernet protocol stack, the Ethernet protocol stack being used to transmit data packets between the debugging device.
4. The method according to claim 3, characterized in that The priorities of the initialization tasks are the same.
5. The method according to claim 2, characterized in that: The method further comprises: When the initialization task is successfully executed, obtaining a handshake task for communication connection with the debugging device as a task to be executed; When the handshake task is successfully executed, the servo driver is communicatively connected with the debugging device, so that the servo driver receives the data message sent by the debugging device and generates a task to be executed according to the data message.
6. The method according to claim 1, characterized in that Executing the to-be-executed task according to the task scheduling strategy includes: Determining the priority of the task to be performed; When the priorities of the tasks to be executed are different, the tasks to be executed are executed according to their priorities.
7. The method according to claim 6, characterized in that Executing the tasks to be executed according to their priorities includes: When the handshake task fails to execute, suspending the handshake task; When the time for suspending the execution of the handshake task reaches the preset delay waiting time, the handshake task is executed again.
8. The method according to claim 7, characterized in that The priority of the handshake task is the highest priority.
9. The method according to claim 6, characterized in that Executing the to-be-executed task according to the task scheduling strategy includes: When the priorities of the tasks to be executed are the same, obtaining the time slice length; Determine the current task to be executed from the tasks to be executed and execute it; When the execution time of the current task to be executed exceeds the length of the time slice, return to the step of determining the current task to be executed from the tasks to be executed and executing it.
10. A task execution device, characterized in that: Applied to a servo drive, the servo drive is connected to a debugging device, the servo drive is installed with a real-time operation program, and the real-time operation program is provided with a task scheduling strategy, the device comprises: A task acquisition module to be executed, used to acquire at least one task to be executed; wherein the task to be executed includes a task sent by the debugging device and a task inside the servo driver; The to-be-executed task execution module is used to execute the to-be-executed task according to the task scheduling strategy.
11. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the method according to any one of claims 1 to 9 when executing the program stored in the memory.
12. A computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 9.
Citation Information
Cited By
OpenHarmony-based task scheduling method with earliest deadline priority
CN120973486A