96boards: Real time and ROS2 | Dragonboard-845c, ROS2 and the pendulum demo

Servando German Serrano
|

Introduction

This is the fourth entry of our 96Boards: Real time and ROS2 series. On the previous ones we have enabled a real time kernel on the Hikey970 and on the Dragonboard-845c and tried the ROS2 pendulum on the Hikey970.

In this blog post we will also run the pendulum demo on the RT-enabled Dragonboard-845c while also evaluating FastRTPS and Eclipse Cyclone DDS implementations.

The post is organized as follows:


Installing Docker

Linaro’s Debian image is based on Debian Buster. At the time of writing Debian Buster is not a Supported platform for ROS2 Dashing Diademata. So, in order to run the ROS2 pendulum demo we need to install Docker in the board.

To install Docker Community Edition on the Dragonboard-845c please follow the next steps:

  • Run:
    $ sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
    
  • Then follow the official steps to install docker on arm64 target for Debian.

ROS2 and the pendulum demo

We will now reproduce the changes to the pendulum demo that were outlined in our previous post. Since we have Docker installed on the board we can pull a ROS2 based Docker image to use. For convenience we have included a ROS2 Dashing Diademata image in the 96Boards/ros Dockerhub repo with a root linaro user enabled by default.

To download and run a container please do:

$ sudo docker pull 96boards/ros:dashing
$ sudo docker run -it --rm --privileged --net=host --user linaro 96boards/ros:dashing

It is now possible to use ROS2 packages within the running container. If we try to run the pendulum demo as it is, we get the following output since the default permisions for memory locking inside the container are not suitable for our real time application:

Couldn't set scheduling priority and policy: Operation not permitted
mlockall failed: Cannot allocate memory
Couldn't lock all cached virtual memory.
Pagefaults from reading pages not yet mapped into RAM will be recorded.

We need to first setup the board memory locking permisions as explained here and then we can run the docker container as:

$ sudo docker run -it --rm --privileged --net=host --ulimit memlock=-1 --ulimit rtprio=98 --user linaro 96boards/ros:dashing

Which provides the container with the needed permisions for memory locking. We can now run the pendulum demo, although, as happened with the Hikey970, the application and container will be killed as the board runs out of memory.

Rttest library modifications

As we did in our previous post we need to create a local RSO2 workspace, clone the realtime_support repository and modify the rttest.cpp lines 683 and 684 to reduce the application memory requirements. So, on the host board (outside the container) we do:

$ mkdir -p ~/ros2_rt/src
$ cd ~/ros2_rt/src
$ git clone https://github.com/ros2/realtime_support.git -b dashing

and change rttest.cpp lines 683 and 684 to:

ptr = new char[32 * page_size];
memset(ptr, 0, 32 * page_size);

We can now mount the local folder as a volume in our ROS2 container, build the library and run the pendulum demo:

$ cd ~
$ sudo docker run -it --rm --privileged --net=host --ulimit memlock=-1 --ulimit rtprio=98 --user linaro  --volume=/home/$USER/ros2_rt:/home/linaro/ros2_rt:rw 96boards/ros:dashing

And , within the container:

$ cd ~/ros2_rt/
$ colcon build
$ source install/local_setup.bash
$ pendulum_demo

We will now see that the memory allocation error messages do not appear and we get an ouput like:

Initial major pagefaults: 14
Initial minor pagefaults: 32715
No results filename given, not writing results
rttest statistics:
  - Minor pagefaults: 0
  - Major pagefaults: 0
  Latency (time after deadline was missed):
    - Min: 6233 ns
    - Max: 80260 ns
    - Mean: 11847.3 ns
    - Standard deviation: 1391.99


PendulumMotor received 1032 messages
PendulumController received 1000 messages

FastRTPS and Eclipse Cyclone DDS

As with the Hikey970, we can compile Eclipse Cyclone DDS locally to also use it with ROS2. To do so, we clone the needed repositories in the host board outside of the container and then start the ROS2 container:

$ cd ~/ros2_rt/src
$ git clone https://github.com/ros2/rmw_cyclonedds
$ git clone https://github.com/eclipse-cyclonedds/cyclonedds
$ sudo docker run -it --rm --privileged --net=host --ulimit memlock=-1 --ulimit rtprio=98 --user linaro  --volume=/home/$USER/ros2_rt:/home/linaro/ros2_rt:rw 96boards/ros:dashing

and within the container:

$ cd ~/ros2_rt
$ rosdep install --from src -i
$ colcon build
$ source ~/ros2_rt/install/local_setup.bash

We can now choose between both DDS implementations to run our ROS2 applications as explained in the Working with multiple ROS 2 middleware implementations tutorial.

For completeness, we have run the pendulum demo using both DDS implementations as we did with the Hikey970. The image below shows the jitter results of the pendulum demo using eProsima FastRTPS DDS (in blue), Eclipse Cyclone DDS (in red) and the 3% (30000ns) maximum jitter as a black dashed line.

db845_fastrtps_vs_cyclone

As happened in the Hikey970 test, we can see that the maximum allowed latency is violated in the first instant of the demo which could be linked to initialization and/or memory allocation tasks. Apart from this, the latency for both DDS implementations is well below the maximum allowed for the system.


Conclusion

In this blog post we have shown that it is possible to use the Qualcomm® Robotics RB3 Development Platform to start building soft real time based applications using ROS2.

This article is Part 4 in a 4-Part Series.

comments powered by Disqus