From b46b2e2c3b027b463bdc01bcd1cea7adb484efaa Mon Sep 17 00:00:00 2001 From: Yu Okamoto Date: Fri, 19 Apr 2024 23:55:50 +0900 Subject: [PATCH] add bp api to create --- Source/rclUE/Public/ROS2ActionClient.h | 8 +++++++- Source/rclUE/Public/ROS2ActionServer.h | 8 +++++++- Source/rclUE/Public/ROS2Publisher.h | 11 ++++++----- Source/rclUE/Public/ROS2ServiceClient.h | 7 ++++++- Source/rclUE/Public/ROS2ServiceServer.h | 7 ++++++- Source/rclUE/Public/ROS2Subscriber.h | 8 +++++++- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Source/rclUE/Public/ROS2ActionClient.h b/Source/rclUE/Public/ROS2ActionClient.h index 5262a2b97..a69d7d385 100644 --- a/Source/rclUE/Public/ROS2ActionClient.h +++ b/Source/rclUE/Public/ROS2ActionClient.h @@ -186,7 +186,8 @@ class RCLUE_API UROS2ActionClientComponent : public UActorComponent FActionCallback FeedbackDelegate; FSimpleCallback CancelResponseDelegate; - virtual void BeginPlay() override + UFUNCTION(BlueprintCallable) + virtual void DefaultCreateActionClient() { if (ActionClient == nullptr) { @@ -202,6 +203,11 @@ class RCLUE_API UROS2ActionClientComponent : public UActorComponent FeedbackQoS, CancelQoS); } + } + + virtual void BeginPlay() override + { + DefaultCreateActionClient(); Super::BeginPlay(); }; }; diff --git a/Source/rclUE/Public/ROS2ActionServer.h b/Source/rclUE/Public/ROS2ActionServer.h index f832d28d2..b352ada17 100644 --- a/Source/rclUE/Public/ROS2ActionServer.h +++ b/Source/rclUE/Public/ROS2ActionServer.h @@ -156,7 +156,8 @@ class RCLUE_API UROS2ActionServerComponent : public UActorComponent FSimpleCallback ResultDelegate; FSimpleCallback CancelDelegate; - virtual void BeginPlay() override + UFUNCTION(BlueprintCallable) + virtual void DefaultCreateActionServer() { if (ActionServer == nullptr) { @@ -171,6 +172,11 @@ class RCLUE_API UROS2ActionServerComponent : public UActorComponent FeedbackQoS, CancelQoS); } + } + + virtual void BeginPlay() override + { + DefaultCreateActionServer(); Super::BeginPlay(); }; }; diff --git a/Source/rclUE/Public/ROS2Publisher.h b/Source/rclUE/Public/ROS2Publisher.h index 8f4f1ebbc..291db6b76 100644 --- a/Source/rclUE/Public/ROS2Publisher.h +++ b/Source/rclUE/Public/ROS2Publisher.h @@ -304,16 +304,17 @@ class RCLUE_API UROS2CustomPublisherComponent : public UActorComponent UPROPERTY(EditAnywhere, BlueprintReadWrite) float PublicationFrequencyHz = 1.f; - virtual void BeginPlay() override + UFUNCTION(BlueprintCallable) + virtual void DefaultCreatePublisher() { if (Publisher == nullptr) { Publisher = UROS2Publisher::CreateLoopPublisherWithClass(this, TopicName, PublisherClass, PublicationFrequencyHz); } - else - { - UE_LOG_WITH_INFO(LogTemp, Warning, TEXT("Publisher class is not created in BeginPlay.")); - } + } + virtual void BeginPlay() override + { + DefaultCreatePublisher(); Super::BeginPlay(); }; }; diff --git a/Source/rclUE/Public/ROS2ServiceClient.h b/Source/rclUE/Public/ROS2ServiceClient.h index 819bd9e48..363ab63ad 100644 --- a/Source/rclUE/Public/ROS2ServiceClient.h +++ b/Source/rclUE/Public/ROS2ServiceClient.h @@ -162,12 +162,17 @@ class RCLUE_API UROS2ServiceClientComponent : public UActorComponent UPROPERTY(EditAnywhere, BlueprintReadWrite) FServiceCallback ResponseDelegate; - virtual void BeginPlay() override + UFUNCTION(BlueprintCallable) + virtual void DefaultCreateServiceClient() { if (ServiceClient == nullptr) { ServiceClient = UROS2ServiceClient::CreateServiceClient(this, ServiceName, SrvClass, ResponseDelegate, QoS); } + } + virtual void BeginPlay() override + { + DefaultCreateServiceClient(); Super::BeginPlay(); }; }; diff --git a/Source/rclUE/Public/ROS2ServiceServer.h b/Source/rclUE/Public/ROS2ServiceServer.h index ddf9ef8f9..b73087738 100644 --- a/Source/rclUE/Public/ROS2ServiceServer.h +++ b/Source/rclUE/Public/ROS2ServiceServer.h @@ -113,12 +113,17 @@ class RCLUE_API UROS2ServiceServerComponent : public UActorComponent UPROPERTY(EditAnywhere, BlueprintReadWrite) FServiceCallback SrvCallback; - virtual void BeginPlay() override + UFUNCTION(BlueprintCallable) + virtual void DefaultCreateServiceServer() { if (ServiceServer == nullptr) { ServiceServer = UROS2ServiceServer::CreateServiceServer(this, ServiceName, SrvClass, SrvCallback, QoS); } + } + virtual void BeginPlay() override + { + DefaultCreateServiceServer(); Super::BeginPlay(); }; }; diff --git a/Source/rclUE/Public/ROS2Subscriber.h b/Source/rclUE/Public/ROS2Subscriber.h index 8e929d735..cc4785bdf 100644 --- a/Source/rclUE/Public/ROS2Subscriber.h +++ b/Source/rclUE/Public/ROS2Subscriber.h @@ -101,12 +101,18 @@ class RCLUE_API UROS2SubscriberComponent : public UActorComponent UPROPERTY(EditAnywhere, BlueprintReadWrite) FSubscriptionCallback Callback; - virtual void BeginPlay() override + UFUNCTION(BlueprintCallable) + virtual void DefaultCreateSubscriber() { if (Subscriber == nullptr) { Subscriber = UROS2Subscriber::CreateSubscriber(this, TopicName, MsgClass, Callback, QoS); } + } + + virtual void BeginPlay() override + { + DefaultCreateSubscriber(); Super::BeginPlay(); }; };