2
0

GripperActionServer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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
  4. * of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #pragma once
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <ROS2Controllers/Gripper/GripperRequestBus.h>
  13. #include <control_msgs/action/gripper_command.hpp>
  14. #include <rclcpp/rclcpp.hpp>
  15. #include <rclcpp_action/rclcpp_action.hpp>
  16. namespace ROS2Controllers
  17. {
  18. //! GripperActionServer is a class responsible for managing an action server controlling a gripper
  19. //! @see <a href="https://docs.ros.org/en/humble/p/rclcpp_action/generated/classrclcpp__action_1_1Server.html"> ROS 2 action
  20. //! server documentation </a>
  21. //! @see <a href="https://docs.ros.org/en/api/control_msgs/html/msg/GripperCommand.html"> GripperCommand documentation </a>
  22. class GripperActionServer
  23. {
  24. public:
  25. using GripperCommand = control_msgs::action::GripperCommand;
  26. using GoalHandleGripperCommand = rclcpp_action::ServerGoalHandle<control_msgs::action::GripperCommand>;
  27. //! Create an action server for GripperAction action and bind Goal callbacks.
  28. //! @param actionName Name of the action, similar to topic or service name.
  29. //! @param entityId entity which will execute callbacks through GripperRequestBus.
  30. GripperActionServer(const AZStd::string& actionName, const AZ::EntityId& entityId);
  31. //! Cancel the current goal.
  32. //! @param result Result to be passed to through action server to the client.
  33. void CancelGoal(std::shared_ptr<GripperCommand::Result> result);
  34. //! Report goal success to the action server.
  35. //! @param result Result which contains success code.
  36. void GoalSuccess(std::shared_ptr<GripperCommand::Result> result);
  37. //! Publish feedback during an active action.
  38. //! @param feedback An action feedback message informing about the progress.
  39. void PublishFeedback(std::shared_ptr<GripperCommand::Feedback> feedback);
  40. //! Check if the goal is in an active state
  41. bool IsGoalActiveState() const;
  42. //! Check if the goal is in a pending state
  43. bool IsReadyForExecution() const;
  44. private:
  45. rclcpp_action::GoalResponse GoalReceivedCallback(
  46. const rclcpp_action::GoalUUID& uuid, std::shared_ptr<const GripperCommand::Goal> goal);
  47. rclcpp_action::CancelResponse GoalCancelledCallback(const std::shared_ptr<GoalHandleGripperCommand> goal_handle);
  48. void GoalAcceptedCallback(const std::shared_ptr<GoalHandleGripperCommand> goal_handle);
  49. rclcpp_action::Server<GripperCommand>::SharedPtr actionServer;
  50. std::shared_ptr<GoalHandleGripperCommand> m_goalHandle;
  51. AZ::EntityId m_entityId; //! Entity that has target gripper component
  52. };
  53. } // namespace ROS2Controllers