ROS Programming

In this tutorial, you will learn how to start programming with ROS. It’s funny and amazing, yet quite simple. The first thing you need to understand in ROS is how to subscribe to a ROS topic, and how to publish a message to a ROS topic as most of ROS operations are based on publishing and subscribing to topics.


It is assumed that you already know the main concepts on ROS including ROS topics, ROS nodes, ROS messages and ROS services. If not, you need to first take the first tutorial on ROS Background.

The code of this tutorial is available in src/ros_basics/talker_listener/ of gaitech_edu package.


The following tutorial is based on the ROS tutorial Writing a Simple Publisher and Subscriber (C++) and Python but provides more practical programming and configuration hints. Although some videos are shown for ROS Hydro, they are also valid for all subsquent versions including Indigo and Jade, as they deal with the basics.

Lecture 1: ROS Publisher and Subscribers in C++ and Python

In this video, you will learn:

  • How to develop the simplest program with ROS
  • How to publish a message to a ROS topic using C++ and Python
  • How to subscribe a message to a ROS topic using C++ and Python
  • How to configure CMakeLists.txt and package.xml to add new required packages for compilation and runtime
  • How to run a program in ROS

Review Questions

  • Write the C++/Python instruction that creates a new topic called chatter of type String?
  • Write the C++/Python instruction that effectively publishes a message on the chatter topic?
  • How to add a new exectuable in CMakeLists.txt and package.xml to be able to compile and run a C++ ROS program?
  • How to declare a topic subscriber in C++/Python?
  • What is the role of the subscriber callback function?
  • in C++, what is the difference between std_msgs::String::ConstPtr and std_msgs::String?

Lecture 2: ROS Services in C++ and Python

Coming soon ..