Creating ROS nodes

In this section, we are going to learn how to create two nodes, where one will publish data and the other will receive this data. This is the most basic way of communicating between two nodes in the ROS system.

We created the ROS package chapter2_tutorials in the earlier section Creating a ROS package and metapackage. Now, we will navigate to the chapter2_tutorials/src/ folder using the following command:

$ roscd chapter2_tutorials/src/

We will create two files with the names example_1a.cpp and example_1b.cpp. The example_1a.cpp file will create a node named example1a, which publishes the data "Hello World!" on the /message topic. Moreover, the example_1b.cpp file will create a node named example1b, which subscribes to ...

Get Robot Operating System Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.