ROS introduction
You can run this tutorial on:
"The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms." - according to the official ROS webpage.
We prepared a set of tutorials to help you start building advanced robots. They are prepared to work with Husarion ROSbot 2.0 but they are also a valuable portion of knowledge for anybody interested in ROS.
System structureβ
ROS is a software suite which allows for quick and easy building of autonomous robotic systems. ROS should be considered as a set of tools for creating new solutions or adjusting already existing ones. A major advantage of this system is a great set of drivers and implemented algorithms widely used in robotics.
Nodesβ
Base unit in ROS is called a node. Nodes are in charge of handling devices or computing algorithms - each node for separate task. Nodes can communicate with each other using topics or services. ROS software is distributed in packages. Single package is usually developed for performing one type of task and can contain one or multiple nodes.
Topicsβ
In ROS, topic is a data stream used to exchange information between nodes. They are used to send frequent messages of one type. This could be a sensor readout or motor goal speed. Each topic is registered under the unique name and with defined message type. Nodes can connect with it to publish messages or subscribe to them. For a given topic, one node can not publish and subscribe to it at the same time, but there is no restrictions in the number of different nodes publishing or subscribing.
Servicesβ
Communication by services resemble client-server model. In this mode one node (the server) registers service in the system. Later any other node can ask that service and get response. In contrast to topics, services allow for two-way communication, as a request can also contain some data.
Basic toolsβ
While working with ROS there are some tools that are most useful. They are intended to examine nodes and topics.
rosnodeβ
Rosnode is a command line application for examining which nodes are registered in the system and also checking their statuses.
Using the application looks as follows:
rosnode command [node_name]
Command could be:
list
- display list of running nodesinfo
- display info regarding selected nodekill
- stop selected node
Detailed info could be found in ROS documentation.
rostopicβ
Rostopic is a command line application for examining which topics are already being published and subscribed, checking details of the selected topic or reading messages being sent in it.
Using the application looks as follows:
rostopic command [topic_name]
Command could be:
list
- display list of topicsinfo
- display info regarding selected topicecho
- display messages published in the topic
Detailed info could be found in ROS documentation.
rqt_graphβ
rqt_graph
is graphical tool for visualization of data flow across different nodes
in the system.
Using the application looks as follows:
rqt_graph
Robot platformβ
This tutorial is created for ROSbot, open-source robot platform. You can read more about it here: ROSbot 2.0 & ROSbot 2.0 PRO.
The platform contains:
- 1 Γ Husarion CORE2-ROS
- 1 Γ RPLIDAR A2/A3 360Β°
- 1 x RGBD camera Orbbec Astra
- 1 Γ BNO055/MPU9250
- 4 Γ VL53L0X Time-of-Flight Distance Sensor
And this is how it looks like:
You can also go through ROS tutorials using ROSbot 2.0 simulation model in Gazebo environment instead of physical robot. It is available here, at our GitHub page.
Another option is to use virtual machine or ROS native installation, this requires Ubuntu 18.04 operating system and you will have to install ROS with Gazebo according to this guide. Native installation but will offer much better performance camparing to virtual machine.
You can also try online simulator at www.theconstructsim.com, it comes with all required packages installed and offer great computing power for a reasonable price.
Another option to run a simulation model is using AWS Robomaker.
We also created package with all nodes and launch files from our ROS tutorials. You can download ready to use pkg from GitHub page.
ROS and CORE2 Work flowβ
According to the method of your choice, proceed to section Connecting to ROSbot or Starting Gazebo.
Connecting to ROSbotβ
Before you start working with ROS on ROSbot 2.0 platform, you need to connect to
your device first. You can establish connection in two ways: using ssh
or via
remote desktop. For both methods you need an IP address of your robot. You can check it using one of methods described in ROSbot - quick start tutorial.
To connect by ssh type in terminal:
ssh husarion@xxx.xxx.xxx.xxx
password is: husarion
To connect via remote desktop you need a remote desktop client application. Depending on your system, you may have various clients.
Parameters for connection are the following:
protocol | `rdp` |
server | `xxx.xxx.xxx.xxx` |
username | `husarion` |
password | `husarion` |
If you are working on Windows, press WinKey + r
then type mstsc
.
You will see a window appear:
Type in your device IP address and click connect
. If you are working on
Mac, you can use Microsoft Remote Desktop available at AppStore.
If you are working on Ubuntu, you can use Remmina.
The first step in working with ROS is to run master process called roscore. This node handles registration of other nodes, topics and services. After this step is complete you can run your nodes.
To start the master process you can use command:
roscore
Starting Gazeboβ
To start using Gazebo with ROSbot model you need to download our package with model and configuration files to ROS workspace directory. Meaning and structure of workspace will be discussed later, now you will just create it with:
mkdir -p ~/ros_workspace/src
cd ~/ros_workspace/src
catkin_init_workspace
sudo apt update
git clone https://github.com/husarion/rosbot_description.git
cd ~/ros_workspace
rosdep install --from-paths src --ignore-src -r -y
catkin_make
source devel/setup.sh
From now your system is ready to run Gazebo with ROSbot. To start simulator use command:
roslaunch rosbot_description rosbot.launch
Starting system step by stepβ
You can start ROS nodes by typing name of each node manually.
To do it you can use the following command:
rosrun package_name node_type [options]
Package_name and node_type are names of package and node that you want
to run. rosrun
executes node in the terminal and outputs text logs to the screen. To start multiple nodes simultaneously use roslaunch
. You will learn about this tool soon.
Defining node nameβ
If you want to bind specific identifier to a node, at the end of the command, add:
__name:=new_node_name
Note that there are two underscores before the name. If you want to learn more about naming convention used by ROS see this docs.
Setting parameterβ
You can also set parameter value by adding:
_param:=value
Note that there is an underscore before the parameter name.
To find what kind of parameters you can set, and what type of data is accepted, check documentation for exact node.
Remapping topic nameβ
If you want to change the name of the topic subscribed or published by a node, you can use remapping option. In order to do it, at the end of the command, add:
old_topic_name:=new_topic_name
Note that there is no underscore before the old name.
Starting system step by step - Exampleβ
In this section, we will set up ROS system that is equipped with a Orbbec Astra camera and show image from camera on display. Use remote desktop client of your choice to connect to your ROSbot. You can also follow the tutorial in simulation mode using Gazebo and Husarion VM mentioned before.
Starting masterβ
We will begin with master by typing in the following code in the ecommand line:
roscore
You should see something like this:
Now you can use tools from chapter 2 in order to examine your system, donβt worry that you didnβt start any node yet.
Examining nodesβ
Letβs begin by checking the list of existing nodes. In the new terminal type in:
rosnode list
As the output you should get:
husarion@husarion:~$ rosnode list
/rosout
This means, that you have now one node running which name is /rosout
and it is responsible for handling console log mechanism.
Next you can check some info about this node:
rosnode info /rosout
And as the output you should get:
husarion@husarion:~$ rosnode info /rosout
-------------------------------------
Node [/rosout]
Publications:
* /rosout_agg [rosgraph_msgs/Log]
Subscriptions:
* /rosout [unknown type]
Services:
* /rosout/set_logger_level
* /rosout/get_loggers
contacting node http://husarion:48067/ ...
Pid: 4594
You can see here that node /rosout
is publishing to topic
/rosout_agg
, subscribing topic /rosout
and offering two services:
/rosout/set_logger_level
and /rosout/get_loggers
.
Examining topicsβ
Now we will check what topics are registered in the system and receivee some info about them. In new console type in:
rostopic list
You should get in the output:
husarion@husarion:~$ rostopic list
/rosout
/rosout_agg
This means that you have two topics registered in the system. Letβs get some info about first of them:
rostopic info /rosout
As the output you should get:
husarion@husarion:~$ rostopic info /rosout
Type: rosgraph_msgs/Log
Publishers: None
Subscribers:
* /rosout (http://husarion:33119/)
From that you can read, that via topic /rosout
only messages of type rosgraph_msgs/Log
can be transmitted, there is no node that publishes to this topic and node /rosout
subscribes it.
Now, leet's try to get similar info about the second topic:
rostopic info /rosout_agg
As the output you should get:
husarion@husarion:~$ rostopic info /rosout_agg
Type: rosgraph_msgs/Log
Publishers:
* /rosout (http://husarion:33119/)
Subscribers: None
From that you can read, that via topic /rosout_agg
only messages of type rosgraph_msgs/Log
can be transmitted, node /rosout
publishes to this topic and there is no node that subscribes it.
Starting camera nodeβ
If you are using simulator, you can skip this section, as the driver for camera will not be necessary.
Now you will run few nodes for handling Astra camera device. For this task you should use astra.launch
from package astra_launch
because this is the default camera installed in ROSbot.
We will explain how launch
file works later.
You can start camera nodes by typing in the terminal:
roslaunch astra_launch astra.launch
As output you should get something like below:
Task 1
Use rosnode
and rostopic
tools to check if new nodes or
topic appeared in the system. Next find some info regarding new node and
topics.
Starting image view nodeβ
Now you have camera node running, but can not see image from it yet. You will use node image_view
from image_view
package. This node by default subscribes to topic image
. You need to remap this name to topic published by the camera node. If you performed task 1, you should know that astra nodes are publishing to many topics. To run image view node with remapping topic name type in the terminal:
rosrun image_view image_view image:=/camera/rgb/image_raw
As the output you should get:
Note for simulator: Simulated environment consist of simple objects (plains, boxes etc.), due to this, image from camera will consist of simple shapes like triangles or rectangles.
Task 2
Use rosnode
and rostopic
tools to check what changed in
the system after running another node. Notice what changed in properties
of /camera/rgb/image_raw
topic.
Examining system with rqt_graphβ
Now you will use rqt_graph
tool in order to get graph of data flow in
the system. In new terminal type in:
rqt_graph
There will be no response in the terminal, but new window will appear. In upper left corner change "Nodes only" option to "Nodes/Topics (active)". You will see:
Interpretation of the graph is as follows:
Ovals represent nodes
Rectangles represent topics
Big rectangles containing other elements represent namespace (shared part of the name)
Arrows pointing from node to topic represent publication to this topic
Arrows pointing from topic to node represent subscription to this topic
Starting system with roslaunch
β
Roslaunch
is a tool that simplifies running of multiple nodes at the samee
time. This tool uses .launch
files which contain configuration of all
nodes to be run. Usage of roslaunch
is simple. In the new terminal type in:
roslaunch package file.launch
or
roslaunch file.launch
The first one is for the case when you use launch file provided with the package- you can run it from any folder. The second option is when you use standalone launch file- you must run it in the folder where the launch file is located or point the path to it.
Structure of .launch fileβ
Structure of .launch
file is defined in a markup language derived from XML and similar to
HTML. Content of the .launch
file is inserted between the start and end tags: <launch>...</launch>
(root element). Other elements including those that define nodes should be placed between them.
You can define node using node
element:
<node pkg="package_name" type="node" name="id" required="true" output="screen">
</node>
Where fields pkg
, type
and name
are required, rest are optional.
Meaning of each field:
pkg
- name of the epackagetype
- node to be runname
- id which will be binded to the noderequired
- if true, all nodes in the.launch
file will be stopped if this node stops or fails, default value is false.output
- if value isscreen
node output will be directed to screen, if value islog
output will be directed to log file, default is log.
For each node parameters can be set or topics can be remapped.
For setting parameters use element param
:
<param name="name" value="value"/>
Meaning of the fields:
name
- name of the parametervalue
- desired value of the parameter
For remapping the topic names use element remap
:
<remap from="/old" to="/new"/>
Meaning of the fields:
from
- old topic's nameto
- desired topic's name
Starting system with roslaunch
- Exampleβ
In this section we will start the same nodes as in previous example, but
this time with use of roslaunch
tool.
At first you will need a .launch
file.
<launch>
<arg name="use_gazebo" default="false"/>
<include unless="$(arg use_gazebo)" file="$(find astra_launch)/launch/astra.launch"/>
<include if="$(arg use_gazebo)" file="$(find rosbot_description)/launch/rosbot.launch"/>
<node pkg="image_view" type="image_view" name="image_view">
<remap from="/image" to="/camera/rgb/image_raw"/>
</node>
</launch>
Copy the above code to text editor (and other parameters if needed) and save it to file tutorial_1.launch
in your home directory.
Next, close all consoles and nodes that are already running, go to new terminal and, if working on ROSbot, type in:
roslaunch tutorial_1.launch
In case of working with Gazebo:
roslaunch tutorial_1.launch use_gazebo:=true
You should get output like this:
Notice that you do not need to run roscore
before using roslaunch
,
if roscore
is not running already, roslaunch
will run it before
starting nodes.
Task 3
Use rosnode
, rostopic
and rqt_graph
tools to examine system started with use of roslaunch
, there should be
no difference in comparison to the esystem started step by step.
Summaryβ
After completing this tutorial you should know what are the basic components and tools of ROS. You should know two methods for starting a node, setting parameters and remapping topic names. You should be able to check what nodes are running in system and to which topics they are publishing and subscribing.
by Εukasz Mitka, Husarion
Do you need any support with completing this tutorial or have any difficulties with software or hardware? Feel free to describe your thoughts on our community forum: https://community.husarion.com/ or to contact with our support: support@husarion.com