ROS2SystemComponent.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <Atom/RPI.Public/Pass/PassSystemInterface.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzCore/std/smart_ptr/unique_ptr.h>
  13. #include <Lidar/LidarSystem.h>
  14. #include <ROS2/Clock/SimulationClock.h>
  15. #include <ROS2/ROS2Bus.h>
  16. #include <builtin_interfaces/msg/time.hpp>
  17. #include <memory>
  18. #include <rclcpp/rclcpp.hpp>
  19. #include <tf2_ros/static_transform_broadcaster.h>
  20. #include <tf2_ros/transform_broadcaster.h>
  21. namespace ROS2
  22. {
  23. //! Central singleton-like System Component for ROS2 Gem.
  24. class ROS2SystemComponent
  25. : public AZ::Component
  26. , public AZ::TickBus::Handler
  27. , protected ROS2RequestBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(ROS2SystemComponent, "{cb28d486-afa4-4a9f-a237-ac5eb42e1c87}");
  31. static void Reflect(AZ::ReflectContext* context);
  32. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  33. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  34. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  35. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  36. ROS2SystemComponent();
  37. ~ROS2SystemComponent() override;
  38. //////////////////////////////////////////////////////////////////////////
  39. // ROS2RequestBus::Handler overrides
  40. std::shared_ptr<rclcpp::Node> GetNode() const override;
  41. builtin_interfaces::msg::Time GetROSTimestamp() const override;
  42. void BroadcastTransform(const geometry_msgs::msg::TransformStamped& t, bool isDynamic) const override;
  43. const SimulationClock& GetSimulationClock() const override;
  44. //////////////////////////////////////////////////////////////////////////
  45. protected:
  46. ////////////////////////////////////////////////////////////////////////
  47. // AZ::Component interface implementation
  48. void Init() override;
  49. void Activate() override;
  50. void Deactivate() override;
  51. ////////////////////////////////////////////////////////////////////////
  52. ////////////////////////////////////////////////////////////////////////
  53. // AZTickBus interface implementation
  54. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  55. ////////////////////////////////////////////////////////////////////////
  56. private:
  57. std::shared_ptr<rclcpp::Node> m_ros2Node;
  58. AZStd::shared_ptr<rclcpp::executors::SingleThreadedExecutor> m_executor;
  59. AZStd::unique_ptr<tf2_ros::TransformBroadcaster> m_dynamicTFBroadcaster;
  60. AZStd::unique_ptr<tf2_ros::StaticTransformBroadcaster> m_staticTFBroadcaster;
  61. SimulationClock m_simulationClock;
  62. //! Load the pass templates of the ROS2 gem.
  63. void LoadPassTemplateMappings();
  64. AZ::RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler m_loadTemplatesHandler;
  65. };
  66. } // namespace ROS2