ros2_control - jazzy
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 "realtime_tools/realtime_publisher.hpp"
26#include "sensor_msgs/msg/joint_state.hpp"
27
28#include "rclcpp/version.h"
29#if RCLCPP_VERSION_GTE(29, 0, 0)
30#include "urdf/model.hpp"
31#else
32#include "urdf/model.h"
33#endif
34
35// auto-generated by generate_parameter_library
36#include "joint_state_broadcaster/joint_state_broadcaster_parameters.hpp"
37
38namespace joint_state_broadcaster
39{
65{
66public:
68
70
72
73 controller_interface::return_type update(
74 const rclcpp::Time & time, const rclcpp::Duration & period) override;
75
76 controller_interface::CallbackReturn on_init() override;
77
78 controller_interface::CallbackReturn on_configure(
79 const rclcpp_lifecycle::State & previous_state) override;
80
81 controller_interface::CallbackReturn on_activate(
82 const rclcpp_lifecycle::State & previous_state) override;
83
84 controller_interface::CallbackReturn on_deactivate(
85 const rclcpp_lifecycle::State & previous_state) override;
86
87protected:
88 bool init_joint_data();
89 void init_auxiliary_data();
91 void init_dynamic_joint_state_msg();
92 bool use_all_available_interfaces() const;
93
94protected:
95 // Optional parameters
96 std::shared_ptr<ParamListener> param_listener_;
97 Params params_;
98 std::unordered_map<std::string, std::string> map_interface_to_joint_state_;
99
100 // For the JointState message,
101 // we store the name of joints with compatible interfaces
102 std::vector<std::string> joint_names_;
103 std::shared_ptr<rclcpp::Publisher<sensor_msgs::msg::JointState>> joint_state_publisher_;
104 std::shared_ptr<realtime_tools::RealtimePublisher<sensor_msgs::msg::JointState>>
105 realtime_joint_state_publisher_;
106
107 // For the DynamicJointState format, we use a map to buffer values in for easier lookup
108 // This allows to preserve whatever order or names/interfaces were initialized.
109 std::unordered_map<std::string, std::unordered_map<std::string, double>> name_if_value_mapping_;
110 std::shared_ptr<rclcpp::Publisher<control_msgs::msg::DynamicJointState>>
111 dynamic_joint_state_publisher_;
112 std::shared_ptr<realtime_tools::RealtimePublisher<control_msgs::msg::DynamicJointState>>
113 realtime_dynamic_joint_state_publisher_;
114
115 urdf::Model model_;
116 bool is_model_loaded_ = false;
117
118 std::vector<double *> mapped_values_;
119
121 {
122 JointStateData(const double & position, const double & velocity, const double & effort)
123 : position_(position), velocity_(velocity), effort_(effort)
124 {
125 }
126
127 const double & position_;
128 const double & velocity_;
129 const double & effort_;
130 };
131
132 std::vector<JointStateData> joint_states_data_;
133
134 std::vector<std::vector<const double *>> dynamic_joint_states_data_;
135};
136
137} // namespace joint_state_broadcaster
138
139#endif // JOINT_STATE_BROADCASTER__JOINT_STATE_BROADCASTER_HPP_
Definition controller_interface.hpp:27
Joint State Broadcaster for all or some state in a ros2_control system.
Definition joint_state_broadcaster.hpp:65
controller_interface::InterfaceConfiguration state_interface_configuration() const override
Get configuration for controller's required state interfaces.
Definition joint_state_broadcaster.cpp:66
controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) override
Definition joint_state_broadcaster.cpp:403
controller_interface::CallbackReturn on_init() override
Extending interface with initialization method which is individual for each controller.
Definition joint_state_broadcaster.cpp:43
controller_interface::InterfaceConfiguration command_interface_configuration() const override
Get configuration for controller's required command interfaces.
Definition joint_state_broadcaster.cpp:60
void init_joint_state_msg()
Definition joint_state_broadcaster.cpp:307
Configuring what command/state interfaces to claim.
Definition controller_interface_base.hpp:58
Definition joint_state_broadcaster.hpp:121