ros2_control - foxy
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#include "rclcpp_lifecycle/lifecycle_publisher.hpp"
27#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
28#include "realtime_tools/realtime_publisher.h"
29#include "sensor_msgs/msg/joint_state.hpp"
30
31namespace joint_state_broadcaster
32{
34{
35public:
36 JOINT_STATE_BROADCASTER_PUBLIC
38
39 JOINT_STATE_BROADCASTER_PUBLIC
40 controller_interface::return_type init(const std::string & controller_name) override;
41
42 JOINT_STATE_BROADCASTER_PUBLIC
43 controller_interface::InterfaceConfiguration command_interface_configuration() const override;
44
45 JOINT_STATE_BROADCASTER_PUBLIC
46 controller_interface::InterfaceConfiguration state_interface_configuration() const override;
47
48 JOINT_STATE_BROADCASTER_PUBLIC
49 controller_interface::return_type update() override;
50
51 JOINT_STATE_BROADCASTER_PUBLIC
52 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_configure(
53 const rclcpp_lifecycle::State & previous_state) override;
54
55 JOINT_STATE_BROADCASTER_PUBLIC
56 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(
57 const rclcpp_lifecycle::State & previous_state) override;
58
59 JOINT_STATE_BROADCASTER_PUBLIC
60 rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_deactivate(
61 const rclcpp_lifecycle::State & previous_state) override;
62
63protected:
64 bool init_joint_data();
66 void init_dynamic_joint_state_msg();
67
68protected:
69 bool use_local_topics_;
70
71 // For the JointState message,
72 // we store the name of joints with compatible interfaces
73 std::vector<std::string> joint_names_;
74 std::shared_ptr<rclcpp::Publisher<sensor_msgs::msg::JointState>> joint_state_publisher_;
75 std::shared_ptr<realtime_tools::RealtimePublisher<sensor_msgs::msg::JointState>>
76 realtime_joint_state_publisher_;
77
78 // For the DynamicJointState format, we use a map to buffer values in for easier lookup
79 // This allows to preserve whatever order or names/interfaces were initialized.
80 std::unordered_map<std::string, std::unordered_map<std::string, double>> name_if_value_mapping_;
81 std::shared_ptr<rclcpp::Publisher<control_msgs::msg::DynamicJointState>>
82 dynamic_joint_state_publisher_;
83 std::shared_ptr<realtime_tools::RealtimePublisher<control_msgs::msg::DynamicJointState>>
84 realtime_dynamic_joint_state_publisher_;
85};
86
87} // namespace joint_state_broadcaster
88
89#endif // JOINT_STATE_BROADCASTER__JOINT_STATE_BROADCASTER_HPP_
Definition controller_interface.hpp:69
Definition joint_state_broadcaster.hpp:34
void init_joint_state_msg()
Definition joint_state_broadcaster.cpp:199
Configuring what command/state interfaces to claim.
Definition controller_interface.hpp:63