rclUE
ROS2ServiceServer.h
Go to the documentation of this file.
1 
15 // Class implementing ROS2 service clients
16 
17 // Service type is defined by SrvClass
18 
19 
20 
21 #pragma once
22 
23 
24 
25 // UE
26 
27 #include "Components/ActorComponent.h"
28 
29 #include "CoreMinimal.h"
30 
31 
32 
33 // rclUE
34 
35 #include "ROS2NodeComponent.h"
36 
37 #include "ROS2Service.h"
38 
39 #include "Srvs/ROS2GenericSrv.h"
40 
41 
42 
43 #include "ROS2ServiceServer.generated.h"
44 
45 
46 
62 class RCLUE_API UROS2ServiceServer : public UROS2Service
63 
64 {
65 
66 
67 
68 public:
69 
84  static UROS2ServiceServer* CreateServiceServer(UObject* InOwner,
85 
86  const FString& InServiceName,
87 
88  const TSubclassOf<UROS2GenericSrv>& InSrvClass,
89 
90  const FServiceCallback& InCallback,
91 
92  const UROS2QoS InQoS = UROS2QoS::Services);
93 
94 
95 
104  virtual void Destroy();
105 
106 
107 
116  virtual void ProcessReady() override;
117 
118 
119 
121 
122 
127  FServiceCallback SrvCallback;
128 
129 
130 
132 
133  rcl_service_t rcl_service;
134 
135 
136 
138 
139  bool Ready;
140 
141 
142 
158  void SetDelegates(const FServiceCallback& InSrvCallback);
159 
160 
161 
162 protected:
163 
174  virtual void InitializeServiceComponent() override;
175 
176 };
177 
178 
179 
193 class RCLUE_API UROS2ServiceServerComponent : public UActorComponent
194 
195 {
196 
197 
198 
199 public:
200 
201 
206  UROS2ServiceServer* ServiceServer = nullptr;
207 
208 
209 
211 
212 
217  FString ServiceName = TEXT("");
218 
219 
220 
222 
223 
228  TSubclassOf<UROS2GenericSrv> SrvClass = UROS2GenericSrv::StaticClass();
229 
230 
231 
233 
234 
240 
241 
242 
244 
245 
250  FServiceCallback SrvCallback;
251 
252 
253 
254  virtual void BeginPlay() override
255 
256  {
257 
258  if (ServiceServer == nullptr)
259 
260  {
261 
262  ServiceServer = UROS2ServiceServer::CreateServiceServer(this, ServiceName, SrvClass, SrvCallback, QoS);
263 
264  }
265 
266  Super::BeginPlay();
267 
268  };
269 
270 };
271 
UROS2Service
Class implementing ROS2 service clients.
Definition: ROS2Service.h:84
UROS2QoS::Services
@ Services
UMETA(DisplayName = "Parameters"),.
UROS2ServiceServer::Ready
bool Ready
Service is ready or not.
Definition: ROS2ServiceServer.h:139
UROS2ServiceServer::CreateServiceServer
static UROS2ServiceServer * CreateServiceServer(UObject *InOwner, const FString &InServiceName, const TSubclassOf< UROS2GenericSrv > &InSrvClass, const FServiceCallback &InCallback, const UROS2QoS InQoS=UROS2QoS::Services)
Create a new UROS2ServiceServer of custom type.
ROS2GenericSrv.h
This should be refactored with other generic ROS2 types (Msgs, Sensors, Actions).
UROS2Service::ProcessReady
virtual void ProcessReady()
Determine the relevant service functions to call.
UROS2QoS
UROS2QoS
used to set QoS policies
Definition: rclcUtilities.h:177
UROS2ServiceServer::SrvCallback
FServiceCallback SrvCallback
used to receive the answer
Definition: ROS2ServiceServer.h:127
UROS2Service::Destroy
virtual void Destroy()
Destroy service with rcl_client_fini.
UROS2ServiceServerComponent
ROS2 ServiceServer Component. Wrapper of UROS2ServiceServer for BP.
Definition: ROS2ServiceServer.h:193
ROS2Service.h
Class implementing ROS2 service.
UROS2ServiceServer::rcl_service
rcl_service_t rcl_service
ROS2 Service server.
Definition: ROS2ServiceServer.h:133
UROS2ServiceServer
Class implementing ROS2 service server.
Definition: ROS2ServiceServer.h:62
UROS2ServiceServerComponent::SrvCallback
FServiceCallback SrvCallback
this is pass to #UROS2ServiceServer::ResponseDelegate in #BeginPlay
Definition: ROS2ServiceServer.h:250
UROS2Service::InitializeServiceComponent
virtual void InitializeServiceComponent()
Initialize ROS2 Action. Should be implemented in UROS2ServiceServer and UROS2ServiceClient.
ROS2NodeComponent.h
Class implementing ROS2 node.