/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #ifndef WITH_GAZEBO_MSGS static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined."); #endif #include "ROS2SpawnPointComponent.h" #include "Spawner/ROS2SpawnerComponentController.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace ROS2 { using GetAvailableSpawnableNamesRequest = std::shared_ptr; using GetAvailableSpawnableNamesResponse = std::shared_ptr; using SpawnEntityRequest = std::shared_ptr; using SpawnEntityResponse = gazebo_msgs::srv::SpawnEntity::Response; using SpawnEntityServiceHandle = std::shared_ptr>; using DeleteEntityRequest = std::shared_ptr; using DeleteEntityServiceHandle = std::shared_ptr>; using DeleteEntityResponse = gazebo_msgs::srv::DeleteEntity::Response; using GetSpawnPointInfoRequest = std::shared_ptr; using GetSpawnPointInfoResponse = std::shared_ptr; using GetSpawnPointsNamesRequest = std::shared_ptr; using GetSpawnPointsNamesResponse = std::shared_ptr; using ROS2SpawnerComponentBase = AzFramework::Components::ComponentAdapter; //! Manages robots spawning. //! Allows user to set spawnable prefabs in the Editor and spawn them using ROS2 service during the simulation. class ROS2SpawnerComponent : public ROS2SpawnerComponentBase { public: AZ_COMPONENT(ROS2SpawnerComponent, "{8ea91880-0067-11ee-be56-0242ac120002}", AZ::Component); // ROS2SpawnerComponentBase interface implementation. ROS2SpawnerComponent() = default; ROS2SpawnerComponent(const ROS2SpawnerComponentConfig& properties); ~ROS2SpawnerComponent() = default; ////////////////////////////////////////////////////////////////////////// // Component overrides void Activate() override; void Deactivate() override; ////////////////////////////////////////////////////////////////////////// static void Reflect(AZ::ReflectContext* context); private: int m_counter = 1; AZStd::unordered_map m_tickets; rclcpp::Service::SharedPtr m_getSpawnablesNamesService; rclcpp::Service::SharedPtr m_getSpawnPointsNamesService; rclcpp::Service::SharedPtr m_spawnService; rclcpp::Service::SharedPtr m_deleteService; rclcpp::Service::SharedPtr m_getSpawnPointInfoService; void GetAvailableSpawnableNames(const GetAvailableSpawnableNamesRequest request, GetAvailableSpawnableNamesResponse response); void SpawnEntity( const SpawnEntityServiceHandle service_handle, const std::shared_ptr header, const SpawnEntityRequest request); void PreSpawn( AzFramework::EntitySpawnTicket::Id, AzFramework::SpawnableEntityContainerView, const AZ::Transform&, const AZStd::string& spawnableName, const AZStd::string& spawnableNamespace); void DeleteEntity( const DeleteEntityServiceHandle service_handle, const std::shared_ptr header, DeleteEntityRequest request); void GetSpawnPointsNames(const GetSpawnPointsNamesRequest request, GetSpawnPointsNamesResponse response); void GetSpawnPointInfo(const GetSpawnPointInfoRequest request, GetSpawnPointInfoResponse response); AZStd::unordered_map GetSpawnPoints(); }; } // namespace ROS2