ROS2SpawnerComponentController.h 3.4 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. #ifndef WITH_GAZEBO_MSGS
  10. static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
  11. #endif
  12. #include "ROS2/Spawner/SpawnerBus.h"
  13. #include "ROS2SpawnPointComponent.h"
  14. #include <AzCore/Component/ComponentBus.h>
  15. #include <AzCore/Component/EntityId.h>
  16. #include <AzCore/Memory/Memory_fwd.h>
  17. #include <AzCore/Memory/SystemAllocator.h>
  18. #include <AzCore/base.h>
  19. #include <AzFramework/Spawnable/Spawnable.h>
  20. namespace ROS2
  21. {
  22. struct ROS2SpawnerServiceNames
  23. {
  24. AZ_TYPE_INFO(ROS2SpawnerServiceNames, "{10D75AAC-BD51-4F33-BCAA-9001CFA219AE}");
  25. AZStd::string m_availableSpawnableNamesServiceName = "get_available_spawnable_names";
  26. AZStd::string m_spawnEntityServiceName = "spawn_entity";
  27. AZStd::string m_deleteEntityServiceName = "delete_entity";
  28. AZStd::string m_spawnPointInfoServiceName = "get_spawn_point_info";
  29. AZStd::string m_spawnPointsNamesServiceName = "get_spawn_points_names";
  30. static void Reflect(AZ::ReflectContext* context);
  31. };
  32. class ROS2SpawnerComponentConfig final : public AZ::ComponentConfig
  33. {
  34. public:
  35. AZ_RTTI(ROS2SpawnerComponentConfig, "{ee71f892-006a-11ee-be56-0242ac120002}");
  36. ROS2SpawnerComponentConfig() = default;
  37. ~ROS2SpawnerComponentConfig() = default;
  38. static void Reflect(AZ::ReflectContext* context);
  39. AZ::EntityId m_editorEntityId;
  40. AZ::Transform m_defaultSpawnPose = { AZ::Vector3{ 0, 0, 0 }, AZ::Quaternion{ 0, 0, 0, 1 }, 1.0 };
  41. ROS2SpawnerServiceNames m_serviceNames;
  42. AZStd::unordered_map<AZStd::string, AZ::Data::Asset<AzFramework::Spawnable>> m_spawnables;
  43. bool m_supportWGS{ true };
  44. };
  45. class ROS2SpawnerComponentController : public SpawnerRequestsBus::Handler
  46. {
  47. public:
  48. AZ_TYPE_INFO(ROS2SpawnerComponentController, "{1e9e040c-006b-11ee-be56-0242ac120002}");
  49. ROS2SpawnerComponentController() = default;
  50. explicit ROS2SpawnerComponentController(const ROS2SpawnerComponentConfig& config);
  51. static void Reflect(AZ::ReflectContext* context);
  52. //////////////////////////////////////////////////////////////////////////
  53. // Controller component
  54. void Init();
  55. void Activate(AZ::EntityId entityId);
  56. void Deactivate();
  57. void SetConfiguration(const ROS2SpawnerComponentConfig& config);
  58. const ROS2SpawnerComponentConfig& GetConfiguration() const;
  59. //////////////////////////////////////////////////////////////////////////
  60. //////////////////////////////////////////////////////////////////////////
  61. // SpawnerRequestsBus::Handler overrides
  62. const AZ::Transform& GetDefaultSpawnPose() const override;
  63. SpawnPointInfoMap GetAllSpawnPointInfos() const override;
  64. //////////////////////////////////////////////////////////////////////////
  65. const ROS2SpawnerServiceNames& GetServiceNames() const;
  66. SpawnPointInfoMap GetSpawnPoints() const;
  67. AZ::EntityId GetEditorEntityId() const;
  68. AZStd::unordered_map<AZStd::string, AZ::Data::Asset<AzFramework::Spawnable>> GetSpawnables() const;
  69. bool GetSupportWGS() const;
  70. private:
  71. ROS2SpawnerComponentConfig m_config;
  72. };
  73. } // namespace ROS2