Example Package on how to handle ROS2 Publishers & Subscribers, used for the Exploration Rover Lecture, Institute for Space Systems, University Stuttgart. Germany
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
winterhalderp ed2f2c95c7 ROS actionlib start 2 years ago
non-ros-files new package created and srv built 2 years ago
src ROS actionlib start 2 years ago
README.md new readme created 2 years ago


pubsub - Publisher & Subscriber Package

Minimal Publisher & Subscriber Template for ROS2.

Created for ROS Workshop 2020  
Course Roverentwicklung für Explorationsaufgaben  
Institute for Space Systems  
University of Stuttgart.

Class Code created by Patrick Winterhalder,
IRS, University of Stuttgart.

Workshop Prerequisites

In order to run ROS2 you must install Ubuntu 20.04 LTS on a capable machine (preferrably desktop/laptop).

For a successful workshop you must conduct this installation on your desktop machine or this installation on your Raspberry Pi. Go through the commands of these *.bash file line by line and check if every commands finishes without errors! Following these .bash files should do the following:

  • Install Visual Studio Code using the Ubuntu Software Installer
  • Install Git (no account required yet)
  • Install ROS2 (choose "desktop" on PC or "base" on Raspberry Pi, this eliminates all GUI tools from the installation, e.g. rviz and rqt).
    • Also install argcomplete
    • No need for ROS 1 bridge or RMW implementations
    • Install and update rosdep

After successfully installing ROS2 you should get to know it by working through the "Beginner: CLI Tools" tutorial. This will teach you how to configure your ROS 2 environment and you will learn about:

  • Source setup files (understand Underlay & Overlay)
  • How to configure the .bashrc file (shell startup script), a good example is here)
  • Add all colcon workspaces to the shell startup script
  • Check environment variables (check for correct installation)
  • Configure ROS_DOMAIN_ID (DDS Network Number)
  • Work through the tutorials covering turtlesim, rqt, topics, services, actions

Install Instructions

The following steps describe how you can create a local copy of this repository containing ROS2 publisher and subscriber class templates.

  • Move to your colcon workspace cd <workspace_path> (eg. cd ~/colcon_ws)
  • Clone this repository: git clone https://egit.irs.uni-stuttgart.de/RoverLehre/ROS2_pubsub.git . (include . at the end of the command in oder to copy everything to this locations!)
  • Build workspace: colcon build , Note: Only the files inside /src/ are of importance.
  • Remember to run source ~/<workspace_path>/install/local_setup.sh after every build.
    In order to avoid this repetitive command, add line 23-27 from .bashrc to your shell startup script for every overlay you want to source. This script runs everytime you start a new console, thus loading your overlays automatically. This is very handy if you are working with multiple colcon workspaces (overlays) simultaneously.

Workshop Content

In this workshop you will:

  • Create a new colcon workspace
  • Create a new package inside your newly created colcon workspace
    • ros2 pkg create --build-type [ament_cmake, ament-python] <package_name>
  • Build your colcon workspace, this means making it a functional ROS2 workspace from which you can start nodes:
    • First move to your workspace root: cd ~/<workspace_path>
    • Run colcon build --symlink-install
  • Add your workspace overlay to the shell startup script for sourcing everytime you open a new console:
    • Add this to the end of .bashrc (sudo nano .bashrc)
    • In this template find all instances of "~/ws_overlay_foxy" and replace it with the path to your own colcon workspace (replace ~/ with $HOME for representing the home directory variable in bash scripts)
  • Create custom message (.msg) or service (.srv) files in order to create custom interfaces to exchange information between nodes. For this you can use the pre-made /custom_interface package and add your own *.msg and/or *.srv files using this instruction document (easy), or you can start from scratch by following these instructions (hard).

Rules and Standard

In order for your code to work and to prevent major problems please read through this document. This will give you a brief oversight over how to develop a ROS2 package using Python.


The workshop's content is covered in this presentation.

Further Documentation:

  • pubsub/pubsub/ Readme.md: Information on the example files and libraries to create communication interfaces between ROS nodes.
  • custom_interface/ Readme.md: Instructions on how to create additional custom interfaces using this pre-made ROS package.