Introduction To ROS FINAL
Introduction To ROS FINAL
2
Presentation Outline
• What is ROS
• Robot Architecture
• ROS Architecture
o Computational Level
o File System Level
• Examples
o Publisher and Subscriber Nodes
o Object Detector and Tracker Node
o Object Detector Node
3
What is ROS?
6
ROS Distributions
The most stable and recent ROS Distributions are:
• ROS Melodic Morenia (Ubuntu 18.04 - Bionic Beaver)
• ROS Noetic Ninjemys (Ubuntu 20.04 - Focal)
http://wiki.ros.org/Distributions 7
ROS Hardware
For ROS application can be used a variety of computer boards:
• Raspbery Pi (Raspberry Pi 4 B)
• PC motherboards (Ashrock X570 Extreme4)
• Embedded motherboards (Nvidia Jetson Nano)
9
Robot Architecture
❑ A Robot may have a variety of hardware devices that a developer has to program
and control such as
• Sensors (Altimeter, LIDAR, Gyroscopes, Humidity Sensors etc.)
• Motors (Brushless Motors, AC Motors, Stepper Motors etc.)
• Displays (LCD Display, TFT etc.)
• Communication Devices (GPS/GSM, Bluetooth, Wifi, IR)
10
Robot Hardware Architecture
Example of Drone
Camera MOTOR 1
Hardware
Block Diagram LIDAR MOTOR 2
MOTOR 3
Gyroscope 2
Altimeter MOTOR 6
Gyroscope 3
GSM/GPS
7
11
Robot Software Architecture
Example of Drone Software Block Diagram
Object Detector
Algorithm DISPLAY
Driver
Object Tracker
Camera Driver Algorithm
GIMBAL Driver
GIMBAL Control
12
Presentation Outline
• What is ROS
• Robot Architecture
• ROS Architecture
o Computational Level
o File System Level
• Examples
o Publisher and Subscriber Nodes
o Object Detector and Tracker Node
o Object Detector Node
13
ROS Architecture
❑ We can describe ROS in two levels:
• File System level
• Computational level
B] Computational Level
How ROS programs communicate with each other.
14
A) ROS Computational Level
The basic ROS concepts are:
• Nodes
• Topics
• Services
• Packages
• ROS Master
• ROS Core
• ROS Tools
15
Nodes
❑ A Node is a piece of code that performs a specific function to the robot.
❑ They are simple programming files with the extension
• .py (Python)
• .cpp (C++)
16
Messages and Bags
MESSAGES
ROS uses messages so as nodes can sent or receive data. Messages contains Fields
and Constants.
• Fields
Fields contain the data. The supported data types are integer, float, boolean,
arrays, structures etc.
• Constants
Constants are values that can used to interpret the fields.
BAGS
A bag contains many messages.
http://wiki.ros.org/Messages 17
Topics
❑ Topics are names that are used from the Nodes to communicate with each other
and exchange messages.
❑ A topic is associated with the message type and thus only nodes with the same
type can send or receive messages. For example, a Node that sends floating point
data to a topic, the data cannot be received by a boolean type Node.
Alarm
TOPIC Node
Type : Boolean
Chemical Chem_Data
Sensor Node Type: Floating Point
14.36905 Plot
Node
Type: Floating Point
18
Services
A Publish/Subscriber model is a very convenient one-way
communication between nodes. In distribution systems, there’s a need
for data exchange between nodes in a two-way direction. For this
reason the Service model is used.
19
Services
20
Packages
Packages
Packages are a set of nodes, manifests, libraries, files (pictures,
videos, data), code pieces that are gathered together in a folder
so it can be reused easily.
Packages have a specific file structure when they are created. That
doesn’t mean that the developer cannot create his own folders and files
inside the package folder.
21
ROS Master
❑ The ROS Master is the coordinator of the communication between
nodes.
22
ROS Master
When an Node wants to publish a message to a Topic, the Publisher Node notify ROS Master to send
data to the Topic.
ROS MASTER
TOPIC
Plot
Chemical Chem_Data Node
Sensor Node Type: Floating Point Type: Floating Point
23
ROS Master
After the notification, the Publisher Node establishes connection the Topic. At this point, the publisher
doesn’t sent any message to the Topic unless a Subscriber Node notify ROS Master.
ROS MASTER
TOPIC
Plot
Chemical Chem_Data Node
Sensor Node Type: Floating Point Type: Floating Point
24
ROS Master
When an Subsciber Node wants to subscibe a message from a Topic, the Subsciber Node notify ROS
Master to connect to the Topic.
ROS MASTER
TOPIC
Plot
Chemical Chem_Data Node
Sensor Node Type: Floating Point Type: Floating Point
25
ROS Master
• After the notification, the Subsciber Node connects to the Topic.
• At this point the Publisher Node publishes the data to the Topic and the Subsciber, subscibes to the
Topic.
• The data is transmitted from the Publisher Node to the Subsciber Node through the Topic.
ROS MASTER
TOPIC
Plot
Chemical Chem_Data Node
Sensor Node Type: Floating Point Type: Floating Point
26
ROS Core
❑ ROS core is a collection of routines,
nodes, libraries that are essential for
ROS system ROS Master
27
ROS Core
28
ROS Tools
ROS provides a variety of tools to build, debug and
simulate . The Most common tools are:
• Catkin
• rqt_graph
• Opencv Library
• Gazebo
29
Catkin
What is Catkin?
30
Rqt graph
Rqt_graph is GUI tool that shows the function of all nodes and topics of a
ROS project.
31
OpenCV Library
OpenCV is an open source library for computer vision, machine
learning and real-time applications. The library includes
functions for:
• Object Detection
• Deep Neural Networks
• Machine Learning
• Image Processing
• Video Analysis
• 3D Reconstruction with Camera
• Image or Video Input and Output
32
Gazebo
Gazebo is a simulator for testing and training robots using
realistic scenarios in virtual environments
34
Catkin Workspace Folder Location
35
Catkin Workspace
36
Catkin Build folder
37
Src Folder with Packages
38
Package Folder
39
Node Folder
40
Presentation Outline
• What is ROS
• Robot Architecture
• ROS Architecture
o Computational Level
o File System Level
• Examples
o Publisher and Subscriber Nodes
o Object Detector and Tracker Node
o Object Detector Node
41
Presentation Outline
• What is ROS
• Robot Architecture
• ROS Architecture
o Computational Level
o File System Level
• Examples
o Publisher and Subscriber Nodes
o Object Detector and Tracker Node
o Object Detector Node
42
Publisher and Subscriber Nodes
Assume that we receive a n image from a camera and we want to show
this image. We must create a Publisher Node, a Topic and a subscriber
Node.
TOPIC
Image
Image Subscriber
Publisher Node Image
Node
43
Publisher Node
44
Subscriber Node
45
Presentation Outline
• What is ROS
• Robot Architecture
• ROS Architecture
o Computational Level
o File System Level
• Examples
o Publisher and Subscriber Nodes
o Object Detector and Tracker Node
o Object Detector Node
46
Object Detector and Tracker Node
47
Example Structure
48
Example Structure
49
Object Detector and Tracker
50
Presentation Outline
• What is ROS
• Robot Architecture
• ROS Architecture
o Computational Level
o File System Level
• Examples
o Publisher and Subscriber Nodes
o Object Detector and Tracker Node
o Object Detector Node
51
Object Detector Node
2
#! /usr/bin/env python
3
4
import rospy
5
from std_msgs.msg import Header
6
from sensor_msgs.msg import CompressedImage
7
from detector.msg import BoundingBox
8
from std_srvs.srv import Empty , EmptyResponse
from keras.applications.imagenet_utils import preprocess_input
9
10
from keras.preprocessing import image
11
import cv2
12
import tensorflow as tf
from deep_learning.ssd_detector.ssd import SSD300 as SSD
Object Detector Node
1 class DetectionPoseNode :
2 def __init__(self) :
3 models_path = join(os.path.dirname(os.path.realpath( __file__) ) , ’ models ’ )
4 self.pub_bbox = rospy.Publisher(’face_detector/bbox ’ , BoundingBox ,
5 queue_size = 10)
6 self.class_names = [ ” background ” , ’face’]
self.num_classes =len(self.class_names)
8 self.input_shape = (300 , 300 , 3)
7 self.conf_thresh = 0.6
9
10
11 self.model = SSD (self.input_shape , num_classes = self. num_classes )
13 self.pose_model = Pose_Estimator(join(models_path ,
‘pose_estimation_model.h5’))
14 self.bbox_util = BBoxUtility(self.num_classes )
15 self.graph = tf.get_default_graph( )
Object Detector Node
1 def listener(self) :
2 rospy.init_node(’detector’ , anonymous=True )
3 rospy.loginfo(’Detector node started!’)
4 rospy.Subscriber(”/usb_cam/image_raw/compressed ” ,
CompressedImage, self.detection_callback , queue_size =1)
5 rospy.spin( )
Object Detector Node
1 if __name__ == ’ __main__ ’ :
2 node = DetectionPoseNode( )
3 node.listener( )
Object Detector Node
9 y = self.model.predict(x)
10 results = self.bbox_util.detection_out(y)
11
12 timestamp = rospy.get_rostime( )
Object Detector Node
60
References
References for Further Reading
Book 1 : “Robot Operating System for Absolute Beginners, Robotics Programmings Made Easy”, Lentin
Joseph, Apress, 2018
Book 2 : “Robot Operating System – The Complete Reference”, Anis Koubaa, Springer, Vol 1, 2016
Book 3 : “Robot Operating System – The Complete Reference”, Anis Koubaa, Springer, Vol 2, 2017
Book 4 : “ROS By Example, A Do-it Yourself Guide to the Robot Operating System”, R. Patrick Goebel,
Vol 1, 2012
61
Q&A
62