Computing task execution method and system for ROS system
Through deep learning, determine the task type and intelligently apply for register space, and formulate a switching strategy based on task type and thread occupation time, solving the problem of low execution efficiency of multi-threaded multi-tasks in ROS systems, improving resource utilization and execution efficiency.
Patent Information
- Application Number
- CN202411654833.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-03-28
AI Technical Summary
In the application environment of ROS system, the execution efficiency of multi-threading and multi-tasks is limited, mainly due to the low efficiency of process context switching of computing tasks, resulting in unreasonable resource consumption and large task switching delay.
Determine the task type through deep learning and intelligently apply for register space according to the task type to avoid unnecessary resource consumption. At the same time, different switching strategies are formulated according to the task type and thread occupation time, including vector delivery and context backup, to ensure the efficiency and smoothness of task switching.
It improves the utilization rate and execution efficiency of system resources, reduces resource waste and delays during task switching, enhances the flexibility and adaptability of the system, and adapts to the execution needs of different types of tasks.
Smart Images

Figure CN119718563A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of operating system management, and in particular to a computing task execution method and system for a ROS system. Background Art
[0002] In the field of robot development, compared with the hardware of robots, algorithms, large models and other software, especially the robot operating system, namely ROS (Robot Operating System), are the shortcomings that hinder the development of intelligent robots. ROS (Robot Operating System) is a computer operating system architecture designed specifically for robot software development. It is an open source meta-level operating system that provides services similar to operating systems, including hardware abstract description, underlying driver management, execution of shared functions, inter-program message passing, and program distribution package management. It also provides some tools and libraries for acquiring, building, writing and executing multi-machine fusion programs.
[0003] The application environment of robots is complex, changeable and extremely harsh. In such circumstances, robots have to undertake multi-task real-time work, which puts higher-level requirements on the robot's hardware and software, especially the real-time and stability of the robot's operating system.
[0004] The process context switch of computing tasks refers to switching from one process to another process, while the same process is always running during the system call process. In fact, the CPU context switch is unavoidable during the system call process, so in the application environment of the ROS system, the execution efficiency of multi-threading and multi-tasking is limited. Summary of the invention
[0005] The present invention provides a computing task execution method and system for a ROS system, so as to solve the defects of the prior art.
[0006] A first aspect of the present invention provides a computing task execution method for a ROS system, comprising:
[0007] S1: receiving a task to be executed, and performing deep learning on the task to be executed to obtain a task type;
[0008] S2: Apply for register space according to the task type;
[0009] S3: Calculate the thread occupancy time of the task to be executed occupying the register space;
[0010] S4: Based on the task type, multiple tasks to be executed are switched through the register space according to the thread occupancy time.
[0011] According to a computing task execution method for a ROS system provided by the present invention, the task types in step S1 include common tasks and vector tasks.
[0012] According to a computing task execution method for a ROS system provided by the present invention, step S2 specifically includes:
[0013] When the task type is a common task, no register space is requested from the CPU;
[0014] When the task type is a vector task, register space is requested from the CPU.
[0015] According to a computing task execution method for a ROS system provided by the present invention, the expression of the thread occupancy time in step S3 is:
[0016]
[0017] Wherein, T is the calculated thread occupancy time, L(P,K) is the total time slice, N is the total number of tasks to be executed, h is the basic occupancy time for executing a single task, P is the total number of processes to be executed, and K is the number of processes to be executed for the task to be executed.
[0018] According to a computing task execution method for a ROS system provided by the present invention, step S4 further comprises:
[0019] S41: acquiring a first task type of a preceding task and a second task type of a succeeding task according to the task type;
[0020] S42: Obtain a switching strategy according to the first task type and the second task type;
[0021] S43: Switch and execute the subsequent task through the register space according to the switching strategy and the total time occupied by the thread, wherein the execution task in the register space at the same time is unique.
[0022] According to a computing task execution method for a ROS system provided by the present invention, the switching strategy in step S42 specifically includes:
[0023] When the first task type is a vector task and the second task type is a common task, the vector of the previous task is transferred to the next task;
[0024] When the first task type is a vector task and the second task type is a vector task, the vector of the previous task is transferred to the next task, and the context information of the previous task is backed up;
[0025] When the first task type is a common task and the second task type is a vector task, the vector of the previous task is transferred to the next task, and the context information of the previous task is backed up;
[0026] When the first task type is a common task and the second task type is a common task, the context information of the previous task is backed up.
[0027] According to a computing task execution method for a ROS system provided by the present invention, step S43 further includes:
[0028] S431: when a task is switched, the variable information of the previous task is backed up according to the total time occupied by the thread;
[0029] S432: copy the state of the register space of the subsequent task to the current register space of the CPU;
[0030] S433: Execute the subsequent task through the current register space.
[0031] A second aspect of the present invention provides a computing task execution system for a ROS system, comprising:
[0032] A judgment module is used to receive a task to be executed, and is also used to perform deep learning on the task to be executed to obtain a task type;
[0033] An application module, used for applying for register space according to the task type;
[0034] A calculation module, used for calculating the thread occupancy time of the task to be executed occupying the register space;
[0035] A switching module is used to switch and execute a plurality of tasks to be executed through the register space based on the task type and the thread occupancy time.
[0036] A third aspect of the present invention provides a computing task execution device for a ROS system, comprising:
[0037] A memory and at least one processor, wherein instructions are stored in the memory;
[0038] The processor calls the instruction in the memory to enable the computing task execution device for the ROS system to execute the computing task execution method for the ROS system as described in any one of the above items.
[0039] A fourth aspect of the present invention provides a computer-readable storage medium having instructions stored thereon, and when the instructions are executed by a processor, a computing task execution method for a ROS system as described in any one of the above items is implemented.
[0040] The present invention provides a computing task execution method and system for ROS system, which determines the task type through deep learning, and intelligently applies for register space according to the task type, thereby avoiding unnecessary resource consumption. For vector tasks that require more computing resources, the application is made, and the differentiated management implemented effectively improves the utilization rate and execution efficiency of system resources. In addition, the present invention provides a refined task switching execution method according to the task type and thread occupancy time. The present invention calculates the thread occupancy time and combines the types of the previous task and the next task to formulate different switching strategies, including vector transfer, context backup, etc., to ensure the efficiency and smoothness of task switching and reduce The method of the present invention allows only one task to be executed in the register space at the same time, avoiding resource conflicts and errors that may be caused by the concurrent execution of multiple tasks. At the same time, the switching strategy is flexibly adjusted according to the different task types, so that the system can adapt to the execution requirements of different types of tasks, thereby enhancing the flexibility and adaptability of the system. Secondly, by identifying the obtained task type and performing resource allocation and task switching based on the task type, it is easy to expand and maintain. With the development of the ROS system and the introduction of new tasks, the new task type can be identified and the resource allocation and switching strategy can be adjusted accordingly, so that the system can continue to maintain high efficiency and stability.
[0041] The present invention provides a computing task execution method and system for a ROS system. In the kernel layer of ROS, a multi-process scheduling idea based on a context switching algorithm is added. The idea is to save the context information of the CPU core that executes the previous task, then load the context counter and register of the next task, and finally jump to the new address space specified by the counter execution program to run the next new task. The introduced context switching algorithm greatly improves the switching efficiency of multi-threads and multi-tasks, clarifies the switching relationship between thread tasks, and improves the multi-task execution efficiency of robots operating in different occasions. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0043] Figure 1 A flowchart of a method for executing a computing task in a ROS system provided by an embodiment of the present invention;
[0044] Figure 2A schematic diagram of the structure of a computing task execution system for a ROS system provided by an embodiment of the present invention;
[0045] Figure 3 A schematic diagram of the architecture of a ROS system based on the computing task execution method for a ROS system of the present invention provided in an embodiment of the present invention;
[0046] Figure 4 A schematic diagram comparing the allocation efficiency of the computing task execution method for the ROS system provided by the embodiment of the present invention.
[0047] Reference numerals:
[0048] 100, judgment module; 200, calculation module; 300, application module; 400, switching module. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings in the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments, and they should not be understood as limitations on the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. In the description of the present invention, it should be understood that the terms used are only for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0050] In order to better understand the present invention, the background of the present invention is first explained in detail below.
[0051] In the era of intelligence, a large amount of practice has proved that industrial robots are widely used in modern production due to their advantages such as high work efficiency, high production quality and good environmental adaptability.
[0052] In the field of robot development, compared with the hardware of robots, algorithms, large models and other software, especially the robot operating system, namely ROS (Robot Operating System), are the shortcomings of my country's intelligent robot development. ROS (Robot Operating System) is a computer operating system architecture designed specifically for robot software development. It is an open source meta-level operating system that provides services similar to operating systems, including hardware abstract description, underlying driver management, execution of shared functions, inter-program message passing, and program distribution package management. It also provides some tools and libraries for acquiring, building, writing and executing multi-machine fusion programs.
[0053] The research and development of traditional robot operating systems is based on the STM32 hardware platform and is developed on the μCOSⅡ system. μCOSⅡ is a priority-based preemptive multi-task real-time operating system that includes real-time kernel, task management, time management, inter-task communication synchronization (semaphore, mailbox, message queue) and memory management functions. μCOSⅡ is a portable, curable and customizable system that is suitable for a variety of microprocessors, controllers and digital processing chips. At the same time, the system source code is open, neat, consistent, and well-annotated, making it suitable for system development.
[0054] Although μCOSⅡ is an open source operating system that is portable, curable, and customizable, and is suitable for a variety of microprocessors; however, the multi-task switching time of the μCOSⅡ system is relatively long, especially the real-time performance of semaphore shuffling is relatively poor, which makes it unsuitable for applications that perform multiple tasks in large-scale complex motion scenarios. Therefore, based on the poor real-time performance of semaphore shuffling of the μCOSⅡ operating system, a lightweight ROS system of the EMBED version was developed.
[0055] Usually, the process context switch of a computing task refers to switching from one process to another, while the same process is always running during the system call process. Therefore, the system call process is usually called a privileged mode switch, not a context switch. But in fact, the context switch of the CPU is still unavoidable during the system call process. However, the so-called task call in the kernel is actually a thread. The biggest difference between a thread and a process is that a thread is the basic unit of scheduling, while a process is the basic unit of resource ownership; a process only provides resources such as virtual memory and global variables to a thread. When a process has multiple threads, these threads will share the same virtual memory and global variables and other resources, which results in the poor real-time performance of each process during the switching process.
[0056] Combine the following Figure 1 and Figure 3 Embodiments of the present invention are described.
[0057] like Figure 1 As shown, the first aspect of the present invention provides a computing task execution method for a ROS system, comprising:
[0058] S1: Receive a task to be executed, and perform deep learning on the task to be executed to obtain a task type.
[0059] In step S1, first use the labeled data set for training and input the task data into the model: input the task data into the deep learning model, let the model classify the tasks, that is, the probability or label of whether the task output by the model belongs to a common task or a vector task, that is, the above-mentioned task type, after determining the task type, the corresponding CPU core resources can be allocated according to the characteristics of the task.
[0060] The task types in step S1 include common tasks and vector tasks.
[0061] Furthermore, robots that perform tasks in complex application scenarios need to perform tasks that are divided into ordinary tasks and vector tasks. Ordinary tasks only involve information collection and some simple programmatic processing of the collected information. There are fewer variables and algorithms involved in the execution program, so the CPU core resources occupied are relatively small, and will not affect the real-time efficiency of the robot's task execution; and vector tasks are actually a nonlinear, high-order, strongly coupled multivariable control system. Due to the complexity of the control system, the amount of calculation involved is relatively large, so the CPU core resources required are also relatively large.
[0062] S2: Apply for register space according to the task type.
[0063] Wherein, step S2 specifically includes:
[0064] When the task type is a common task, no register space is requested from the CPU;
[0065] When the task type is a vector task, register space is requested from the CPU.
[0066] Furthermore, in step S1, if the task type is determined to be a vector task, the register space of the vector context is immediately requested from the CPU, and the requested space is then recorded in the vector context of the task control block; otherwise, the vector context in the task control block is set to empty.
[0067] S3: Calculate the thread occupancy time of the register space occupied by the task to be executed.
[0068] The expression of the thread occupancy time in step S3 is:
[0069]
[0070] Wherein, T is the calculated thread occupancy time, L(P,K) is the total time slice, N is the total number of tasks to be executed, h is the basic occupancy time for executing a single task, P is the total number of processes to be executed, and K is the number of processes to be executed for the task to be executed.
[0071] The total thread time refers to the total CPU computing time that the thread of the executed task takes up. Therefore, the allocation of the total thread time is synchronized with the total number of thread executions. Time slices must be allocated at the appropriate time per process, and then the total thread time is evenly divided among the sub-threads.
[0072] The process first obtains the total time occupied by the thread. The total time is calculated based on the total number of processes to be executed by the task K and the total number of processes to be executed P, and then allocated to the processes to be executed. Assume that the basic time occupied by the system is h, and the total time slice is L(P,K), that is, the total time increases with the increase of P and K, that is, it indicates the total number of time slices allocated by the system for all tasks under the given P (total number of processes) and K (actual number of processes executed). According to the given formula, L(P,K) is related to the values of P and K, and increases as they increase.
[0073] From the calculation formula of L(P,K), we can see that N is the total number of computing tasks. The larger the value of P, the larger the value of N. When P is a constant value, the changes of L and N are proportional and linear. Therefore, the time T that each task to be calculated is reasonably allocated is calculated as shown above.
[0074] S4: Based on the task type, multiple tasks to be executed are switched through the register space according to the thread occupancy time.
[0075] Step S4 further comprises:
[0076] S41: According to the task type, a first task type of a preceding task and a second task type of a succeeding task are acquired.
[0077] S42: Obtain a switching strategy according to the first task type and the second task type.
[0078] When processes switch between each other, the categories of the previous task and the next task are determined. The combination categories include: vector task to ordinary task, vector task to vector task, ordinary task to ordinary task, and ordinary task to vector task. Then, the following switching strategies can be used to quickly switch between the processes.
[0079] The switching strategy in step S42 specifically includes:
[0080] When the first task type is a vector task and the second task type is a common task, the vector of the previous task is transferred to the next task;
[0081] When the first task type is a vector task and the second task type is a vector task, the vector of the previous task is transferred to the next task, and the context information of the previous task is backed up;
[0082] When the first task type is a common task and the second task type is a vector task, the vector of the previous task is transferred to the next task, and the context information of the previous task is backed up;
[0083] When the first task type is a common task and the second task type is a common task, the context information of the previous task is backed up.
[0084] S43: Switch and execute the subsequent task through the register space according to the switching strategy and the total time occupied by the thread, wherein the execution task in the register space at the same time is unique.
[0085] Wherein, step S43 further comprises:
[0086] S431: When the task is switched, the variable information of the previous task is backed up according to the total time occupied by the thread.
[0087] S432: Copy the state of the register space of the subsequent task to the current register space of the CPU.
[0088] S433: Execute the subsequent task through the current register space.
[0089] The principle of context switching of the executed task process is that when the controller issues a process switching instruction, it needs to save the registers and variable signals of the previous task to the memory, and copy the state of the registers of the next task process to be switched to the current working CPU registers so that it can continue to execute commands. Only one task is allowed to have exclusive use of the registers at the same time. The task switching process involves the saving and restoring operations of the task context.
[0090] like Figure 2 As shown, the present invention also provides a computing task execution system for a ROS system, comprising:
[0091] A judgment module is used to receive a task to be executed, and is also used to perform deep learning on the task to be executed to obtain a task type;
[0092] An application module, used for applying for register space according to the task type;
[0093] A calculation module, used for calculating the thread occupancy time of the task to be executed occupying the register space;
[0094] A switching module is used to switch and execute a plurality of tasks to be executed through the register space based on the task type and the thread occupancy time.
[0095] The present invention also provides a computing task execution device for a ROS system, comprising:
[0096] A memory and at least one processor, wherein instructions are stored in the memory;
[0097] The processor calls the instruction in the memory to enable the computing task execution device for the ROS system to execute the computing task execution method for the ROS system as described in any one of the above items.
[0098] The present invention also provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed by a processor, the computing task execution method for a ROS system as described in any one of the above items is implemented.
[0099] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0100] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0101] like Figure 3 As shown, the diagram shows a specific implementation architecture of a computing task execution method, system, device and storage medium for a ROS system provided by the present invention.
[0102] The ROS2 software stack is the top layer of the architecture, which includes the core functions and features of ROS2, and provides APIs and tools so that developers can easily build, deploy and manage robot applications. Under the ROS2 software stack, the ROS2 application package is a layer of multiple parallel ROS2 application packages, which is the basic component unit of the ROS2 system, and specifically includes code, configuration files and dependencies for implementing specific functions. The ROS2 C language API provides the C language interface of ROS2, allowing developers to use C language to write and integrate robot applications. rmw is the ROS2 middleware interface, which abstracts the underlying communication mechanism and provides a unified communication interface for upper-level applications, which can achieve interoperability between different communication protocols. In addition, it also provides a lightweight DDS (Data Distribution Service) client for efficient communication in resource-constrained environments. By interacting with the DDS communication layer, data distribution and subscription are realized; and DDS distributed communication middleware provides data distribution, discovery, subscription and other functions. The middle layer is located between DDS communication and PCIE high-speed interface to ensure smooth communication between different levels. The PCIE interface provides high-speed data transmission capability, which helps to achieve real-time and low-latency communication requirements. Based on the computing task execution method for ROS system of the present invention, the present invention also provides EMBED version of ROS, which is a ROS version optimized for embedded systems and provides features and functions suitable for embedded devices, including a kernel responsible for key functions such as task scheduling, resource management, and interrupt processing. In the described architecture, the kernel supports the execution of concurrent tasks through the multi-threaded scheduling based on the context switching algorithm of the present invention. Ubuntu is an operating system platform for running the kernel and ROS2 system. It also includes a Loongson 2K hardware platform using a multi-core Loongson processor and supports multi-core parallel processing, which helps to improve the computing power and response speed of the system.
[0103] like Figure 4 As shown, the diagram is a schematic diagram of the allocation efficiency comparison between different allocation algorithms, the x-axis of the diagram represents the total number of multi-threaded tasks, the y-axis represents the running time of the process or thread, the dotted line represents the time allocation under the traditional algorithm, and the solid line represents the time allocation under the improved algorithm of the present invention.
[0104] from Figure 4 It can be seen that as the number of multi-threaded tasks increases, the process or thread running time under the traditional algorithm will also increase rapidly, which will lead to excessive occupation of system resources and reduced task execution efficiency. In contrast, the curve of the improved algorithm of the present invention is relatively gentle. This shows that even when the number of multi-threaded tasks is large, the improved algorithm can maintain a relatively stable process or thread running time, optimize the utilization of system resources, and improve the efficiency of task execution.
[0105] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A computing task execution method for a ROS system, characterized in that: include: S1: receiving a task to be executed, and performing deep learning on the task to be executed to obtain a task type; S2: Apply for register space according to the task type; S3: Calculate the thread occupancy time of the task to be executed occupying the register space; S4: Based on the task type, multiple tasks to be executed are switched through the register space according to the thread occupancy time.
2. A computing task execution method for a ROS system according to claim 1, characterized in that: The task types in step S1 include common tasks and vector tasks.
3. A computing task execution method for a ROS system according to claim 2, characterized in that: Step S2 specifically includes: When the task type is a common task, no register space is requested from the CPU; When the task type is a vector task, register space is requested from the CPU.
4. A computing task execution method for a ROS system according to claim 1, characterized in that: The expression of the thread occupancy time in step S3 is: Wherein, T is the calculated thread occupancy time, L(P,K) is the total time slice, N is the total number of tasks to be executed, h is the basic occupancy time for executing a single task, P is the total number of processes to be executed, and K is the number of processes to be executed for the task to be executed.
5. A computing task execution method for a ROS system according to claim 1, characterized in that: Step S4 further comprises: S41: acquiring a first task type of a preceding task and a second task type of a succeeding task according to the task type; S42: Obtain a switching strategy according to the first task type and the second task type; S43: Switch and execute the subsequent task through the register space according to the switching strategy and the total time occupied by the thread, wherein the execution task in the register space at the same time is unique.
6. A computing task execution method for a ROS system according to claim 5, characterized in that: The switching strategy in step S42 specifically includes: When the first task type is a vector task and the second task type is a common task, the vector of the previous task is transferred to the next task; When the first task type is a vector task and the second task type is a vector task, the vector of the previous task is transferred to the next task, and the context information of the previous task is backed up; When the first task type is a common task and the second task type is a vector task, the vector of the previous task is transferred to the next task, and the context information of the previous task is backed up; When the first task type is a common task and the second task type is a common task, the context information of the previous task is backed up.
7. A computing task execution method for a ROS system according to claim 5, characterized in that: Step S43 further includes: S431: when a task is switched, the variable information of the previous task is backed up according to the total time occupied by the thread; S432: copy the state of the register space of the subsequent task to the current register space of the CPU; S433: Execute the subsequent task through the current register space.
8. A computing task execution system for a ROS system, characterized in that: include: A judgment module is used to receive a task to be executed, and is also used to perform deep learning on the task to be executed to obtain a task type; An application module, used for applying for register space according to the task type; A calculation module, used for calculating the thread occupancy time of the task to be executed occupying the register space; A switching module is used to switch and execute a plurality of tasks to be executed through the register space based on the task type and the thread occupancy time.
9. A computing task execution device for a ROS system, characterized in that: include: A memory and at least one processor, wherein instructions are stored in the memory; The processor calls the instruction in the memory to enable the computing task execution device for the ROS system to execute the computing task execution method for the ROS system according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed by the processor, the computing task execution method for the ROS system according to any one of claims 1 to 7 is implemented.