ros2_control - iron
Loading...
Searching...
No Matches
joint_state_broadcaster.hpp
1// Copyright 2017 Open Source Robotics Foundation, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef JOINT_STATE_BROADCASTER__JOINT_STATE_BROADCASTER_HPP_
16#define JOINT_STATE_BROADCASTER__JOINT_STATE_BROADCASTER_HPP_
17
18#include <memory>
19#include <string>
20#include <unordered_map>
21#include <vector>
22
23#include "control_msgs/msg/dynamic_joint_state.hpp"
24#include "controller_interface/controller_interface.hpp"
25#include "joint_state_broadcaster/visibility_control.h"
26// auto-generated by generate_parameter_library
27#include "joint_state_broadcaster_parameters.hpp"
28#include "rclcpp_lifecycle/lifecycle_publisher.hpp"
29#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
30#include "realtime_tools/realtime_publisher.h"
31#include "sensor_msgs/msg/joint_state.hpp"
32
33namespace joint_state_broadcaster
34{
60{
61public:
62 JOINT_STATE_BROADCASTER_PUBLIC
64
65 JOINT_STATE_BROADCASTER_PUBLIC
67
68 JOINT_STATE_BROADCASTER_PUBLIC
70
71 JOINT_STATE_BROADCASTER_PUBLIC
72 controller_interface::return_type update(
73 const rclcpp::Time & time, const rclcpp::Duration & period) override;
74
75 JOINT_STATE_BROADCASTER_PUBLIC
76 controller_interface::CallbackReturn on_init() override;
77
78 JOINT_STATE_BROADCASTER_PUBLIC
79 controller_interface::CallbackReturn on_configure(
80 const rclcpp_lifecycle::State & previous_state) override;
81
82 JOINT_STATE_BROADCASTER_PUBLIC
83 controller_interface::CallbackReturn on_activate(
84 const rclcpp_lifecycle::State & previous_state) override;
85
86 JOINT_STATE_BROADCASTER_PUBLIC
87 controller_interface::CallbackReturn on_deactivate(
88 const rclcpp_lifecycle::State & previous_state) override;
89
90protected:
91 bool init_joint_data();
93 void init_dynamic_joint_state_msg();
94 bool use_all_available_interfaces() const;
95
96protected:
97 // Optional parameters
98 std::shared_ptr<ParamListener> param_listener_;
99 Params params_;
100 std::unordered_map<std::string, std::string> map_interface_to_joint_state_;
101
102 // For the JointState message,
103 // we store the name of joints with compatible interfaces
104 std::vector<std::string> joint_names_;
105 std::shared_ptr<rclcpp::Publisher<sensor_msgs::msg::JointState>> joint_state_publisher_;
106 std::shared_ptr<realtime_tools::RealtimePublisher<sensor_msgs::msg::JointState>>
107 realtime_joint_state_publisher_;
108
109 // For the DynamicJointState format, we use a map to buffer values in for easier lookup
110 // This allows to preserve whatever order or names/interfaces were initialized.
111 std::unordered_map<std::string, std::unordered_map<std::string, double>> name_if_value_mapping_;
112 std::shared_ptr<rclcpp::Publisher<control_msgs::msg::DynamicJointState>>
113 dynamic_joint_state_publisher_;
114 std::shared_ptr<realtime_tools::RealtimePublisher<control_msgs::msg::DynamicJointState>>
115 realtime_dynamic_joint_state_publisher_;
116};
117
118} // namespace joint_state_broadcaster
119
120#endif // JOINT_STATE_BROADCASTER__JOINT_STATE_BROADCASTER_HPP_
Definition controller_interface.hpp:29
Joint State Broadcaster for all or some state in a ros2_control system.
Definition joint_state_broadcaster.hpp:60
JOINT_STATE_BROADCASTER_PUBLIC controller_interface::InterfaceConfiguration state_interface_configuration() const override
Get configuration for controller's required state interfaces.
Definition joint_state_broadcaster.cpp:72
JOINT_STATE_BROADCASTER_PUBLIC controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) override
Definition joint_state_broadcaster.cpp:339
JOINT_STATE_BROADCASTER_PUBLIC controller_interface::CallbackReturn on_init() override
Extending interface with initialization method which is individual for each controller.
Definition joint_state_broadcaster.cpp:49
JOINT_STATE_BROADCASTER_PUBLIC controller_interface::InterfaceConfiguration command_interface_configuration() const override
Get configuration for controller's required command interfaces.
Definition joint_state_broadcaster.cpp:66
void init_joint_state_msg()
Definition joint_state_broadcaster.cpp:283
Configuring what command/state interfaces to claim.
Definition controller_interface_base.hpp:56