Sei sulla pagina 1di 102

ROS - Session 1

ROS Workshop at the


School of Engineering, UNAM

Viktor Seib
vseib@uni-koblenz.de
Institute for Computational Visualistics
University of Koblenz-Landau

August 10th, 2015

V. Seib ROS - Session 1

Slide 1

About me

Diploma in Computer Sciences in


Koblenz (2010)

since 2011: Research assistant in


the Active Vision Group, supervised
by Prof. Dr.-Inf. Dietrich Paulus

Research topics: Affordance


detection, 2D/3D object recognition
for service robots

Team Leader of team


homer@UniKoblnez since 2012

1st place in RoboCup@Home 2015!

Viktor Seib

V. Seib ROS - Session 1

Slide 2

About Koblenz

located at the confluence of


the rivers Rhine and Mosel

about 109,000 inhabitants

university with 7,000


students (1,500 in
computer sciences)

V. Seib ROS - Session 1

Koblenz

Slide 3

Agenda

V. Seib ROS - Session 1

Slide 4

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 5

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 6

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS (Robot Operating System)

ROS is an open-source middleware for robots.


it provides implementation of commonly-used functionality,

message-passing between processes, and package management.1


all ROS core code is licensed BSD easy to integrate in your project
maintained by the Open Source Robotics Foundation, supported by

Willow Garage
many device drivers and algorithms are available

http://www.ros.org (where the following material is taken from)

V. Seib ROS - Session 1

Slide 7

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Goals

ROS is a distributed framework of processes (aka


Nodes)

enables executables to be individually designed and


loosely coupled at runtime

supports code reuse in robotics research and development

Language independence: Python and C++ (and others)

Scaling: ROS is appropriate for large runtime systems and


for large development processes

V. Seib ROS - Session 1

Slide 8

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Highlights
Enables separate communities to exchange software and
knowledge. Resources:

Distributions: ROS Distributions are collections of


versioned packages that you can install (comparable to
Linux distributions)

Repositories: Different institutions can develop and


release their own robot software components

The ROS Wiki: The ROS community Wiki is the main


forum for documenting information about ROS (where
most of this information comes from!)

Mailing Lists: ros-users mailing list

Blog: http://planet.ros.org/

V. Seib ROS - Session 1

Slide 9

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Highlights

ROS is a common platform with worldwide acceptance:


14 of 17 teams in this years RoboCup@Home use ROS
RoCKIn@Home competition assumes ROS as default middleware
ROS website2 lists instructions to install ROS on 74 different robots

Current releases:
newest: Jade Turtle (supported till May 2017)
long term support: Indigo Igloo (supported till April 2019) (used here)

http://wiki.ros.org/Robots

V. Seib ROS - Session 1

Slide 10

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Concepts

ROS has two important levels of concepts:

Filesystem level: ROS resources on disk

Computation Graph level: peer-to-peer network of ROS


processes during runtime

V. Seib ROS - Session 1

Slide 11

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Concepts: Filesystem level


ROS resources that you encounter on disk
Workspace: A catkin workspace contains your ROS packages
Packages: Main unit for organizing software in ROS, e.g. ROS runtime

processes (nodes), ROS-dependent libraries, datasets, configuration


files
Manifests: Package manifests (package.xml) provide metadata

about a package (e.g. dependencies, compiler flags).


Message (msg) types: Message descriptions, define the data

structures for messages sent in ROS.


Service (srv) types: Service descriptions, define the request and

response data structures for services in ROS.


Action (action) types: Action descriptions, define advanced request

and response data structures for the actionlib in ROS.

V. Seib ROS - Session 1

Slide 12

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Concepts: Computation Graph Level


Computation Graph: Peer-to-peer network of ROS processes
that are processing data together.
The basic computation graph components of ROS are:

master

parameter server

nodes

messages

topics

services

bags

V. Seib ROS - Session 1

Slide 13

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 14

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Tutorial

ROS: http://www.ros.org/wiki/ROS/Tutorials
Catkin: http://www.ros.org/wiki/catkin
Also see: ROS Cheat Sheet

V. Seib ROS - Session 1

Slide 15

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Installation

Preferred platform: Ubuntu (and other UNIX based OS)

For installation see


www.ros.org/wiki/indigo/Installation/Ubuntu
Examples given for Ubuntu 14.04:

Setup your sources.list file (ROS server)


$ sudo sh -c echo "deb http://packages.ros.org/ros/ubuntu
$(lsb_release -sc) main" >
/etc/apt/sources.list.d/ros-latest.list
Set up your keys
$ sudo apt-key adv --keyserver hkp://pool.sks-keyservers.net
--recv-key 0xB01FA116

V. Seib ROS - Session 1

Slide 16

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Setup

Update your package list and install ROS:

$ sudo apt-get update

$ sudo apt-get install


ros-indigo-desktop-full

Initialize rosdep before using ROS

rosdep is a tool to manage system dependencies


$ sudo rosdep init
$ rosdep update

V. Seib ROS - Session 1

Slide 17

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Setup

Environment setup (add to /.bashrc):


$ source /opt/ros/indigo/setup.bash
simply type:
$ echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
$ source ~/.bashrc

Optionally: select an editor (add to /.bashrc):


$ export EDITOR=gedit

Get rosinstall (convenient tool to download many


source trees for ROS packages):
$ sudo apt-get install python-rosinstall

V. Seib ROS - Session 1

Slide 18

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Catkin3

catkin is the official build system of ROS and the


successor to rosbuild (used until ROS fuerte)

catkin extends CMake to manage dependencies between


packages

catkin adds support for automatic find package


infrastructure and building multiple projects at the same
time

To start developing with ROS we first need a catkin


workspace

see http://www.ros.org/wiki/catkin

V. Seib ROS - Session 1

Slide 19

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Prepare Catkin Workspace

Prerequisites: catkin installed and environment sourced:


$ source /opt/ros/indigo/setup.sh

Create a catkin workspace:


$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace

V. Seib ROS - Session 1

Slide 20

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Prepare Catkin Workspace

We have an empty workspace with a CMakeLists.txt link


Build the workspace:

$ cd ~/catkin_ws/
$ catkin_make
Source the new setup:

$ source devel/setup.bash
for convenience, add it to your .bashrc:

$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc


also add your workspace to the $ROS_PACKAGE_PATH:

$ echo "export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:


~/catkin_ws" >> ~/.bashrc

V. Seib ROS - Session 1

Slide 21

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Building Packages in a catkin Workspace


When calling catkin_make

source files, scripts or any other static files will remain in


the source space

any generated files such as libraries, executables, or


generated code will be placed in the devel space

in the devel space also setup.*sh files will be generated

you should source them to include your workspace in the


environment

Also take a look at http://www.ros.org/wiki/catkin/Tutorials/


workspace_overlaying for advanced uses of a workspace.

V. Seib ROS - Session 1

Slide 22

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Catkin Workspace
A typical catkin workspace looks like this:
workspace_folder/
-- WORKSPACE
src/
-- SOURCE SPACE
# this is where your packages (source code) will be
build/
-- BUILD SPACE
# this will contain CMake and catkin cache files etc.
devel/
-- DEVELOPMENT SPACE
# this will contain generated files such as
# libraries and executables

Unofficial rule of thumb:

if you get strange errors that you can not resolve otherwise:
delete the build space and rebuild your workspace

V. Seib ROS - Session 1

Slide 23

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Creating a Package

Please remember the filesystem concepts:

Workspace: A catkin workspace contains your ROS


packages

Packages: Main unit for organizing software in ROS, e.g.


ROS runtime processes (nodes), ROS-dependent libraries,
datasets, configuration files

Manifests: Package manifests (package.xml) provide


metadata about a package (e.g. dependencies, compiler
flags).

V. Seib ROS - Session 1

Slide 24

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Creating a Package

ROS code is organized in packages

To start developing with ROS we need a package within


our catkin workspace

The simplest possible package might look like this:


my_package/
CMakeLists.txt
package.xml

V. Seib ROS - Session 1

Slide 25

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Creating a Package

Requirements for valid catkin packages:

the package must contain a catkin compliant package.xml


file that provides meta information about the package

the package must contain a CMakeLists.txt which uses


catkin

there can be no more than one package in each folder (no


nested packages, no multiple packages in the same
directory)

V. Seib ROS - Session 1

Slide 26

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Creating a Package

catkin_create_pkg: creates a new ROS package

Usage: catkin_create_pkg <package_name>

Dependencies to other packages:


catkin_create_pkg <package_name> [depend1]
[depend2] ...
Files in a fresh package:

V. Seib ROS - Session 1

package.xml
CMakeLists.txt

Slide 27

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Creating a ROS Package


Try it!

change to folder:
cd ~/catkin_ws/src

Create package (all in one line):


$ catkin_create_pkg beginner_tutorials
std_msgs rospy roscpp

V. Seib ROS - Session 1

Slide 28

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Customizing your Package

Customize the auto-generated file package.xml:

description tag: change the description to anything you like


the first sentence should be short and cover the scope of
the package

maintainer tags: lets others know who to contact about the


package

license tag: choose a license and fill it in here

V. Seib ROS - Session 1

Slide 29

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Customizing your Package


Customize the auto-generated file package.xml:

dependencies tags: dependencies of your package

dependencies are split into build_depend,


buildtool_depend, run_depend, test_depend

all listed dependencies when creating the package have


been added as build_depend

in this case we want all of them to be also available at run


time, we add:
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>

V. Seib ROS - Session 1

Slide 30

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Customizing your Package


The final package.xml (comments removed):
<package>
<name>beginner_tutorials</name>
<version>0.1.0</version>
<description>The beginner_tutorials package</description>
<maintainer email="you@yourdomain.tld">Your Name</maintainer>
<license>BSD</license>
<url type="website">http://wiki.ros.org/beginner_tutorials</url>
<author email="you@yourdomain.tld">Jane Doe</author>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>std_msgs</run_depend>
</package>

V. Seib ROS - Session 1

Slide 31

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Building Packages in a catkin Workspace

catkin_make is a command line tool which adds some


convenience to the standard CMake workflow

usage in a catkin workspace:


$ catkin_make [make_targets] [-DCMAKE_VARIABLES=...]

V. Seib ROS - Session 1

Slide 32

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Building Packages in a catkin Workspace

catkin_make is equivalent to the following in a CMake


project:
$
$
$
$

mkdir build
cd build
cmake ..
make

this needs to be done for each CMake project

V. Seib ROS - Session 1

Slide 33

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Building Packages in a catkin Workspace

in contrast catkin projects can be built together in workspaces


building zero to many catkin packages in a workspace follows this work

flow:
# In a catkin workspace
$ catkin_make
catkin_make will build any catkin projects found in the src folder
For more advanced uses of catkin_make see:
http://www.ros.org/wiki/catkin/commands/catkin_make

V. Seib ROS - Session 1

Slide 34

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Building Packages in a catkin Workspace

Typical workflow in a catkin package:


$ cd ~/catkin_ws/src/beginner_tutorials/src
Add/Edit source files
$ cd ~/catkin_ws/src/beginner_tutorials
Update CMakeFiles.txt to reflect any changes to your sources
$ cd ~/catkin_ws
$ catkin_make

V. Seib ROS - Session 1

Slide 35

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Navigating the ROS Filesystem

For ROS there is lots of code spread across many packages

tools for easier file system navigation provided

will only search/find (sub)directories of your


ROS_PACKAGE_PATH environment variable

View your ROS_PACKAGE_PATH:


$ echo $ROS_PACKAGE_PATH

V. Seib ROS - Session 1

Slide 36

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Navigating the ROS Filesystem


Note:

For catkin, the most important environment variable is the


CMAKE_PREFIX_PATH

helps CMake find other CMake projects

Catkin packages are a special case of a CMake project,


hence the need for this variable

When a catkin setup file is sourced, this variable gets


appended with the corresponding package path

In a sense, the CMAKE_PREFIX_PATH essentially has the


same role as ROS_PACKAGE_PATH

V. Seib ROS - Session 1

Slide 37

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Navigating the ROS Filesystem

Filesystem Tools:

rospack: A tool to inspect packages

try rospack help to see more options

rospack list: List all packages


rospack find: Get information about packages

V. Seib ROS - Session 1

try $ rospack find roscpp

Slide 38

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Navigating the ROS Filesystem

Filesystem Tools:
roscd allows you to change directory directly to a package

roscd roscpp
roscd roscpp/msg

ROS commands provide Tab-completition

V. Seib ROS - Session 1

roscd roscpp_tut TAB key


roscd tur TAB key

Slide 39

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Inspecting the new ROS Package

Make sure new directories are found:


$ rospack profile

try it out: rospack find beginner_tutorials

try it out: roscd beginner_tutorials

V. Seib ROS - Session 1

Slide 40

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Package Dependencies

with catkin_create_pkg a few package dependencies


were provided

these first-order dependencies can be reviewed with the


rospack tool

rospack depends1 [package] shows the first-order


dependencies of the package

Try it!
$ rospack depends1 beginner_tutorials
std_msgs
rospy
roscpp

V. Seib ROS - Session 1

Slide 41

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Package Dependencies

these dependencies for a package are stored in the


package.xml file

in many cases, a dependency will also have its own


dependencies

rospack can recursively determine all nested


dependencies
$ rospack depends beginner_tutorials

find out which packages depend on another package:


$ rospack depends-on beginner_tutorials

the output of this command should be empty

V. Seib ROS - Session 1

Slide 42

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Package Dependencies

What to do if system dependencies are missing?

rosdep: Resolve system dependencies

Install the system dependencies:


$ rosdep install turtlesim

V. Seib ROS - Session 1

Slide 43

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Summary tools and catkin

catkin_init_workspace = creates a catkin workspace

catkin_make = makes (compiles) a catkin workspace

catkin_create_pkg = creates a new catkin package

rospack = ros+pack(age) : provides information related to


ROS packages

roscd = ros+cd : changes directory to a ROS package or


stack

rosdep = ros+dep(endencies) : resolve and install ROS


dependencies

V. Seib ROS - Session 1

Slide 44

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 45

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Understanding ROS Nodes

Quick Overview of Graph Concepts

nodes: A node is an executable that uses ROS to


communicate with other nodes.

roscore: Master + rosout + parameter server

rosout: ROS equivalent of stdout/stderr

V. Seib ROS - Session 1

Slide 46

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Nodes

A node really isnt much more than an executable file


within a ROS package.

Nodes can publish or subscribe to a Topic and can provide


or use a Service.

ROS nodes use a ROS client library to communicate with


other nodes.
ROS client libraries allow nodes written in different
programming languages to communicate:

V. Seib ROS - Session 1

rospy = python client library


roscpp = c++ client library

Slide 47

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

roscore

roscore: Starts the ROS system.


$ roscore

... logging to /home/vseib/.ros/log/d5f3df62-39bf-11e5-9918-f0def1fd396c/roslaunch-vseib-tp-23


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://vseib-tp:60231/
ros_comm version 1.11.9
SUMMARY
========
PARAMETERS
* /rosdistro: indigo
* /rosversion: 1.11.9
NODES
auto-starting new master
process[master]: started with pid [23614]
ROS_MASTER_URI=http://vseib-tp:11311/
setting /run_id to d5f3df62-39bf-11e5-9918-f0def1fd396c
process[rosout-1]: started with pid [23627]
started core service [/rosout]

V. Seib ROS - Session 1

Slide 48

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosnode

rosnode displays information about the ROS nodes that


are currently running

typing rosnode shows available commands:


Commands:
rosnode
rosnode
rosnode
rosnode
rosnode
rosnode

ping
list
info
machine
kill
cleanup

test connectivity to node


list active nodes
print information about node
list nodes running on a particular machine
kill a running node
purge registration information of unreachable nodes

rosnode [command] -h displays command specific


help

V. Seib ROS - Session 1

Slide 49

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosnode

Try it!

Open up a new terminal

Start rosnode list to see what running roscore did.


$ rosnode list
/rosout

only one node running so far

also try
$ rosnode ping /rosout

V. Seib ROS - Session 1

Slide 50

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosnode

rosnode info : information about a specific node.


$ 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://vseib-tp:49804/ ...
Pid: 23627

V. Seib ROS - Session 1

Slide 51

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosrun

rosrun allows you to use the package name to directly


run a node within a package

package path not required

$ rosrun [package_name] [node_name]

Try it:

run turtlesim_node (from the turtlesim package)

in a new terminal
$ rosrun turtlesim turtlesim_node

V. Seib ROS - Session 1

Slide 52

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosrun (turtlesim)

Try (in a new terminal window):


$ rosnode list
/rosout
/turtlesim

Figure : turtlesim

V. Seib ROS - Session 1

Slide 53

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosrun
Try:

Ctrl-C to stop the node (in the terminal window where you
started turtlesim)

Re-run it with a Remapping Argument to change the


nodes name:

$ rosrun turtlesim turtlesim_node __name:=my_turtle


List the nodes again: $ rosnode list

/my_turtle
/rosout
You can stop turtlesim now (Ctrl-C in the turtlesim terminal)

V. Seib ROS - Session 1

Slide 54

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Review Nodes

roscore = ros+core : starts the ROS system (master +


rosout + parameter server)

rosnode = ros+node : ROS tool to get information about a


node.

rosrun = ros+run : runs a node from a given package.

V. Seib ROS - Session 1

Slide 55

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 56

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Understanding ROS Topics

Quick Overview of Graph Concepts

Nodes: A node is an executable that uses ROS to


communicate with other nodes.

Topics: Nodes can publish messages to a topic as well


subscribe to a topic to receive messages.

Messages: ROS data types used when subscribing or


publishing to a topic.

V. Seib ROS - Session 1

Slide 57

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Topics: turtlesim

Make sure that roscore is running (in a new terminal):


$ roscore

Start turtlesim again (in a new terminal):


$ rosrun turtlesim turtlesim_node

V. Seib ROS - Session 1

Slide 58

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Topics: turtlesim

Start turtle keyboard teleoperation


(in a new terminal):
$ rosrun turtlesim
turtle_teleop_key

You can move the turtle with the arrow


keys (terminal needs to have the focus).
Figure : turtlesim with
moving turtle

V. Seib ROS - Session 1

Slide 59

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Topics: Behind the scenes

turtlesim_node and the turtle_teleop_key:


communication over a ROS Topic

turtle_teleop_key publishes the key strokes on a


topic

turtlesim_node subscribes to the same topic

examine what is going on with rqt_graph

rqt_graph creates a dynamic graph of whats going on in


the system

Enter in a new terminal:


$ rosrun rqt_graph rqt_graph

or simply:
$ rqt_graph

V. Seib ROS - Session 1

Slide 60

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Topics: Behind the scenes


$ rosrun rqt_graph rqt_graph

Figure : rqt_graph output


V. Seib ROS - Session 1

Slide 61

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic

rostopic tool allows you to get information about ROS


topics.

Syntax:
$ rostopic -h
rostopic
rostopic
rostopic
rostopic
rostopic
rostopic

V. Seib ROS - Session 1

bw
echo
hz
list
pub
type

display bandwidth used by topic


print messages to screen
display publishing rate of topic
information about active topics
publish data to topic
print topic type

Slide 62

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic list

lets display active topics:


$ rostopic list

Output:
/rosout
/rosout_agg
/turtle1/color_sensor
/turtle1/cmd_vel
/turtle1/pose

V. Seib ROS - Session 1

Slide 63

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic echo

rostopic echo displays data published on a specific


topic

Try (in a new terminal):


$ rostopic echo /turtle1/cmd_vel

Then go back to the turtle_teleop_key-Terminal and push


the keys.

V. Seib ROS - Session 1

Slide 64

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic echo
Output:
linear:
x: 2.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0
--Also check rqt_graph: rostopic echo now also
subscribed to the turtle1/cmd_vel topic!

V. Seib ROS - Session 1

Slide 65

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic list

rostopic list returns a list of all topics currently


subscribed to and published.

Example:
$ rostopic list -h
Usage: rostopic list [/topic]
Options:
-h, --help
show this help message and exit
-b BAGFILE, --bag=BAGFILE
list topics in .bag file
-v, --verbose
list full details about each topic
-p
list only publishers
-s
list only subscribers

V. Seib ROS - Session 1

Slide 66

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic list

$ rostopic list -v
Published topics:
* /turtle1/color_sensor [turtlesim/Color] 1 publisher
* /turtle1/cmd_vel [geometry_msgs/Twist] 1 publisher
* /rosout [roslib/Log] 3 publishers
* /rosout_agg [roslib/Log] 1 publisher
* /turtle1/pose [turtlesim/Pose] 1 publisher
Subscribed topics:
* /turtle1/cmd_vel [geometry_msgs/Twist] 2 subscribers
* /rosout [roslib/Log] 1 subscriber

V. Seib ROS - Session 1

Slide 67

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

ROS Messages

Communication on topics happens by sending ROS


messages between nodes.

The publisher and subscriber must send and receive the


same type of message.

The topic type is defined by the message type published


on it.

V. Seib ROS - Session 1

Slide 68

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic type

rostopic type determines the type of the message


sent on a topic.

In a new terminal try:


$ rostopic type /turtle1/cmd_vel
Output:
geometry_msgs/Twist

V. Seib ROS - Session 1

Slide 69

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosmsg show

rosmsg show shows the fields of a message

In a new terminal try:


$ rosmsg show geometry_msgs/Twist
geometry_msgs/Vector3 linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z
You can also combine rostopic type and rosmsg show:
$ rostopic type /turtle1/cmd_vel | rosmsg show
V. Seib ROS - Session 1

Slide 70

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic pub

Lets send a message!

rostopic pub publishes data on to a topic currently


advertised.

Usage rostopic pub [topic] [msg_type] [args]


Try in a new terminal (all in one line):

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -[2.0,0.0,0.0] [0.0,0.0,1.8]

V. Seib ROS - Session 1

Slide 71

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic pub
The effect:

Figure : Moving turtle


V. Seib ROS - Session 1

Slide 72

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic pub
What does the command mean?
$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -[2.0,0.0,0.0] [0.0,0.0,1.8]

rostopic pub: publish messages to a given topic

-1: only publish one message, then exit

/turtle1/cmd_vel: name of the topic to publish to

geometry_msgs/Twist: message type

- -: none of the following arguments is an option

2.0 1.8: two floating point elements: linear and angular


values

Parameters are given in YAML syntax


(see http://www.ros.org/wiki/ROS/YAMLCommandLine)
V. Seib ROS - Session 1

Slide 73

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic pub

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -[2.0,0.0,0.0] [0.0,0.0,1.8]

Observation: Turtle stops moving after some time.

Reason: Turtle requires a steady stream of commands at


1 Hz to keep moving.
Publish steady stream of commands using pub -r
command (and removing the -1):

$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist


-r 1 -- [2.0,0.0,0.0] [0.0,0.0,1.8]

Again take a look at rqt_graph.

V. Seib ROS - Session 1

Slide 74

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rostopic hz

rostopic hz reports the rate at which data is published.

try it out (in a new terminal):


$ rostopic hz /turtle1/cmd_vel
subscribed to [/turtle1/cmd_vel]
average rate: 1.000
min: 1.000s max: 1.000s std dev: 0.00000s window: 2
average rate: 1.000
min: 1.000s max: 1.000s std dev: 0.00028s window: 3
...

also try:
$ rostopic hz /turtle1/pose

V. Seib ROS - Session 1

Slide 75

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Review Topics

rostopic = ros+topic : tool to display information about


topics

rosmsg = ros+msg : tool to display information about


messages

rqt_graph : graphical tool to display active nodes and


topics

V. Seib ROS - Session 1

Slide 76

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 77

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Services

Services are another way for nodes to communicate with


each other

Services allow nodes to send a request and receive a


response

V. Seib ROS - Session 1

Slide 78

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Messages vs. Services


Messages:

sender view:
1:n communication

system view:
n:n communication

non-blocking

no response message
needed

V. Seib ROS - Session 1

Services:

caller view:
1:1 communication

system view:
n:1 communication

blocking

always gets a response

Slide 79

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosservice

rosservice tool for listing and querying ROS services

Syntax:
$ rosservice -h
rosservice
rosservice
rosservice
rosservice
rosservice

V. Seib ROS - Session 1

list
call
type
find
uri

print information about active services


call the service with the provided args
print service type
find services by service type
print service ROSRPC uri

Slide 80

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosservice
Try:
$ rosservice list
Output:
/clear
/kill
/reset
/rosout/get_loggers
/rosout/set_logger_level
/spawn
/teleop_turtle/get_loggers
/teleop_turtle/set_logger_level
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/get_loggers
/turtlesim/set_logger_level

V. Seib ROS - Session 1

Slide 81

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosservice type

rosservice type: Find out what type a service has

Usage: rosservice type [service]

Try:
$ rosservice type clear
std_srvs/Empty

Empty means:

V. Seib ROS - Session 1

it sends no data when making a request


it receives no data when receiving a response

Slide 82

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Calling a service: rosservice call

rosservice call: Call a service

Usage: rosservice call [service] [args]

Try:
$ rosservice call clear

clears the background of the turtlesim window

V. Seib ROS - Session 1

Slide 83

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

rosservice and rostopic

We have alredy used

rostopic type [topic] and


rosmsg show [topic type]

Now the corresponding commands for services

rosservice type [service] and


rossrv show [service type]

Short form:
rosservice type [service] | rossrv show

V. Seib ROS - Session 1

Slide 84

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Calling a service: rosservice call

First find out which arguments are required:

Try:
$ rosservice type spawn | rossrv show
float32 x
float32 y
float32 theta
string name
--string name

This service lets us spawn a new turtle at a given location


and orientation.

V. Seib ROS - Session 1

Slide 85

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Calling a service: rosservice call

Before calling the service, try:

rosnode list

rostopic list

rosservice list

V. Seib ROS - Session 1

Slide 86

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Calling a service: rosservice call


Remember the service type:
float32 x
float32 y
float32 theta
string name
--string name
Try:

$ rosservice call spawn 2 2 0.2 ""

It returns the new name of the turtle: name: turtle2

V. Seib ROS - Session 1

Slide 87

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Calling a service: rosservice call

Again, try:

rosnode list

rostopic list

rosservice list

Figure : A second turtle!

V. Seib ROS - Session 1

Slide 88

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Calling a service: rosservice call


You may want to try now (each in one line):

rostopic pub /turtle1/cmd_vel geometry_msgs/Twist


-- [2.0,0.0,0.0] [0.0,0.0,1.8]

rostopic pub /turtle2/cmd_vel geometry_msgs/Twist


-- [2.0,0.0,0.0] [0.0,0.0,2.0]

rosservice call turtle1/teleport_absolute


-- 5 8 3.14

rosservice call turtle2/teleport_absolute


-- 7 8 3.14

V. Seib ROS - Session 1

Slide 89

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 90

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

roscore: Master + rosout + parameter server

Master: Name service for ROS (i.e. helps nodes find each
other)

rosout: ROS equivalent of stdout/stderr

parameter server: a shared dictionary

V. Seib ROS - Session 1

Slide 91

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

parameter server: a shared dictionary

runs inside the ROS Master

nodes store and retrieve parameters at runtime

not designed for high-performance

best used for static, non-binary data

V. Seib ROS - Session 1

Slide 92

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

The parameter server can store

integers: 1

floats: 1.0

boolean: true

lists: [1, 2, 3]

dictionaries: {a: b, c: d}

(Syntax: YAML (YAML Aint Markup Language))

V. Seib ROS - Session 1

Slide 93

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

rosparam: store and manipulate data on the ROS


Parameter Server

Usage:
rosparam
rosparam
rosparam
rosparam
rosparam
rosparam

V. Seib ROS - Session 1

set
get
load
dump
delete
list

set parameter
get parameter
load parameters from file
dump parameters to file
delete parameter
list parameter names

Slide 94

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

Try:
$ rosparam list
/background_b
/background_g
/background_r
/rosdistro
/roslaunch/uris/host_vseib_tp__45837
/rosversion
/run_id

V. Seib ROS - Session 1

Slide 95

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

Try:

$ rosparam get background_g


86

$ rosparam set background_r 150


(nothing happens)

$ rosservice call clear


(changes take effect)

V. Seib ROS - Session 1

Figure :
Background
changed

Slide 96

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

To display all parameters on the parameter server, try:

$ rosparam get /

background_b: 255
background_g: 86
background_r: 69
rosdistro: indigo
roslaunch:
uris: {host_vseib_tp__45837: http://vseib-tp:45837/}
rosversion: 1.11.9
run_id: 89725d34-cfb6-11e0-9200-0024e83031ad

V. Seib ROS - Session 1

Slide 97

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Parameter Server

$ rosparam dump [file name]


save parameters to file

$ rosparam load [file name] [namespace]


load from file

Try:
$ rosparam dump params.yaml
$ rosparam load params.yaml copy
$ rosparam get copy/background_b
255

V. Seib ROS - Session 1

Slide 98

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Review Services and Parameters

rosservice = ros+service: tool for listing and querying


ROS services

rossrv = ros+srv: tool to display information about


services

rosparam = ros+param: store and manipulate data on the


ROS Parameter Server

V. Seib ROS - Session 1

Slide 99

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Introduction
ROS Filesystem and Catkin
Nodes
Topics and Messages
Services
Parameter Server
Summary

V. Seib ROS - Session 1

Slide 100

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Summary

ROS Introduction:

concepts of ROS (nodes, topics, messages, services)

packages: rospack, rosdep

file system: roscd

catkin: catkin_init_workspace, catkin_make,


catkin_create_pkg

V. Seib ROS - Session 1

Slide 101

Introduction

ROS Filesystem and Catkin

Nodes

Topics and Messages

Services

Parameter Server

Summary

Summary

ROS nodes, messages, and topics:

start ROS system: roscore

nodes: rosnode, rosrun

topics and messages: rostopic, rosmsg

ROS services and parameters:

services: rosservice, rossrv

parameters: rosparam

V. Seib ROS - Session 1

Slide 102

Potrebbero piacerti anche