-
Notifications
You must be signed in to change notification settings - Fork 3
Add Spline Path Publisher Component #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6470d8a
init spline subscriber
w-czerski 6ccf97e
clang format
w-czerski 915d029
fix | get spline and convert into vector of vertex
w-czerski 1b9affd
remove auto
w-czerski 57322f8
apply review changes
w-czerski ee5c565
remove comments
w-czerski 399c2d1
use emplace | format | apply reviews
w-czerski 5b7dd26
change ros2 -> ROS 2
w-czerski 3fc175d
review resolved | topic changed to spline
w-czerski 9cf218a
review resolved | use proper ROS 2 naming
w-czerski 4651355
get ros2frame outside tick
w-czerski 45bd34c
add update frequency
w-czerski ffa7f34
add readme info | add update frequency
w-czerski 23e9891
add readme info | add update frequency
w-czerski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
Gems/RobotecSplineTools/Code/Source/Clients/SplinePublisher.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include "SplinePublisher.h" | ||
|
||
#include "ROS2/Utilities/ROS2Names.h" | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#include <ROS2/Frame/ROS2FrameComponent.h> | ||
#include <ROS2/ROS2Bus.h> | ||
|
||
namespace SplineTools | ||
{ | ||
SplinePublisherConfiguration::SplinePublisherConfiguration() | ||
{ | ||
m_TopicConfig.m_type = "nav_msgs::msg::Path"; | ||
m_TopicConfig.m_topic = "spline_path"; | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
void SplinePublisherConfiguration::Reflect(AZ::ReflectContext* context) | ||
{ | ||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context)) | ||
{ | ||
serializeContext->Class<SplinePublisherConfiguration>()->Version(0)->Field( | ||
"m_topicName", &SplinePublisherConfiguration::m_TopicConfig); | ||
if (auto editContext = serializeContext->GetEditContext()) | ||
{ | ||
editContext | ||
->Class<SplinePublisherConfiguration>( | ||
"SplinePublisherConfiguration", "Configuration for the SplineSubscriber component") | ||
->ClassElement(AZ::Edit::ClassElements::Group, "SplineSubscriber Configuration") | ||
->DataElement( | ||
AZ::Edit::UIHandlers::Default, &SplinePublisherConfiguration::m_TopicConfig, "Topic Config", "Topic Config"); | ||
} | ||
} | ||
} | ||
|
||
void SplinePublisher::Reflect(AZ::ReflectContext* context) | ||
{ | ||
SplinePublisherConfiguration::Reflect(context); | ||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context)) | ||
{ | ||
serializeContext->Class<SplinePublisher, AZ::Component>()->Version(0)->Field("m_config", &SplinePublisher::m_config); | ||
if (auto editContext = serializeContext->GetEditContext()) | ||
{ | ||
editContext->Class<SplinePublisher>("SplinePathPublisher", "Enables to publish spline as a ros2 path.") | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
->ClassElement(AZ::Edit::ClassElements::EditorData, "SplinePathPublisher") | ||
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game")) | ||
->Attribute(AZ::Edit::Attributes::Category, "RobotecTools") | ||
->Attribute(AZ::Edit::Attributes::AutoExpand, true) | ||
->DataElement( | ||
AZ::Edit::UIHandlers::Default, | ||
&SplinePublisher::m_config, | ||
"Configuration", | ||
"Configuration for the SplinePathPublisher component"); | ||
} | ||
} | ||
} | ||
|
||
SplinePublisher::SplinePublisher(const SplinePublisherConfiguration& config) | ||
: m_config(config) | ||
{ | ||
} | ||
|
||
void SplinePublisher::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) | ||
{ | ||
required.push_back(AZ_CRC("SplineService", 0x2b674d3c)); | ||
required.push_back(AZ_CRC_CE("ROS2Frame")); | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
void SplinePublisher::Activate() | ||
{ | ||
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()); | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
AZ::TickBus::Handler::BusConnect(); | ||
} | ||
} | ||
|
||
void SplinePublisher::Deactivate() | ||
{ | ||
AZ::TickBus::Handler::BusDisconnect(); | ||
m_publisher.reset(); | ||
} | ||
|
||
void SplinePublisher::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) | ||
{ | ||
AZ_UNUSED(deltaTime); | ||
AZ_UNUSED(time); | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
PublishSplineAsPath(); | ||
} | ||
|
||
void SplinePublisher::PublishSplineAsPath() const | ||
{ | ||
if (!m_publisher) | ||
{ | ||
return; | ||
} | ||
|
||
const ROS2::ROS2FrameComponent* ros2Frame = GetEntity()->FindComponent<ROS2::ROS2FrameComponent>(); | ||
|
||
nav_msgs::msg::Path pathMessage; | ||
pathMessage.header.frame_id = ros2Frame->GetFrameID().data(); | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pathMessage.header.stamp = ROS2::ROS2Interface::Get()->GetROSTimestamp(); | ||
|
||
// Retrieve spline data | ||
AZStd::shared_ptr<AZ::Spline> spline; | ||
LmbrCentral::SplineComponentRequestBus::EventResult(spline, GetEntityId(), &LmbrCentral::SplineComponentRequests::GetSpline); | ||
|
||
if (!spline) | ||
{ | ||
AZ_Warning("SplinePublisher::PublishSplineAsPath", false, "Spline not found. Cannot generate spline path."); | ||
return; | ||
} | ||
|
||
// Retrieve vertices from the spline | ||
const size_t vertexCount = spline->GetVertexCount(); | ||
for (size_t i = 0; i < vertexCount; ++i) | ||
{ | ||
const AZ::Vector3& vertex = spline->GetVertex(i); | ||
|
||
// Convert each vertex into a PoseStamped and add to the path | ||
geometry_msgs::msg::PoseStamped poseStamped; | ||
poseStamped.pose.position.x = vertex.GetX(); | ||
poseStamped.pose.position.y = vertex.GetY(); | ||
poseStamped.pose.position.z = vertex.GetZ(); | ||
pathMessage.poses.push_back(poseStamped); | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
// Publish the message | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
m_publisher->publish(pathMessage); | ||
} | ||
} // namespace SplineTools | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
52 changes: 52 additions & 0 deletions
52
Gems/RobotecSplineTools/Code/Source/Clients/SplinePublisher.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
michalpelka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <AzCore/Component/Component.h> | ||
#include <AzCore/Serialization/SerializeContext.h> | ||
#include <AzFramework/Components/TransformComponent.h> | ||
#include <LmbrCentral/Shape/SplineComponentBus.h> | ||
#include <ROS2/Communication/TopicConfiguration.h> | ||
#include <SplineTools/SplineToolsTypeIds.h> | ||
|
||
#include <nav_msgs/msg/path.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
namespace SplineTools | ||
{ | ||
struct SplinePublisherConfiguration | ||
{ | ||
SplinePublisherConfiguration(); | ||
|
||
AZ_TYPE_INFO(SplinePublisherConfiguration, SplinePublisherConfigTypeId); | ||
static void Reflect(AZ::ReflectContext* context); | ||
ROS2::TopicConfiguration m_TopicConfig{ rclcpp::ServicesQoS() }; | ||
}; | ||
|
||
class SplinePublisher | ||
: public AZ::Component | ||
, public AZ::TickBus::Handler | ||
{ | ||
public: | ||
AZ_COMPONENT(SplinePublisher, SplinePublisherComponentTypeId); | ||
|
||
static void Reflect(AZ::ReflectContext* context); | ||
|
||
SplinePublisher() = default; | ||
~SplinePublisher() override = default; | ||
explicit SplinePublisher(const SplinePublisherConfiguration& config); | ||
|
||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); | ||
|
||
// AZ::Component interface implementation | ||
void Activate() override; | ||
void Deactivate() override; | ||
|
||
// AZ::TickBus::Handler interface implementation | ||
void OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) override; | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
private: | ||
void PublishSplineAsPath() const; | ||
|
||
SplinePublisherConfiguration m_config; | ||
rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr m_publisher; | ||
}; | ||
} // namespace SplineTools | ||
w-czerski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.