Installing the ROS2 Environment - nps-ros2/nps-ros2-examples GitHub Wiki

This setup describes installing the following:

  • Ubuntu 18
  • Scripts and programs contained in this repository (tailored for Ubuntu 18 and ROS2)
  • ROS2 Dashing
  • Security Keys for ROS2 topics

Once setup is complete, please verify the installation by running the talker-listener demo.

Install Ubuntu

Install Ubuntu 18 from an .iso image: https://howtoubuntu.org/how-to-install-ubuntu-18-04-bionic-beaver.

Download this Repository

Download this repository for access to its scripts and code as described in Home.

Install ROS2

Install the latest version of ROS2 as described in https://index.ros.org//doc/ros2/Installation/Linux-Install-Binary/. If you downloaded this repository you may run its install script to automate this process:

cd ~/gits/nps-ros2-examples/scripts
./install_ros2_dashing_binaries.bash

This installation will fail if global variables are set for another ROS2 installation, for example if they are set by your .bashrc file. We typically define global variables and source setup scripts in our .bashrc file so that global variables are defined when we open a new command window. The easiest way to undefine global variables from a shell window is to remove any ROS2 definitions from our .bashrc file, close the shell window so we don't accidentally use it, then open a new shell window.

Generate Security Keys

If you would like DDS Security (for example for packet encryption) then generate a keystore and security keys for the demo's talker and listener nodes. Later we will add environment variables instructing ROS2 to use these settings. Ref. https://github.com/ros2/sros2/blob/master/SROS2_Linux.md.

source /opt/ros/dashing/setup.bash
mkdir ~/sros2_demo
cd ~/sros2_demo
ros2 security create_keystore demo_keys
ros2 security create_key demo_keys /talker
ros2 security create_key demo_keys /listener

Set Global Variables

Global variables must be set in your command window so that the following can happen:

  • Tools and resources for this version of ROS2 can be found.
  • Desired DDS security settings are configured.

Global variables are set by exporting them in your command window shell. This can be done by exporting them directly, by sourcing a script that exports them, or by updating your ~/.bashrc file so that it sets them when your command window opens up. We recommend that you use the ~/.bashrc approach and then close and open all command windows so that your ROS2 and Security global variables will be exported and present when you open new ones.

Put the following ROS2 setup code at the bottom of your ~/.bashrc file so it can execute when your command windows are opened:

# ROS2 Dashing
source /opt/ros/dashing/setup.bash

If you will be working with security keys, then also put in this Security part. When using this, you may disable Security by changing export ROS_SECURITY_ENABLE=true to export ROS_SECURITY_ENABLE=false.

# Security
export ROS_SECURITY_ROOT_DIRECTORY=~/sros2_demo/demo_keys
export ROS_SECURITY_ENABLE=true
# export ROS_SECURITY_ENABLE=false
export ROS_SECURITY_STRATEGY=Enforce

Verify your Installation

Verify your installation by running the talker-listener demo:

Open a command window and start a talker:

ros2 run demo_nodes_cpp talker

Open a command window and start a listener:

ros2 run demo_nodes_cpp listener