Amr Aboushousha
[Link]
What is ROS ?
• ROS is an open-source robot opera ng system
• A set of so ware libraries and tools that help you build robot
applica ons that work across a wide variety of robo c pla orm
• The opera ng system side, which provides standard opera ng
services.
• A suite of user contributed packages that implement common
func onality such as SLAM, planning, percep on, vision,
manipula on, etc.
History
ROS Core Concepts
• Nodes
• Messages and Topics
• Services
• ROS Master
• Parameters
• packages
ROS Master
ROS Distribu on Releases
ROS Supported Pla orms
• ROS is currently supported only on Ubuntu or Debian
• other variants such as Windows and Mac OS X are considered
experimental
• ROS Indigo supports the following Ubuntu versions:
• Trusty (14.04 LTS)
• Saucy (13.10)
ROS Installa on
• If you already have Ubuntu installed, follow the instruc on
• h p://[Link]/indigo/Installa on/Ubuntu
• You can also download a VM with ROS Indigo Pre-installe
here:
h p://[Link]fi[Link]/file/igqxpi58rh4x114/Ubuntu_1
• You can import this file into VirtualBox or VMWare
Catkin workspace
A set of directories in which a set of related ROS code lives
You can have mul ple ROS workspaces, but you can only work in one of them at any one me
ROS Environment
• A er you install ROS you will have setup.*sh files in
'/opt/ros/<distro>/', and you could source them like so:
$ source /opt/ros/indigo/[Link]
• You will need to run this command on every new shell you ope
have access to the ros commands, unless you add this line to y
bash startup file (~/.bashrc)
ROS Basic Commands
• roscore
• rosrun
• rosnode
• rostopic
roscore
rosrun
• rosrun allows you to run a node
• Usage:
$ rosrun <package> <executable>
• Example:
$ rosrun turtlesim turtlesim_node
Demo - Turtlesim
• In separate terminal windows run:
• roscore
• rosrun turtlesim turtlesim_node
• rosrun turtlesim turtle_teleop_key
Demo - Turtlesim
rosnode
• Displays debugging informa on about ROS nodes, including
publica ons, subscrip ons and connec ons
Command
List ac ve nodes $rosnode list
Test connec vity to node $rosnode ping
Print informa on about a node $rosnode info
Kill a running node $rosnode kill
List nodes running on a par cular machine $rosnode machine
rosnode info
rostopic
• Gives informa on about a topic and allows to publish mes
on a topic
Command
List ac ve topics $rostopic list
Prints messages of the topic to the screen $rostopic echo /topic
Print informa on about a topic $rostopic info /topic
Prints the type of messages the topic $rostopic type /topic
publishes
Publishes data to a topic $rostopic pub /topic type args
rostopic list
• Displays the list of current topics:
Publish to ROS Topic
• Use the rostopic pub command to publish messages to a t
• For example, to make the turtle move forward at a 0.2m/s
you can publish a cmd_vel message to the topic
/turtle1/cmd_vel:
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist '{linear: {x: 0.2, y:
• To specify
0, z:only the linear
0}, angular: {x: 0, y:x0,velocity:
z: 0}}'
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist '{linear: {x: 0.2}}'
Publish to ROS Topic
• If you want to publish a message con nuously use the arg
-r with the loop rate in Hz
• For example, to make the turtle turn in circles con nuous
type:
$ rostopic pub /turtle1/cmd_vel -r 10 geometry_msgs/Twist ‘{angular:
{z: 0.5}}'
Publish to ROS Topic
Talker and Listener
• We’ll now create a package with two nodes:
• talker publishes messages to topic “cha er”
• listener reads the messages from the topic and prints them out to the s
• First create the package chat_pkg
• Open the package source directory
• Copy the$ cdfollowing code into it
~/catkin_ws/src
catkin_create_pkg chat_pkg std_msgs rospy roscpp
[Link]
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker"); // Initiate new ROS node named "talker"
ros::NodeHandle node;
ros::Publisher chatter_pub = [Link]<std_msgs::String>("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok()) // Keep spinning loop until user presses Ctrl+C
{
std_msgs::String msg;
[Link] = “hello”;
ROS_INFO("%s", [Link].c_str());
chatter_pub.publish(msg);
ros::spinOnce(); // Need to call this function often to allow ROS to process incoming messages
loop_rate.sleep(); // Sleep for the rest of the cycle, to enforce the loop rate
count++;
}
return 0;
}
[Link]
#include "ros/ros.h"
#include "std_msgs/String.h"
// Topic messages callback
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
int main(int argc, char **argv)
{
// Initiate a new ROS node named "listener"
ros::init(argc, argv, "listener");
ros::NodeHandle node;
// Subscribe to a given topic
ros::Subscriber sub = [Link]("chatter", 1000, chatterCallback);
// Enter a loop, pumping callbacks
ros::spin();
return 0;
}
ros::spinOnce()
• A common pa ern is to call spinOnce() periodically:
Compile the Nodes
• Add the following to the package’s CMakeLists file
cmake_minimum_required(VERSION 2.8.3)
project(chat_pkg)
…
## Declare a cpp executable
add_executable(talker src/[Link])
add_executable(listener src/[Link])
## Specify libraries to link a library or executable target against
target_link_libraries(talker ${catkin_LIBRARIES})
target_link_libraries(listener ${catkin_LIBRARIES})
Building the Nodes
• Now build the package and compile all the nodes using the
catkin_make tool:
cd ~/catkin_ws
catkin_make
• This will create two executables, talker and listener, at
~/catkin_ws/devel/lib/chat_pkg
Running the Nodes From Terminal
• Run roscore
• Run the nodes in two different terminals:
$ rosrun chat_pkg talker
$ rosrun chat_pkg listener
rqt_graph
• rqt_graph creates a dynamic graph of what's going on in the sy
• Use the following command to run it:
$ rosrun rqt_graph rqt_graph
ROS Names
• ROS names must be unique
• If the same node is launched twice, roscore directs the old
node to exit
• To change the name of a node on the command line, the s
__name remapping syntax can be used
• The following two shell commands would launch two insta
of talker named talker1 and talker2
$ rosrun chat_pkg talker __name:=talker1
$ rosrun chat_pkg talker __name:=talker2
roslaunch
• a tool for easily launching mul ple ROS nodes as well as se
parameters on the Parameter Server
• roslaunch operates on launch files which are XML files tha
specify a collec on of nodes to launch along with their
parameters
• By conven on these files have a suffix of .launch
• Syntax:
• roslaunch automa
$ roslaunch cally
PACKAGE runs roscore for you
LAUNCH_FILE
Launch File Example
• Launch file for launching the talker and listener nodes:
<launch>
<node name="talker" pkg="chat_pkg" type="talker" output="screen"/>
<node name="listener" pkg="chat_pkg" type="listener"
output="screen"/>
• Each <node> tag includes a ributes declaring the ROS
</launch>
graph name of the node, the package in which it can be
found, and the type of node, which is the filename of th
executable program
• output=“screen” makes the ROS log messages appear on
the launch terminal window
Launch File Example
$ roslaunch chat_pkg [Link]
Velocity Commands
• To make a robot move in ROS we need to publish Twist messag
the topic cmd_vel
• This message has a linear component for the (x,y,z) veloci es,
angular component for the angular rate about the (x,y,z) axes
geometry_msgs/Vector3 linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z
A Move Turtle Node
• For the demo, we will create a new ROS package called my_tur
$ cd ~/catkin_ws/src
• Add anew source file to
$ catkin_create_pkg the package
my_turtle called
std_msgs rospy Move_Turtle.cpp
roscpp
• Add the following code
[Link]
#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
int main(int argc, char **argv)
{
const double FORWARD_SPEED_MPS = 0.5;
// Initialize the node
ros::init(argc, argv, "move_turtle");
ros::NodeHandle node;
// A publisher for the movement data
ros::Publisher pub = [Link]<geometry_msgs::Twist>("turtle1/cmd_vel", 10);
// Drive forward at a given speed. The robot points up the x-axis.
// The default constructor will set all commands to 0
geometry_msgs::Twist msg;
[Link].x = FORWARD_SPEED_MPS;
// Loop at 10Hz, publishing movement commands until we shut down
ros::Rate rate(10);
ROS_INFO("Starting to move forward");
while (ros::ok()) {
[Link](msg);
[Link]();
}
}
Gazebo
Gazebo
• ROS Indigo comes with Gazebo V2.2
• Gazebo home page - h p://[Link]/
• Gazebo tutorials - h p://[Link]/tutorials
Gazebo Architecture
Gazebo consists of two processes:
• Server: Runs the physics loop and generates sensor data
• Executable: gzserver
• Libraries: Physics, Sensors, Rendering, Transport
• Client: Provides user interac on and visualiza on of a simula
• Executable: gzclient
• Libraries: Transport, Rendering, GUI
(C)2016 Roi Yehoshua
Running Gazebo from ROS
• To launch Gazebo type:
$ rosrun gazebo_ros gazebo
• Note: When you first launch Gazebo it may take a few min
update its model database
Add a Model
To add a model to the world:
• le -click on the desired model in the Insert Tab on the le
• move the cursor to the desired loca on in World View
• le -click again to release
• Use the Translate and Rotate modes to orient the model m
precisely
Inser ng PR2 Robot
Clock
• You can start, pause and step through the simula on with
clock
• It is located at the bo om of the World View
• Real Time Factor: Displays how fast or slow the simula on
running in comparison to real me
• A factor less than 1.0 indicates simula on is running slower than real
• Greater then 1.0 indicates faster than real me
provide space to hold a netbook computer and
depth camera and other devices
• Does not have a laser scanner
• Despite this, mapping and naviga on can work quite well
for indoor spaces
Turtlebot Simula on
• To install Turtlebot simula on stack type:
$ sudo apt-get install ros-indigo-turtlebot-gazebo ros-indigo-turtlebot-
apps ros-indigo-turtlebot-rviz-launchers
• To launch a simple world with a Turtlebot, type:
$ roslaunch turtlebot_gazebo turtlebot_world.launch
Turtlebot Simula on
Moving Turtlebot with Teleop
• Let’s launch the teleop package so we can move it around
environment
$ roslaunch turtlebot_teleop keyboard_teleop.launch
ROS Clock
• Normally, ROS client libraries use the computer's system clock
"wall-clock“
• When you are running a simula on or playing back logged data
o en desirable to instead have the system use a simulated cloc
that you can have accelerated, slowed, or stepped control ove
system's perceived me
• To support this, the ROS client libraries can listen to the /clock
that is used to publish "simula on me“
• For that purpose, set the /use_sim_ me parameter to true be
node is ini alized
$ rosrun rviz rviz
External Hardware
References
[Link]
[Link]
[Link]
[Link]
Other Resources
[Link]
list=PLooO7wy8UxZ7OvFsl4g-WXEF27GwNO8ZF
[Link]
Ubuntu_1.ova