ROS2FrameEditorComponent.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/EntityId.h>
  11. #include <AzFramework/Components/TransformComponent.h>
  12. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  13. #include <ROS2/Frame/NamespaceConfiguration.h>
  14. #include <ROS2/Frame/ROS2FrameConfiguration.h>
  15. #include <ROS2/Frame/ROS2FrameEditorComponentBus.h>
  16. #include <ROS2/Frame/ROS2Transform.h>
  17. #include <ROS2/ROS2TypeIds.h>
  18. namespace ROS2
  19. {
  20. //! This component marks a reference frame for ROS 2 ecosystem.
  21. //! It serves as sensor data frame of reference and is responsible, through ROS2Transform, for publishing
  22. //! ros2 static and dynamic transforms (/tf_static, /tf). It also facilitates namespace handling.
  23. //! An entity can only have a single ROS2Frame on each level. Many ROS 2 Components require this component.
  24. //! @note A robot should have this component on every level of entity hierarchy (for each joint, fixed or dynamic)
  25. class ROS2FrameEditorComponent
  26. : public AzToolsFramework::Components::EditorComponentBase
  27. , public ROS2FrameEditorComponentBus::Handler
  28. , public AZ::EntityBus::Handler
  29. {
  30. public:
  31. AZ_COMPONENT(ROS2FrameEditorComponent, ROS2FrameEditorComponentTypeId, AzToolsFramework::Components::EditorComponentBase);
  32. ROS2FrameEditorComponent() = default;
  33. ~ROS2FrameEditorComponent() = default;
  34. //! Initialize to a specific frame id
  35. ROS2FrameEditorComponent(const AZStd::string& frameId);
  36. ROS2FrameEditorComponent(const ROS2FrameConfiguration ros2FrameConfiguration);
  37. // AzToolsFramework::Components::EditorComponentBase overrides
  38. void Init() override;
  39. void Activate() override;
  40. void Deactivate() override;
  41. void BuildGameEntity(AZ::Entity* gameEntity) override;
  42. static void Reflect(AZ::ReflectContext* context);
  43. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  44. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  45. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  46. //! Set the frame id.
  47. //! @param frameId frameId to be set in the configuration.
  48. void SetFrameID(const AZStd::string& frameId);
  49. //! Set the joint name
  50. //! @note May be populated during URDF import or set by the user in the Editor view
  51. //! @param jointName joint name without the namespace (the namespace prefix is added automatically).
  52. void SetJointName(const AZStd::string& jointName);
  53. //! Updates the namespace and namespace strategy of the underlying namespace configuration
  54. //! @param ros2Namespace Namespace to set.
  55. //! @param strategy Namespace strategy to use.
  56. void UpdateNamespaceConfiguration(const AZStd::string& ros2Namespace, const NamespaceConfiguration::NamespaceStrategy& strategy);
  57. // ROS2FrameEditorComponentBus::Handler overrides
  58. AZStd::string GetNamespacedFrameID() const override;
  59. AZ::Name GetNamespacedJointName() const override;
  60. AZStd::string GetNamespace() const override;
  61. void UpdateNamespace(const AZStd::string& parentNamespace) override;
  62. AZStd::string GetGlobalFrameName() const override;
  63. bool IsTopLevel() const override; //!< True if this entity does not have a parent entity with ROS2.
  64. AZ::EntityId GetFrameParent() const override;
  65. AZStd::set<AZ::EntityId> GetFrameChildren() const override;
  66. //! Get the configuration of this component.
  67. ROS2FrameConfiguration GetConfiguration() const;
  68. private:
  69. AZ::Crc32 OnFrameConfigurationChange();
  70. // AZ::EntityBus::Handler override.
  71. void OnEntityNameChanged(const AZStd::string& name) override;
  72. ROS2FrameConfiguration m_configuration;
  73. };
  74. } // namespace ROS2