6#include <rclcpp/rclcpp.hpp>
8#include <modulo_interfaces/msg/joint_positions.hpp>
9#include <modulo_interfaces/msg/joint_positions_collection.hpp>
10#include <state_representation/space/joint/JointPositions.hpp>
12#include "modulo_core/joint_positions_options.hpp"
26 template<
class NodeT,
class AllocatorT = std::allocator<
void>>
28 NodeT&& node,
const rclcpp::QoS& qos = rclcpp::QoS(1).transient_local(),
29 const rclcpp::PublisherOptionsWithAllocator<AllocatorT>& options =
30 detail::get_default_joint_positions_options<rclcpp::PublisherOptionsWithAllocator<AllocatorT>>())
32 rclcpp::node_interfaces::get_node_parameters_interface(node),
33 rclcpp::node_interfaces::get_node_topics_interface(node), qos, options) {}
38 template<
class AllocatorT = std::allocator<
void>>
40 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters,
41 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics,
42 const rclcpp::QoS& qos = rclcpp::QoS(1).transient_local(),
43 const rclcpp::PublisherOptionsWithAllocator<AllocatorT>& options =
44 detail::get_default_joint_positions_options<rclcpp::PublisherOptionsWithAllocator<AllocatorT>>()) {
45 publisher_ = rclcpp::create_publisher<modulo_interfaces::msg::JointPositionsCollection>(
46 node_parameters, node_topics,
"/joint_positions", qos, options);
55 void send(
const T& joint_positions);
63 void send(
const std::vector<T>& joint_positions);
68 const std::vector<T>& joint_positions, std::function<std::string(T)> get_name,
69 std::function<modulo_interfaces::msg::JointPositions(T)> translator);
71 std::shared_ptr<rclcpp::Publisher<modulo_interfaces::msg::JointPositionsCollection>> publisher_;
72 modulo_interfaces::msg::JointPositionsCollection net_message_;
77 send(std::vector<T>{joint_positions});
82 const std::vector<T>& joint_positions, std::function<std::string(T)> get_name,
83 std::function<modulo_interfaces::msg::JointPositions(T)> translator) {
84 for (
auto it_in = joint_positions.begin(); it_in != joint_positions.end(); ++it_in) {
85 bool match_found =
false;
86 for (
auto it_msg = net_message_.joint_positions.begin(); it_msg != net_message_.joint_positions.end(); ++it_msg) {
87 if (get_name(*it_in) == it_msg->header.frame_id) {
88 *it_msg = translator(*it_in);
94 net_message_.joint_positions.push_back(translator(*it_in));
97 publisher_->publish(net_message_);
The JointPositionsBroadcaster is a TF2 style class that publishes a collection of JointPositions mess...
void send(const T &joint_positions)
Send a JointPositions object.
JointPositionsBroadcaster(rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters, rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics, const rclcpp::QoS &qos=rclcpp::QoS(1).transient_local(), const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &options=detail::get_default_joint_positions_options< rclcpp::PublisherOptionsWithAllocator< AllocatorT > >())
Constructor of the JointPositionsBroadcaster with node interfaces.
JointPositionsBroadcaster(NodeT &&node, const rclcpp::QoS &qos=rclcpp::QoS(1).transient_local(), const rclcpp::PublisherOptionsWithAllocator< AllocatorT > &options=detail::get_default_joint_positions_options< rclcpp::PublisherOptionsWithAllocator< AllocatorT > >())
Constructor of the JointPositionsBroadcaster with a node.
void send(const std::vector< T > &joint_positions)
Send a vector of JointPositions objects.