FollowJointTrajectoryActionServer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/EntityId.h>
  10. #include <AzCore/std/string/string.h>
  11. #include <ROS2Controllers/Manipulation/JointsTrajectoryRequests.h>
  12. #include <control_msgs/action/follow_joint_trajectory.hpp>
  13. #include <rclcpp_action/rclcpp_action.hpp>
  14. #include <rclcpp_action/server.hpp>
  15. namespace ROS2Controllers
  16. {
  17. //! A class wrapping ROS 2 action server for joint trajectory controller.
  18. //! @see <a href="https://control.ros.org/master/doc/ros2_controllers/joint_trajectory_controller/doc/userdoc.html"> joint trajectory
  19. //! controller </a>.
  20. class FollowJointTrajectoryActionServer
  21. {
  22. public:
  23. using FollowJointTrajectory = control_msgs::action::FollowJointTrajectory;
  24. //! Create an action server for FollowJointTrajectory action and bind Goal callbacks.
  25. //! @param actionName Name of the action, similar to topic or service name.
  26. //! @param entityId entity which will execute callbacks through JointsTrajectoryRequestBus.
  27. //! @see <a href="https://docs.ros.org/en/humble/p/rclcpp_action/generated/classrclcpp__action_1_1Server.html"> ROS 2 action
  28. //! server documentation </a>
  29. FollowJointTrajectoryActionServer(const AZStd::string& actionName, const AZ::EntityId& entityId);
  30. //! Cancel the current goal.
  31. //! @param result Result to be passed to through action server to the client.
  32. void CancelGoal(std::shared_ptr<FollowJointTrajectory::Result> result);
  33. //! Report goal success to the action server.
  34. //! @param result Result which contains success code.
  35. void GoalSuccess(std::shared_ptr<FollowJointTrajectory::Result> result);
  36. //! Publish feedback during an active action.
  37. //! @param feedback An action feedback message informing about the progress.
  38. void PublishFeedback(std::shared_ptr<FollowJointTrajectory::Feedback> feedback);
  39. private:
  40. using GoalHandle = rclcpp_action::ServerGoalHandle<FollowJointTrajectory>;
  41. using TrajectoryActionStatus = JointsTrajectoryRequests::TrajectoryActionStatus;
  42. AZ::EntityId m_entityId;
  43. rclcpp_action::Server<FollowJointTrajectory>::SharedPtr m_actionServer;
  44. std::shared_ptr<GoalHandle> m_goalHandle;
  45. bool IsGoalActiveState() const;
  46. bool IsReadyForExecution() const;
  47. bool IsExecuting() const;
  48. rclcpp_action::GoalResponse GoalReceivedCallback(
  49. const rclcpp_action::GoalUUID& uuid, std::shared_ptr<const FollowJointTrajectory::Goal> goal);
  50. rclcpp_action::CancelResponse GoalCancelledCallback(const std::shared_ptr<GoalHandle> goalHandle);
  51. void GoalAcceptedCallback(const std::shared_ptr<GoalHandle> goalHandle);
  52. };
  53. } // namespace ROS2Controllers