[ROS2 tutorial]- How to launch a ROS2 node
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 pkg list
ros2 pkg executables
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 the
rosrun <package_name> <executable_name> command. With ROS2 it’s you almost don’t see any difference, given that we use
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 the
demo_nodes_cpppackage, let’s filter it with
ros2 pkg executables | grep demo_nodes_cpp.
The output will be something like:
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:
- ROS Basics in 5 days (Python): http://bit.ly/2DrzR87
- ROS Basics in 5 days (C++): http://bit.ly/2Dt3GFk
Those are online courses in the Robot Ignite Academy, where you are going to learn ROS fast using online simulations.
- ROS Development Studio (RDS): develop your ROS2 project online
- ROS2 Basics Course
- ROS Python (For beginners)
- ROS C++ (For beginners)
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.
- Click to share on Twitter (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to email this to a friend (Opens in new window)
- Click to print (Opens in new window)
- Click to share on Google+ (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Share on Skype (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to share on WhatsApp (Opens in new window)
- Click to share on Telegram (Opens in new window)