Skip to content

Commit

Permalink
apply review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Wojciech Czerski <[email protected]>
  • Loading branch information
w-czerski committed Jan 28, 2025
1 parent 1b9affd commit 57322f8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ namespace SplineTools
inline constexpr const char* SplineSubscriberComponentTypeId = "{89B8A92A-8F17-4C30-AE0D-6B088C133283}";
inline constexpr const char* SplineSubscriberConfigTypeId = "{44317FD2-51A1-41CA-BA44-F8BCAE9757CE}";

inline constexpr const char* SplinePublisherComponentTypeId = "{29c02686-04f6-416d-8f47-d2456a3e114c}";
inline constexpr const char* SplinePublisherConfigTypeId = "{dc7ac312-0f47-4ef2-a1b7-02e8716cf4ee}";
inline constexpr const char* SplinePublisherComponentTypeId = "{29C02686-04F6-416D-8F47-D2456A3E114C}";
inline constexpr const char* SplinePublisherConfigTypeId = "{DC7AC312-0F47-4EF2-A1B7-02E8716CF4EE}";
} // namespace SplineTools
41 changes: 32 additions & 9 deletions Gems/RobotecSplineTools/Code/Source/Clients/SplinePublisher.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "SplinePublisher.h"

#include "ROS2/Utilities/ROS2Names.h"

#include <ROS2/Frame/ROS2FrameComponent.h>
#include <ROS2/ROS2Bus.h>
#include <ROS2/Utilities/ROS2Names.h>

namespace SplineTools
{
Expand Down Expand Up @@ -60,20 +59,43 @@ namespace SplineTools

void SplinePublisher::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("SplineService", 0x2b674d3c));
required.push_back(AZ_CRC_CE("SplineService"));
required.push_back(AZ_CRC_CE("ROS2Frame"));
}

void SplinePublisher::Activate()
{
const ROS2::ROS2FrameComponent* ros2Frame = GetEntity()->FindComponent<ROS2::ROS2FrameComponent>();
if (!ros2Frame)
{
AZ_Warning("SplinePublisher::Activate", false, "ROS2 Frame Component is not available!");
return;
}

AZStd::string frameNamespace = ros2Frame->GetNamespace();
if (!frameNamespace.empty())
{
m_config.m_TopicConfig.m_topic = AZStd::string::format("%s/%s", frameNamespace.c_str(), m_config.m_TopicConfig.m_topic.c_str());
}

// Create the ROS2 Publisher
auto ros2Node = ROS2::ROS2Interface::Get()->GetNode();
if (ros2Node)
{
m_publisher =
ros2Node->create_publisher<nav_msgs::msg::Path>(m_config.m_TopicConfig.m_topic.data(), m_config.m_TopicConfig.GetQoS());
ros2Node->create_publisher<nav_msgs::msg::Path>(m_config.m_TopicConfig.m_topic.c_str(), m_config.m_TopicConfig.GetQoS());

AZ::TickBus::Handler::BusConnect();
}

// const auto ros2Node = ROS2::ROS2Interface::Get()->GetNode();
// if (ros2Node)
// {
// m_publisher =
// ros2Node->create_publisher<nav_msgs::msg::Path>(m_config.m_TopicConfig.m_topic.data(), m_config.m_TopicConfig.GetQoS());
//
// AZ::TickBus::Handler::BusConnect();
// }
}

void SplinePublisher::Deactivate()
Expand All @@ -84,9 +106,6 @@ namespace SplineTools

void SplinePublisher::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
{
AZ_UNUSED(deltaTime);
AZ_UNUSED(time);

PublishSplineAsPath();
}

Expand All @@ -98,6 +117,11 @@ namespace SplineTools
}

const ROS2::ROS2FrameComponent* ros2Frame = GetEntity()->FindComponent<ROS2::ROS2FrameComponent>();
if (!ros2Frame)
{
AZ_Warning("SplinePublisher::PublishSplineAsPath", false, "ROS2 Frame Component is not available!");
return;
}

nav_msgs::msg::Path pathMessage;
pathMessage.header.frame_id = ros2Frame->GetFrameID().data();
Expand Down Expand Up @@ -127,7 +151,6 @@ namespace SplineTools
pathMessage.poses.push_back(poseStamped);
}

// Publish the message
m_publisher->publish(pathMessage);
}
} // namespace SplineTools
} // namespace SplineTools
4 changes: 2 additions & 2 deletions Gems/RobotecSplineTools/Code/Source/Clients/SplinePublisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ namespace SplineTools
void Deactivate() override;

// AZ::TickBus::Handler interface implementation
void OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) override;
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;

private:
void PublishSplineAsPath() const;

SplinePublisherConfiguration m_config;
rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr m_publisher;
};
} // namespace SplineTools
} // namespace SplineTools
24 changes: 12 additions & 12 deletions Gems/RobotecSplineTools/Code/splinetools_private_files.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

set(FILES
Source/SplineToolsModuleInterface.cpp
Source/SplineToolsModuleInterface.h
Source/Clients/SplineToolsSystemComponent.cpp
Source/Clients/SplineToolsSystemComponent.h
Source/Clients/VisualizeSplineComponent.cpp
Source/Clients/VisualizeSplineComponent.h
Source/Clients/SplineSubscriber.h
Source/Clients/SplineSubscriber.cpp
Source/Clients/SplineSubscriberConfig.h
Source/Clients/SplineSubscriberConfig.cpp
Source/Clients/SplinePublisher.h
Source/Clients/SplinePublisher.cpp
Source/Clients/SplinePublisher.cpp
Source/Clients/SplinePublisher.h
Source/Clients/SplineSubscriber.cpp
Source/Clients/SplineSubscriber.h
Source/Clients/SplineSubscriberConfig.cpp
Source/Clients/SplineSubscriberConfig.h
Source/Clients/SplineToolsSystemComponent.cpp
Source/Clients/SplineToolsSystemComponent.h
Source/Clients/VisualizeSplineComponent.cpp
Source/Clients/VisualizeSplineComponent.h
Source/SplineToolsModuleInterface.cpp
Source/SplineToolsModuleInterface.h
)

0 comments on commit 57322f8

Please sign in to comment.