[ROS2 tutorial]- How to launch a ROS2 node

ROS2 Tutorials #1: How to Launch a ROS2 Node| [UPDATED]

Written by Alberto Ezquerro

02/07/2019

Welcome to the ROS2 tutorial series. In this first video we are going to show How to launch a node in ROS2.

COMMANDS TO USE:

  • ros2 run
  • ros2 pkg list
  • ros2 pkg executables
  • source /opt/ros/crystal/setup.bash

Step1. Let’s do this in ROS Development Studio(RDS)

At first, we have to find a Linux computer, install ROS, build all the package we need and…crash…NOOOOO!!!

Of course, you can do all this painfully on your own computer, but…

We’ll use ROSDS through this ROS2 tutorial because we can easily build a project on it without setting up any environment locally. You can create an account here for free.

After logging in, click on the New ROSject button. Let’s call this project ros2_tutorial and open it by clicking on the Open ROSject button.

Step2. Launching a ROS2 node

If you know ROS1 you may remember that in order to run a node on that ROS version we use therosrun <package_name> <executable_name> command. With ROS2 it’s you almost don’t see any difference, given that we use  ros2 run<package_name> <executable_name>.

Before launching a node we first need to know the list of ROS2 packages installed. We can do that with the following command:

ros2 pkg list

With the command above we can see that among the packages we have one named demo_nodes_cpp, as can be seen with ros2 pkg list | grep demo. To see the list of ROS2 executable files on our system we can run the command below:

ros2 pkg executables

The output provided by the command below is a list of <package_name> <executable_name>.In case you want to reduce the output and list only the desired package, by using grep  we can do that. Given that we are interested on thedemo_nodes_cpppackage, let’s filter it with  ros2 pkg executables | grep demo_nodes_cpp.

The output will be something like:

demo_nodes_cpp add_two_ints_client
demo_nodes_cpp add_two_ints_client_async
demo_nodes_cpp add_two_ints_server
demo_nodes_cpp allocator_tutorial
demo_nodes_cpp imu_listener
demo_nodes_cpp list_parameters
demo_nodes_cpp list_parameters_async
demo_nodes_cpp listener
demo_nodes_cpp listener_best_effort
demo_nodes_cpp one_off_timer
demo_nodes_cpp parameter_events
demo_nodes_cpp parameter_events_async
demo_nodes_cpp parameter_node
demo_nodes_cpp reuse_timer
demo_nodes_cpp ros2param
demo_nodes_cpp set_and_get_parameters
demo_nodes_cpp set_and_get_parameters_async
demo_nodes_cpp talker
demo_nodes_cpp_native talker

We can see that we have among the executable files we have one called talker  and another one called listener. For former writes data on a topic while the latter listens to that topic and print the received messages.

Let’s first launch the listener in background:

ros2 run demo_nodes_cpp listener &

Now let’s launch the talker and see the logs of both nodes:

ros2 run demo_nodes_cpp talker

After running the talker you should see something like the messages below:

[INFO] [talker]: Publishing: "Hello world: 1"

[INFO] [listener]: I heard: [Hello world: 1] 

[INFO] [talker]: Publishing: "Hello world: 2"

[INFO] [listener]: I heard: [Hello world: 2] 

...

So this is the post for today. It is really simple, but let’s go step by step learning a little bit of ROS2 every day. Let’s keep pushing and we will be ROS2 experts in no time.

To conclude, in case you also want to learn ROS1, we have complete courses in python and C++ on that subject. You can take those courses by clicking on the links below:

Those are online courses in the Robot Ignite Academy, where you are going to learn ROS fast using online simulations.

RELATED RESOURCES:

 

FEEDBACK:

Did you like this post? Whatever the case, please leave a comment on the comments section of our youtube (https://www.youtube.com/watch?v=8NgpjHOVCV8) video associated to this post. You can also subscribe to our channel and press the bell for a new video every day.

Keep pushing your ROS learning.

Topics: ros2
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This