PresentationPDF Available

Programming for Robotics - Introduction to ROS

Authors:

Abstract and Figures

This course gives an introduction to the Robot Operating System (ROS) including many of the available tools that are commonly used in robotics. With the help of different examples, the course should provide a good starting point for students to work with robots. They learn how to create software including simulation, to interface sensors and actuators, and to integrate control algorithms. Objective: – ROS architecture: Master, nodes, topics, messages, services, parameters and actions – Console commands: Navigating and analyzing the ROS system and the catkin workspace – Creating ROS packages: Structure, launch-files, and best practices – ROS C++ client library (roscpp): Creating your own ROS C++ programs – Simulating with ROS: Gazebo simulator, robot models (URDF) and simulation environments (SDF) – Working with visualizations (RViz) and user interface tools (rqt) – Inside ROS: TF transformation system, time, bags
No caption available
… 
No caption available
… 
No caption available
… 
No caption available
… 
No caption available
… 
Content may be subject to copyright.
|
|
Péter Fankhauser, Dominic Jud, Martin Wermelinger, Marco Hutter
20.02.2017 1
Programming for Robotics
Introduction to ROS
Péter Fankhauser
|
|1.12.2014
Péter Fankhauser 2
Presentation videos
https://www.youtube.com/playlist?list=PLE-
BQwvVGf8HOvwXPgtDfWoxd4Cc6ghiP
Course Material & Exercises
http://www.rsl.ethz.ch/education-students/lectures/ros.html
|
|
§Part 1
§ROS architecture & philosophy
§ROS master, nodes, and topics
§Console commands
§Catkin workspace and build system
§Launch-files
§Gazebo simulator
§Part 2
§ROS package structure
§Integration and programming with Eclipse
§ROS C++ client library (roscpp)
§ROS subscribers and publishers
§ROS parameter server
§RViz visualization
Péter Fankhauser 3
Overview
§Part 3
§TF Transformation System
§rqt User Interface
§Robot models (URDF)
§Simulation descriptions (SDF)
§Part 4
§ROS services
§ROS actions (actionlib)
§ROS time
§ROS bags
§Debugging strategies
§Part 5
§Case study
20.02.2017
|
|
§ROS architecture & philosophy
§ROS master, nodes, and topics
§Console commands
§Catkin workspace and build system
§Launch-files
§Gazebo simulator
Péter Fankhauser 4
Overview Part 1
20.02.2017
|
|
Péter Fankhauser 5
What is ROS?
ROS = Robot Operating System
§Process
management
§Inter-process
communication
§Device drivers
§Simulation
§Visualization
§Graphical user
interface
§Data logging
§Control
§Planning
§Perception
§Mapping
§Manipulation
§Package organization
§Software distribution
§Documentation
§Tutorials
ros.org
20.02.2017
|
|
§Originally developed in 2007 at the
Stanford Artificial Intelligence
Laboratory
§Since 2013 managed by OSRF
§Today used by many robots,
universities and companies
§De facto standard for robot
programming
Péter Fankhauser 6
History of ROS
ros.org
20.02.2017
|
|
§Peer to peer
Individual programs communicate over defined API (ROS messages, services, etc.).
§Distributed
Programs can be run on multiple computers and communicate over the network.
§Multi-lingual
ROS modules can be written in any language for which a client library exists (C++, Python,
MATLAB, Java, etc.).
§Light-weight
Stand-alone libraries are wrapped around with a thin ROS layer.
§Free and open-source
Most ROS software is open-source and free to use.
Péter Fankhauser 7
ROS Philosophy
20.02.2017
|
|
§Defines context for the current workspace
§Default workspace loaded with
Péter Fankhauser 8
ROS Workspace Environment
Overlay your catkin workspace with
> cd ~/catkin_ws
> source devel/setup.bash
> source /opt/ros/indigo/setup.bash
Check your workspace with
> echo $ROS_PACKAGE_PATH
More info
http://wiki.ros.org/indigo/Installation/Ubuntu
http://wiki.ros.org/catkin/workspaces
This is
already
setup in the
provided
installation.
> cat ~/.bashrc
See setup with
20.02.2017
|
|
§Manages the communication between nodes
§Every node registers at startup with the
master
Péter Fankhauser 9
ROS Master
Start a master with
> roscore
ROS Master
More info
http://wiki.ros.org/Master
20.02.2017
|
|
§Single-purpose, executable program
§Individually compiled, executed, and
managed
§Organized in packages
Péter Fankhauser 10
ROS Nodes
> rosrun package_name node_name
Run a node with
ROS Master
Node 1 Node 2
More info
http://wiki.ros.org/rosnode
> rosnode list
See active nodes with
> rosnode info node_name
Retrieve information about a node with
RegistrationRegistration
20.02.2017
|
|
§Nodes communicate over topics
§Nodes can publish or subscribe to a topic
§Typically, 1 publisher and nsubscribers
§Topic is a name for a stream of messages
Péter Fankhauser 11
ROS Topics
> rostopic list
List active topics with
ROS Master
Node 1
Publisher
Node 2
Subscriber
RegistrationRegistration
> rostopic echo /topic
Subscribe and print the contents of a topic with
> rostopic info /topic
Show information about a topic with
More info
http://wiki.ros.org/rostopic
topic
Publish Subscribe
Subscribe
Messages
Informs about
connection
20.02.2017
|
|
§Data structure defining the type of a topic
§Compromised of a nested structure of
integers, floats, booleans, strings etc. and
arrays of objects
§Defined in *.msg files
Péter Fankhauser 12
ROS Messages
> rostopic type /topic
See the type of a topic
ROS Master
Node 1
Publisher
Node 2
Subscriber
RegistrationRegistration
> rostopic pub /topic type args
Publish a message to a topic
More info
http://wiki.ros.org/Messages
topic
Publish Subscribe
Subscribe
int number
double width
string description
etc.
Message definition
*.msg
20.02.2017
|
|
Péter Fankhauser 13
ROS Messages
Pose Stamped Example
float64 x
float64 y
float64 z
geometry_msgs/Point.msg
std_msgs/Header header
uint32 seq
time stamp
string frame_id
geometry_msgs/Pose pose
geometry_msgs/Point position
float64 x
float64 y
float64 z
geometry_msgs/Quaternion
orientation
float64 x
float64 y
float64 z
float64 w
geometry_msgs/PoseStamped.msg
std_msgs/Header header
uint32 seq
time stamp
string frame_id
uint32 height
uint32 width
string encoding
uint8 is_bigendian
uint32 step
uint8[] data
sensor_msgs/Image.msg
20.02.2017
|
|
Péter Fankhauser 14
Example
Console Tab Nr. 1 Starting a roscore
Start a roscore with
> roscore
20.02.2017
|
|
Péter Fankhauser 15
Example
Console Tab Nr. 2 Starting a talker node
Run a talker demo node with
> rosrun roscpp_tutorials talker
20.02.2017
|
|
Péter Fankhauser 16
Example
Console Tab Nr. 3 Analyze talker node
See the list of active nodes
> rosnode list
See information about the chatter topic
> rostopic info /chatter
Show information about the talker node
> rosnode info /talker
20.02.2017
|
|
Péter Fankhauser 17
Example
Console Tab Nr. 3 Analyze chatter topic
Show the message contents of the topic
> rostopic echo /chatter
Check the type of the chatter topic
> rostopic type /chatter
Analyze the frequency
> rostopic hz /chatter
20.02.2017
|
|
Péter Fankhauser 18
Example
Console Tab Nr. 4 Starting a listener node
Run a listener demo node with
> rosrun roscpp_tutorials listener
20.02.2017
|
|
Péter Fankhauser 19
Example
Console Tab Nr. 3 – Analyze
See the new listener node with
> rosnode list
> rostopic info /chatter
Show the connection of the nodes over the
chatter topic with
20.02.2017
|
|
Péter Fankhauser 20
Example
Console Tab Nr. 3 – Publish Message from Console
Close the talker node in console nr. 2 with Ctrl +C
> rostopic pub /chatter std_msgs/String
"data: 'ETH Zurich ROS Course'"
Publish your own message with
Check the output of the listener in console nr. 4
20.02.2017
|
|
Péter Fankhauser 21
catkin Build System
> cd ~/catkin_ws
Navigate to your catkin workspace with
§catkin is the ROS build system to generate
executables, libraries, and interfaces
§We suggest to use the Catkin Command Line Tools
Use catkin build instead of catkin_make
More info
http://wiki.ros.org/catkin/Tutorials
https://catkin-tools.readthedocs.io/
> catkin build package_name
Build a package with
> source devel/setup.bash
Whenever you build a new package, update your environment
The catkin
command line
tools are pre-
installed in the
provided
installation.
!
20.02.2017
|
|
The catkin workspace contains the following spaces
Péter Fankhauser 22
catkin Build System
The source space contains
the source code. This is where
you can clone, create, and
edit source code for the
packages you want to build.
The build space is where
CMake is invoked to build the
packages in the source
space. Cache information and
other intermediate files are
kept here.
The development (devel)
space is where built targets
are placed (prior to being
installed).
More info
http://wiki.ros.org/catkin/workspaces
Work here Don’t touch Don’t touch
> catkin clean
If necessary, clean the entire build and devel space with
20.02.2017
|
|
Péter Fankhauser 23
catkin Build System
> catkin config
The catkin workspace setup can be checked with
> catkin build --cmake-args
-DCMAKE_BUILD_TYPE=Release
For example, to set the CMake build type to Release
(or Debug etc.), use
More info
http://catkin-tools.readthedocs.io/en/latest/verbs/catkin_config.html
http://catkin-tools.readthedocs.io/en/latest/cheat_sheet.html
Already
setup in the
provided
installation.
20.02.2017
|
|
Péter Fankhauser 24
Example
Open a terminal and browse to your git folder
> cd ~/git
Clone the Git repository with
> git clone https://github.com/ethz-
asl/ros_best_practices.git
Symlink the new package to your catkin workspace
> ln -s ~/git/ros_best_practices/ ~/catkin_ws/src/
Note: You could also directly clone to your catkin workspace, but using a
common git folder is convenient if you have multiple catkin workspaces.
https://github.com/ethz-asl/ros_best_practices
20.02.2017
|
|
Péter Fankhauser 25
Example
Go to your catkin workspace
> cd ~/catkin_ws
Build the package with
> catkin build ros_package_template
Re-source your workspace setup
> source devel/setup.bash
Launch the node with
> roslaunch ros_package_template
ros_package_template.launch
20.02.2017
|
|
Péter Fankhauser 26
ROS Launch
> roslaunch file_name.launch
Browse to the folder and start a launch file with
§launch is a tool for launching multiple nodes
(as well as setting parameters)
§Are written in XML as *.launch files
§If not yet running, launch automatically starts
a roscore
> roslaunch package_name file_name.launch
Start a launch file from a package with
More info
http://wiki.ros.org/roslaunch
Example console output for
roslaunch roscpp_tutorials talker_listener.launch
20.02.2017
|
|
Péter Fankhauser 27
ROS Launch
File Structure
talker_listener.launch
§launch: Root element of the launch file
§node: Each <node> tag specifies a node to be launched
§name: Name of the node (free to choose)
§pkg: Package containing the node
§type: Type of the node, there must be a corresponding executable with the same name
§output: Specifies where to output log messages (screen: console, log: log file)
More info
http://wiki.ros.org/roslaunch/XML
http://wiki.ros.org/roslaunch/Tutorials/Roslaunch%20tips%20for%20larger%20projects
<launch>
<node name="listener" pkg="roscpp_tutorials"type="listener" output="screen"/>
<node name="talker" pkg="roscpp_tutorials"type="talker" output="screen"/>
</launch>
Notice the syntax difference
for self-closing tags:
<tag></tag> and <tag/>
!
20.02.2017
|
|
Péter Fankhauser 28
ROS Launch
Arguments
<arg name="arg_name"default="default_value"/>
§Create re-usable launch files with <arg> tag,
which works like a parameter (default optional)
<?xml version="1.0"?>
<launch>
<arg name="use_sim_time"default="true"/>
<arg name="world" default="gazebo_ros_range"/>
<arg name="debug" default="false"/>
<arg name="physics" default="ode"/>
<group if="$(arg use_sim_time)">
<param name="/use_sim_time"value="true" />
</group>
<include file="$(find gazebo_ros)
/launch/empty_world.launch">
<arg name="world_name"value="$(find gazebo_plugins)/
test/test_worlds/$(arg world).world"/>
<arg name="debug" value="$(arg debug)"/>
<arg name="physics" value="$(arg physics)"/>
</include>
</launch>
range_world.launch (simplified)
§Use arguments in launch file with
More info
http://wiki.ros.org/roslaunch/XML/arg
> roslaunch launch_file.launch arg_name:=value
$(arg arg_name)
§When launching, arguments can be set with
20.02.2017
|
|
Péter Fankhauser 29
ROS Launch
Including Other Launch Files
<include file="package_name"/>
§Include other launch files with <include> tag to
organize large projects
<?xml version="1.0"?>
<launch>
<arg name="use_sim_time"default="true"/>
<arg name="world" default="gazebo_ros_range"/>
<arg name="debug" default="false"/>
<arg name="physics" default="ode"/>
<group if="$(arg use_sim_time)">
<param name="/use_sim_time"value="true" />
</group>
<include file="$(find gazebo_ros)
/launch/empty_world.launch">
<arg name="world_name"value="$(find gazebo_plugins)/
test/test_worlds/$(arg world).world"/>
<arg name="debug" value="$(arg debug)"/>
<arg name="physics" value="$(arg physics)"/>
</include>
</launch>
range_world.launch (simplified)
§Find the system path to other packages with
More info
http://wiki.ros.org/roslaunch/XML/include
$(find package_name)
§Pass arguments to the included file
<arg name="arg_name" value="value"/>
20.02.2017
|
|
§Simulate 3d rigid-body dynamics
§Simulate a variety of sensors including noise
§3d visualization and user interaction
§Includes a database of many robots and
environments (Gazebo worlds)
§Provides a ROS interface
§Extensible with plugins
Péter Fankhauser 30
Gazebo Simulator
> rosrun gazebo_ros gazebo
Run Gazebo with
More info
http://gazebosim.org/
http://gazebosim.org/tutorials
Object tree Too lb ar
Start and pause simulation
Properties
20.02.2017
|
|
§ROS package structure
§Integration and programming with Eclipse
§ROS C++ client library (roscpp)
§ROS subscribers and publishers
§ROS parameter server
§RViz visualization
Péter Fankhauser 31
Overview Part 2
23.02.2017
|
|
Péter Fankhauser 32
ROS Packages
> catkin_create_pkg package_name
{dependencies}
To create a new package, use
§ROS software is organized into
packages, which can contain
source code, launch files,
configuration files, message
definitions, data, and
documentation
§A package that builds up
on/requires other packages (e.g.
message definitions), declares
these as dependencies
config
Parameter files (YAML)
include/package_name
C++ include headers
launch
*.launch files
src
Source files
test
Unit/ROS tests
package_name
CMakeLists.txt
CMake build file
package.xml
Package information
package_name_msgs
action
Action definitions
msg
Message definitions
srv
Service definitions
CMakeLists.txt
Cmake build file
package.xml
Package information
More info
http://wiki.ros.org/Packages
Separate message definition
packages from other packages!
23.02.2017
|
|
§The package.xml file defines the
properties of the package
§Package name
§Version number
§Authors
§Dependencies on other packages
§
Péter Fankhauser 33
ROS Packages
package.xml
<?xml version="1.0"?>
<package format="2">
<name>ros_package_template</name>
<version>0.1.0</version>
<description>A template for ROS packages.</description>
<maintainer email="pfankhauser@e…">Peter Fankhauser</maintainer>
<license>BSD</license>
<url type="website">https://github.com/ethz-asl/ros_best_pr</url>
<author email="pfankhauser@ethz.ch">Peter Fankhauser</author>
<buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>
<depend>sensor_msgs</depend>
</package>
package.xml
More info
http://wiki.ros.org/catkin/package.xml
23.02.2017
|
|
The CMakeLists.txt is the input to the CMakebuild system
1. Required CMake Version (cmake_minimum_required)
2. Package Name (project())
3. Find other CMake/Catkin packages needed for build
(find_package())
4. Message/Service/Action Generators (add_message_files(),
add_service_files(), add_action_files())
5. Invoke message/service/action generation (generate_messages())
6. Specify package build info export (catkin_package())
7. Libraries/Executables to build
(add_library()/add_executable()/target_link_libraries())
8. Tests to build (catkin_add_gtest())
9. Install rules (install())
Péter Fankhauser 34
ROS Packages
CMakeLists.xml
cmake_minimum_required(VERSION 2.8.3)
project(ros_package_template)
## Use C++11
add_definitions(--std=c++11)
## Find catkin macros and libraries
find_package(catkin REQUIRED
COMPONENTS
roscpp
sensor_msgs
)
CMakeLists.txt
More info
http://wiki.ros.org/catkin/CMakeLists.txt
23.02.2017
|
|
Péter Fankhauser 35
ROS Packages
CMakeLists.xml Example
23.02.2017
cmake_minimum_required(VERSION 2.8.3)
project(husky_highlevel_controller)
add_definitions(--std=c++11)
find_package(catkin REQUIRED
COMPONENTS roscpp sensor_msgs
)
catkin_package(
INCLUDE_DIRS include
# LIBRARIES
CATKIN_DEPENDS roscpp sensor_msgs
# DEPENDS
)
include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} src/${PROJECT_NAME}_node.cpp
src/HuskyHighlevelController.cpp)
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
Use the same name as in the package.xml
We use C++11 by default
List the packages that your package requires to
build (have to be listed in package.xml)
Specify build export information
INCLUDE_DIRS: Directories with header files
LIBRARIES: Libraries created in this project
CATKIN_DEPENDS: Packages dependent projects also need
DEPENDS: System dependencies dependent projects also need
(have to be listed in package.xml)
Specify libraries to link the executable against
Declare a C++ executable
Specify locations of of header files
|
|
§Build the Eclipse project files with additional build flag
§The project files will be generated in ~/catkin_ws/build
Péter Fankhauser 36
Setup a Project in Eclipse
> catkin build package_name -G"Eclipse CDT4 -Unix Makefiles"
-DCMAKE_CXX_COMPILER_ARG1=-std=c++11
The build
flags are
already
setup in the
provided
installation.
23.02.2017
|
|
§Start Eclipse and set the workspace folder
Péter Fankhauser 37
Setup a Project in Eclipse
The Eclipse
workspace
is already
set in the
provided
installation.
23.02.2017
|
|
§Import your project to Eclipse
File àImport àGeneral
àExisting Projects into Workspace
Péter Fankhauser 38
Setup a Project in Eclipse
23.02.2017
|
|
§The project files can be imported from the
~/catkin_ws/build folder
Péter Fankhauser 39
Setup a Project in Eclipse
23.02.2017
|
|
§Rebuild the C/C++ index of your project by
Right click on Project àIndex àRebuild
§Resolving the includes enables
§Fast navigation through links (Ctrl + click)
§Auto-completion (Ctrl + Space)
§Building (Ctrl + B) and debugging your code in
Eclipse
Péter Fankhauser 40
Setup a Project in Eclipse
23.02.2017
|
|
§Within the project a link [Source directory]
is provided such that you can edit your project
§Useful Eclipse shortcuts
§Ctrl + Space: Auto-complete
§Ctrl + /: Comment / uncomment line or section
§Ctrl + Shift + F: Auto-format code using code
formatter
§Alt + Arrow Up / Arrow Down: Move line or
selection up or down
§Ctrl + D: Delete line
Péter Fankhauser 41
Setup a Project in Eclipse
23.02.2017
|
|
Péter Fankhauser 42
ROS C++ Client Library (roscpp)
#include <ros/ros.h>
int main(int argc, char** argv)
{
ros::init(argc, argv, "hello_world");
ros::NodeHandle nodeHandle;
ros::Rate loopRate(10);
unsigned int count = 0;
while (ros::ok()) {
ROS_INFO_STREAM("Hello World " << count);
ros::spinOnce();
loopRate.sleep();
count++;
}
return 0;
}
hello_world.cpp
More info
http://wiki.ros.org/roscpp
http://wiki.ros.org/roscpp/Overview
ROS main header file include
ros::init(…) has to be called before calling other ROS functions
The node handle is the access point for communications with the
ROS system (topics, services, parameters)
ros::Rate is a helper class to run loops at a desired frequency
ros::ok() checks if a node should continue running
Returns false if SIGINT is received (Ctrl + C) or ros::shutdown() has been called
ROS_INFO() logs messages to the filesystem
ros::spinOnce() processes incoming messages via callbacks
23.02.2017
|
|
§There are four main types of node handles
1. Default (public) node handle:
nh_ = ros::NodeHandle();
2. Private node handle:
nh_private_ = ros::NodeHandle("~");
3. Namespaced node handle:
nh_eth_ = ros::NodeHandle("eth");
4. Global node handle:
nh_global_ = ros::NodeHandle("/");
Péter Fankhauser 43
ROS C++ Client Library (roscpp)
Node Handle
More info
http://wiki.ros.org/roscpp/Overview/NodeHandles
For a node in namespace looking up topic,
these will resolve to:
/namespace/topic
/namespace/node/topic
/namespace/eth/topic
/topic
Recommended
Not
recommended
23.02.2017
|
|
§Mechanism for logging human readable text
from nodes in the console and to log files
§Instead of std::cout, use e.g. ROS_INFO
§Automatic logging to console, log file, and
/rosout topic
§Different severity levels (Info, Warn, Error etc.)
§Supports both printf- and stream-style formatting
§Further features such as conditional, throttled,
delayed logging etc.
Péter Fankhauser 44
ROS C++ Client Library (roscpp)
Logging
23.02.2017
More info
http://wiki.ros.org/rosconsole
http://wiki.ros.org/roscpp/Overview/Logging
ROS_INFO("Result: %d", result);
ROS_INFO_STREAM("Result: " << result);
Debug
Info Warn Error Fatal
stdout
x x
stderr
x x x
Log file
x x x x x
/
rosout x x x x x
To see the output in the console, set the output
configuration to screen in the launch file
!<launch>
<node name="listener" output="screen"/>
</launch>
|
|
Péter Fankhauser 45
ROS C++ Client Library (roscpp)
Subscriber
ros::Subscriber subscriber =
nodeHandle.subscribe(topic, queue_size,
callback_function);
§Start listening to a topic by calling the
method subscribe() of the node handle
#include "ros/ros.h"
#include "std_msgs/String.h"
void chatterCallback(const std_msgs::String& msg)
{
ROS_INFO("I heard: [%s]", msg.data.c_str());
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle nodeHandle;
ros::Subscriber subscriber =
nodeHandle.subscribe("chatter",10, chatterCallback);
ros::spin();
return 0;
}
listener.cpp
§When a message is received, callback
function is called with the contents of the
message as argument
§Hold on to the subscriber object until you
want to unsubscribe
ros::spin() processes callbacks and will not
return until the node has been shutdown More info
http://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers
23.02.2017
|
|
Péter Fankhauser 46
ROS C++ Client Library (roscpp)
Publisher
§Create a publisher with help of the node
handle
#include <ros/ros.h>
#include <std_msgs/String.h>
int main(int argc, char **argv) {
ros::init(argc, argv, "talker");
ros::NodeHandle nh;
ros::Publisher chatterPublisher =
nh.advertise<std_msgs::String>("chatter", 1);
ros::Rate loopRate(10);
unsigned int count = 0;
while (ros::ok()) {
std_msgs::String message;
message.data = "hello world " + std::to_string(count);
ROS_INFO_STREAM(message.data);
chatterPublisher.publish(message);
ros::spinOnce();
loopRate.sleep();
count++;
}
return 0;
}
talker.cpp
§Create the message contents
§Publish the contents with
ros::Publisher publisher =
nodeHandle.advertise<message_type>(topic,
queue_size);
More info
http://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers
publisher.publish(message);
23.02.2017
|
|
Péter Fankhauser 47
ROS C++ Client Library (roscpp)
Object Oriented Programming
#include <ros/ros.h>
#include "my_package/MyPackage.hpp"
int main(int argc, char** argv)
{
ros::init(argc, argv, "my_package");
ros::NodeHandle nodeHandle("~");
my_package::MyPackage myPackage(nodeHandle);
ros::spin();
return 0;
}
my_package_node.cpp
MyPackage.hpp
MyPackage.cpp
Algorithm.hpp
Algorithm.cpp
class MyPackage
Main node class
providing ROS interface
(subscribers, parameters,
timers etc.)
class Algorithm
Class implementing the
algorithmic part of the
node
Note: The algorithmic part of the
code could be separated in a
(ROS-independent) library
Specify a function handler to a method from within the class as
subscriber_ = nodeHandle_.subscribe(topic, queue_size,
&ClassName::methodName, this);
More info
http://wiki.ros.org/roscpp_tutorials/Tutorials/
UsingClassMethodsAsCallbacks
23.02.2017
!
|
|
Péter Fankhauser 48
ROS Parameter Server
§Nodes use the parameter server to store and
retrieve parameters at runtime
§Best used for static data such as
configuration parameters
§Parameters can be defined in launch files or
separate YAML files
More info
http://wiki.ros.org/rosparam
> rosparam list
List all parameters with
> rosparam get parameter_name
Get the value of a parameter with
> rosparam set parameter_name value
Set the value of a parameter with
camera:
left:
name: left_camera
exposure: 1
right:
name: right_camera
exposure: 1.1
config.yaml
<launch>
<node name="name"pkg="package"type="node_type">
<rosparam command="load"
file="$(find package)/config/config.yaml"/>
</node>
</launch>
package.launch
23.02.2017
|
|
§Get a parameter in C++ with
§Method returns true if parameter was found,
false otherwise
§Global and relative parameter access:
§Global parameter name with preceding /
§Relative parameter name (relative to the node handle)
§For parameters, typically use the private node handle
ros::NodeHandle("~")
Péter Fankhauser 49
ROS Parameter Server
C++ API
nodeHandle.getParam(parameter_name, variable)
More info
http://wiki.ros.org/roscpp/Overview/Parameter%20Server
nodeHandle.getParam("/package/camera/left/exposure", variable)
nodeHandle.getParam("camera/left/exposure", variable)
23.02.2017
ros::NodeHandle nodeHandle("~");
std::string topic;
if (!nodeHandle.getParam("topic", topic)) {
ROS_ERROR("Could not find topic
parameter!");
}
|
|
Péter Fankhauser 50
RViz
§3D visualization tool for ROS
§Subscribes to topics and visualizes the
message contents
§Different camera views (orthographic, top-
down, etc.)
§Interactive tools to publish user information
§Save and load setup as RViz configuration
§Extensible with plugins
More info
http://wiki.ros.org/rviz
> rosrun rviz rviz
Run RViz with
Too lsDisplays Views
Time
23.02.2017
|
|
Péter Fankhauser 51
RViz
Display Plugins
23.02.2017
|
|
Péter Fankhauser 52
RViz
Visualizing Point Clouds Example
23.02.2017
Frame in which the data is
displayed (has to exist!)
!
Choose the topic for the display
Change the display options (e.g. size)
|
|
§TF Transformation System
§rqt User Interface
§Robot models (URDF)
§Simulation descriptions (SDF)
Péter Fankhauser 53
Overview Part 3
24.02.2017
|
|
§Tool for keeping track of coordinate frames over time
§Maintains relationship between coordinate frames in
a tree structure buffered in time
§Lets the user transform points, vectors, etc. between
coordinate frames at desired time
§Implemented as publisher/subscriber model on the
topics /tf and /tf_static
Péter Fankhauser 54
TF Transformation System
Node
Node
Node
/tf
More info
http://wiki.ros.org/tf2
24.02.2017
|
|
§TF listeners use a buffer to listen to all broadcasted
transforms
§Query for specific transforms from the transform tree
Péter Fankhauser 55
TF Transformation System
Transform Tree
geometry_msgs/TransformStamped[] transforms
std_msgs/Header header
uint32 seqtime stamp
string frame_id
string child_frame_id
geometry_msgs/Transform transform
geometry_msgs/Vector3 translation
geometry_msgs/Quaternion rotation
tf2_msgs/TFMessage.msg
24.02.2017
|
|
Péter Fankhauser 56
TF Transformation System
Tools
Command line View Frames RViz
Print information about the
current tranform tree
> rosrun tf tf_monitor
Print information about the
transform between two frames
> rosrun tf tf_echo
source_frame target_frame
Creates a visual graph (PDF)
of the transform tree
> rosrun tf view_frames
3D visualization of the
transforms
24.02.2017
|
|
Péter Fankhauser 57
TF Transformation System
RViz Plugin
24.02.2017
|
|
§Create a TF listener to fill up a buffer
§Make sure, that the listener does not run out of
scope!
§To lookup transformations, use
§For time, use ros::Time(0) to get the latest
available transform
Péter Fankhauser 58
TF Transformation System
Transform Listener C++ API
tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
More info
http://wiki.ros.org/tf2/Tutorials/Writing%20a%20tf2%20listener%20%28C%2B%2B%29
geometry_msgs::TransformStamped transformStamped =
tfBuffer.lookupTransform(target_frame_id,
source_frame_id, time);
#include <ros/ros.h>
#include <tf2_ros/transform_listener.h>
#include <geometry_msgs/TransformStamped.h>
int main(int argc, char** argv) {
ros::init(argc, argv, "tf2_listener");
ros::NodeHandle nodeHandle;
tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
ros::Rate rate(10.0);
while (nodeHandle.ok()) {
geometry_msgs::TransformStamped transformStamped;
try {
transformStamped = tfBuffer.lookupTransform("base",
"odom", ros::Time(0));
} catch (tf2::TransformException &exception) {
ROS_WARN("%s", exception.what());
ros::Duration(1.0).sleep();
continue;
}
rate.sleep();
}
return 0;
};
24.02.2017
|
|
§User interface base on Qt
§Custom interfaces can be setup
§Lots of existing plugins exist
§Simple to write own plugins
Péter Fankhauser 59
rqt User Interface
Run RQT with
> rosrun rqt_gui rqt_gui
More info
http://wiki.ros.org/rqt/Plugins
or
> rqt
24.02.2017
|
|
Péter Fankhauser 60
rqt User Interface
rqt_image_view
§Visualizing images
More info
http://wiki.ros.org/rqt_image_view
Run rqt_graph with
> rosrun rqt_image_view rqt_image_view
24.02.2017
|
|
Péter Fankhauser 61
rqt User Interface
rqt_multiplot
§Visualizing numeric
values in 2D plots
More info
http://wiki.ros.org/rqt_multiplot
Run rqt_multiplot with
> rosrun rqt_multiplot rqt_multiplot
24.02.2017
|
|
Péter Fankhauser 62
rqt User Interface
rqt_graph
§Visualizing the ROS
computation graph
More info
http://wiki.ros.org/rqt_graph
Run rqt_graph with
> rosrun rqt_graph rqt_graph
24.02.2017
|
|
Péter Fankhauser 63
rqt User Interface
rqt_console
§Displaying and filtering
ROS messages
More info
http://wiki.ros.org/rqt_console
Run rqt_console with
> rosrun rqt_console rqt_console
24.02.2017
|
|
Péter Fankhauser 64
rqt User Interface
rqt_logger_level
§Configuring the logger level
of ROS nodes
More info
http://wiki.ros.org/rqt_logger_level
Run rqt_logger_level with
> rosrun rqt_logger_level
rqt_logger_level
24.02.2017
|
|
§Defines an XML format for representing a
robot model
§Kinematic and dynamic description
§Visual representation
§Collision model
§URDF generation can be be scripted
with XACRO
Péter Fankhauser 65
Robot Models
Unified Robot Description Format (URDF)
More info
http://wiki.ros.org/urdf
http://wiki.ros.org/xacro
Mesh for visuals Primitives for collision
24.02.2017
|
|
§Description consists of a set of link elements
and a set of joint elements
§Joints connect the links together
Péter Fankhauser 66
Robot Models
Unified Robot Description Format (URDF)
More info
http://wiki.ros.org/urdf/XML/model
<link name="link_name">
<visual>
<geometry>
<mesh filename="mesh.dae"/>
</geometry>
</visual>
<collision>
<geometry>
<cylinder length="0.6" radius="0.2"/>
</geometry>
</collision>
<inertial>
<mass value="10"/>
<inertia ixx="0.4" ixy="0.0" />
</inertial>
</link>
<joint name="joint_name" type="revolute">
<axis xyz="0 0 1"/>
<limit effort="1000.0" upper="0.548"…/>
<origin rpy="0 0 0" xyz="0.2 0.01 0"/>
<parent link="parent_link_name"/>
<child link="child_link_name"/>
</joint>
<robot name="robot">
<link> ... </link>
<link> ... </link>
<link> ... </link>
<joint> .... </joint>
<joint> .... </joint>
<joint> .... </joint>
</robot>
robot.urdf
24.02.2017
|
|
Péter Fankhauser 67
Robot Models
Usage in ROS
<include file="$(find husky_gazebo)/launch/spawn_husky.launch">
<arg name="laser_enabled" value="$(arg laser_enabled)"/>
<arg name="ur5_enabled" value="$(arg ur5_enabled)"/>
<arg name="kinect_enabled" value="$(arg kinect_enabled)"/>
</include>
husky_empty_world.launch
<param name="robot_description" command="$(find xacro)/xacro.py
'$(arg husky_gazebo_description)'
laser_enabled:=$(arg laser_enabled)
ur5_enabled:=$(arg ur5_enabled)
kinect_enabled:=$(arg kinect_enabled)" />
spawn_husky.launch
§The robot description (URDF) is stored on
the parameter server (typically) under
/robot_description
§You can visualize the robot model in Rviz
with the RobotModel plugin
24.02.2017
|
|
§Defines an XML format to describe
§Environments (lighting, gravity etc.)
§Objects (static and dynamic)
§Sensors
§Robots
§SDF is the standard format for Gazebo
§Gazebo converts a URDF to SDF
automatically
Péter Fankhauser 68
Simulation Descriptions
Simulation Description Format (SDF)
More info
http://sdformat.org
24.02.2017
|
|
§ROS services
§ROS actions (actionlib)
§ROS time
§ROS bags
§Debugging strategies
Péter Fankhauser 69
Overview Part 4
27.02.2017
|
|
§Request/response communication between
nodes is realized with services
§The service server advertises the service
§The service client accesses this service
§Similar in structure to messages, services
are defined in *.srv files
Péter Fankhauser 70
ROS Services
Node 1
Service Client
Node 2
Service Server
> rosservice list
List available services with
> rosservice type /service_name
Show the type of a service
> rosservice call /service_name args
Call a service with the request contents More info
http://wiki.ros.org/Services
Request
Response
service
name
Request Request
Response
Response
Request
---
Response
Service definition
*.srv
27.02.2017
|
|
Péter Fankhauser 71
ROS Services
Examples
---
bool success
string message
std_srvs/Trigger.srv geometry_msgs/PoseStamped start
geometry_msgs/PoseStamped goal
float32 tolerance
---
nav_msgs/Path plan
nav_msgs/GetPlan.srv
Request
Response
27.02.2017
|
|
Péter Fankhauser 72
ROS Service Example
Starting a roscore and aadd_two_ints_server node
In console nr. 1:
Start a roscore with
> roscore
In console nr. 2:
Run a service demo node with
> rosrun roscpp_tutorials add_two_ints_server
27.02.2017
|
|
Péter Fankhauser 73
ROS Service Example
Console Nr. 3 Analyze and call service
See the available services with
> rosservice list
See the type of the service with
> rosservice type /add_two_ints
Show the service definition with
> rossrv show roscpp_tutorials/TwoInts
Call the service (use Tab for auto-complete)
> rosservice call /add_two_ints "a: 10
b: 5"
27.02.2017
|
|
Péter Fankhauser 74
ROS C++ Client Library (roscpp)
Service Server
§Create a service server with
#include <ros/ros.h>
#include <roscpp_tutorials/TwoInts.h>
bool add(roscpp_tutorials::TwoInts::Request &request,
roscpp_tutorials::TwoInts::Response &response)
{
response.sum = request.a+ request.b;
ROS_INFO("request: x=%ld, y=%ld", (long int)request.a,
(long int)request.b);
ROS_INFO(" sending back response: [%ld]",
(long int)response.sum);
return true;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "add_two_ints_server");
ros::NodeHandle nh;
ros::ServiceServer service =
nh.advertiseService("add_two_ints", add);
ros::spin();
return 0;
}
add_two_ints_server.cpp
§When a service request is received,
callback function is called with the request
as argument
§Fill in the response to the response
argument
§Return to function with true to indicate that it
has been executed properly
More info
http://wiki.ros.org/roscpp/Overview/Services
ros::ServiceServer service =
nodeHandle.advertiseService(service_name,
callback_function);
27.02.2017
|
|
Péter Fankhauser 75
ROS C++ Client Library (roscpp)
Service Client
§Create a service client with
#include <ros/ros.h>
#include <roscpp_tutorials/TwoInts.h>
#include <cstdlib>
int main(int argc, char **argv) {
ros::init(argc, argv, "add_two_ints_client");
if (argc != 3) {
ROS_INFO("usage: add_two_ints_client X Y");
return 1;
}
ros::NodeHandle nh;
ros::ServiceClient client =
nh.serviceClient<roscpp_tutorials::TwoInts>("add_two_ints");
roscpp_tutorials::TwoInts service;
service.request.a= atoi(argv[1]);
service.request.b= atoi(argv[2]);
if (client.call(service)) {
ROS_INFO("Sum: %ld", (long int)service.response.sum);
} else {
ROS_ERROR("Failed to call service add_two_ints");
return 1;
}
return 0;
}
add_two_ints_client.cpp
§Create service request contents
service.request
§Call service with
§Response is stored in service.response
More info
http://wiki.ros.org/roscpp/Overview/Services
ros::ServiceClient client =
nodeHandle.serviceClient<service_type>
(service_name);
client.call(service);
27.02.2017
|
|
§Similar to service calls, but provide possibility to
§Cancel the task (preempt)
§Receive feedback on the progress
§Best way to implement interfaces to time-
extended, goal-oriented behaviors
§Similar in structure to services, action are
defined in *.action files
§Internally, actions are implemented with a set of
topics
Péter Fankhauser 76
ROS Actions (actionlib)
Node 1
Action Client
Node 2
Action Server
Goal
More info
http://wiki.ros.org/actionlib
http://wiki.ros.org/actionlib/DetailedDescription
Action
Goal
---
Result
---
Feedback
Action definition
*.action
Cancel
Status
Result
Feedback
27.02.2017
|
|
Péter Fankhauser 77
ROS Actions (actionlib)
int32 samples
---
float32 mean
float32 std_dev
---
int32 sample
float32 data
float32 mean
float32 std_dev
Averaging.action
navigation_msgs/Path path
---
bool success
---
float32 remaining_distance
float32 initial_distance
FollowPath.action
Goal
Feedback
Result
27.02.2017
|
|
Péter Fankhauser 78
ROS Parameters, Dynamic Reconfigure, Topics, Services, and
Actions Comparison
Parameters
Dynamic
Reconfigure
Topics
Services
Actions
Description
Global constant
parameters
Local,
changeable
parameters
Continuous data
streams
Blocking
call for
processing a request
Non
-blocking,
preemptable
goal
oriented
tasks
Application
Constant settings
Tuning parameters
One
-way continuous
data flow
Short triggers
or
calculations
Task executions and
robot actions
Examples
Topic names, camera
settings, calibration
data,
robot setup
Controller parameters
Sensor data, robot
state
Trigger
change,
request state,
compute quantity
Navigation, grasping,
motion execution
27.02.2017
|
|
§Normally, ROS uses the PC’s system clock
as time source (wall time)
§For simulations or playback of logged data, it
is convenient to work with a simulated time
(pause, slow-down etc.)
§To work with a simulated clock:
§Set the /use_sim_time parameter
§Publish the time on the topic /clock from
§Gazebo (enabled by default)
§ROS bag (use option --clock)
§To take advantage of the simulated time, you
should always use the ROS Time APIs:
§ros::Time
§ros::Duration
§ros::Rate
§If wall time is required, use
ros::WallTime,ros::WallDuration,
and ros::WallRate
Péter Fankhauser 79
ROS Time
> rosparam set use_sim_time true
More info
http://wiki.ros.org/Clock
http://wiki.ros.org/roscpp/Overview/Time
ros::Time begin = ros::Time::now();
double secs =begin.toSec();
ros::Duration duration(0.5); // 0.5s
ros::Rate rate(10); // 10Hz
27.02.2017
|
|
§A bag is a format for storing message data
§Binary format with file extension *.bag
§Suited for logging and recording datasets for
later visualization and analysis
Péter Fankhauser 80
ROS Bags
More info
http://wiki.ros.org/rosbag/Commandline
Record all topics in a bag
> rosbag record --all
Record given topics
> rosbag record topic_1 topic_2 topic_3
Stop recording with Ctrl + C
Bags are saved with start date and time as file
name in the current folder (e.g. 2017-02-07-
01-27-13.bag)
Show information about a bag
> rosbag info bag_name.bag
Read a bag and publish its contents
> rosbag play bag_name.bag
Playback options can be defined e.g.
> rosbag play --rate=0.5 bag_name.bag
--rate=factor Publish rate factor
--clock Publish the clock time (set
param use_sim_time to true)
--loop Loop playback
etc.
27.02.2017
|
|
Debug with the tools you have learned
§Compile and run code often to catch bugs early
§Understand compilation and runtime error messages
§Use analysis tools to check data flow (rosnode
info, rostopic echo, roswtf, rqt_graph etc.)
§Visualize and plot data (RViz, RQT Multiplot etc.)
§Divide program into smaller steps and check
intermediate results (ROS_INFO, ROS_DEBUG etc.)
§Make your code robust with argument and return
value checks and catch exceptions
§If things don’t make sense, clean your workspace
Learn new tools
§Build in debug mode and use GDB or Valgrind
§Use Eclipse breakpoints
§Maintain code with unit tests and integration tests
Péter Fankhauser 81
Debugging Strategies
More info
http://wiki.ros.org/UnitTesting
http://wiki.ros.org/gtest
http://wiki.ros.org/rostest
http://wiki.ros.org/roslaunch/Tutorials/Roslaunch%20Nodes%20in
%20Valgrind%20or%20GDB
> catkin config --cmake-args
-DCMAKE_BUILD_TYPE=Debug
> catkin clean --all
27.02.2017
|
|
Péter Fankhauser 82
Setting Up up a Developers PC
27.02.2017
|
|
§ROS Wiki
§http://wiki.ros.org/
§Installation
§http://wiki.ros.org/ROS/Installation
§Tutorials
§http://wiki.ros.org/ROS/Tutorials
§Available packages
§http://www.ros.org/browse/
§ROS Cheat Sheet
§https://github.com/ros/cheatsheet/releases/dow
nload/0.0.1/ROScheatsheet_catkin.pdf
§ROS Best Practices
§https://github.com/ethz-
asl/ros_best_practices/wiki
§ROS Package Template
§https://github.com/ethz-
asl/ros_best_practices/tree/master/ros_packag
e_template
Péter Fankhauser 83
Further References
27.02.2017
|
|
P. Fankhauser, R. Diethelm, S. Bachmann, C. Gehring, M. Wermelinger, D. Bellicoso, V. Tsounis, A. Lauber, M. Bloesch, P.
Leemann, G. Hottiger, D. Jud, R. Kaestner, L. Isler, M. Hoepflinger, R. Siegwart, and M. Hutter, “ANYmal at the ARGOS Challenge
Tools a nd E xperi en ces f rom the Autonom ou s In spect io n of O il & Gas Site s with a Le gg ed Rob ot ,” in ROSCon, 2016.
Péter Fankhauser 84
Part 5 – Case Study
Using ROS in Complex Real-World Applications
https://vimeo.com/187696096
Presentation Slides
https://www.researchgate.net/publication/308953021
27.02.2017
|
|
Péter Fankhauser 85
Contact Information
ETH Zurich
Robotic Systems Lab
Prof. Dr. Marco Hutter
LEE J225
Leonhardstrasse 21
8092 Zurich
Switzerland
http://www.rsl.ethz.ch
Lecturers
Péter Fankhauser (pfankhauser@ethz.ch)
Dominic Jud
Martin Wermelinger
Course website:
http://www.rsl.ethz.ch/education-
students/lectures/ros.html
27.02.2017
ResearchGate has not been able to resolve any citations for this publication.
ResearchGate has not been able to resolve any references for this publication.