ros2_control - jazzy
Loading...
Searching...
No Matches
r6bot_controller.hpp
1// Copyright 2023 ros2_control Development Team
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 ROS2_CONTROL_DEMO_EXAMPLE_7__R6BOT_CONTROLLER_HPP_
16#define ROS2_CONTROL_DEMO_EXAMPLE_7__R6BOT_CONTROLLER_HPP_
17
18#include <atomic>
19#include <chrono>
20#include <memory>
21#include <mutex>
22#include <string>
23#include <unordered_map>
24#include <utility>
25#include <vector>
26
27#include "control_msgs/action/follow_joint_trajectory.hpp"
28#include "control_msgs/msg/joint_trajectory_controller_state.hpp"
29#include "controller_interface/controller_interface.hpp"
30#include "hardware_interface/types/hardware_interface_type_values.hpp"
31#include "rclcpp/duration.hpp"
32#include "rclcpp/subscription.hpp"
33#include "rclcpp/time.hpp"
34#include "rclcpp/timer.hpp"
35#include "rclcpp_lifecycle/lifecycle_publisher.hpp"
36#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
37#include "realtime_tools/realtime_thread_safe_box.hpp"
38#include "trajectory_msgs/msg/joint_trajectory.hpp"
39#include "trajectory_msgs/msg/joint_trajectory_point.hpp"
40
41namespace ros2_control_demo_example_7
42{
44{
45public:
47
49
51
52 controller_interface::return_type update(
53 const rclcpp::Time & time, const rclcpp::Duration & period) override;
54
55 controller_interface::CallbackReturn on_init() override;
56
57 controller_interface::CallbackReturn on_configure(
58 const rclcpp_lifecycle::State & previous_state) override;
59
60 controller_interface::CallbackReturn on_activate(
61 const rclcpp_lifecycle::State & previous_state) override;
62
63 controller_interface::CallbackReturn on_deactivate(
64 const rclcpp_lifecycle::State & previous_state) override;
65
66protected:
67 std::vector<std::string> joint_names_;
68 std::vector<std::string> command_interface_types_;
69 std::vector<std::string> state_interface_types_;
70
71 rclcpp::Subscription<trajectory_msgs::msg::JointTrajectory>::SharedPtr joint_command_subscriber_;
73 std::atomic<bool> new_msg_ = false;
74 rclcpp::Time start_time_;
75 trajectory_msgs::msg::JointTrajectory trajectory_msg_;
76 trajectory_msgs::msg::JointTrajectoryPoint point_interp_;
77
78 std::vector<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
79 joint_position_command_interface_;
80 std::vector<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
81 joint_velocity_command_interface_;
82 std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
83 joint_position_state_interface_;
84 std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
85 joint_velocity_state_interface_;
86
87 std::unordered_map<
88 std::string, std::vector<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> *>
89 command_interface_map_ = {
90 {"position", &joint_position_command_interface_},
91 {"velocity", &joint_velocity_command_interface_}};
92
93 std::unordered_map<
94 std::string, std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> *>
95 state_interface_map_ = {
96 {"position", &joint_position_state_interface_},
97 {"velocity", &joint_velocity_state_interface_}};
98};
99
100} // namespace ros2_control_demo_example_7
101
102#endif // ROS2_CONTROL_DEMO_EXAMPLE_7__R6BOT_CONTROLLER_HPP_
Definition controller_interface.hpp:27
Definition realtime_thread_safe_box.hpp:68
Definition r6bot_controller.hpp:44
controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) override
Definition r6bot_controller.cpp:162
controller_interface::InterfaceConfiguration state_interface_configuration() const override
Get configuration for controller's required state interfaces.
Definition r6bot_controller.cpp:66
controller_interface::CallbackReturn on_init() override
Extending interface with initialization method which is individual for each controller.
Definition r6bot_controller.cpp:34
controller_interface::InterfaceConfiguration command_interface_configuration() const override
Get configuration for controller's required command interfaces.
Definition r6bot_controller.cpp:49
Configuring what command/state interfaces to claim.
Definition controller_interface_base.hpp:58