Skip to content

ROS2 in practice

Nick Ng edited this page Jun 12, 2020 · 1 revision

ROS2 in practice

This is an exploration of ROS 2 development.

Motivation

  • What is the minimal setup required for building ROS 2 packages?
    • Focus:
      • build systems/pipelines/workflows that are replicable
  • What is the minimal setup required for running ROS 2 packages?
    • Focus:
      • deployment automation
      • emulation/virtualization/containerization
  • To explain the steps needed to achieve the above.

In the future:

Definitions

Machine types

  • Development machine
    • Primarily used for development.
    • ROS 2 Desktop install.
    • A development machine may also be used as a 'build machine' or 'target machine'.
  • Build machine
    • Primarily used for building.
    • ROS 2 Base install.
  • Target machine
    • Primarily used for running a ROS 2 based application.
    • ROS 2 Base install.

Approach

Virtualization and containerization

In the course of working with ROS 2, many dependencies will be installed in a machine. This leads to:

  • dependency hell
  • lack of clarity of what is required to build a ROS 2 package, leading to difficulties in replicating build environments.
  • lack of clarity of what is required to run a ROS 2 package, leading to difficulties in replicating runtime environments.

This exploration uses Vagrant and Docker to isolate dependencies in order to provide blank slates from which to work from.

Typical build steps

The first step is to set up a workspace. Typically, this has the structure:

  • dev_ws/
    • src/

Example:

mkdir -p dev_ws/src && \
cd dev_ws

Importing sources

The src/ contains the ROS 2 packages to be built. These may be imported into the src/ directory via:

  • vcs import src < my_project.repos
  • manually using a VCS tool (such as git)
    • cd src && git clone $MY_PROJECT_REPO_URL && cd ..
  • manually copying it into the directory
  • or a mix of the above

Example:

cd src && \
git clone https://github.com/ros2/examples.git && \
cd ..

Build steps

The following steps assume that the ROS 2 installation has been sourced.

  1. Select the packages to be built.
    • Example:
      • examples_rclcpp_minimal_publisher
      • examples_rclcpp_minimal_subscriber
      SELECTED_PACKAGES="examples_rclcpp_minimal_publisher examples_rclcpp_minimal_subscriber"
      
  2. List the source paths for these packages.
    • Often times source repositories may contain multiple packages, this step excludes unnecessary packages.
    • Example:
      SOURCE_PATHS=$(colcon list -p --packages-up-to ${SELECTED_PACKAGES})
      echo ${SOURCE_PATHS}
      
  3. Download and install the dependencies of the selected packages.
    • Example:
      rosdep install -i -y --from-paths ${SOURCE_PATHS}
      
  4. Build the selected packages.
    • Example:
      colcon build --packages-select ${SELECTED_PACKAGES}
      

Generating the list of system dependencies

  1. List the rosdep keys that the packages defined in those source paths depend on.
    • Example:
      ROSDEP_KEYS=$(rosdep keys --from-paths ${SOURCE_PATHS})
      echo ${ROSDEP_KEYS}
      
  2. Resolve rosdeps to system dependencies.
    • Example:
      rosdep resolve ${ROSDEP_KEYS}
      
      # the output lists the dependencies that need to installed (on build machines or target machines)
      # this output will require parsing/processing
      
    • Example output:
      #ROSDEP[std_msgs]
      #apt
      ros-dashing-std-msgs
      #ROSDEP[ament_cmake]
      #apt
      ros-dashing-ament-cmake
      #ROSDEP[rclcpp]
      #apt
      ros-dashing-rclcpp
      

ros2-vagrant

A Vagrant/Docker-based approach can be found here:

Clone this wiki locally