[ROS in 5 mins] 005 – What is a ROS Node?

Hello ROS Developers! In this post, we’ll see what a ROS node is in just 5 minutes! We’ll see how to launch a ROS node, what a ROS node does and some commands to get basic and extended information about ROS nodes.

Let’s go!

Step 1: Setup your development environment

To follow this post, you need a computer with ROS already installed. There are three options; I recommend the last one as it’s the easiest!

  1. You have ROS installed locally (kinetic <=  version < crystal). Great, nothing more is needed, just be ready to spin up a terminal at short notice 🙂 .
  2. You don’t have ROS installed but you have installed docker . Don’t worry, there’s a way out – run docker run -it osrf/ros:kinetic-destop in your terminal to pull a ROS docker image. Please note:
    • Docker will “pull” this image if you don’t have it locally already.
    • You need to run this command on every terminal you use in this post, before typing any other command!
  3. Neither ROS nor docker is installed? No problem – launch a ready-to-go development environment on ROS Development Studio (ROSDS) within your browser! If you don’t have an account yet, you can create a free account here. Once you log in, create a project and call it rosnode_test. In your project configuration, select Ubuntu 16.04 + ROS Kinetic + Gazebo 7. To “open a terminal”, pick the Shell app from the Tools menu.

Step 2: Run some commands to learn about ROS nodes

Open a terminal and run the following command to start roscore:

user:~$ roscore
... logging to /home/user/.ros/log/34f74d7a-4482-11e9-b7ad-06484a70109a/roslaunch-ip-172-31-44-254-32219.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://instance:35586/
ros_comm version 1.12.14


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES

auto-starting new master
process[master]: started with pid [32244]
ROS_MASTER_URI=http://instance:11311/

setting /run_id to 34f74d7a-4482-11e9-b7ad-06484a70109a
process[rosout-1]: started with pid [32273]
started core service [/rosout]

(roscore gets the ROS system started and ready to work. You can read more about it here)

Looking at the output of the command we ran above, you’ll find a section labeled NODES, and under it you’ll see the phrase started core service [/rosout]. Back up there and run the command shown below in a new terminal!

user:~$ rosnode list
/rosout

The list command shows the list of ROS nodes currently running. Now let’s get some information about the single node shown, in the same terminal:

user:~$ rosnode info /rosout
--------------------------------------------------------------------------------
Node [/rosout]
Publications:
 * /rosout_agg [rosgraph_msgs/Log]

Subscriptions:
 * /rosout [unknown type]

Services:
 * /rosout/get_loggers
 * /rosout/set_logger_level


contacting node http://instance:42806/ ...
Pid: 32273

From the output of this program we can see that node /rosout publishes to topic /rosout_agg, subscribes to topic /rosout and provides services /rosout/get_loggers and /rosout/set_logger_level.Quite some work, you might say.  In future posts we’ll learn about ROS topics, publishers, subscribers and services, but we need to get the concept of nodes now because it’s a the root of them all.

And we’re all done for this section!

Step 3: Master the concept – what is a ROS node?

You might already know it, but the output of the programs in the section above were blaring it from the speakers 🙂 .

To use the words from ROS wiki, a node is a [computer] process that performs computation. Let’s break that down:

  • A computer process…: yes, as you can see from the output of the roscore commands, two computer processes were started.
  • …that performs computation: yes, but not necessarily math! We saw that node rosout performs quite a bit of work; that’s the “computation” we’re talking about here. There was another node there, master (http://wiki.ros.org/Master). Though not listed in the list of nodes, it also “performs computation” by providing naming and registration services for other nodes.

That’s basically it! If you’ll like more theory, read more about ROS nodes at http://wiki.ros.org/Nodes.

Bonus: Video

Prefer to see the ‘sights and sounds’ version of this post? The video below is for you. Please tell us what you think about it.

Feedback

Did you like this post? Whatever the case, please leave a comment on 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/video about it.

Thank you!

[ROS IN 5 MIN] 004 – What is roscore?

[ROS IN 5 MIN] 004 – What is roscore?

Hello ROS Developers! In this post, we are going to answer the question “What is roscore”?

Our approach will be to SHOW what happens when roscore is NOT running and what happens when it is. And then we go briefly over the theory behind this. We’ll also look at the command to start roscore and what the output of this command means.

Let’s go!

Step 1: Setup your development environment

To follow this post, you need a computer with ROS already installed. There are three options; I recommend the last one as it’s the easiest!

  1. You have ROS installed locally (kinetic <=  version < crystal). Great, nothing more is needed, just be ready to spin up a terminal at short notice 🙂 .
  2. You don’t have ROS installed but you have docker installed. Don’t worry, there’s a way out – run docker run -it osrf/ros:kinetic-destop in your terminal to pull a ROS docker image. Please note:
    1. Docker will “pull” this image if you don’t have it locally already.
    2. You need to run this command on every terminal you use in this post, before typing any other command!
  3. Neither ROS nor docker is installed? No problem – launch ready-to-go development environment on ROS Development Studio (ROSDS) within your browser! If you don’t have an account yet, you can create a free account here. Once you log in, create a project. You can call it roscore_test. To “launch a terminal” in ROSDS, pick the Shell app from the Tools menu.

Step 2: Run the test

Open a terminal and type the command shown. You should get an output like the one shown below:

user:~$ rosnode list
ERROR: Unable to communicate with master!

That command was supposed to display a list of available ROS notes, not ERROR: Unable to communicate with master. Mitchew, what’s going on?

Let’s try something different: let’s display a list of ROS topics:

user:~$ rostopic list
ERROR: Unable to communicate with master!

Same thing! Okay, okay, maybe this will work. Open another terminal and run the following command:

user:~$ roscore
... logging to /home/user/.ros/log/9a7bf8ba-3b1a-11e9-b53e-0663119dbe5e/roslaunch-ip-172-31-35-10-26176.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://instance:45720/
ros_comm version 1.12.14


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES

auto-starting new master
process[master]: started with pid [26195]
ROS_MASTER_URI=http://instance:11311/

setting /run_id to 9a7bf8ba-3b1a-11e9-b53e-0663119dbe5e
process[rosout-1]: started with pid [26226]
started core service [/rosout]

Now go back and re-run the previous commands:

user:~$ rosnode list
/rosout
user:~$ rostopic list
/rosout
/rosout_agg

Great, now it’s working, but what’s the catch? Let’s check that in the theory section!

Step 3: Master the concept – what is roscore?

In the “Run the test” section, we see that we couldn’t do anything until we started roscore.  This is because it’s the node (program) that prepares the ROS system and gets it ready to work and accept commands. ROS is a centralized system, a master node (program) is always needed for other nodes and should be executed before other nodes. roscore starts this master node.

You might have noticed that our error message whined about being unable to communicate with ‘master’, and the output of the roscore program mentioned something about starting ‘master’. In the same output, you’ll also see that roscore started a core service /rosout, which is shown in the list of nodes. This /rosout service is responsible for managing ROS output, using the topics /rosout and /rosout_agg.

If you are interested and want to learn more, please check our  ROS In 5 Days (Python) course. The course explains what roscore, node, topic, service, action, etc, are, in detail.

Read more about roscore from ROS Wiki: http://wiki.ros.org/roscore.

Extra 1: Video

Prefer to see the ‘sights and sounds’ version of this post? Please see the video below and be sure to tell us what you think about it.

Related Courses

ROS Basics for Beginners (Python)

ROS-Basics-cpp course background

ROS Basics for Beginners (C++)

Extra 2: Infographic

Here is the whole roscore story in a small “flyer” that you can share with your friends for some quick learning!

Infographic:

what-is-roscore-infographic

Feedback

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

[ROS In 5 Minutes] 003 – How to create a ROS Publisher

[ROS In 5 Minutes] 003 – How to create a ROS Publisher

Hi all!

Welcome to this “ROS In 5 Minutes” videos series.

In today’s video we are going to see how to create a ROS Publisher.

But before we start, if you want to Learn ROS Fast, we recommend you the following courses:

Remember that if you prefer to watch a video, the following video covers the same content of this post.

Step 1. Create an account in Robot Ignite Academy (RIA)

The steps explained in this post can be executed in your local computer without any problem, but if you want an environment that has everything already set, we highly recommend you creating an account in RIA. The platform helps you to Learn ROS Fast in the easiest way possible, without you having to setup the ROS environment locally. The only thing you need is a web browser! If you want to try the platform, you can easily create an account here and start to browse the trial course for free now! We’ll use the ROS Basic course as an example today.

Step 2. Create a package

In order to create our publisher we first need a package. Let’s create one called tutorial under the ~/catkin_ws/src directory with the following command

cd ~/catkin_ws/src
catkin_create_pkg tutorial rospy

Then we create a file called publisher.py  under the ~/catkin_ws/src/tutorial/src  folder and insert the following content on that file:

#! /usr/bin/env python

import rospy
from std_msgs.msg import String

rospy.init_node('tutorial')

publisher = rospy.Publisher('/say_hello', String, queue_size=1)
rate = rospy.Rate(3) # 3 Hz

while not rospy.is_shutdown():
    publisher.publish('Hey!')
    rate.sleep()

Before we execute our file let’s analyze what that code does, starting with the first 3 lines:

#! /usr/bin/env python 

import rospy 
from std_msgs.msg import String

In the first line we basically tell Linux that we use Python code. In the subsequent two lines we import the required packages. The rospy package contains classes and functions that allow us to easily instantiate ROS Nodes (among other functionalities) using python. The type of message we will publish is a String , that is why we imported it. Let’s analyze the remaining code.

rospy.init_node('tutorial') 

publisher = rospy.Publisher('/say_hello', String, queue_size=1) 
rate = rospy.Rate(3) # 3 Hz

With rospy.init_node(‘tutorial’)  we basically initialize our ROS Node and call it tutorial. A ROS Node can have the name you want, as far it doesn’t contain spaces. If you choose a name of a node that already exists, then ROS will automatically kill the existing one when you launch yours. Be aware of that.

After initializing our node we create our publisher. In the first parameter of rospy.Publisher we provide name of the topic in which we want to publish. If you don’t know yet what is a Topic, please check our other posts or take our ROS In 5 Days (Python) course that explains that and also shows you how to create publishers, subscribers, services, actions, how to use debugging tools, etc. Now, back torospy.Publisher , in the second parameter we specify the type of message we want to publish in that topic, which in this case is String. The third parameter is the queue_size, which specify the amount of messages that will be queued before the messages are dropped if not consumed.

The rate variable we created is because we want to publish 3 messages per second. Let’s now check the last part of our code:

while not rospy.is_shutdown(): 
    publisher.publish('Hey!')
    rate.sleep()

The line while not rospy.is_shutdown(): is to keep our node publishing messages while roscore is running. If somehow roscore is killed, our ROS Node just finishes. This way, whoever is running our code won’t have to manually kill our node, which is really useful in case you have hundreds of nodes, really common on real robots.

Inside the while block we publish our message. In this example we publish the message Hey!. You can publish any message, like Congratulations YOU_NAME, you have your first ROS Publisher working.

To make sure we publish 3 messages a second we use rate.sleep().

With everything in place, it’s time to run our node. You have to make sure your file is executable. Let’s do that with the following commands:

cd ~/catkin_ws/src/tutorial/src
chmod +x publisher.py

rosrun tutorial publisher.py

In Robot Ignite Academy you already have a roscore running and if you are using the platform, your code should have been executed without any problem. If you are running it on your own computer, you must run roscore in a separated shell (or run it in background with roscore & before actually running your node.

Assuming your node is running, you shouldn’t see any message because we are not printing any, but you can check that your node is running by executing the command below in a separated shell:

rosnode list

That command shows the list of nodes running in your ROS environment. You should see a node called /tutorial, which is the name we gave to our node.

To make sure your publisher is publishing on the correct topic, you can use the command below to list the topics.

rostopic list

You should see a topic called /say_hello because it is what we defined when creating our publisher.

Now, in order to see the messages that are being publishing we just run the command below:

rostopic echo /say_hello

You should see the messages being printed.

That is all for today guys. I hope you have liked the post and the video, if so, please share this post or the video with your friends.

Whether you like the video or not, please leave a comment on the comments section of the video on YouTube.

Keep pushing your ROS Learning.

 

Edit by: Tony Huang and Ruben Alves

[ROS In 5 Minutes] 002 – How to create a ROS Package

[ROS In 5 Minutes] 002 – How to create a ROS Package

Hi all,

welcome to this “ROS In 5 Minutes” videos series.

In today’s video, we are going to see how to create a ROS Package.

But before we start, if you want to Learn ROS Fast, we recommend you the following courses:

ROS In 5 Days (Python) 
ROS In 5 Days (C++)

Either you like the video or not, please leave a comment on the comments section below, so we can interact and learn from each other.

Step1. Create a project in Robot Ignite Academy(RIA)

We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now! We’ll use the ROS Basics in 5 Days course as an example today.

Step2. Create a ROS Package

You can see the help about the catkin_create_pkg by passing the “-h” parameter: catkin_create_pkg -h

To create your package in the catkin_ws/src folder with the command catkin_create_pkg +package name +package dependencies. For example,

catkin_create_pkg tutorial rospy std_msgs

Here we create a package called tutorial with the dependencies rospy and std_msgs because we want to use the python api and std_msgs package.

After that, ROS will create a package for you. Inside the package, you’ll find the package.xml and CMakeLists.txt which will help you to compile the package.

You can compile them with the catkin_make command.

But sometimes when you create a package, ROS is not able to find it “instantly”. If this happens, just type source devel/setup.bash  to source the file.

Want to learn more?

If you are interested in this topic please visit our ROS In 5 Days (Python)  course. You’ll learn how to create workspace, package, topic, service, and action in this course.

 

Edit by: Tony Huang

Pin It on Pinterest