rclUE
ROS2ActionClient.h
Go to the documentation of this file.
1 
19 #pragma once
20 
21 
22 
23 #include "ROS2Action.h"
24 
25 #include "ROS2NodeComponent.h"
26 
27 
28 
29 #include <rcl_action/action_client.h>
30 
31 
32 
33 #include "ROS2ActionClient.generated.h"
34 
35 
36 
54 class RCLUE_API UROS2ActionClient : public UROS2Action
55 
56 {
57 
58 
59 
60 public:
61 
86  static UROS2ActionClient* CreateActionClient(UObject* InOwner,
87 
88  const FString& InActionName,
89 
90  const TSubclassOf<UROS2GenericAction>& InActionClass,
91 
92  const FActionCallback& InGoalResponseDelegate,
93 
94  const FActionCallback& InResultResponseDelegate,
95 
96  const FActionCallback& InFeedbackDelegate,
97 
98  const FSimpleCallback& InCancelResponseDelegate,
99 
100  const UROS2QoS InGoalQoS = UROS2QoS::Services,
101 
102  const UROS2QoS InResultQoS = UROS2QoS::Services,
103 
104  const UROS2QoS InFeedbackQoS = UROS2QoS::Default,
105 
106  const UROS2QoS InCancelQoS = UROS2QoS::Services);
107 
116  virtual void Destroy() override;
117 
118 
119 
130  virtual void ProcessReady(rcl_wait_set_t* wait_set) override;
131 
132 
133 
147  bool SendGoal();
148 
149 
150 
163  template<typename TAction, typename TUEStruct>
164 
165  void SendGoal(const TUEStruct& InGoalData)
166 
167  {
168 
169  if (IsValid(OwnerNode) && OwnerNode->State == UROS2State::Initialized && State == UROS2State::Initialized)
170 
171  {
172 
173  // Update [TopicMessage] with [InMessageData]
174 
175  CastChecked<TAction>(Action)->SetGoalRequest(InGoalData);
176 
177 
178 
179  // Send [Action]
180 
181  SendGoal();
182 
183  }
184 
185  else
186 
187  {
188 
189  UE_LOG_WITH_INFO_NAMED(LogTemp, Log, TEXT("Action client or node is not yet initialized"));
190 
191  }
192 
193  }
194 
195 
196 
210  void SendResultRequest();
211 
212 
213 
227  void SendCancelRequest();
228 
229 
230 
254  void SetDelegates(const FActionCallback& InFeedbackDelegate,
255 
256  const FActionCallback& InResultResponseDelegate,
257 
258  const FActionCallback& InGoalResponseDelegate,
259 
260  const FSimpleCallback& InCancelResponseDelegate);
261 
262 
263 
265 
266  rcl_action_client_t client;
267 
268 
269 
270 private:
271 
272  rmw_request_id_t goal_res_id;
273 
274  rmw_request_id_t result_res_id;
275 
276  rmw_request_id_t cancel_res_id;
277 
278 
279 
280  FActionCallback GoalResponseDelegate;
281 
282  FActionCallback ResultResponseDelegate;
283 
284  FActionCallback FeedbackDelegate;
285 
286  FSimpleCallback CancelResponseDelegate;
287 
288 
289 
300  virtual void InitializeActionComponent() override;
301 
302 };
303 
304 
305 
319 class RCLUE_API UROS2ActionClientComponent : public UActorComponent
320 
321 {
322 
323 
324 
325 public:
326 
327 
332  UROS2ActionClient* ActionClient = nullptr;
333 
334 
335 
337 
338 
343  FString ActionName = TEXT("");
344 
345 
346 
348 
349 
354  TSubclassOf<UROS2GenericAction> ActionClass;
355 
356 
357 
359 
360 
366 
367 
368 
370 
371 
377 
378 
379 
381 
382 
388 
389 
390 
392 
393 
398  UROS2QoS FeedbackQoS = UROS2QoS::Default;
399 
400 
401 
402  FActionCallback GoalResponseDelegate;
403 
404  FActionCallback ResultResponseDelegate;
405 
406  FActionCallback FeedbackDelegate;
407 
408  FSimpleCallback CancelResponseDelegate;
409 
410 
411 
412  virtual void BeginPlay() override
413 
414  {
415 
416  if (ActionClient == nullptr)
417 
418  {
419 
420  ActionClient = UROS2ActionClient::CreateActionClient(this,
421 
422  ActionName,
423 
424  ActionClass,
425 
426  GoalResponseDelegate,
427 
428  ResultResponseDelegate,
429 
430  FeedbackDelegate,
431 
432  CancelResponseDelegate,
433 
434  GoalQoS,
435 
436  ResultQoS,
437 
438  FeedbackQoS,
439 
440  CancelQoS);
441 
442  }
443 
444  Super::BeginPlay();
445 
446  };
447 
448 };
449 
UROS2Action::ProcessReady
virtual void ProcessReady(rcl_wait_set_t *wait_set)
Determine the relevant action functions to call.
UROS2QoS::Services
@ Services
UMETA(DisplayName = "Parameters"),.
UROS2ActionClient::client
rcl_action_client_t client
ROS2 action client from rclc.
Definition: ROS2ActionClient.h:266
UROS2Action
Base class implementing ROS2 actions from which ActionServer and ActionClient should inherit.
Definition: ROS2Action.h:82
UROS2QoS
UROS2QoS
used to set QoS policies
Definition: rclcUtilities.h:177
ROS2Action.h
Base class implementing ROS2 actions from which ActionServer and ActionClient should inherit.
UROS2ActionClientComponent::ActionClass
TSubclassOf< UROS2GenericAction > ActionClass
this is pass to UROS2ActionClient::ActionClass in #BeginPlay
Definition: ROS2ActionClient.h:354
UROS2ActionClient::SendGoal
void SendGoal(const TUEStruct &InGoalData)
Send a goal.
Definition: ROS2ActionClient.h:165
UROS2ActionClientComponent
ROS2 Action client Component. Wrapper of UROS2ActionClient for BP.
Definition: ROS2ActionClient.h:319
UROS2Action::Destroy
virtual void Destroy()
Destroy this actor component.
UROS2ActionClient::CreateActionClient
static UROS2ActionClient * CreateActionClient(UObject *InOwner, const FString &InActionName, const TSubclassOf< UROS2GenericAction > &InActionClass, const FActionCallback &InGoalResponseDelegate, const FActionCallback &InResultResponseDelegate, const FActionCallback &InFeedbackDelegate, const FSimpleCallback &InCancelResponseDelegate, const UROS2QoS InGoalQoS=UROS2QoS::Services, const UROS2QoS InResultQoS=UROS2QoS::Services, const UROS2QoS InFeedbackQoS=UROS2QoS::Default, const UROS2QoS InCancelQoS=UROS2QoS::Services)
Create Action Client.
UE_LOG_WITH_INFO_NAMED
#define UE_LOG_WITH_INFO_NAMED(CategoryName, Verbosity,...)
Definition: logUtilities.h:139
Initialized
@ Initialized
UMETA(DisplayName = "Created"),.
Definition: rclcUtilities.h:158
UROS2ActionClient
Class implementing ROS2 action clients. Wrapper class of rclc action client. Callbacks are set throug...
Definition: ROS2ActionClient.h:54
UROS2Action::InitializeActionComponent
virtual void InitializeActionComponent()
Initialize ROS2 Action. Should be implemented in UROS2ActionServer and UROS2ActionClient.
ROS2NodeComponent.h
Class implementing ROS2 node.