16 #ifndef NAV2_UTIL__TWIST_PUBLISHER_HPP_
17 #define NAV2_UTIL__TWIST_PUBLISHER_HPP_
24 #include "geometry_msgs/msg/twist.hpp"
25 #include "geometry_msgs/msg/twist_stamped.hpp"
26 #include "rclcpp/parameter_service.hpp"
27 #include "rclcpp/qos.hpp"
29 #include "nav2_ros_common/node_utils.hpp"
30 #include "nav2_ros_common/lifecycle_node.hpp"
54 nav2::LifecycleNode::SharedPtr node,
55 const std::string & topic,
59 is_stamped_ = node->declare_or_get_parameter(
"enable_stamped_cmd_vel",
true);
61 twist_stamped_pub_ = node->create_publisher<geometry_msgs::msg::TwistStamped>(
65 twist_pub_ = node->create_publisher<geometry_msgs::msg::Twist>(
74 twist_stamped_pub_->on_activate();
76 twist_pub_->on_activate();
83 twist_stamped_pub_->on_deactivate();
85 twist_pub_->on_deactivate();
89 [[nodiscard]]
bool is_activated()
const
92 return twist_stamped_pub_->is_activated();
94 return twist_pub_->is_activated();
98 void publish(std::unique_ptr<geometry_msgs::msg::TwistStamped> velocity)
101 twist_stamped_pub_->publish(std::move(velocity));
103 auto twist_msg = std::make_unique<geometry_msgs::msg::Twist>(velocity->twist);
104 twist_pub_->publish(std::move(twist_msg));
108 [[nodiscard]]
size_t get_subscription_count()
const
111 return twist_stamped_pub_->get_subscription_count();
113 return twist_pub_->get_subscription_count();
119 bool is_stamped_{
true};
120 nav2::Publisher<geometry_msgs::msg::Twist>::SharedPtr twist_pub_;
121 nav2::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr
A QoS profile for standard reliable topics with a history of 10 messages.
A simple wrapper on a Twist publisher that provides either Twist or TwistStamped.
TwistPublisher(nav2::LifecycleNode::SharedPtr node, const std::string &topic, const rclcpp::QoS &qos=nav2::qos::StandardTopicQoS())
A constructor.