# A New Algorithm for Real-Time Scheduling and Resource Mapping for Robot Operating Systems (ROS)

## Abstract

**:**

## Featured Application

**Real-Time Systems: Architectures, Software and Applications.**

## Abstract

## 1. Introduction

- A formal model to analyze the system.
- A low-complexity heuristic algorithm to build executors from a set of callbacks.
- A method to assign priority to executors and to define the order of execution of callbacks inside an executor.

## 2. Related Works

## 3. Background of ROS-2 Architecture

#### Scheduling in ROS-2

**Callback**- This is the smallest executable code scheduled in ROS-2. ROS-2 defines five types of callbacks: timers that are time-triggered by system-level timers, subscribers that are triggered by the reception of new messages at a topic, services, and clients callbacks that are triggered by service requests and responses, respectively.
**Node**- The node is the minimal self-contained unit of behavior. A node contains a set of callbacks organized by application programmers for the modularity and logical partitioning of functions. All callbacks from the same node are executed by the same executor.
**Executor**- The executor reads the incoming messages from a ready list and executes, in a non-preemptive manner, the corresponding callback according to their type and activation instant in this order: timer callbacks first, then subscriber callbacks, service callbacks, and, finally, client callbacks, as illustrated in Figure 3. Unlike common real-time priority-based scheduling algorithms, the executor does not always execute callbacks in their activation instances. Instead, the executor updates the ready status of non-timer callbacks in their respective queues when all queues are empty (called a polling point), and such a delayed update of callback readiness makes the priority assignment of non-timer callbacks ineffective and lets chains run in a round-robin-like manner.

## 4. System Model

**Definition 1**

**Definition 2**

- ${c}_{i}$: The worst-case execution time (WCET).
- ${p}_{i}$: The callback period.
- ${d}_{i}$: The deadline for a callback.
- ${k}_{i}$: A positive integer that defines the order of callback execution within the executor.

- ${D}_{j}$: The executor deadline.
- ${P}_{j}$: The executor priority.
- ${T}_{j}$: The executor period.
- $\overrightarrow{{E}_{j}}=[{C}_{j,0},{C}_{j,1},\dots ,{C}_{j,s},\dots ,{C}_{j,N-1}]$: A vector of ${N}_{j}$ components. Each component ${C}_{j,i}$ represents the execution time of ${e}_{j}$ in frame j.

## 5. Heuristic Scheduling Algorithm

Algorithm 1: Assigning callbacks to executors. |

#### 5.1. Algorithm 2: Assignment

**Theorem 1.**

**Proof.**

Algorithm 2: Mapping feasibility test |

#### 5.2. Algorithm 3: Executor Creation

**Condition 1:**- $\forall i\in \Lambda :T=GC{D}_{i=1}^{\left|\Lambda \right|}{p}_{i}>1$
**Condition 2:**- $\overline{E}={\sum}_{s=0}^{N-1}{C}_{s}\le {T}_{j}$
**Condition 3:**- $R\le {min}_{i=1}^{\left|{\Lambda}_{j}\right|}{d}_{i}$

Algorithm 3: CreateExecutor |

Algorithm 4: Bucket select algorithm |

## 6. Experimental Results

- In the first step, callbacks that have the same periods are grouped in the same executor with a time complexity of $\mathcal{O}\left(mn\right)$;
- In the second step, a merge sort algorithm is used to define callback priority by assigning high priority to the shortest deadlines with a time complexity of $\mathcal{O}\left({m}^{2}\right)$.

Algorithm 5: Rate monotonic scheduling (RMS) algorithm. |

Algorithm 6: GBFS algorithm. |

#### 6.1. Workload Generation

#### 6.2. Performance Metrics

**Success ratio:**- Consider a set $\Sigma =\{{\Delta}_{1},{\Delta}_{2},\dots ,{\Delta}_{i},\dots ,{\Delta}_{N}\}$ composed of N subsets of callbacks ${\Delta}_{i}$, and A as a scheduling algorithm. We say that ${\Delta}_{i}$ can be scheduled by the scheduling algorithm A if all callbacks from ${\Delta}_{i}$ meet their deadlines, denoted by $A\left({\Delta}_{i}\right)=1$, and if not, we denote it by $A\left({\Delta}_{i}\right)=0$. As a result, the success rate $SR$ of the scheduling algorithm A on $\Sigma $ is defined by the following:$$SR=100\ast \frac{{\sum}_{i=1}^{N}A\left({\Delta}_{i}\right)}{N}$$
**Number of executors:**- This metric represents the number of executors provided by the algorithm to schedule all callbacks while meeting real-time constraints. We try to minimize this metric.
**Runtime:**- This metric measures the time it takes the algorithm to obtain a solution.
**Average response time:**- Average response time is the time elapsed between the activation and completion of a callback. The following equation is defined to calculate the average response time rate $TRm$ for a set of callbacks with cardinality n:$$TRm=100\ast \frac{{\sum}_{i=1}^{n}\frac{{c}_{i}}{{d}_{i}}}{n}$$

#### 6.3. Schedulability Test

#### 6.4. Number of Executors

#### 6.5. Runtime Analysis Comparison (in ms)

#### 6.6. Response Time Analysis

## 7. Limitations, Extensions, and Conclusions

## Funding

## Acknowledgments

## Conflicts of Interest

## References

- Quigley, M.; Gerkey, B.; Conley, K.; Faust, J.; Foote, T.; Leibs, J.; Berger, E.; Wheeler, R.; Ng, A. ROS: An open-source Robot Operating System. ICRA Workshop Open Source Softw.
**2009**, 3, 1–6. [Google Scholar] - Koubaa, A. Robot Operating System (ROS): The Complete Reference (Volume 3); Studies in Computational Intelligence; Springer: Cham, Switzerland, 2018; Volume 778. [Google Scholar] [CrossRef]
- Li, Z.; Hasegawa, A.; Azumi, T. A_Perf: A tracing and performance analysis framework for ROS 2 applications. J. Syst. Archit.
**2021**, 123, 102341. [Google Scholar] [CrossRef] - Macenski, S.; Foote, T.; Gerkey, B.; Lalancette, C.; Woodall, W. Robot Operating System 2: Design, architecture, and uses in the wild. J. Sci. Robot.
**2022**, 7, abm6074. [Google Scholar] [CrossRef] [PubMed] - Yang, Y.; Azumi, T. Exploring Real-Time Executor on ROS 2. In Proceedings of the 2020 IEEE International Conference on Embedded Software and Systems (ICESS), Shanghai, China, 10–11 December 2020; pp. 1–8. [Google Scholar] [CrossRef]
- Casini, D.; Blaß, T.; Lütkebohle, I.; Brandenburg, B. Response-Time Analysis of ROS 2 Processing Chains Under Reservation-Based Scheduling. In Proceedings of the 31th Euromicro Conference on Real-Time Systems (ECRTS 2019), Stuttgart, Germany, 9–12 July 2019. [Google Scholar] [CrossRef]
- Maruyama, Y.; Kato, S.; Azumi, T. Exploring the Performance of ROS-2. In Proceedings of the 13th International Conference on Embedded Software, EMSOFT ’16, Pittsburgh, PA, USA, 1–7 October 2016. [Google Scholar] [CrossRef]
- Choi, H.; Xiang, Y.; Kim, H. PiCAS: New Design of Priority-Driven Chain-Aware Scheduling for ROS2. In Proceedings of the 2021 IEEE 27th Real-Time and Embedded Technology and Applications Symposium (RTAS), Online, 18–21 May 2021; pp. 251–263. [Google Scholar] [CrossRef]
- Blaß, T.; Casini, D.; Bozhko, S.; Brandenburg, B.B. A ROS 2 Response-Time Analysis Exploiting Starvation Freedom and Execution-Time Variance. In Proceedings of the 2021 IEEE Real-Time Systems Symposium (RTSS), Dortmund, Germany; 2021; pp. 41–53. [Google Scholar] [CrossRef]
- Rota, G.C. The Number of Partitions of a Set. Am. Math. Mon.
**1964**, 71, 498–504. [Google Scholar] [CrossRef] - Wilhelm, T.; Weber, R. Towards Model-Based Generation and Optimization of AUTOSAR Runnable-to-Task Mapping. In Proceedings of the 2019 ACM/IEEE 22nd International Conference on Model Driven Engineering Languages and Systems Companion (MODELS-C), Munich, Germany, 15–20 September 2019; pp. 38–43. [Google Scholar] [CrossRef]
- Zhao, Q.; Gu, Z.; Zeng, H. Design optimization for AUTOSAR models with preemption thresholds and mixed-criticality scheduling. J. Syst. Archit.
**2017**, 72, 61–68. [Google Scholar] [CrossRef] - Gupta, P.; Singh, N.P.; Srinivasan, G. An Efficient Approach For Mapping AUTOSAR Runnables in Multi-core Automotive systems to Minimize Communication Cost. In Proceedings of the 2019 Innovations in Power and Advanced Computing Technologies (i-PACT), Vellore, India; 2019; Volume 1, pp. 1–4. [Google Scholar] [CrossRef]
- Saidi, S.E.; Cotard, S.; Chaaban, K.; Marteil, K. An ILP Approach for Mapping AUTOSAR Runnables on Multi-core Architectures. In Proceedings of the 2015 Workshop on Rapid Simulation and Performance Evaluation: Methods and Tools, Amsterdam, The Netherlands, 19–21 January 2015; pp. 6:1–6:8. [Google Scholar] [CrossRef]
- Al-bayati, Z.; Sun, Y.; Zeng, H.; Natale, M.D.; Zhu, Q.; Meyer, B.H. Partitioning and Selection of Data Consistency Mechanisms for Multicore Real-Time Systems. ACM Trans. Embed. Comput. Syst.
**2019**, 18, 1–28. [Google Scholar] [CrossRef] - Wozniak, E.; Mehiaoui, A.; Mraidha, C.; Tucci-Piergiovanni, S.; Gerard, S. An optimization approach for the synthesis of AUTOSAR architectures. In Proceedings of the 2013 IEEE 18th Conference on Emerging Technologies & Factory Automation (ETFA), Cagliari, Italy, 10–13 September 2013; pp. 1–10. [Google Scholar]
- Bertout, A.; Forget, J.; Olejnik, R. A Heuristic to Minimize the Cardinality of a Real-time Task Set by Automated Task Clustering. In Proceedings of the 29th Annual ACM Symposium on Applied Computing, Gyeongju, Republic of Korea, 24–28 March 2014; pp. 1431–1436. [Google Scholar] [CrossRef]
- Mixed Harmonic Runnable Scheduling for Automotive Software on Multi-Core Processors. Int. J. Automot. Technol.
**2018**, 19, 323–330. [CrossRef] - Khenfri, F.; Chaaban, K.; Chetto, M. Efficient mapping of runnables to tasks for embedded AUTOSAR applications. J. Syst. Archit.
**2020**, 110, 101800. [Google Scholar] [CrossRef] - Kim, S. Efficient Exact Response Time Analysis for Fixed Priority Scheduling in Lowest Priority First-Based Feasibility Tests. IEEE Embed. Syst. Lett.
**2021**, 13, 69–72. [Google Scholar] [CrossRef] - Liu, C.L.; Layland, J.W. Scheduling Algorithms for Multiprogramming in a Hard-Real-Time Environment. J. ACM
**1973**, 20, 46–61. [Google Scholar] [CrossRef] - Bini, E.; Buttazzo, G. Measuring the Performance of Schedulability Tests. Real-Time Syst.
**2005**, 30, 129–154. [Google Scholar] [CrossRef] - Saito, Y.; Azumi, T.; Kato, S.; Nishio, N. Priority and Synchronization Support for ROS. In Proceedings of the 2016 IEEE 4th International Conference on Cyber-Physical Systems, Networks, and Applications (CPSNA), Nagoya, Japan, 6–7 October 2016; pp. 77–82. [Google Scholar] [CrossRef]
- Tang, Y.; Feng, Z.; Guan, N.; Jiang, X.; Lv, M.; Deng, Q.; Yi, W. Response Time Analysis and Priority Assignment of Processing Chains on ROS2 Executors. In Proceedings of the 2020 IEEE Real-Time Systems Symposium (RTSS), Houston, TX, USA, 1–4 December 2020; pp. 231–243. [Google Scholar] [CrossRef]
- Chaaban, K. A seamless integration of fault-tolerant and real-time capabilities for Robot Operating System (ROS). In Proceedings of the 4th International Conference on Applied Automation and Industrial Diagnostics ICAAID, Hail, Saudi Arabia, 29–31 March 2022. [Google Scholar] [CrossRef]
- Krichen, M.; Lahami, M.; Cheikhrouhou, O.; Alroobaea, R.; Maâlej, A.J. Security Testing of Internet of Things for Smart City Applications: A Formal Approach. In Smart Infrastructure and Applications: Foundations for Smarter Cities and Societies; Mehmood, R., See, S., Katib, I., Chlamtac, I., Eds.; Springer International Publishing: Cham, Switzerland, 2020; pp. 629–653. [Google Scholar] [CrossRef]
- Fernandez, J.; Allen, B.; Thulasiraman, P.; Bingham, B. Performance Study of the Robot Operating System 2 with QoS and Cyber Security Settings. In Proceedings of the 2020 IEEE International Systems Conference (SysCon), Montreal, QC, Canada, 24 August–20 September 2020; pp. 1–6. [Google Scholar] [CrossRef]
- Lu, Q.; Li, X.; Guan, Y.; Wang, R.; Shi, Z. Modeling and Analysis of Data Flow-Oriented ROS2 Data Distribution Service. Int. J. Softw. Inform.
**2021**, 11, 505–520. [Google Scholar] [CrossRef] - Chen, J.; Du, C.; Zhang, Y.; Han, P.; Wei, W. A Clustering-Based Coverage Path Planning Method for Autonomous Heterogeneous UAVs. IEEE Trans. Intell. Transp. Syst.
**2022**, 23, 25546–25556. [Google Scholar] [CrossRef] - Chen, J.; Ling, F.; Zhang, Y.; You, T.; Liu, Y.; Du, X. Coverage path planning of heterogeneous unmanned aerial vehicles based on ant colony system. Swarm Evol. Comput.
**2022**, 69, 101005. [Google Scholar] [CrossRef] - Chen, J.; Zhang, Y.; Wu, L.; You, T.; Ning, X. An Adaptive Clustering-Based Algorithm for Automatic Path Planning of Heterogeneous UAVs. IEEE Trans. Intell. Transp. Syst.
**2022**, 23, 16842–16853. [Google Scholar] [CrossRef] - Pardo-Castellote, G. OMG Data-Distribution Service: Architectural overview. In Proceedings of the IEEE Military Communications Conference, Boston, MA, USA; 2003; Volume 1, pp. 242–247. [Google Scholar] [CrossRef]
- Cousins, S. Exponential growth of ROS. Robot. Autom. Mag.
**2011**, 18, 19–20. [Google Scholar] [CrossRef] - Mok, A.K.; Chen, D. A multiframe model for real-time tasks. IEEE Trans. Softw. Eng.
**1997**, 23, 635–645. [Google Scholar] [CrossRef] - Monot, A.; Navet, N.; Bavoux, B.; Simonot-Lion, F. Multisource Software on Multicore Automotive ECUs Combining Runnable Sequencing With Task Scheduling. Ind. Electron.
**2012**, 59, 3934–3942. [Google Scholar] [CrossRef] - Audsley, N. Optimal Priority Assignment and Feasibility of Static Priority Tasks with Arbitrary Start Times; Department of Computer Science, University of York: York, UK, 1991. [Google Scholar]
- Cottet, F.; Delacroix, J.; Kaiser, C.; Mammeri, Z. Scheduling in Real-Time Systems; Wiley: Oxford, UK, 2002; p. 282. ISBN 0-470-84766-2. [Google Scholar]

**Figure 3.**Scheduling semantics in ROS-2 (source: ros.org).

**Figure 4.**Example of assigning callbacks to the executor ${e}_{1}$. ${\pi}_{1}=LCM(10,15,15,30)=30$. ${T}_{1}$ = $GCD(10,15,15,30)=5$. ${D}_{1}=min\{8,10,12,19\}=8$. $Number\phantom{\rule{4pt}{0ex}}of\phantom{\rule{4pt}{0ex}}frames\phantom{\rule{4pt}{0ex}}N=30/5=6$.

Method Class | References | Online/Offline | Built-in ROS-2 | Variables | Optimization Goals |
---|---|---|---|---|---|

Formal Analysis | [15,20,21,22] | Offline | No | priority | latency-success ratio, data consistency |

[6,23,24] | Offline | Yes | priority | latency | |

[8] | Online | Yes | priority, mapping | latency, core balancing | |

[26] | Offline | N/A | QoS profiles, threat generation | loss rate, coverage, latency | |

Measurement-based | [3,7,27] | Offline | No | QoS policy, security | loss rate, latency, throughput |

Heuristic | [28] | Offline | No | priority, mapping | real-time performance, reliability |

[11,19] | Offline | No | mapping, priority, sequencing | real-time performance, reliability | |

[12,19] | Offline | No | mapping, scheduling | success ratio, latency | |

[13] | Offline | No | mapping, scheduling | inter-cores communication overhead, latency | |

Metaheuristic | [29,30,31] | Offline | No | clustering | path cost |

[11] | Offline | No | mapping, core balancing | resp. time analysis |

Symbol | Description |
---|---|

$\tau $ | Callback |

c | Worst-case execution time (wcrt) of callback |

p | Callback period |

d | Callback deadline |

k | Execution order of callback within executor |

e | Executor |

$\overline{{E}_{j}}$ | Maximum execution time of executor |

T | Executor period |

D | Executor deadline |

P | Executor priority |

$\pi $ | Major cycle of the executor |

GCD | Greatest common divider |

LCM | Least common multiple |

${\mathit{s}}^{\mathbf{th}}$ Frame | ${\mathit{f}}_{\mathit{i}}\left(\mathit{s}\right)$ | ${\mathit{h}}_{\mathit{i}}\left(\mathit{s}\right)$ | ${\mathit{C}}_{1,\mathit{s}}$ | ||||||
---|---|---|---|---|---|---|---|---|---|

${\tau}_{\mathbf{1}}$ | ${\tau}_{\mathbf{2}}$ | ${\tau}_{\mathbf{3}}$ | ${\tau}_{\mathbf{4}}$ | ${\tau}_{\mathbf{1}}$ | ${\tau}_{\mathbf{2}}$ | ${\tau}_{\mathbf{3}}$ | ${\tau}_{\mathbf{4}}$ | ||

0 | 0 | 1 | 0 | 5 | 1 | 0 | 1 | 0 | 2 |

1 | 0 | 1 | 0 | 5 | 0 | 1 | 0 | 0 | 1 |

2 | 2 | 1 | 0 | 5 | 1 | 0 | 0 | 0 | 1 |

3 | 2 | 4 | 3 | 5 | 0 | 0 | 1 | 0 | 1 |

4 | 4 | 4 | 3 | 5 | 1 | 1 | 0 | 0 | 2 |

5 | 4 | 4 | 3 | 5 | 0 | 0 | 0 | 1 | 1 |

Callback Cardinality | GBFS | RMS | LL | Proposed Algorithm |
---|---|---|---|---|

50 | 12,000 | 1345 | 1744 | 30 |

60 | n/a | 1862 | 732 | 160 |

80 | n/a | 2668 | 1260 | 924 |

100 | n/a | 5316 | n/a | 769 |

200 | n/a | 16,705 | n/a | 2483 |

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |

© 2023 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Chaaban, K. A New Algorithm for Real-Time Scheduling and Resource Mapping for Robot Operating Systems (ROS). *Appl. Sci.* **2023**, *13*, 1532.
https://doi.org/10.3390/app13031532

**AMA Style**

Chaaban K. A New Algorithm for Real-Time Scheduling and Resource Mapping for Robot Operating Systems (ROS). *Applied Sciences*. 2023; 13(3):1532.
https://doi.org/10.3390/app13031532

**Chicago/Turabian Style**

Chaaban, Khaled. 2023. "A New Algorithm for Real-Time Scheduling and Resource Mapping for Robot Operating Systems (ROS)" *Applied Sciences* 13, no. 3: 1532.
https://doi.org/10.3390/app13031532