SimulateStepsActionServerHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/TickBus.h>
  10. #include <Interfaces/ISimulationFeaturesBase.h>
  11. #include <ROS2/Handlers/ROS2ActionBase.h>
  12. #include <SimulationInterfaces/SimulationMangerRequestBus.h>
  13. #include <simulation_interfaces/action/simulate_steps.hpp>
  14. namespace ROS2SimulationInterfaces
  15. {
  16. class SimulateStepsActionServerHandler
  17. : public ROS2::ROS2ActionBase<simulation_interfaces::action::SimulateSteps>
  18. , public AZ::TickBus::Handler
  19. , public SimulationInterfaces::SimulationManagerNotificationsBus::Handler
  20. , public ISimulationFeaturesBase
  21. {
  22. public:
  23. ~SimulateStepsActionServerHandler();
  24. // IROS2HandlerBase overrides
  25. AZStd::unordered_set<SimulationFeatureType> GetProvidedFeatures() override;
  26. AZStd::string_view GetTypeName() const override;
  27. AZStd::string_view GetDefaultName() const override;
  28. void Initialize(rclcpp::Node::SharedPtr& node) override;
  29. // ROS2ActionBase<simulation_interfaces::action::SimulateSteps> overrides
  30. rclcpp_action::GoalResponse GoalReceivedCallback(const rclcpp_action::GoalUUID& uuid, std::shared_ptr<const Goal> goal) override;
  31. rclcpp_action::CancelResponse GoalCancelledCallback(const std::shared_ptr<GoalHandle> goal_handle) override;
  32. void GoalAcceptedCallback(const std::shared_ptr<GoalHandle> goal_handle) override;
  33. protected:
  34. // AZ::TickBus::Handler overrides
  35. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  36. // SimulationInterfaces::SimulationManagerNotificationsBus::Handler
  37. void OnSimulationStepFinish(const AZ::u64 remainingSteps) override;
  38. private:
  39. AZ::u64 m_goalSteps{ 0 };
  40. bool m_cancelAction{ false };
  41. };
  42. } // namespace ROS2SimulationInterfaces