JointStatePublisher.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 <ROS2/Communication/PublisherConfiguration.h>
  11. #include <ROS2Controllers/Manipulation/JointInfo.h>
  12. #include <rclcpp/publisher.hpp>
  13. #include <sensor_msgs/msg/joint_state.hpp>
  14. #include <ROS2/Sensor/Events/EventSourceAdapter.h>
  15. #include <ROS2/Sensor/Events/PhysicsBasedSource.h>
  16. namespace ROS2Controllers
  17. {
  18. struct JointStatePublisherContext
  19. {
  20. AZ::EntityId m_entityId;
  21. AZStd::string m_frameId;
  22. AZStd::string m_publisherNamespace;
  23. };
  24. //! A class responsible for publishing the joint positions on ROS2 /joint_states topic.
  25. //!< @see <a href="https://docs.ros2.org/latest/api/sensor_msgs/msg/JointState.html">jointState message</a>.
  26. class JointStatePublisher
  27. {
  28. public:
  29. JointStatePublisher(const ROS2::PublisherConfiguration& configuration, const JointStatePublisherContext& context);
  30. virtual ~JointStatePublisher();
  31. void InitializePublisher();
  32. private:
  33. void PublishMessage();
  34. ROS2::EventSourceAdapter<ROS2::PhysicsBasedSource> m_eventSourceAdapter;
  35. typename ROS2::PhysicsBasedSource::AdaptedEventHandlerType m_adaptedEventHandler;
  36. ROS2::PublisherConfiguration m_configuration;
  37. JointStatePublisherContext m_context;
  38. std::shared_ptr<rclcpp::Publisher<sensor_msgs::msg::JointState>> m_jointStatePublisher;
  39. sensor_msgs::msg::JointState m_jointStateMsg;
  40. AZStd::vector<AZStd::string> m_jointNames;
  41. AZStd::vector<JointInfo> m_jointInfos;
  42. };
  43. } // namespace ROS2Controllers