[ROS2 in 5 mins] 004 – What is a ROS2 node? ROS1 and ROS2 nodes compared

[ROS2 in 5 mins] 004 – What is a ROS2 node? ROS1 and ROS2 nodes compared

Hello ROS enthusiasts!

In this post, we’ll see what a ROS(2) node is, and the similarities and differences between ROS1 and ROS2 nodes. We’ll do this using both practicals and theory, practicals first!

Let’s go!

Setup for the practicals

I believe passionate engineers like to get their hands dirty as much as they like to have solid theoretical foundations. And, since I get to decide here ?, we’ll start with the latter.

Now, the required setup for practicals (installation of ROS and other packages) can take a lot of time but, thankfully, we have an easy way out – ROSDS. With this online tool, you will have access to ROS-ready computers (both ROS1 and ROS2) within your browser in a few seconds. If you don’t have one already, you can create a free account here.

PS:

  1. When you create a project (ROSject) on ROSDS, be sure to select the Ubuntu 16.04 + ROS Kinetic + Gazebo 7 configuration.
  2. If you have access to local installations of ROS1 and ROS2, and you don’t want to embrace the online revolution yet, then you can also use your local installations.
  3. When I say ‘terminal’ in this post, that means picking the Shell app from the ROSDS Tools menu or opening a terminal on your local PC.

Practicals – ROS nodes in action

For a practical-oriented topic, we’ve had enough theory already; let’s get down to it and see ROS nodes in action! Fire up a terminal and run the command that displays a list of nodes in ROS1. Your output might be different, but you should have a list of items like this:

user:~$ rosnode list
/rosapi
/rosbridge_websocket
/rosout
/web_video_server

Take note of the items listed above and then run the following command in another terminal:

user:~$ rosrun turtlesim turtlesim_node
[ INFO] [1548414518.301208787]: Starting turtlesim with nodename /turtlesim
[ INFO] [1548414518.309271531]: Spawning turtle [turtle1] atx=[5.544445], y=[5.544445], theta=[0.000000]

To see the turtle on ROSDS, pick the Graphical Tools app from the Tools menu to see your cute turtle:

Well done! Now go back to the previous terminal and re-run the command that displays a list of nodes in ROS1. Now you should see an extra node (“/turtlesim”) in your list.

user:~$ rosnode list
/rosapi
/rosbridge_websocket
/rosout
/turtlesim
/web_video_server

So far so good, but all that is ROS1, so now let’s #goROS2! In another terminal, run the command shown. That should bring up a ROS2-ready docker machine, waiting for your command:

user:~$ docker run -it osrf/ros2:bouncy-desktop
Unable to find image 'osrf/ros2:bouncy-desktop' locally
bouncy-desktop: Pulling from osrf/ros2
...
root@43a5e0d0c74c:/#

As we also need two terminals for the ROS2 “tinkertoons”, spin up a second terminal and run the same command as above. In the first ROS2 terminal run the following commands that display the list of nodes in ROS2. Observe the outputs (the -a switch shows hidden nodes).

root@43a5e0d0c74c:/# ros2 node list
root@43a5e0d0c74c:/# ros2 node list -a
_ros2cli_node_daemon_0

Basically, no user-created node is running now. Let’s change that: in the second ROS2 terminal, run:

root@e12db20394fb:/# ros2 run demo_nodes_cpp talker
[INFO] [talker]: Publishing: 'Hello World: 1'
[INFO] [talker]: Publishing: 'Hello World: 2'
[INFO] [talker]: Publishing: 'Hello World: 3'
[INFO] [talker]: Publishing: 'Hello World: 4'

Now get back to the first ROS2 terminal and rerun the last command. You should see an addition node (talker) displayed, thanks to the talker(tive) program we just ran:

root@43a5e0d0c74c:/# ros2 node list -a
_ros2cli_node_daemon_0
talker

And we are all done for the practicals! But what’s the catch? At this point, we could use some theory. Next!

So, what is a ROS(2) node?

Let’s hear from the horse’s mouth:

A node is a process that performs computation. – http://wiki.ros.org/Nodes

A node really isn’t much more than an executable file within a ROS package. ROS nodes use a ROS client library to communicate with other nodes.  – http://wiki.ros.org/ROS/Tutorials/UnderstandingNodes

As we saw from the practicals, the turtlesim_node and talker executables displayed a turtle and some text on-screen, respectively, by performing computations and communicating with other nodes. For one, they both communicated with nodes responsible for displaying output. So, in both ROS1 and ROS2, a node is essentially the same thing.

Done. Now you know what a ROS(2) node is. We’ll examine the similarities and different between ROS1 and ROS2 nodes in the next section.

ROS1 and ROS2 nodes compared

From the previous sections, we’ve already seen that ROS1 and ROS2 nodes are essentially the same. You may also have seen from the practical session that the commands for running and displaying a list of nodes in ROS1 and ROS2 are similar, even if they are not the same.

In this section, we’ll look briefly at some fundamental similarities and differences between ROS1 and ROS2 nodes. The table below summarizes these. Black text represents similarities while red text represents differences.

ROS2 node ROS1 node
 What is it? An executable using ROS2 to communicate with other nodes An executable using ROS1 to communicate with other nodes
(De)advertises itself and discovers other nodes using… A distributed discovery process (which does not depend on a single node) The ROS1 Master (a single node)
After discovery, communicates with other nodes… Peer to peer Peer to peer
Uses these client libraries (among others) rclcpp = C++ client library
rclpy = Python client library
roscpp = C++ client library
rospy = Python client library

And that’s it!

Summary

ROS nodes are the executables that make things happen in a ROS system, and they are essentially the same for both ROS1 and ROS2, even if there are some differences. If you’re already familiar with ROS1, you can hit the ground running with ROS2, with just a few differences to master.

Video Version

If you prefer see the audio-visual version of this post, we’ve got you covered. Just click to watch the video below.

Feedback

Did you like this post? Whatever the case, please leave a comment in the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a post or video about it.

Keep pushing your ROS(2) learning!

Where is roscore in ROS2?

Where is roscore in ROS2?

Hello ROS developers! In this post, we’ll find out what happened to roscore in ROS2 and how similar functions of the ROS1 master were implemented in ROS2. Sit back and get ready to have some fun!

In order to approach this theory-like topic with as much practical as possible, this post has two main sections:

  1. Some tinkering with a ROS2 installation. This is the real fun part: trying to find roscore in ROS2.
  2. Some theory. As this might be a little boring, so we’ll keep it short and sweet!

Section 1: Trying to find roscore in a ROS2 installation

Since ROS2 arrived in town, there has been a rumour going round that “roscore is missing”! But don’t take anyone’s word for it; let’s find out for ourselves. Shall we?

We need a functional ROS2 installation for this. We will use one of the awesome Docker images of ROS2 provided by the Open Source Robotics Foundation (OSRF), to keep it easy for everyone and make sure we can tinker with ROS2 without committing too much time to installing it (yet). Choose any of the following options:

  1. Spin a free ROS development environment at ROSDS. With this, you skip all installations; just a few clicks and you will have access a ROS-ready computer within your browser. This is the recommended option.
  2. You have docker installed on your local development machine. Please note that a ROS2 installation is not necessary since we’re using a docker image, but if you have ROS2 installed already you may choose to use it instead of the docker image.

We are using option 1 for this post.  It’s about time we skipped local installations and start developing within our browsers, but I digress.

Now is time for action: fire up a terminal on your machine and get ready to shoot some commands at it! Our first task is spinning up the ROS2 docker installation:

user:~$ docker run -it osrf/ros2:bouncy-ros-core
Unable to find image 'osrf/ros2:bouncy-ros-core' locally
...

root@d213f10c91f9:/#

You should get something like the above, ending with a prompt that grants access to the ROS2 docker machine. Now type the following commands and study the output.

root@d213f10c91f9:/# roscore
bash: roscore: command not found
root@d213f10c91f9:/# ros2core
bash: ros2core: command not found
root@d213f10c91f9:/# ros2 core
usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: argument Call `ros2 <command> -h` for more detailed usage.: invalid choice: 'core' (choose from 'daemon', 'extension_points', 'extensions', 'launch', 'lifecycle', 'msg', 'node', 'param', 'pkg', 'run', 'service', 'srv', 'topic')
root@d213f10c91f9:/# ros2 master
usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: argument Call `ros2 <command> -h` for more detailed usage.: invalid choice: 'master' (choose from 'daemon', 'extension_points', 'extensions', 'launch', 'lifecycle', 'msg', 'node', 'param', 'pkg', 'run', 'service', 'srv', 'topic')

You may want to try other commands to find roscore in ROS2, but I’m done here. ?

Conclusion: could not find roscore in ROS2The rumour appears true after all.

But what happened to roscore – it was the “core” of ROS, so now what? Let’s find out in the next section.

Section 2: ROS2 – ending the ROS “slave trade”

“Hey, are you saying the people of ROS engaged in slave trade?!” Of course not! It’s just a fun way of describing how ROS1 worked. Relieved? ?

So let’s break the news here: roscore is dead in ROS2. It was killed, buried for good, and replaced by a better system. Here are some highlights:

  • In ROS1, roscore is the master node. Other nodes depend on it. But in ROS2, no more “master” (and “slaves”). Exit roscore. Enter DDS (Data Distribution Service).
  • In ROS1, roscore drives a client/server (or slave/master) architecture. For ROS2, DDS drives a distributed architecture.
    • Peer-to-peer communication (not master-slave :D). This sounds more democratic, doesn’t it?
    • No more single point of failure (fault tolerance). roscore can hold other nodes to ransom in ROS1, but no node can do that in ROS2.
    • Configurable Quality of Service (QoS). ROS1 provides a “best effort” service, but in ROS2 we can set the QoS required for a specific use case.
  • ROS2 also uses DDS for serialization and transport, in addition to “discovery”, which was the main function of roscore in ROS1.
  • You can read more about DDS here.

In short, in ROS2, DDS is the new Sherrif in town; roscore has been fired!

Wrapping up

You still have your terminal open? Great, let’s see an example of how one of the core functions performed by roscore is ROS1 is now done in ROS2:

root@d213f10c91f9:/# ros2 node list -a
_ros2cli_node_daemon_0

The command above “finds existing nodes, including hidden ones”. In ROS1,  roscore, which was a single node, used to rule this space. But no more in ROS2!

Video

Do you prefer to see this post in “audio and video” instead of “black and white”? If yes, the video below is for you. Enjoy!

We want to hear you!

Did you like this post? Whatever the case, please leave a comment in the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, then please let us know on the comments area and we will do a post or video about it.

Keep pushing you ROS2 learning!

RDP 017: ROS 2 and DDS for IoT devices with HaoChih Lin

RDP 017: ROS 2 and DDS for IoT devices with HaoChih Lin

In this episode, HaoChih uses ROS 2 and DDS to create IoT products based on ROS 2 while working at ADLink Technology.

He will explain some solutions he has been creating while at ADLink like:

* Adlink_DDS bot

* Adlink Neuron bot system

How they use DDS and ROS 2 for ARM based robotic solutions.

He will also talk about his Hypha ROS workshop organized last year in Taiwan.

HaoChih ROS 2 DDS ADlink ROS Developers Podcast

HaoChih LIN

Selected quote from the interview:

We use industrial computers with ROS 2 and DDS and we use it to control two different Turtlebots

—-Haochih Lin

[irp posts=”9806″ name=”ROS Developers LIVE-Class #24: How to create basic markers in ROS Rviz”]

Related links:

Subscribe to the podcast using any of the following methods

RDP 012: Everything about ROS2 with Dirk Thomas

RDP 012: Everything about ROS2 with Dirk Thomas

Hi ROS Developers and welcome to the ROS Developers Podcast: the program, the podcast that gives you insights from the experts about how to program your robots with ROS.

In this episode, I talk to Dirk Thomas about ROS2 and some other details about development tools of ROS 1.

He will explain about:

  • Why roscd bring us to the devel directory instead of to the compilation directory.
  • Why they decided to change from rosbuild to catkin_make
  • What can be used ROS buildfarm for
  • Why ROS2 is necessary
  • How to use the ros1_bridge to connect ROS1 programs with ROS 2 ones
  • Some examples of ROS2 applications already working
  • What is the ROS2 roadmap
  • … and many more things

Selected quote from the interview:

With ROS2, the communication protocol is DDS which allows a completely distributed system. The main advantage is that you don’t have a central instance being the unique point of failure.

Dirk Thomas

Dirk Thomas talks about ROS2 for the ROS Developers Podcast

Dirk Thomas talks about ROS2 for the ROS Developers Podcast

[irp posts=”11803″ name=”ROS2 vs ROS1? Or more like ROS2 + ROS1?”]

Related links:

Subscribe to the podcast using any of the following methods

ROS 2 vs. ROS 1 : Which One Is Better For Me?

ROS 2 vs. ROS 1 : Which One Is Better For Me?

ros1-vs-ros2

If you want to learn more about the differences betwwen ROS 1 and ROS 2, you can find more information on the links below:

If you want to start learning ROS 1, you can learn through the following resources:

If you want to start learning ROS 2, you can learn through the following resources:

Pin It on Pinterest