rclUE
ROS2Subscriber.h
Go to the documentation of this file.
1 
17 #pragma once
18 
19 
20 
21 #include <Components/ActorComponent.h>
22 
23 #include <CoreMinimal.h>
24 
25 
26 
27 // rclUE
28 
29 #include "Msgs/ROS2GenericMsg.h"
30 
31 #include "ROS2NodeComponent.h"
32 
33 #include "ROS2Topic.h"
34 
35 
36 
37 #include "ROS2Subscriber.generated.h"
38 
39 
40 
54 class RCLUE_API UROS2Subscriber : public UROS2Topic
55 
56 {
57 
58 
59 
60 public:
61 
76  static UROS2Subscriber* CreateSubscriber(UObject* InOwner,
77 
78  const FString& InTopicName,
79 
80  const TSubclassOf<UROS2GenericMsg>& InMsgClass,
81 
82  const FSubscriptionCallback& InCallback,
83 
84  const UROS2QoS InQoS = UROS2QoS::Default);
85 
86 
87 
96  virtual void Destroy() override;
97 
98 
99 
101 
102 
107  FSubscriptionCallback Callback;
108 
109 
110 
117  virtual void ProcessReady();
118 
119 
120 
121 
126  void SetDelegates(const FSubscriptionCallback& InCallback);
127 
128 
129 
130  bool Ready = false;
131 
132 
133 
135 
136  rcl_subscription_t rcl_subscription;
137 
138 
139 
140 protected:
141 
150  virtual void InitializeTopicComponent();
151 
152 };
153 
154 
155 
169 class RCLUE_API UROS2SubscriberComponent : public UActorComponent
170 
171 {
172 
173 
174 
175 public:
176 
177 
182  UROS2Subscriber* Subscriber = nullptr;
183 
184 
185 
187 
188 
193  FString TopicName = TEXT("");
194 
195 
196 
198 
199 
204  TSubclassOf<UROS2GenericMsg> MsgClass = UROS2GenericMsg::StaticClass();
205 
206 
207 
209 
210 
215  UROS2QoS QoS = UROS2QoS::Default;
216 
217 
218 
220 
221 
226  FSubscriptionCallback Callback;
227 
228 
229 
230  virtual void BeginPlay() override
231 
232  {
233 
234  if (Subscriber == nullptr)
235 
236  {
237 
238  Subscriber = UROS2Subscriber::CreateSubscriber(this, TopicName, MsgClass, Callback, QoS);
239 
240  }
241 
242  Super::BeginPlay();
243 
244  };
245 
246 };
247 
UROS2Subscriber::CreateSubscriber
static UROS2Subscriber * CreateSubscriber(UObject *InOwner, const FString &InTopicName, const TSubclassOf< UROS2GenericMsg > &InMsgClass, const FSubscriptionCallback &InCallback, const UROS2QoS InQoS=UROS2QoS::Default)
Create a new UROS2Subscriber of custom type.
UROS2Topic::Destroy
virtual void Destroy()
Destroy topic and TopicMessage.
UROS2QoS
UROS2QoS
used to set QoS policies
Definition: rclcUtilities.h:177
UROS2SubscriberComponent::Callback
FSubscriptionCallback Callback
this is pass to UROS2Subscriber::Callback in #BeginPlay
Definition: ROS2Subscriber.h:226
UROS2SubscriberComponent
ROS2 Subscriber Component. Wrapper of UROS2Subscriber for BP.
Definition: ROS2Subscriber.h:169
UROS2Subscriber::rcl_subscription
rcl_subscription_t rcl_subscription
ROS2 subscriber.
Definition: ROS2Subscriber.h:136
UROS2Topic::InitializeTopicComponent
virtual void InitializeTopicComponent()
Initialize ROS2 Topic. Should be implemented in UROS2Publisher and UROS2Subscriber.
ROS2Topic.h
Class implementing ROS2 topic.
UROS2Topic
ROS2 topic class. Parent class of UROS2Publisher and UROS2Subscriber.
Definition: ROS2Topic.h:86
ROS2GenericMsg.h
This should be refactored with other generic ROS2 types (Msgs, Sensors, Actions).
UROS2Subscriber::Callback
FSubscriptionCallback Callback
Delegate which is Bound with #UpdateMessage by SetDelegates.
Definition: ROS2Subscriber.h:107
UROS2Subscriber
ROS2 Subscriber class.
Definition: ROS2Subscriber.h:54
ROS2NodeComponent.h
Class implementing ROS2 node.