Transcript 04 ROS Tutorial - Università degli Studi di Bergamo
ROS Robot Operating System
Robotica Prof. Davide Brugali Università degli Studi di Bergamo
2
Tutorials
[online] http://wiki.ros.org/ [2014] Jason M. O’Kane
A Gentle Introduction to ROS
https://cse.sc.edu/~jokane/agitr/agitr-letter.pdf
[2013] Aaron Martinez, Enrique Fernández
Learning ROS for Robotics Programming
http://www.ict.griffith.edu.au/~vlad/teaching/robotics.d/R EADINGS/Learning20ROS%20for%20Robotics%20Pro gramming%20%5BeBook%5D.pdf
UNIBG - Robotica - Brugali
3
Speed control
y Odometry Y
WL
y V
WR
x
w
Twist
{
V
w
x Odometry X
UNIBG - Robotica - Brugali
4 Sviluppo di un sistema composto da tre applicazioni (nodi) Legge la tastiera e modifica il twist corrente
velocity_keyboard VelocityCmd
Implementato da noi Trasmette periodicamente il twist corrente al robot
velocity_controller Twist
Simula il movimento del robot
rover_driver
Implementato da noi Simulatore Turtlesim fornito con ROS UNIBG - Robotica - Brugali
Software components
rover_driver main()
twist
velocity_controller main()
command
velocity_keyboard main()
5
RoverDriver + setTwist() + getOdometry() VelocityController + updateTwist() + getTwist()
UNIBG - Robotica - Brugali
VelocityKeyboard + readKeyboard()
6
Connectors implementation : Middleware
rover_driver velocity_controller velocity_keyboard Runtime Infrastructure (Concurrency, Communication) Operating System Runtime Infrastructure (Concurrency, Communication) Operating System UNIBG - Robotica - Brugali
7
Connectors : Publish-subscribe styles (Event flow)
Components interact via announced events Components subscribe to a set of events The runtime infrastructure ensures that each published event is delivered to all subscribers The connector is an event bus Set of subscribers are unknown to the publisher UNIBG - Robotica - Brugali
Robot Operating system (ROS)
8 UNIBG - Robotica - Brugali
Example of ROS Node: velocity_controller
Nome Tipo
velocity_controller main() subscribes to keyboard/ cmd_vel VelocityCmd
9
main loop VelocityController + updateTwist() + getTwist() publishes turtle1/ cmd_vel Twist
Nome Tipo UNIBG - Robotica - Brugali
velocity_controller_node.cpp
10 UNIBG - Robotica - Brugali
velocity_controller_node.cpp
11 UNIBG - Robotica - Brugali
VelocityController.hpp
12 UNIBG - Robotica - Brugali
VelocityController.cpp
13 … etc.
UNIBG - Robotica - Brugali
Workspace di sviluppo per ROS
mobile_robot / src / CMakeLists.txt
build / devel / -- WORKSPACE - SOURCE SPACE (contains the packages) -- The 'toplevel' CMake file - - BUILD SPACE CATKIN_IGNORE DEVELOPMENT SPACE 14 Workspace CMakeList.txt
/ ROS-Tutorial /mobile_robot/
http://wiki.ros.org/catkin/Tutorials/create_a_workspace UNIBG - Robotica - Brugali
15
Creazione del Workspace e compilazione
$ mkdir ~ / ROS-Tutorial / mobile_robot / src $ cd ~ / ROS-Tutorial / mobile_robot / src $ catkin_init_workspace $ cd ~ / ROS-Tutorial / mobile_robot $ catkin_make $ source devel / setup.bash
UNIBG - Robotica - Brugali
ROS Packages
Software in ROS is organized in useful module.
packages
. A package might contain ROS nodes, a ROS-independent library, a dataset, configuration files, a third-party piece of software, or anything else that logically constitutes a The goal of these packages it to provide this useful functionality in an easy-to-consume manner so that software can be easily reused. This means that a package is the smallest individual thing you can build in ROS and it is the way software is bundled for release (meaning, for example, there is one debian package for each ROS package), respectively. 16 http://wiki.ros.org/Packages UNIBG - Robotica - Brugali
Workspace di sviluppo per ROS
packages 17 Node Class Message Workspace velocity_keyboard velocity_keyboard_node.hpp
velocity_keyboard_node.cpp
VelocityKeyboard.hpp VelocityKeyboard.cpp
VelocityCmd.msg
CMakeList.txt
package.xml
velocity_controller velocity_controller_node.hpp
velocity_controller_node.cpp
VelocityController.hpp VelocityController.cpp
CMakeList.txt
package.xml
CMakeList.txt
/ ROS-Tutorial /mobile_robot/
http://wiki.ros.org/catkin/Tutorials/create_a_workspace UNIBG - Robotica - Brugali turtlesim
18
Package velocity_controller
$ cd ~/ROS-Tutorial/mobile_robot/src $ catkin_create_pkg velocity_controller std_msgs rospy roscpp $ source ~/ROS-Tutorial/mobile_robot/devel/setup.bash
mobile_robot / src / CMakeLists.txt
velocity_controller/ CMakeLists.txt
package.xml
-- package UNIBG - Robotica - Brugali
19
ROS Nodes
A
node
is a process that performs computation. Nodes are combined together into a graph and communicate with one another using streaming topics , RPC services , and the Parameter Server . These nodes are meant to operate at a fine-grained scale; a robot control system will usually comprise many nodes. For example, one node controls a laser range-finder, one Node controls the robot's wheel motors, one node performs localization, one node performs path planning, one node provide a graphical view of the system, and so on.
UNIBG - Robotica - Brugali
ROS Nodes
20 All running nodes have a
graph resource name
that uniquely identifies them to the rest of the system. For example, /hokuyo_node could be the name of a Hokuyo driver broadcasting laser scans. Nodes also have a node type, that simplifies the process of referring to a node executable on the fileystem. These node types are
package resource name
with the name of the node's package and the name of the node executable file. In order to resolve a node type, ROS searches for all executables in the package with the specified name and chooses the first that it finds. As such, you need to be careful and not produce different executables with the same name in the same package .
UNIBG - Robotica - Brugali
Nodo velocity_controller
velocity_controller_node
main program 21
VelocityController
N.B. comando per spostarsi direttamente nella cartella base di un package $ roscd velocity_controller/ $ gedit include/VelocityController.hpp
$ gedit src/VelocityController.cpp
UNIBG - Robotica - Brugali class
VelocityKeyboard.hpp
22 UNIBG - Robotica - Brugali
23 UNIBG - Robotica - Brugali
velocity_keyboard_node.hpp
24 UNIBG - Robotica - Brugali
velocity_keyboard_node.cpp
25 UNIBG - Robotica - Brugali
Messaggio “VelocityCmd”
26 velocity_controller include VelocityController.hpp
velocity_controller_node.hpp
msg
VelocityCmd.msg
src VelocityController.cpp
velocity_controller_node.cpp
CMakeList.txt
package.xml
UNIBG - Robotica - Brugali
Messaggio “VelocityCmd”
VelocityCmd.msg
int8
command 27 UNIBG - Robotica - Brugali
CMakeLists.txt
## Declare a cpp executable add_executable( velocity_controller_node src/VelocityController.cpp
src/velocity_controller_node.cpp)
nome del file eseguibile
28 UNIBG - Robotica - Brugali
Compilare il codice sorgente in ROS
Aprire un terminale selezionando l’icona Digitare i seguenti comandi: $ cd ~/ROS-Tutorial/mobile_robot/src $ source ~/ROS-Tutorial/mobile_robot/devel/setup.bash
$ catkin_make 29 Se serve, modificare il codice sorgente Ricompilare i progetti con il comando catkin_make UNIBG - Robotica - Brugali
30
ROS Messages
velocity_controller Twist turtlesim
geometry_msgs / Twist.msg
nav_msgs / Odometry.msg
UNIBG - Robotica - Brugali
POSE
31 UNIBG - Robotica - Brugali
TWIST
32 UNIBG - Robotica - Brugali
Odometry
33 UNIBG - Robotica - Brugali
Esecuzione di programmi ROS
Cambiare workspace di Ubuntu selezionando l’icona Selezionare una delle trefinestre libere Aprire quattro terminali cliccando il tasto destro sull’icona 34 UNIBG - Robotica - Brugali
Digitare i seguenti comandi
TERMINALE 1 : avviare il core di ROS $ roscore 35 TERMINALE 2 : avviare il simulatore del robot Turtle $ source ~/ROS-Tutorial/mobile_robot/devel/setup.bash
$ rosrun turtlesim turtlesim_node UNIBG - Robotica - Brugali
Digitare i seguenti comandi
TERMINALE 3 : avviare l’applicazione velocity_controller $ source ~/ROS-Tutorial/mobile_robot/devel/setup.bash
$ roscd velocity_controller $ rosrun velocity_controller velocity_controller_node 36 TERMINALE 4 : avviare l’applicazione velocity_keyboard $ source ~/ROS-Tutorial/mobile_robot/devel/setup.bash
$ roscd velocity_keyboard $ rosrun velocity_keyboard velocity_keyboard_node UNIBG - Robotica - Brugali
Simulatore TurtleSim
37 UNIBG - Robotica - Brugali
38 Sviluppo di un sistema composto da tre nodi
Keyboard Target position_controller Twist turtlesim Odometry
UNIBG - Robotica - Brugali