Prechádzať zdrojové kódy

Robot control with namespaced topic

Signed-off-by: Adam Dąbrowski <[email protected]>
Adam Dąbrowski 3 rokov pred
rodič
commit
3ef4494875

+ 11 - 11
Gems/ROS2/Code/Source/RobotControl/ROS2RobotControlComponent.cpp

@@ -12,25 +12,26 @@
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/EditContextConstants.inl>
 
-#include "ROS2RobotControlComponent.h"
-#include "TwistControl.h"
+#include "RobotControl/ROS2RobotControlComponent.h"
+#include "RobotControl/TwistControl.h"
+#include "Utilities/ROS2Names.h"
 
 namespace ROS2
 {
-    void ROS2RobotControlComponent::Init()
+    void ROS2RobotControlComponent::Activate()
     {
+        auto ros2Frame = GetEntity()->FindComponent<ROS2FrameComponent>();
+        auto namespacedTopic = ROS2Names::GetNamespacedName(ros2Frame->GetNamespace(), m_topic);
+
         // TODO - instead, create/reset robot control in Activate based on selected implementation (in the component)
         m_robotControl = std::make_unique<TwistControl>();
-    }
-
-    void ROS2RobotControlComponent::Activate()
-    {
-        m_robotControl->Activate(GetEntity(), m_topic);
+        m_robotControl->Activate(GetEntity(), namespacedTopic);
     }
 
     void ROS2RobotControlComponent::Deactivate()
     {
         m_robotControl->Deactivate();
+        m_robotControl.reset();
     }
 
     void ROS2RobotControlComponent::Reflect(AZ::ReflectContext* context)
@@ -53,10 +54,9 @@ namespace ROS2
         }
     }
 
-    /*
     void ROS2RobotControlComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
     {
-        // TODO - query current/selected RobotControl implementation for what components are required
+        // TODO - also, dependent on current/selected RobotControl implementation for what components are required
+        required.push_back(AZ_CRC("ROS2Frame"));
     }
-    */
 }  // namespace ROS2

+ 1 - 1
Gems/ROS2/Code/Source/RobotControl/ROS2RobotControlComponent.h

@@ -20,9 +20,9 @@ namespace ROS2
         AZ_COMPONENT(ROS2RobotControlComponent, "{CBFB0764-99F9-40EE-9FEE-F5F5A66E59D2}", AZ::Component);
 
         // AZ::Component interface implementation.
-        void Init() override;
         void Activate() override;
         void Deactivate() override;
+        static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
 
         // Required Reflect function.
         static void Reflect(AZ::ReflectContext* context);