Running test nodes

Now that your ROS environments have been set up properly, let's try testing the ROS-2 nodes. Follow these steps to test the nodes:

  1. Open a Terminal and source the ROS-2 environment workspace using the following command:
$ initros2

You should see a message, as shown here:

Distro warning
  1. Let's run the traditional talker node that we saw, similar to ROS-1, using the following command:
$ ros2 run demo_nodes_cpp talker

As you may have noticed, there isn't much difference between the way ROS-1 and ROS-2 run the nodes. You could very well say from the preceding command that the package name is demo_nodes_cpp and that the node name is talker. And instead of rosrun in ROS-1, it is ros2 run in ROS-2.

Notice the space between ros2 and run.
  1. In another Terminal, let's initialize ROS-2 once again using the following command:
$ initros2
  1. Let's run the traditional listener node that we saw, similar to ROS-1, using the following command:
$ ros2 run demo_nodes_py listener

You should see talker saying that it's Publishing: 'Hello World: 1,2...' and listener saying I heard: [Hello World: <respective count>]. The output should look like this:

ROS-2 publisher and subscriber output

You could use the ros2 topic list command to see the list of topics that are available as well, as shown here:

ROS-2 topic list

This brings us to the end of ROS-2's installation. Now, let's learn to set up our ROS-2 workspace.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.0.192