0% found this document useful (0 votes)
28 views62 pages

Introduction To ROS FINAL

Robot Operating System
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views62 pages

Introduction To ROS FINAL

Robot Operating System
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Introduction to ROS

A. Angelou, Prof. Ioannis Pitas


Aristotle University of Thessaloniki
[email protected]
www.aiia.csd.auth.gr
Version 1.0
Date: 8/12/2020
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

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?

• ROS stands for “Robotic Operating System”


• It’s not an operating system, but a development tool
• Runs through Linux
• Is Open Source
• Supports C++ and Python programming languages
ROS Applications
ROS is used
• For research purposes
• In Research and Development (R & D) Departments in Industry
• By individuals for personal projects

ROS can be used in a wide range of applications such as:


• Autonomous Driving
BlueROV2 [BLRV] IRB 120 Robot [ABB]
• Controlling Robotic Arms
• Drones
• Object Detection
• Object Tracking
• Object Recognition
• Gesture Recognition
• Control of Multi-Drones
ROS Software
• ROS is an open source software and can be installed in any
computer with Linux operating system.
• ROS 2 is supported by Windows 10, MacOS and Linux.
• Each ROS distribution is supported by a specific Linux Distribution.
• ROS has tools, libraries and drivers for both C++ and Python
programming languages that helps you out to develop your
application.
• Has a large community
• It is well supported. Provides tutorials, documentation, libraries etc
• Events (RoboCon, ROS-Industrial Conference, ROS Summer
School)

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)

Raspberry Pi 4 ASHROCK PC Motherboard NVIDIA Jetson Nano


[RASP] [ASHR] [NVID]
8
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

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)

❑ But also may develop algorithms necessary for


• Processing Data
(Calculations, Filters, Object Detector, Image Segmentation etc)
• Optimization
(PID Controller, Bee-Hive Algorithm, Wolf-Pack Algorithm, Differential Evolution
Algorithms etc.)

10
Robot Hardware Architecture
Example of Drone
Camera MOTOR 1
Hardware
Block Diagram LIDAR MOTOR 2

MOTOR 3

Control Unit MOTOR 4


Gyroscope 1
MOTOR 5

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

A] File System Level


How ROS Directories, Folders and files are organized in the system.

B] Computational Level
How ROS programs communicate with each other.

14
A) ROS Computational Level
The basic ROS concepts are:
• Nodes

• Topics

• Messages and Bags

• 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++)

A Robot usually consist of many nodes, such as


• Camera control
• LIDAR
• GIMBAL Control
• Display
• Object Detector
• Object Tracker
• Image Filter
• Etc.

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.

A Service is a request/reply model for node communication using two


types of messages:
• A Request message
• A Reply message

Like messages, a service type depends on the data type.

19
Services

Service Server Service Service


Node Name Client
Type: Floating Node
Point

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.

❑ All Nodes, Topics Services are registered to ROS Master.


❑ When a Node wants to sent a message to a Topic or exchange
messages with the another Node, ROS Master provides a way to the
Nodes to locate each other.
❑ After the Nodes identify each other, they are communicating

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

❑ It runs at the background. ROS Parameter


Server

❑ ROS Core starts the ROS Master to rosout


enable the registration of all Nodes,
Topics and Services.

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?

❑ Catkin is a tool that is included with ROS and it is used to


build packages.
❑ The name Catkin was given by the Willow Garage
Company that created ROS.
❑ It was created for easy package installation and
distribution.
❑ It consist of macro instructions and scripts to build
packages Image of male Catkin
[CTKN]

30
Rqt graph
Rqt_graph is GUI tool that shows the function of all nodes and topics of a
ROS project.

A typical rqt_graph showing the nodes and topics at a graph level


[RQTG]

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

A simulation of a scenario with various robots in Gazebo


[GZBO]
33
B) File System Level

The image is from the paper [RRSham]

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 )

12 self.model.load_weights (join(models_path , ’ fddb_model. hdf5 ’ ) )

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 def detection_callback(self, data) : ,


2 # Compressed image
3 np_arr = np.fromstring(data.data , np.uint8)
4 cv_image = cv2.imdecode (np_arr , cv2.IMREAD_COLOR)
5 # For uncompressed images we need to use the cv2 bridge
6 # cv_image = self.bridge.imgmsg_to_cv2( data , ” bgr8 ” )
7 self.process_image(cv_image)
Object Detector Node

1 if __name__ == ’ __main__ ’ :
2 node = DetectionPoseNode( )
3 node.listener( )
Object Detector Node

1 def process_image(self , orig_image) :


2 resized = cv2.resize(orig_image, (self.input_shape[0] , self.input_shape[1]))

3 rgb = cv2.cvtColor(resized, cv2 .COLOR_BGR2RGB)


4
5
6 # Use model to predict
7 with self.graph.as_default( ) :
8 x = preprocess_input(np.array([image.img_to_array(rgb) ]))

9 y = self.model.predict(x)
10 results = self.bbox_util.detection_out(y)
11
12 timestamp = rospy.get_rostime( )
Object Detector Node

1 if len(results) > 0 and len(results[0]) > 0 :


2 det_label , det_conf, det_xmin = results[0][ : , 0 ] ,
results[0][: , 1 ] , results[0][: , 2 ]
3 det_ymin , det_xmax , det_ymax = results[0][: , 3 ] ,
results[0][: , 4 ] , results[0][: , 5 ]
4
5 top_indices = [ i for i , conf in enumerate(det_conf) if
conf >= self.conf_thresh]
6
7 top_conf = det_conf[top_indices]
8 top_label_indices = det_label[top_indices]. tolist()
9 top_xmin , top_ymin , top_xmax , top_ymax = det_xmin [
top_indices] , det_ymin [top_indices], det_xmax [
top_indices], det_ymax [top_indices]
Object Detector Node

1 for i in range ( top_conf.shape[0] ) :


2 xmin , ymin = top_xmin [ i ] , top_ymin [ i ]
3 xmax , ymax = top_xmax [ i ] , top_ymax [ i ]
4 bbox = BoundingBox ( header=Header ( stamp=timestamp ) ,
x_min=xmin , x_max=xmax , y_min=ymin , y_max=ymax)
5 self.pub_bbox.publish( bbox )
References
[BLVR] https://bluerobotics.com/store/rov/bluerov2
[ABBR] https://new.abb.com/products/robotics/industrial-robots/irb-120
[RASP] https://www.raspberrypi.org/products
[ASHR] https://www.asrock.com/mb/AMD/X570%20Extreme4/index.asp
[NVID] https://developer.nvidia.com/embedded/jetson-nano-developer-kit
[CTKN] https://upload.wikimedia.org/wikipedia/commons/8/83/Ostrya_carpinifolia_in_Italy_male_
catkins.jpg
[RRSham] Redmond R. Shamshiri, Ibrahim A. Hameed, et.al, “Robotic Harvesting of Fruiting Vegetables: A
Simulation Approach in V-Rep, ROS and MATLAB”, Automation in Agriculture - Securing Food Supplies for
Future Generations, InTechOpen, Feb, 2018
[RQTG] https://roboticsbackend.com/rqt-graph-visualize-and-debug-your-ros-graph
[GZBO] https://en.wikipedia.org/wiki/File:Gazebo_screenshot_v5.0.png
[BLVR] https://bluerobotics.com/store/rov/bluerov2
[ABBR] https://new.abb.com/products/robotics/industrial-robots/irb-120

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

ROS Wiki Link : http://wiki.ros.org


OpenCV Link : https://opencv.org
Gazebo Link : http://gazebosim.org
Robots with ROS: https://robots.ros.org

61
Q&A

Thank you very much for your attention!

Contact: Prof. I. Pitas


[email protected]

62

You might also like