Execution scheduling method of robot operating system and related device
By calculating the longest path and new priority of each ROS2 node in the intelligent automobile operating system and determining the execution order, the problem of insufficient real-time and certainty under the ROS2 framework is solved, and efficient task execution and security improvement are achieved.
Patent Information
- Application Number
- CN202510184141.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-19
- Publication Date
- 2025-05-30
AI Technical Summary
When smart car operating systems process large amounts of sensor data, there are problems of insufficient real-time and certainty. Especially under the ROS2 framework, end-to-end certainty is difficult to guarantee and there are security risks.
By obtaining node information of each ROS2 node, the total execution time of the longest path from each node to the end point is calculated, and a new priority is calculated based on the preset priority and execution time, and the execution order of each node is determined to achieve efficient cross-process coordination and end-to-end real-time and determinism.
It realizes efficient real-time and certainty of the intelligent automotive operating system when processing sensor data, maximizes task execution efficiency and reduces security risks.
Smart Images

Figure CN120066723A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of vehicles, and particularly to an execution scheduling method and related device for a robot operating system. Background Art
[0002] With the development of intelligent vehicles, the real-time performance of vehicle operating systems has become an increasingly prominent important factor. In the past, vehicles mainly relied on mechanical and electrical systems, but with the improvement of advanced technology integration and automation levels, vehicle operating systems have gradually evolved into highly complex software and hardware integration systems. This transformation has made the demand for real-time performance particularly urgent. Intelligent vehicle operating systems need to process a large amount of sensor data in real time, including information from various sensors such as radar, cameras, lidar, etc. These data need to be accurately collected, analyzed, and applied within milliseconds to ensure that the vehicle can respond in a timely manner and adapt to complex and changing road conditions and traffic environments. At the same time, intelligent vehicles not only need to perceive the surrounding environment in real time but also need to immediately respond to the driver's instructions and various control signals within the system. This places higher requirements on the real-time performance of vehicle operating systems, requiring the system to be able to execute tasks quickly and reliably in various situations to ensure the safety and performance of the vehicle. Currently, many manufacturers choose ROS2 as the development framework for intelligent vehicles, but at present, ROS2 cannot guarantee good end-to-end determinacy and there are certain security risks. Summary of the Invention
[0003] In view of the above problems, the present invention provides an execution scheduling method and related device for a robot operating system that overcomes or at least partially solves the above problems.
[0004] In a first aspect, an execution scheduling method for a robot operating system includes:
[0005] Obtaining node information of each ROS2 node, where the node information includes execution time, subscription and publication information, and a preset priority;
[0006] Calculating the total execution time of the longest path from each ROS2 node to the end point according to the execution time and subscription and publication information of each ROS2 node, where the longest path is the path that takes the longest time for the ROS2 node to execute to the end point;
[0007] For any node, calculating a new priority of the ROS2 node according to the preset priority and execution time of the ROS2 node;
[0008] Determining the execution order of each ROS2 node according to the total execution time and new priority corresponding to each ROS2 node.
[0009] Optionally, in some alternative embodiments, obtaining the node information of each ROS2 node includes:
[0010] Obtaining the node information of each of the ROS2 nodes through a server, where the server is established based on a socket, and each of the ROS2 nodes creates a client using the socket during initialization and sends the node information of the ROS2 node to the server through the client.
[0011] Optionally, in some alternative embodiments, calculating the total execution time of the longest path from each of the ROS2 nodes to the end point according to the execution time and subscription / publishing information of each of the ROS2 nodes includes:
[0012] For any one of the ROS2 nodes, determine each path from the ROS2 node to the end point according to the subscription / publishing information of the ROS2 node;
[0013] Calculate the total execution time of the longest path according to the execution time of each ROS2 node on each of the paths.
[0014] Optionally, in some alternative embodiments, for any one of the ROS2 nodes, determining each path from the ROS2 node to the end point according to the subscription / publishing information of the ROS2 node includes:
[0015] If there is only one end point in the system itself, for any one of the ROS2 nodes, determine the next-level ROS2 node of the ROS2 node according to the subscription / publishing information of the ROS2 node and determine the next-next-level ROS2 node of the ROS2 node according to the subscription / publishing information of the next-level ROS2 node, and so on in a loop until each path from the ROS2 node to the end point is determined;
[0016] If there are multiple end points in the system itself, create a new end point and connect the new end point to each of the multiple end points existing in the system respectively. According to the subscription / publishing information of the ROS2 node, determine the next-level ROS2 node of the ROS2 node and determine the next-next-level ROS2 node of the ROS2 node according to the subscription / publishing information of the next-level ROS2 node, and so on in a loop until each path from the ROS2 node to the new end point is determined, where the execution time of the new end point is set to 0.
[0017] Optionally, in some alternative embodiments, calculating the total execution time of the longest path according to the execution time of each ROS2 node on each of the paths includes:
[0018] Using the SPFA algorithm, calculate the total execution time of each path based on the execution time of each ROS2 node on each of the paths;
[0019] Determine the total execution time of the longest path from the total execution times of each of the paths, where the path with the absolutely largest execution time is the longest path.
[0020] Optionally, in some alternative embodiments, for any node, calculating the new priority of the ROS2 node according to the preset priority and execution time of the ROS2 node includes:
[0021] For any node, calculate the sum of the preset priority of the ROS2 node and the largest preset priority among the next-level nodes to obtain the new priority of the ROS2 node.
[0022] Optionally, in some alternative embodiments, determining the execution order of each of the ROS2 nodes according to the total execution time and new priority corresponding to each of the ROS2 nodes includes:
[0023] For any of the ROS2 nodes, calculate the first product of the total execution time of the ROS2 node and a preset time coefficient;
[0024] Calculate the second product of the new priority of the ROS2 node and a preset priority coefficient;
[0025] Calculate the sum of the first product and the second product to obtain the influence factor of the ROS2 node;
[0026] Determine the execution order of each of the ROS2 nodes according to the influence factors of each of the ROS2 nodes.
[0027] Optionally, in some alternative embodiments, after determining the execution order of each of the ROS2 nodes according to the total execution time and new priority corresponding to each of the ROS2 nodes, the method further includes:
[0028] For any of the ROS2 nodes other than the start node, if the ROS2 node does not receive the first signal from the upper-level ROS2 node within the first time range, then the ROS2 node sets the value of the first signal to the previous value or the ROS2 node ignores the first signal and processes other signals;
[0029] If the ROS2 node does not receive the first signal from the upper-level ROS2 node for more than the first time range, then terminate the system operation and report an error, where the second time length is greater than the first time range.
[0030] In a second aspect, an execution scheduling device for a robot operating system includes: a node information acquisition unit, a total time calculation unit, a priority calculation unit, and an execution order determination unit;
[0031] The node information acquisition unit is configured to acquire the node information of each ROS2 node, where the node information includes an execution time, subscription and publication information, and a preset priority;
[0032] The total time calculation unit is configured to calculate the total execution time of the longest path from each ROS2 node to the end point according to the execution time and subscription and publication information of each ROS2 node, where the longest path is the path that takes the longest time for the ROS2 node to execute to the end point;
[0033] The priority calculation unit is configured to calculate a new priority of any ROS2 node according to the preset priority and execution time of the ROS2 node;
[0034] The execution order determination unit is configured to determine the execution order of each ROS2 node according to the total execution time and the new priority corresponding to each ROS2 node.
[0035] In a third aspect, an electronic device includes at least one processor, at least one memory connected to the processor, and a bus; wherein, the processor and the memory communicate with each other through the bus; the processor is configured to call program instructions in the memory to execute the execution scheduling method of the robot operating system described in any one of the above.
[0036] By means of the above technical solutions, an execution scheduling method and related device for a robot operating system provided by the present invention can acquire the node information of each ROS2 node, where the node information includes an execution time, subscription and publication information, and a preset priority; calculate the total execution time of the longest path from each ROS2 node to the end point according to the execution time and subscription and publication information of each ROS2 node, where the longest path is the path that takes the longest time for the ROS2 node to execute to the end point; calculate a new priority of any ROS2 node according to the preset priority and execution time of the ROS2 node; determine the execution order of each ROS2 node according to the total execution time and the new priority corresponding to each ROS2 node. It can be seen from this that the present invention can identify the longest path and the new priority based on the node information of the ROS2 node, and then plan a determined execution order based on the longest path and the new priority. The determined execution order can not only maximize the task execution efficiency, but also has very clear certainty and will not cause confusion in multiple orders.
[0037] The above description is only an overview of the technical solution of the present invention. In order to understand the technical means of the present invention more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable, the specific embodiments of the present invention are hereinafter specifically exemplified. Description of the Drawings
[0038] By reading the following detailed description of the preferred embodiments, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered to be a limitation of the present invention. Moreover, throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:
[0039] Figure 1 A flowchart showing an execution scheduling method of a robot operating system provided by the present invention is shown;
[0040] Figure 2 The first ROS2 node graph provided by the present invention is shown;
[0041] Figure 3 A schematic diagram showing a scheduling path provided by the present invention is shown;
[0042] Figure 4 The second ROS2 node graph provided by the present invention is shown;
[0043] Figure 5 A schematic structural diagram of an execution scheduling device of a robot operating system provided by the present invention is shown;
[0044] Figure 6 A schematic structural diagram of an electronic device provided by the present invention is shown. Detailed Embodiments
[0045] With the development of intelligent vehicles, the real-time performance of vehicle operating systems has become an increasingly prominent important factor. In the past, vehicles mainly relied on mechanical and electrical systems. However, with the integration of advanced technologies and the improvement of automation levels, vehicle operating systems have gradually evolved into highly complex software and hardware integration systems. This transformation has made the demand for real-time performance particularly urgent. Intelligent vehicle operating systems need to process a large amount of sensor data in real time, including information from various sensors such as radar, cameras, lidar, etc. This data needs to be accurately collected, analyzed, and applied within milliseconds to ensure that the vehicle can respond in a timely manner and adapt to complex and changing road conditions and traffic environments. At the same time, intelligent vehicles not only need to perceive the surrounding environment in real time but also need to immediately respond to the driver's instructions and various control signals within the system. This places higher requirements on the real-time performance of vehicle operating systems, requiring the system to be able to execute tasks quickly and reliably in various situations to ensure the safety and performance of the vehicle. Currently, many manufacturers choose ROS2 as the development framework for intelligent vehicles, but currently, ROS2 cannot guarantee good end-to-end determinism and there are certain security risks.
[0046] To solve this problem, the present invention provides an execution scheduling method and related device for ROS2 based on data flow, which realizes efficient cross-process coordination within the ROS2 framework and ensures end-to-end real-time performance and determinism during the system execution process. The present invention designs a control system by establishing inter-process socket communication and designs a scheduling strategy using the idea of the longest path based on task priorities and task execution times to ensure the determinism of real-time task execution times.
[0047] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present invention can be more thoroughly understood and the scope of the present invention can be completely conveyed to those skilled in the art.
[0048] As Figure 1 described, the present invention provides an execution scheduling method for a robot operating system, including: S100, S200, S300, and S400;
[0049] S100, obtaining the node information of each ROS2 node, where the node information includes execution time, subscription and publication information, and a preset priority;
[0050] Optionally, ROS2 refers to Robot Operating System 2. ROS2 is a flexible and distributed robot operating system designed to provide higher performance, stronger real-time capabilities, better security, and better portability. Compared with ROS1, ROS2 introduces a more flexible distributed architecture and advanced communication middleware, making ROS2 the development framework of intelligent vehicle operating systems chosen by many manufacturers.
[0051] ROS2 Nodes: Various resources in ROS2 are also connected together through a computational graph. The computational graph is a network composed of various ROS2 elements that jointly complete data transmission. Each module that performs a specific function is called a "node". Each node in ROS should be responsible for a single module purpose (for example, one node is used to control the wheel motor, and one node is used to control the laser rangefinder, etc.). Nodes communicate with each other through topics, services, actions, or parameters to achieve data transmission and reception.
[0052] The scheduling of data streams refers to the effective management and scheduling of the data streams generated, transmitted, and processed in the system to ensure that data flows in the system according to certain rules and priorities. In vehicle operating systems, data stream scheduling is particularly important because vehicle systems involve multiple sensors, actuators, and control units that need to work together to achieve various functions, such as environmental perception, decision-making, and control.
[0053] End-to-End Determinism: It means that the entire process of a system or process from one endpoint to another is predictable and deterministic. In computer science and engineering, this concept is usually related to the stability, reliability of the system, as well as the consistency and predictability of the output. In the field of intelligent vehicles or autonomous driving, end-to-end determinism is a key concept because these systems need to make highly autonomous decisions and controls in complex traffic environments. End-to-end determinism helps improve the reliability of the system and reduce the risk of accidents.
[0054] Optionally, there are multiple ROS2 nodes in the ROS2 system. Generally, there is a start node, at least one end node, and at least one intermediate node. Adjacent nodes can transmit data (subscribe to data and publish data). For example, as Figure 2 shown, the circles represent different nodes ( Figure 2The corresponding ones are Node 1 to Node 8), the straight lines represent the subscription and publication relationships, and there are two numbers beside the circles. The first number represents the execution time required for the current node task, and the second number represents the priority of the node task. The larger the number, the higher the priority (for example, the number "100.10" beside Node 1 indicates that the execution time required for Node 1 to execute the current node task is 100 milliseconds and the priority is 10). The timer of Node 1 represents that this is a task triggered by a timer.
[0055] Optionally, as described above, the execution time reflects the execution time required for the current node to execute the current node task; the subscription and publication information characterizes the superior-subordinate relationship between the current node and other nodes, that is, which superior nodes and which subordinate nodes the current node has; the preset priority reflects the priority assigned when the current node task is assigned to the current node. The present invention places no restrictions on this.
[0056] Optionally, the present invention can set up a control system within the ROS2 framework to collect the node information of ROS2 nodes. The present invention places no restrictions on this.
[0057] For example, in some alternative embodiments, the S100 includes: Step 1.1;
[0058] Step 1.1, obtaining the node information of each of the ROS2 nodes through a server, where the server is established based on a socket, and each of the ROS2 nodes uses the socket to establish a client when initializing and sends the node information of the ROS2 node to the server through the client.
[0059] Optionally, a socket, also known as a socket, is an abstraction of the endpoints for two-way communication between application processes on different hosts in a network. A socket is one end of the process communication on the network, providing a mechanism for application layer processes to exchange data using network protocols. In terms of its position, a socket is connected to the application process above and the network protocol stack below. It is the interface for the application program to communicate through the network protocol and the interface for the application program to interact with the network protocol stack.
[0060] Optionally, this patent can classify ROS2 nodes into three categories. The first category is Node 1 as shown in Figure 2 , which is a node triggered by a timer and then publishes a topic, named timenode. The second category is Node 2, Node 3, Node 5, and Node 6 as shown in Figure 2 , which are nodes that subscribe to a topic and publish a topic, named normalnode. The third category is as shown in Figure 2The 4th node and the 7th node shown, such nodes subscribe to n topics and publish n topics, named callnode.
[0061] Optionally, the present invention also defines a structure to describe node information. Before the dividing line is the information common to the three types of nodes, and after the dividing line is the information specific to the nodes. The node type is set and judged through type, and the information that does not belong to this type of node is set to a null value.
[0062] Optionally, the present invention records the node information of each node by setting dataflownode, and these node information are set before creating the node. A server is established using sockets. Each node creates a client using sockets during initialization and sends dataflownode to the server. The server collects the information and schedules it according to the subsequent node scheduling method. At the same time, the server uses a polling method to process the information sent by the client.
[0063] S200. Calculate the total execution time of the longest path from each of the ROS2 nodes to the end point according to the execution time and subscription / publishing information of each of the ROS2 nodes, where the longest path is the path that takes the longest time for the ROS2 node to execute to the end point;
[0064] Optionally, as described above, there are multiple ROS2 nodes in ROS2. For each node (which can include the end point or exclude the end point), the present invention can calculate the total execution time of the corresponding longest path. Since any ROS2 node can have multiple different paths to the end point, the present invention can determine how many paths there are from this ROS2 node to the end point, and then calculate the total execution time of each path respectively to find the total execution time of the longest path. The present invention does not limit this.
[0065] For example, in some optional embodiments, the S200 includes: Step 2.1 and Step 2.2;
[0066] Step 2.1. For any one of the ROS2 nodes, determine each path from the ROS2 node to the end point according to the subscription / publishing information of the ROS2 node;
[0067] Optionally, in some optional embodiments, the Step 2.1 includes: Step 3.1 and Step 3.2;
[0068] Step 3.1: If there is only one end point in the system, for any of the ROS2 nodes, determine the next-level ROS2 node of the ROS2 node according to the subscription and publication information of the ROS2 node, and determine the second-next-level ROS2 node of the ROS2 node according to the subscription and publication information of the next-level ROS2 node, and so on in a loop until all paths from the ROS2 node to the end point are determined;
[0069] Optionally, as Figure 2 shown by Node 4 in, Node 4 has a total of two paths leading to Node 8 (the end point). One path is Node 4 - Node 5 - Node 7 - Node 8, and the other is Node 4 - Node 6 - Node 7 - Node 8. The present invention does not limit this.
[0070] Step 3.2: If there are multiple end points in the system itself, create a new end point and connect the new end point to each of the multiple end points that exist in the system itself. According to the subscription and publication information of the ROS2 node, determine the next-level ROS2 node of the ROS2 node and determine the second-next-level ROS2 node of the ROS2 node according to the subscription and publication information of the next-level ROS2 node, and so on in a loop until all paths from the ROS2 node to the new end point are determined, where the execution time of the new end point is set to 0.
[0071] Optionally, taking Figure 2 as an example, if Figure 2 does not have Node 8, then Figure 2 Nodes 2, 3, and 7 in are all end points in the system itself. In the case of many end points, it is not conducive to calculating the longest path and subsequent planning of the execution order. Therefore, the present invention can add a node, that is, add Figure 2 Node 8 (the new end point) in, and then connect Node 8 to the above-mentioned Nodes 2, 3, and 7 respectively to obtain the node graph shown in Figure 2 . Since Node 8 is added for the convenience of calculation and does not perform corresponding tasks in the actual project, the present invention can set the execution time of Node 8 to 0 to avoid bringing errors to the calculation results due to the addition of Node 8. The present invention does not limit this.
[0072] Step 2.2: Calculate the total execution time of the longest path according to the execution times of each ROS2 node on each of the paths.
[0073] Optionally, in some alternative embodiments, the Step 2.2 includes: Step 4.1 and Step 4.2;
[0074] Step 4.1: Using the SPFA algorithm, calculate the total execution time of each path based on the execution time of each ROS2 node on each path.
[0075] Step 4.2: Determine the total execution time of the longest path from the total execution times of each path, where the path with the absolute maximum execution time is the longest path.
[0076] Optionally, the SPFA (Shortest Path Faster Algorithm) algorithm. SPFA is an algorithm for calculating the shortest path, and there may be multiple nodes that can be regarded as the end point in the actual scenario. Therefore, in most cases, a new end point needs to be added. Since SPFA is an algorithm for calculating the shortest path, the present invention can multiply the execution time of all nodes by -1. In this way, the shortest path calculated by SPFA can be regarded as the longest path in the case of positive values. Finally, the result calculated by SPFA for each node is taken as a negative value, and the present invention does not limit this.
[0077] Of course, the present invention can also directly input the node graph as shown in Figure 2 into a pre-trained model or algorithm, and then directly output the total execution time of the longest path of each node. The present invention does not limit this.
[0078] Optionally, in combination with Figure 2 , for any node, after all the nodes pointed to by its incoming edges (the upper-level nodes) have completed their respective tasks, this node can be added to the ready_list. For the tasks added to the ready_list, the CPU preferentially schedules the longest path. For example, taking node 7 as an example, if node 5 and node 6 have both completed their respective tasks, then node 7 can be added to the ready_list. The present invention does not limit this.
[0079] Optionally, for any node, the present invention can also be that this node is added to the ready_list and then calculate the total execution time of its longest path. The present invention does not limit this.
[0080] In combination with Figure 2 the node graph and Figure 3 the different scheduling paths shown in Figure 3As can be seen from Schedule1 and Schedule2 in [the relevant context], the time taken by Schedule1 is less than that of Schedule2 (i.e., Overhand of Schedule1 = 400, Overhand of Schedule2 = 500). Because at Step2, Schedule2 couldn't run node 8 as the task of node 7 wasn't completed yet. Although there are two CPU cores, only one core has tasks to do. The execution scheduling of ROS2 randomly schedules executable tasks. So in this situation, the execution route is uncertain each time. It might choose Schedule1 or Schedule2. In actual scenarios, there are even more random choices, resulting in a lack of determinacy. However, the time-based scheduling of the present invention can select scheduling nodes based on the longest path each time, and the scheduling strategy is determined each time. The time-based scheduling strategy can well ensure end-to-end determinacy. That is, the present invention clearly finds that the longest path for executing node 4 at Step2 is the longest. So when executing, it can make more full use of the CPU time and prevent the CPU from being idle, thus clarifying the scheduling strategy.
[0081] For Figure 3 the understanding, taking Schedule1 and two CPU cores as an example, at Step1, the two CPU cores respectively execute node 3 and node 4. Since the next node of node 3 is the end point 8, at Step2, the two CPU cores respectively execute node 5 and node 6 to avoid the core executing node 3 from being idle; at Step3, the two CPU cores respectively execute node 2 and node 7; at Step4, it reaches the end point 8, and the present invention places no restrictions on this.
[0082] S300. For any node, calculate the new priority of the ROS2 node according to the preset priority and execution time of the ROS2 node;
[0083] For example, in some optional embodiments, the S300 includes: Step 5.1;
[0084] Step 5.1. For any node, calculate the sum of the preset priority of the ROS2 node and the maximum preset priority among the next-level nodes to obtain the new priority of the ROS2 node.
[0085] Optionally, if only scheduling each ROS2 node based on the preset priority simply, some unreasonable situations will occur. For example, as Figure 2The shown node graph. In the case of having two CPU cores, after executing Node 1, since the priorities of Node 2 and Node 3 are higher than that of Node 4, Node 2 and Node 3 are executed first. However, this hides that there is a Node 7 below Node 4 with a priority of 100. Because Node 2 and Node 3 are executed first, the execution of Node 7 will be postponed. Therefore, certain processing needs to be done on the initially set preset priorities. Starting from the end point and pushing back towards the start point, the priority of each node is changed to the initially set preset priority plus the maximum priority among the nodes pointed to by all out-edges (the edges pointing to the next-level nodes) (updated step by step, and the priority of the current-level node is updated by adding on the basis of the updated priority of the previous-level node). The final server calculates the priority based on Figure 2 as shown in Figure 4 . Starting from Figure 2 the update to obtain Figure 4 is as follows:
[0086] The first-round update: Since the next-level nodes of Node 2, Node 3, and Node 7 are the end points, the priorities of Node 2, Node 3, and Node 7 remain unchanged. Mainly update Node 1, Node 5, and Node 6. That is, the priority of Node 1 = 10 + 50 = 60, the priority of Node 5 = 10 + 100 = 110, and the priority of Node 6 = 10 + 100 = 110;
[0087] The second-round update: Based on the first-round update, the priority of Node 5 = 110, the priority of Node 6 = 100. In this round, only Node 4 needs to be updated. That is, the priority of Node 4 = 10 + 110 = 120.
[0088] After the above two rounds of step-by-step updates, the node graph as shown in Figure 4 is obtained. The present invention places no restrictions on this.
[0089] Optionally, the principle of priority scheduling is the same. For any node, after all the nodes pointed to by its in-edges (the previous-level nodes) have completed their respective tasks, this node can be added to the ready_list. For the tasks added to the ready_list, the CPU preferentially schedules the longest path. For example, taking Node 7 as an example, if Node 5 and Node 6 have both completed their respective tasks, then Node 7 can be added to the ready_list. Generally, the node with the highest priority in the ready_list is preferentially scheduled for execution. The present invention places no restrictions on this.
[0090] S400. Determine the execution order of each of the ROS2 nodes according to the total execution time corresponding to each of the ROS2 nodes and the new priorities.
[0091] Optionally, to further improve the accuracy of the present invention, in addition to relying solely on the total execution time or solely on the new priority scheduling of ROS2 nodes, the present invention can also comprehensively consider the total execution time and the new priority scheduling of ROS2 nodes.
[0092] That is, in some optional embodiments, S400 includes: Step 6.1, Step 6.2, Step 6.3, and Step 6.4;
[0093] Step 6.1, for any one of the ROS2 nodes, calculate the first product of the total execution time of the ROS2 node and a preset time coefficient;
[0094] Step 6.2, calculate the second product of the new priority of the ROS2 node and a preset priority coefficient;
[0095] Step 6.3, calculate the sum of the first product and the second product to obtain the influence factor of the ROS2 node;
[0096] Step 6.4, determine the execution order of each ROS2 node according to the influence factors of each ROS2 node.
[0097] Optionally, the preset time coefficient and the preset priority coefficient can be set according to actual needs, and the present invention does not limit this.
[0098] Optionally, as can be seen from the foregoing, the nodes that require longer execution time should be executed first, and the nodes with higher priorities should be executed first.
[0099] Optionally, in some optional embodiments, after S400, the method further includes:
[0100] For any one of the ROS2 nodes other than the start node, if the ROS2 node does not receive the first signal from the upper-level ROS2 node within the first time range, the ROS2 node sets the value of the first signal to the previous value or the ROS2 node ignores the first signal and processes other signals;
[0101] If the ROS2 node does not receive the first signal from the upper-level ROS2 node for more than the first time range, terminate the system operation and report an error, where the second time length is greater than the first time range.
[0102] Optionally, in combination with Figure 2, when transmitting data from node 6 to node 7, data delay may occur due to certain reasons. There is no suitable timeout handling strategy in ROS2, which obviously cannot meet end-to-end determinism. The present invention provides a timeout supervision strategy: set the first duration range T - 3T. If no information is received within the time of T - 3T, this signal can be ignored to process other signals or the value of this signal can be set to the previous value; if the timeout exceeds 3T, then choose to terminate the system and report an error to the user. The present invention does not limit this.
[0103] In summary, the present invention can identify the longest path and new priorities based on the node information of ROS2 nodes, and then plan a definite execution order based on the longest path and new priorities. The determined execution order can not only maximize the task execution efficiency, but also has very clear determinism and will not cause chaos in multiple orders.
[0104] The present invention efficiently realizes cross-process coordination within the ROS2 framework. Through the time-based scheduling strategy and the priority-based scheduling strategy, it ensures end-to-end real-time performance during the system execution process, and this method enhances the reliability of the intelligent vehicle operating system.
[0105] As Figure 5 shown, the present invention provides an execution scheduling device for a robot operating system, including: a node information acquisition unit 100, a total time calculation unit 200, a priority calculation unit 300, and an execution order determination unit 400;
[0106] The node information acquisition unit 100 is used to acquire the node information of each ROS2 node, where the node information includes execution time, subscription and publication information, and a preset priority;
[0107] The total time calculation unit 200 is used to calculate the total execution time of the longest path from each ROS2 node to the end point according to the execution time and subscription and publication information of each ROS2 node, where the longest path is the path that takes the longest time for the ROS2 node to execute to the end point;
[0108] The priority calculation unit 300 is used to calculate a new priority of any ROS2 node according to the preset priority and execution time of the ROS2 node;
[0109] The execution order determination unit 400 is used to determine the execution order of each ROS2 node according to the total execution time and new priority corresponding to each ROS2 node.
[0110] Optionally, in some alternative embodiments, the node information acquisition unit 100 includes: a node information acquisition subunit;
[0111] The node information acquisition subunit is used to obtain the node information of each of the ROS2 nodes through the server. Among them, the server is established based on a socket. When each of the ROS2 nodes is initialized, a client is established using the socket, and the node information of the ROS2 node is sent to the server through the client.
[0112] Optionally, in some alternative embodiments, the total time calculation unit 200 includes: a path determination subunit and a total time calculation subunit;
[0113] The path determination subunit is used to, for any one of the ROS2 nodes, determine each path from the ROS2 node to the end point according to the subscription and publication information of the ROS2 node;
[0114] The total time calculation subunit is used to calculate the total execution time of the longest path according to the execution times of the ROS2 nodes on each of the paths.
[0115] Optionally, in some alternative embodiments, the path determination subunit includes: a unique end point subunit and a multiple end points subunit;
[0116] The unique end point subunit is used to, if there is only one end point in the system itself, for any one of the ROS2 nodes, determine the next-level ROS2 node of the ROS2 node according to the subscription and publication information of the ROS2 node, and determine the next-next-level ROS2 node of the ROS2 node according to the subscription and publication information of the next-level ROS2 node, and so on in a loop until each path from the ROS2 node to the end point is determined;
[0117] The multiple end points subunit is used to, if there are multiple end points in the system itself, establish a new end point and connect the new end point to each of the multiple end points existing in the system respectively. According to the subscription and publication information of the ROS2 node, determine the next-level ROS2 node of the ROS2 node and determine the next-next-level ROS2 node of the ROS2 node according to the subscription and publication information of the next-level ROS2 node, and so on in a loop until each path from the ROS2 node to the new end point is determined, where the execution time of the new end point is set to 0.
[0118] Optionally, in some alternative embodiments, the total time calculation subunit includes: an SPFA algorithm subunit and a longest path subunit;
[0119] The SPFA algorithm subunit is used to use the SPFA algorithm to calculate the total execution time of each path based on the execution times of the ROS2 nodes on each of the paths;
[0120] The longest path subunit is used to determine the total execution time of the longest path from the total execution times of all the paths, where the path with the absolutely maximum execution time is the longest path.
[0121] Optionally, in some alternative embodiments, the priority calculation unit 300 includes: a new priority subunit;
[0122] The new priority subunit is used to calculate, for any node, the sum of the preset priority of the ROS2 node and the maximum preset priority among the next-level nodes, to obtain the new priority of the ROS2 node.
[0123] Optionally, in some alternative embodiments, the execution order determination unit 400 includes: a first product subunit, a second product subunit, an influence factor subunit, and an order determination subunit;
[0124] The first product subunit is used to calculate, for any of the ROS2 nodes, the first product of the total execution time of the ROS2 node and a preset time coefficient;
[0125] The second product subunit is used to calculate the second product of the new priority of the ROS2 node and a preset priority coefficient;
[0126] The influence factor subunit is used to calculate the sum of the first product and the second product, to obtain the influence factor of the ROS2 node;
[0127] The order determination subunit is used to determine the execution order of each of the ROS2 nodes according to the influence factors of each of the ROS2 nodes.
[0128] Optionally, in some alternative embodiments, the device further includes: a first time subunit and a second time subunit;
[0129] The first time subunit is used, after determining the execution order of each of the ROS2 nodes according to the total execution time and the new priority corresponding to each of the ROS2 nodes, for any of the ROS2 nodes other than the start node, if the ROS2 node does not receive a first signal from a superior ROS2 node within a first time range, the ROS2 node sets the value of the first signal to the previous value or the ROS2 node ignores the first signal and processes other signals;
[0130] The second time subunit is used to terminate the system operation and report an error if the ROS2 node does not receive the first signal from a superior ROS2 node beyond the first time range, where the second time length is greater than the first time range.
[0131] The present invention provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the execution scheduling method of the robot operating system described in any one of the above is implemented.
[0132] As Figure 6 shown, the present invention provides an electronic device 70, and the electronic device 70 includes at least one processor 701, and at least one memory 702 and a bus 703 connected to the processor 701; wherein, the processor 701 and the memory 702 complete communication with each other through the bus 703; the processor 701 is configured to call program instructions in the memory 702 to execute the execution scheduling method of the robot operating system described in any one of the above.
[0133] In the present invention, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the element.
[0134] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts can be referred to the partial description of the method embodiment.
[0135] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined in the present invention can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown in the present invention, but will be accorded the widest scope consistent with the principles and novel features disclosed in the present invention.
[0136] The above are only the preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention are all included within the protection scope of the present invention.
Claims
1. A method for executing and scheduling a robot operating system, characterized in that: include: Obtain node information of each ROS2 node, wherein the node information includes execution time, subscription and publishing information, and preset priority; According to the execution time of each ROS2 node and the subscription publishing information, the total execution time of the longest path from each ROS2 node to the end point is calculated, wherein the longest path is the path that takes the longest time for the ROS2 node to execute to the end point; For any node, calculate a new priority of the ROS2 node according to the preset priority and execution time of the ROS2 node; The execution order of each ROS2 node is determined according to the total execution time corresponding to each ROS2 node and the new priority.
2. The method according to claim 1, characterized in that The obtaining of node information of each ROS2 node includes: The node information of each ROS2 node is obtained through the server, wherein the server is established based on a socket, each ROS2 node uses the socket to establish a client during initialization and sends the node information of the ROS2 node to the server through the client.
3. The method according to claim 1, characterized in that The step of calculating the total execution time of the longest path from each ROS2 node to the end point according to the execution time of each ROS2 node and the subscription publishing information includes: For any of the ROS2 nodes, determine each path from the ROS2 node to the end point according to the subscription and publishing information of the ROS2 node; According to the execution time of each ROS2 node on each of the paths, the total execution time of the longest path is calculated.
4. The method according to claim 3, characterized in that The step of determining, for any of the ROS2 nodes, paths from the ROS2 node to the end point according to subscription and publishing information of the ROS2 node, includes: If there is only one end point in the system, for any of the ROS2 nodes, the next-level ROS2 node of the ROS2 node is determined according to the subscription and publishing information of the ROS2 node, and the next-level ROS2 node of the ROS2 node is determined according to the subscription and publishing information of the next-level ROS2 node, and this cycle is repeated until all paths from the ROS2 node to the end point are determined; If there are multiple endpoints in the system, a new endpoint is established and connected to the multiple endpoints in the system respectively. According to the subscription and publishing information of the ROS2 node, the next-level ROS2 node of the ROS2 node is determined, and the next-level ROS2 node of the ROS2 node is determined according to the subscription and publishing information of the next-level ROS2 node. This cycle is repeated until the paths from the ROS2 node to the new endpoint are determined, wherein the execution time of the new endpoint is set to 0.
5. The method according to claim 3, characterized in that: The total execution time of the longest path is calculated according to the execution time of each ROS2 node on each path, including: Using the SPFA algorithm, based on the execution time of each ROS2 node on each path, the total execution time of each path is calculated; The total execution time of the longest path is determined from the total execution time of each of the paths, wherein the path with the absolute maximum total execution time is the longest path.
6. The method according to claim 1, characterized in that The step of calculating, for any node, a new priority of the ROS2 node according to the preset priority and execution time of the ROS2 node comprises: For any node, the sum of the preset priority of the ROS2 node and the maximum preset priority of the next-level nodes is calculated to obtain a new priority of the ROS2 node.
7. The method according to claim 1, characterized in that Determining the execution order of each ROS2 node according to the total execution time and the new priority corresponding to each ROS2 node includes: For any of the ROS2 nodes, calculating a first product of the total execution time of the ROS2 node and a preset time coefficient; Calculating a second product of the new priority of the ROS2 node and a preset priority coefficient; Calculate the sum of the first product and the second product to obtain the impact factor of the ROS2 node; The execution order of each of the ROS2 nodes is determined according to the influencing factors of each of the ROS2 nodes.
8. The method according to claim 1, characterized in that After determining the execution order of each of the ROS2 nodes according to the total execution time and the new priority corresponding to each of the ROS2 nodes, the method further includes: For any of the ROS2 nodes except the start node, if the ROS2 node does not receive the first signal from the upper-level ROS2 node within the first time range, the ROS2 node sets the value of the first signal to the previous value or the ROS2 node ignores the first signal and processes other signals; If the ROS2 node does not receive the first signal from the upper-level ROS2 node within the first time range, the system operation is terminated and an error is reported, wherein the second time length is greater than the first time range.
9. An execution scheduling device for a robot operating system, characterized in that: include: A node information obtaining unit, a total time calculating unit, a priority calculating unit and an execution order determining unit; The node information obtaining unit is used to obtain the node information of each ROS2 node, wherein the node information includes execution time, subscription and publishing information, and preset priority; The total time calculation unit is used to calculate the total execution time of the longest path from each ROS2 node to the end point according to the execution time of each ROS2 node and the subscription and publishing information, wherein the longest path is the path that takes the longest time for the ROS2 node to execute to the end point; The priority calculation unit is used to calculate a new priority of the ROS2 node for any node according to the preset priority and execution time of the ROS2 node; The execution order determination unit is used to determine the execution order of each of the ROS2 nodes according to the total execution time and the new priority corresponding to each of the ROS2 nodes.
10. An electronic device, characterized in that: The electronic device includes at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call program instructions in the memory to execute the execution scheduling method of the robot operating system as described in any one of claims 1 to 8.