3
3
Service Client Example
4
4
=============================
5
5
6
- Please follow the instructions in :ref: `setup_and_run_ue_project ` to setup the UE project
6
+ Please follow the instructions in :ref: `setup_and_run_ue_project ` to setup the UE project
7
7
and open `ROS2ServiceExample.umap <https://github.com/rapyuta-robotics/turtlebot3-UE/blob/devel/Content/Maps/ROS2TopicExamples.umap >`_.
8
8
9
9
-----------------------------
@@ -121,10 +121,10 @@ Code
121
121
}
122
122
123
123
^^^^^^^^^^^^^^^^^^
124
- Examin the code
124
+ Examining the code
125
125
^^^^^^^^^^^^^^^^^^
126
126
127
- On an AROS2ServiceClientNode Actor, similar to the AROS2PublisherrNode,
127
+ On an AROS2ServiceClientNode Actor, similar to the AROS2PublisherNode,
128
128
NodeComponent is created and initialized in the constructor but ROS2 Node is not created here.
129
129
Please check :ref: `publisher_examin_code ` for the reason.
130
130
@@ -140,8 +140,8 @@ Please check :ref:`publisher_examin_code` for the reason.
140
140
}
141
141
142
142
143
- When the simulation starts, BeginPlay is called.
144
- In BeginPlay, firstly create and initialize the ROS2 Node by calling
143
+ When the simulation starts, BeginPlay is called.
144
+ In BeginPlay, firstly create and initialize the ROS2 Node by calling
145
145
`UROS2NodeComponent::Init <../doxygen_generated/html/d7/d68/class_u_r_o_s2_node_component.html#ab9b7b990c4ca38eb60acf8e0a53c3e52 >`_
146
146
.
147
147
@@ -152,9 +152,9 @@ In BeginPlay, firstly create and initialize the ROS2 Node by calling
152
152
Super::BeginPlay();
153
153
Node->Init();
154
154
155
- You can create a service client by using the
156
- `ROS2_CREATE_SERVICE_CLIENT_WITH_QOS <../doxygen_generated/html/d1/d79/_r_o_s2_node_component_8h.html#afc35f3065562037d23b39eb0baa32f0d >`_
157
- macro, which creates a service client and adds it to the node.
155
+ You can create a service client by using the
156
+ `ROS2_CREATE_SERVICE_CLIENT_WITH_QOS <../doxygen_generated/html/d1/d79/_r_o_s2_node_component_8h.html#afc35f3065562037d23b39eb0baa32f0d >`_
157
+ macro, which creates a service client and adds it to the node.
158
158
When the node receives a service response, AROS2ServiceClientNode::ReceiveResponse is called.
159
159
160
160
@@ -168,10 +168,10 @@ When the node receives a service response, AROS2ServiceClientNode::ReceiveRespon
168
168
&AROS2ServiceClientNode::ReceiveResponse, // Callback for response
169
169
UROS2QoS::DynamicBroadcaster,
170
170
AddTwoIntsSrvClient)
171
-
172
- The implementation of ROS2_CREATE_SERVICE_CLIENT_WITH_QOS is as follows.
173
- It uses Unreal Engine's dynamic delegate to call the bound function
174
- when the node receives the message.
171
+
172
+ The implementation of ROS2_CREATE_SERVICE_CLIENT_WITH_QOS is as follows.
173
+ It uses Unreal Engine's dynamic delegate to call the bound function
174
+ when the node receives the message.
175
175
You can find more information about Unreal Engine's dynamic delegate .
176
176
`here <https://docs.unrealengine.com/5.1/en-US/dynamic-delegates-in-unreal-engine/ >`_.
177
177
@@ -189,13 +189,13 @@ You can find more information about Unreal Engine's dynamic delegate .
189
189
}
190
190
191
191
In this example, service client is set to send request periodically by create
192
- `UE Timer <https://docs.unrealengine.com/5.1/en-US/quick-start-guide-to-variables-timers-and-events-in-unreal-engine-cpp/ >`_
192
+ `UE Timer <https://docs.unrealengine.com/5.1/en-US/quick-start-guide-to-variables-timers-and-events-in-unreal-engine-cpp/ >`_
193
193
.
194
194
195
- We create a ` FTimerDelegate < https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/FTimerDelegate/ >`_
196
- with a lambda function that will be called by the timer.
197
- Inside the lambda function, create the request structure (FROSAddTwoIntsReq)
198
- for the corresponding service (UROS2AddTwoIntsSrv).
195
+ We create a FTimerDelegate
196
+ with a lambda function that will be called by the timer.
197
+ Inside the lambda function, create the request structure (FROSAddTwoIntsReq)
198
+ for the corresponding service (UROS2AddTwoIntsSrv).
199
199
Set the value of the request structure, and then send the request by calling SendRequest().
200
200
201
201
.. code-block :: C++
@@ -228,7 +228,7 @@ Then start a timer to call the sendRequest method every 1 second.
228
228
229
229
When the node receives a service response, AROS2ServiceClientNode::ReceiveResponse is called.
230
230
231
- To retrieve the response, you need to create a response structure (FROSAddTwoIntsRes)
231
+ To retrieve the response, you need to create a response structure (FROSAddTwoIntsRes)
232
232
for the corresponding service (UROS2AddTwoIntsSrv) and retrieve the request by calling GetResponse().
233
233
234
234
ReceiveResponse method simply prints the received response in this example.
@@ -251,16 +251,16 @@ ReceiveResponse method simply prints the received response in this example.
251
251
BP Service Client
252
252
-----------------------------
253
253
254
- Blueprint implementation of a service client is very similar to a C++ implementation.
254
+ Blueprint implementation of a service client is very similar to a C++ implementation.
255
255
Blueprints allow you to set logic/processes, parameters, and other details from the editor.
256
256
257
257
You can add components such as UROS2Publisher from `Components ` panel in the editor (left side in the fig below)
258
258
and set each component parameters in `Details ` panel in the editor (right side in the fig below).
259
259
260
- The main difference from the C++ implementation is that it uses
260
+ The main difference from the C++ implementation is that it uses
261
261
`UROS2ServiceClientComponent <../doxygen_generated/html/d1/db9/class_u_r_o_s2_service_client_component.html >`_
262
- instead of UROS2ServiceClient.
263
- As UROS2ServiceClientComponent is a child class of
262
+ instead of UROS2ServiceClient.
263
+ As UROS2ServiceClientComponent is a child class of
264
264
`UActorComponent <https://docs.unrealengine.com/5.1/en-US/API/Runtime/Engine/Components/UActorComponent/ >`_
265
265
and has UROS2ServiceClient as a member variable, you can easily add it to the Actor and set parameters from the editor.
266
266
@@ -270,17 +270,17 @@ The Service client component is attached to an Actor, which is displayed in the
270
270
271
271
.. image :: ../images/service_client_node.png
272
272
273
- Initialize the ROS2 Node using the BeginPlay event.
274
- You can set the ROSNode parameters, such as Name and Namespace,
273
+ Initialize the ROS2 Node using the BeginPlay event.
274
+ You can set the ROSNode parameters, such as Name and Namespace,
275
275
from the `Details ` panel on the right.
276
276
277
- Compared to C++, which uses ROS2_CREATE_SERVICE_CLIENT_WITH_QOS,
278
- in Blueprint, the service client is already generated as a Component before BeginPlay.
279
- Therefore, we use
277
+ Compared to C++, which uses ROS2_CREATE_SERVICE_CLIENT_WITH_QOS,
278
+ in Blueprint, the service client is already generated as a Component before BeginPlay.
279
+ Therefore, we use
280
280
`UROS2NodeComponent::AddServiceClient <../doxygen_generated/html/d7/d68/class_u_r_o_s2_node_component.html#a5e52bd6256f3c5db5c0392cee93d7156 >`_
281
- to initialize the UROS2ServiceClient and
282
- `UROS2ServiceClient::SetDelegates <../doxygen_generated/html/d7/df5/class_u_r_o_s2_service_client.html#ae965105e696c1662ce1655249b9d864b >`_
283
- to bind callback method instead.
281
+ to initialize the UROS2ServiceClient and
282
+ `UROS2ServiceClient::SetDelegates <../doxygen_generated/html/d7/df5/class_u_r_o_s2_service_client.html#ae965105e696c1662ce1655249b9d864b >`_
283
+ to bind callback method instead.
284
284
The ROS2_CREATE_SERVICE_CLIENT_WITH_QOS macro in C++ internally calls CreateServiceClient which calls AddServiceClient and SetDelegates.
285
285
286
286
We also create a UE Timer to send request every 1 second.
@@ -292,5 +292,5 @@ Then increment the value of A and B and print those.
292
292
293
293
.. image :: ../images/service_client_res.png
294
294
295
- Callback function is bound to a custom event, indicated by the red node on the left.
296
- This callback function is called when the node receives a response.
295
+ Callback function is bound to a custom event, indicated by the red node on the left.
296
+ This callback function is called when the node receives a response.
0 commit comments