In this video, we will see how to launch a ROS node in just 5 minutes. We’ll see four different way nodes can be launched in ROS, and how to check that a node has been launched:
* rosnode list
If you are a ROS beginner and want to learn ROS basics fast, we recommend you take any of the following courses on Robot Ignite Academy:
Start a Tools > Shell and start the roscore with following command
$ roscore
This command starts the roscore. If the roscore is already running then it shows a warning message with roscore ip address information (as shown in green box in image)
The roscore starts as a node called /rosout. We can check the node with rostopic list command in another Shell
One way to launch a rosnode is using the rosrun command. For example
$ rosrun turtlesim turtlesim_node
This command will start the following nodes
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
We can verify these nodes with rostopic list command in a new window
Next we will see about running a custom node. We will create a project using catkin_create_pkg command. Then we will create a python script with following contents
#! /usr/bin/env python
import rospy
rospy.init_node('Obiwan')
rate = rospy.Rate(2)
while not rospy.is_shutdown():
print("Help me Obi-wan Kenobi, you're my only hope")
rate.sleep()
## This program creates an endless loop that repeats itself 2 times per second
Next we will launch the script with the following command
$ rosrun node_demo simple.py
We can check if the node is running or not with rostopic list command in a new shell
Now we will see how to run several nodes at the same time. This is done with the help of launch files and roslaunch command. For example:
$ roslaunch openni_launch openni.launch
This command will launch various nodes that can be listed with the rostopic list command.
If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.
Whether you like the video or not, or if you want to learn about specific ROS subjects, please leave a comment on the comments section below, so we can interact and learn from each other.
Follow these steps to recreate the project as shown in the video
Go to Robot Ignite Academy. You will need to signup if you have not registered already.
In the home page, choose the course ROS Autonomous Vehicles 101 in the Advanced Courses category
Once you start the course, you will be greeted with the workspace like following (note: it will take a while to load the full page)
Now we will use the rosrun command to start a rqt_image_view node. Enter the following command in one of the SHELLS
rosrun rqt_image_view rqt_image_view
In order to see the visualisation we need to open the Graphical View by clicking on the graphical tool icon shown in the previous image. The graphical view opens in a new tab like follows
Since the model we are using (autonomous car) has many camera topics, we will need to choose one from the drop-down in the graphical view (shown in image).
rosrun essentially lets us start a single node. However, in many cases one needs to start multiple nodes at a time. To do this (launching multiple nodes simultaneously) we have launch file and the roslaunch command. Lets create such a launch file to launch xyz. Navigate to ~/catkin_ws/tuto/src/ and create a launch directory and create a file inside this directory launch_rviz.launch. Use the following command to achieve this
$ cd ~/catkin_ws/src/tuto/ $ mkdir launch
$ cd launch
$ touch launch_rviz.launch
Next, we will add the following content to this file using the cloud9 editor. Use the editor to browse to the file and then double click on the file name to open it (as shown in image)
Whether you like the video or not, or if you want to learn about specific ROS subjects, 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 Mastering with ROS: TIAGO course as an example today.
Step2. What is rosrun and how it works?
At first, let’s try the command directly! Please type rosrun key_teleop key_teleop.py in the shell. You can move the robot with the arrow key now. If you type rosrun -h , you’ll see how you can use this command. The command will try to find the executable in the given package and execute it. If you go to the package directly, you can of course execute the executable with ./ command. The rosrun , however, offers you a much faster way to find your executable located in different packages.
Want to learn more?
If you are interested in this topic, please visit our ROS In 5 Days (Python) course. You’ll learn not only how to create the workspace, but also packages, topic, service, and action in ROS.
Whether 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 Basic course as an example today.
Step2. Create package
Let’s create a package called tutorial first with the following command
cd ~/catkin_ws/src
catkin_create_pkg tutorial rospy
Under the tutorial/src folder, create 2 files called publisher.py and subscriber.py.
#! /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()
#! /usr/bin/env python
import rospy
from std_msgs.msg import String
rospy.init_node('subscriber')
def callback(data):
print 'Subscriber received a msg: ', data.data
sub = rospy.Subscriber('/say_hello', String, callback)
rospy.spin()
Remember to give execute permission to the file with chmod +x command. Then you can run the file with rosrun command. However, it’s not quite convenient, right? What if you want to run several files at the same time?
That’s why we need launch files. Let’s create one called pub_sub.launch under the tutorial/launch folder with the following content.
Then we can run it with roslaunch tutorial pub_sub.launch . You can see a launch file is a powerful tool for us to launch multiple files in one single file.
If you want to learn more about this topic, please check our ROS In 5 Days (Python) course. You’ll learn much more about what launch files can do in this course.
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!
You have ROS installed locally (kinetic <= version < crystal). Great, nothing more is needed, just be ready to spin up a terminal at short notice 🙂 .
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!
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:
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.
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!
You have ROS installed locally (kinetic <= version < crystal). Great, nothing more is needed, just be ready to spin up a terminal at short notice 🙂 .
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:
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!
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.
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 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:
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!