ROS Tutorial
ROS Tutorial
LAAS-CNRS
Robotics, Action and Perception (RAP) group
ROS Tutorial:
Robotics Operation System
Author:
Antonio Marin-Hernandez
1 ROS Installation 1
1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Environment Setup . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.1 Creating a Workspace . . . . . . . . . . . . . . . . . . 2
iii
iv CONTENTS
6 References 21
Chapter 1
ROS Installation
1.1 Requirements
Depending on your OS, the installation of ROS requires different packages
and dependencies, as example:
1.2 Installation
Along this tutorial ROS Kinetic and Ubuntu 16.04 (Precise) are preferred,
so here are instructions to install on this particular distribution.
To begin with the installation, first of all, setup your computer to accept
software from the site: packages.ros.org. ROS Kinetic ONLY supports
Wily and Xenial distributions. However, you can install another ROS ver-
sion following instructions on the web, Melodic is then prefered.
We begin adding the ROS repository by the following instruction:
$ sudo sh -c ’echo "deb http://packages.ros.org/ros/ubuntu $(
lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.
list’
1
2 CHAPTER 1. ROS INSTALLATION
\begin{lstlisting}
$ sudo apt update
To install this tool and other dependencies for building ROS packages,
run:
sudo apt install python-rosdep python-rosinstall python-rosinstall
-generator python-wstool build-essential
Before you can use ROS, you will need to initialize rosdep.
rosdep enables you to easily install system dependencies for source you
want to compile and is required to run some core components in ROS.
sudo apt install python-rosdep
from now, the directory my_workspace (without src directory) will be your
workspace and be referred as </path/to/your/workspace>.
This path will be the root from where ROS will search to find your
projects. In order to access by ROS commands, it should be initiated. To
do it, in your workspace execute following lines in your terminal:
1.3. ENVIRONMENT SETUP 3
source <path/to/ros/install>/setup.bash
Even though the workspace is empty (there are no packages in the ’src’
folder, just a single CMakeLists.txt link) you can still "build" the workspace:
cd <path/to/your/workspace>
catkin_make
and type
roscd
In this section, we will discuss about initial concepts and tools to query
system and/or communicate between modules (nodes) in ROS.
5
6 CHAPTER 2. BEGINNING WITH ROS
2.2.1 rosversion
The rosversion command tool, is used to recover current version in your
system, by running the following command, you should get:
$ rosversion -d
kinetic
unless you are using another ROS distribution (i.e. groovy or fuerte)
2.2.2 roscd
roscd will locate you at your ROS workspace:
$ roscd
$ pwd
<path/to/your/workspace>/devel
2.2.3 rospack
You can find the path where a package is installed by:
$ rospack find <package>
<the/path/to/package>
2.2.4 rosmsg
Depending on your installed packages different types of messages can be
provided. It’s possible to list all types of messages installed by running the
following command:
$ rosmsg list
geometry_msgs/Point
geometry_msgs/Point32
geometry_msgs/PointStamped
geometry_msgs/Polygon
...
2.2.5 rostopic
In another terminal write the following command:
$ rostopic list
/rosout
/rosout_agg
ROS includes a physics based simulation engine called Gazebo, initially de-
veloped in conjunction with the Player/Stage project.
Gazebo in ROS is considered as a node, offering different topics and
services.
3.1 Requirements
To successful do this section it is required the following ROS packages:
gazebo_ros
turtlebot_bringup
turtlebot_description
turtlebot_gazebo
9
10 CHAPTER 3. SIMULATION WITH GAZEBO
/gazebo/delete_model
/gazebo/get_joint_properties
/gazebo/get_link_properties
/gazebo/get_link_state
/gazebo/get_loggers
/gazebo/get_model_properties
/gazebo/get_model_state
/gazebo/get_physics_properties
/gazebo/get_world_properties
/gazebo/pause_physics
/gazebo/reset_simulation
/gazebo/reset_world
/gazebo/set_joint_properties
/gazebo/set_link_properties
/gazebo/set_link_state
/gazebo/set_logger_level
/gazebo/set_model_configuration
/gazebo/set_model_state
/gazebo/set_parameters
/gazebo/set_physics_properties
/gazebo/spawn_gazebo_model
/gazebo/spawn_urdf_model
/gazebo/unpause_physics
To put objects in the world there are many ways. All objects in the
world are considered robots, while some of them are not autonomous.
Change to gazebo_worlds path by:
$ roscd gazebo_worlds/
13
14 CHAPTER 4. CREATING PACKAGES IN ROS WITH CATKIN
The previous list returned by rospack command, are the primarily de-
pendencies. However as each dependencies have also their dependencies, our
package has indirect dependencies. They can be recovered by:
$ rospack depends my_first_rospkg
catkin
console_bridge
cpp_common
rostime
roscpp_traits
roscpp_serialization
genmsg
genpy
message_runtime
gencpp
genlisp
message_generation
rosbuild
rosconsole
std_msgs
rosgraph_msgs
xmlrpcpp
roscpp
rosgraph
rospack
roslib
rospy
$ catkin_make
Base path: </path/to/your/workspace>
Source space: </path/to/your/workspace>/src
Build space: </path/to/your/workspace>/build
Devel space: </path/to/your/workspace>/devel
Install space: </path/to/your/workspace>/install
####
#### Running command: "cmake </path/to/your/workspace>/src -
DCATKIN_DEVEL_PREFIX=</path/to/your/workspace>/devel -
DCMAKE_INSTALL_PREFIX=</path/to/your/workspace>/install" in
"</path/to/your/workspace>/build"
####
-- Using CATKIN_DEVEL_PREFIX: </path/to/your/workspace>/devel
-- Using CMAKE_PREFIX_PATH: </path/to/your/workspace>/devel;/opt/
ros/hydro
-- This workspace overlays: </path/to/your/workspace>/devel;/opt/
ros/hydro
-- Using PYTHON_EXECUTABLE: /usr/bin/X11/python
-- Using Debian Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: </path/to/your/workspace>/build/
test_results
-- Found gtest sources under ’/usr/src/gtest’: gtests will be
built
-- catkin 0.5.81
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - my_first_rospkg
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: ’my_first_rospkg’
-- ==> add_subdirectory(my_first_rospkg)
-- Configuring done
-- Generating done
-- Build files have been written to: </path/to/your/workspace>/
build
####
#### Running command: "make -j4 -l4" in "</path/to/your/workspace
>/build"
####
int count = 0;
while (ros::ok()) {
geometry_msgs::Twist speedMsg;
speedMsg.linear.x=0.0;
speedMsg.linear.y=0.0;
speedMsg.linear.z=0.0;
speedMsg.angular.x=0.0;
speedMsg.angular.y=0.0;
speedMsg.angular.z=0.5;
speed_pub.publish(speedMsg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
and
## Specify libraries to link a library or executable target
against
target_link_libraries(my_first_rospkg_node
${catkin_LIBRARIES}
)
Now lets compile the node by running catkin_make command on the top
of your workspace. At this stage you are able to make move your simulated
robot on gazebo by running the command:
$ rosrun my_first_package my_first_rospkg_node
ros::Publisher speed_pub;
geometry_msgs::Twist speedMsg;
speedMsg.linear.x=0.5;
speedMsg.linear.y=0.0;
speedMsg.linear.z=0.0;
speedMsg.angular.x=0.0;
speedMsg.angular.y=0.0;
speedMsg.angular.z=0.0;
if ((fabs(odomMsg->pose.pose.position.x)>2.00) ||
(fabs(odomMsg->pose.pose.position.y)>2.00)){
speedMsg.linear.x=-0.5;
}
speed_pub.publish(speedMsg);
}
speed_pub = n.advertise<geometry_msgs::Twist>("/mobile_base/
commands/velocity", 1000);
4.5 Exercises
4.5.1 Circles
Make your simulated robot to move describing a circle of radius r = 1.0m
4.5.2 Square
Following a square of 1m by side
4.5.3 Spiral
Chapter 5
19
20 CHAPTER 5. CREATING YOUR OWN ROBOT MODEL
Chapter 6
References
21