Ros Lab 3
Ros Lab 3
O UTLINE
1
Basics of ROS Services
Basics of ROS Services Create Custom ROS 2 Services.
ROS 2 topics are unidirectional and allow communication of 1:N, N:1 or N:N.
2
Basics of ROS Services Create Custom ROS 2 Services.
ROS services allow for bidirectional communications between a server and client.
Blocked client: The client is waiting for the response from server.
3
Basics of ROS Services Create Custom ROS 2 Services.
ROS S ERVICES
ROS S ERVICES
5
Basics of ROS Services Create Custom ROS 2 Services.
Note: Any service with parameter in its name is out of the scope of this tutorial.
let’s focus on the turtlesim-specific services: /clear, /kill, /reset, /spawn,
/turtle1/set pen, /turtle1/teleport absolute, and
/turtle1/teleport relative 6
Basics of ROS Services Create Custom ROS 2 Services.
7
Basics of ROS Services Create Custom ROS 2 Services.
7
Basics of ROS Services Create Custom ROS 2 Services.
Calling a service
ros2 service call <service name> <service type> <arguments>
8
Basics of ROS Services Create Custom ROS 2 Services.
9
Create Custom ROS 2 Services.
Basics of ROS Services Create Custom ROS 2 Services.
10
Basics of ROS Services Create Custom ROS 2 Services.
11
Basics of ROS Services Create Custom ROS 2 Services.
Create a new ROS 2 package with cmake build option to define our service file.
$ ros2 pkg create --build-type ament cmake my own srv
note: ROS 2 services cannot be created with pure python packages, i.e.
ament python.
Navigate inside the newly created package and create a new folder named srv
$ mkdir srv
Inside the srv folder create a new text file named AddTwoInts.srv file and add the
following
int64 a
int64 b
---
int64 sum
12
Basics of ROS Services Create Custom ROS 2 Services.
To convert the service you defined into language-specific code, add the following lines to
CMakeLists.txt:
13
Basics of ROS Services Create Custom ROS 2 Services.
S TEP 3: U PDATE THE PACKAGE . XML FILE AND BUILD THE PACKAGE .
14
Basics of ROS Services Create Custom ROS 2 Services.
15
Basics of ROS Services Create Custom ROS 2 Services.
16
Basics of ROS Services Create Custom ROS 2 Services.
17
Basics of ROS Services Create Custom ROS 2 Services.
18
Basics of ROS Services Create Custom ROS 2 Services.
20
Basics of ROS Services Create Custom ROS 2 Services.
ACTIVITY
Activity
Develop a ROS 2 service that control a Turtlbot3 inside Gazebo to move to a certain goal
given by the client in (x, y, θ). The server will return the time taken by the robot to reach the
goal.
21
Basics of ROS Services Create Custom ROS 2 Services.
End of Lecture
haitham.elhussieny@ejust.edu.eg
22