/neuROS

Prototype Operating System for UPDATE based on micro-ROS project

Primary LanguageC

neuROS

Prototype Real-time Operating System for UPDATE based on micro-ROS project

Design Goals

  1. Workload management: mapping event-based execution model in micro-ROS to fixed periodic scheduling scheme( in AUTOSAR) or server-based scheduling
  2. DDS resource management: DDS and network communication should be wrapped in a RTOS thread
  3. Event-trigger method: OS manages event trigger logic through OS Event Manager
  4. Intra/Inter Process Communication: Middleware should be able to choose intra-process, inter-process or remote-process communication automatically
  5. Low overhead DDS: use embeddedRTPS to replace XRCE-DDS, so that the microcontroller can act as a master node in the DDS network
  6. Reuse ROS2 and Posix-like API as much as possible

Background

A. Basic Concepts

  1. Callback: is the minimal schedulable workload in ROS2. There are 5 types of callbacks in ROS2: timer, subscription, client, service and waitable callbacks. In this work, we only focus on the support of timer and subscription callbacks, and leave the other functionality support to future work. As mentioned before, a timer callback arrives periodically at a predefined rate, while subscription callbacks follow an event-triggered fashion.
  2. Node: is a collection of callback functions, organized by application programmers for modularity and composability.
  3. Topic: is used as a means of communication among different nodes. In ROS2, a node can publish its data to a topic, so that all nodes subscribed to that topic can receive the message. By default, ROS2 kernel provides two kinds of communication mechanisms. DDS provides both inter and intra-process communication. And the intra-process API which resides in ROS2 can provide more efficient intra-process communication.
  4. Chain:

B. About micro-ROS

  1. Optimized client-library for ROS concepts on microcontrollers The client-library of ROS 2 (rcl) includes the concepts of nodes, publishers/subscriptions, topics, client/service, node graph, lifecycle, actions, parameters etc. Micro-ROS brings all these core concepts onto microcontrollers along with the set of extensions and convenience functions (rclc) allowing implementation of common scheduling patterns from embedded systems. Together, rcl+rclc form a complete clientlibrary in micro-ROS.
  2. Flexible middleware, considering extremely resource-constraint environment ROS 2 is implemented with DDS as it middleware. Micro-ROS comes with a new DDS for extremely resource-constraint environment, called Micro XRCE-DDS, implemented by eProsima, meeting all the necessary requirements for embedded systems. Micro XRCE-DDS follows a client-server architecture, in which Micro XRCE-DDS Client, running on resource-constraint embedded devices connects to Micro XRCE-DDS Agent, running on larger processors. The Agent is responsible to route the information from clients to DDS world and vice versa.
  3. Indefectible integration with ROS 2 As explained in the last key feature, micro-ROS nodes running on microcontrollers seamlessly connects to the external ROS 2 system with the help of micro-ROS Agent running on that system. As a result, with the known ROS 2 tools and APIs, micro-ROS nodes could be accessed just as normal ROS nodes.
  4. Support on any POSIX-compliant RTOS Micro-ROS application can be built and ported on any RTOS such as FreeRTOS, NuttX, Zephyr with POSIX interface. In ROS 2 package, RTOS-specific tools are integrated with a few generic setup scripts that can be run through command line. During the firmware creation step, application developers can choose the RTOS and these scripts will build the framework.

Design of neuROS

A. Overview

overview

1. Executor Task - (the highest priority)

A Executor Task is responsible for collecting the ready callbacks periodically and dispatching callbacks to other Slaver Tasks. So those functionalities should be designed in detail:

  • $Wait_{set}$ update strategy:
  • Callback dispatching policy:

2. Slaver Task - (a lower priority)

A Slaver Task is used to fetch ready callback from Dual-buffer with respect to callback priority and execute the corresponding callback function.

  • Callback fetching policy:

3. Dual-buffer

Each Slaver Task has a Dual-buffer, which is responsible for recording the dispatched callbacks to this Slaver Task. Specifically, a Dual-buffer consists of two FIFO buffers, one for Timer callbacks and the other for Subscription callbacks.

4. An Example

  • 设置两条任务链,每条任务链包含一个Timer和两个Subscription,手动为Timer或Subscription对应的callback绑定优先级,设置任务链一内callback的优先级不高于10,任务链二内callback的优先级不低于10,示意图如下:
  • 一共两个SlaverTask,设置Task2的优先级高于Task1,Task1处理优先级不高于10的callback,Task2处理优先级不低于10的callback。
  • 利用FreeRTOS的队列机制,一个SlaverTask对应一个Dual-buffer,Dual-buffer中包含两个队列,一个队列存储Timer_callback,一个队列存储Subscription_callback,SlaverTask的每次循环,先看timer_queue是否为空,再看subscription_queue是否为空,如果两个队列都为空,则将自身挂起,ExecutorTask每次分发任务时会对SlaverTask进行判断,如果SlaverTask为挂起态,ExecutorTask会将SlaverTask设置为执行态。
  • 将任务链一的定时器周期设置为5000ms,任务链二的定时器周期设置为2000ms,运行结果如下:

B. Design of Executor Task

overview

  • $Wait_{set}$ update strategy: Active $Wait_{set}$ update is the same with micro-ROS.
  • Callback dispatching policy: Simply put callbacks into different slaver tasks with different priority.

C. Design of Slaver Task

overview

D. Design of Dual-buffer

overview

Timer buffer: high priority -> check first Subscriber buffer: low priority

Limitation of Current Implementation: priority in each callback class is not supported. So for each buffer, enqueue and dequeue are both FIFO.

E. Design of Ring buffer for each publisher/subscriber

  • 每个publisher或subscription拥有一个专属ring_buffer;
  • 创建的publisher或subscription依据topic_name连接在一起;
  • publisher发布消息时,将消息发送到自己的ring_buffer中,根据注册表将消息复制到对应的所有subscription的ring_buffer中;
  • 一个publisher可同时向多个subscription发布消息。

Implementation of neuROS

TODO

Setup and Build

A. Supported platforms

RTOS Platform Version Example Others
FreeRTOS ST Nucleo F446ZE STM32CubeMX latest freertos nucleo_f446ze micro-ROS utils for STM32CubeMX and STM32CubeIDE

B. Building

  1. First micro-ROS Application on FreeRTOS
  2. micro_ros_setup