ros2_control - rolling
chainable_controller_interface.hpp
1 // Copyright (c) 2022, Stogl Robotics Consulting UG (haftungsbeschränkt)
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 CONTROLLER_INTERFACE__CHAINABLE_CONTROLLER_INTERFACE_HPP_
16 #define CONTROLLER_INTERFACE__CHAINABLE_CONTROLLER_INTERFACE_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "controller_interface/controller_interface_base.hpp"
24 #include "controller_interface/visibility_control.h"
25 #include "hardware_interface/handle.hpp"
26 
27 namespace controller_interface
28 {
31 
38 {
39 public:
40  CONTROLLER_INTERFACE_PUBLIC
42 
43  CONTROLLER_INTERFACE_PUBLIC
44  virtual ~ChainableControllerInterface() = default;
45 
55  CONTROLLER_INTERFACE_PUBLIC
56  return_type update(const rclcpp::Time & time, const rclcpp::Duration & period) final;
57 
58  CONTROLLER_INTERFACE_PUBLIC
59  bool is_chainable() const final;
60 
61  CONTROLLER_INTERFACE_PUBLIC
62  std::vector<hardware_interface::StateInterface::ConstSharedPtr> export_state_interfaces() final;
63 
64  CONTROLLER_INTERFACE_PUBLIC
65  std::vector<hardware_interface::CommandInterface::SharedPtr> export_reference_interfaces() final;
66 
67  CONTROLLER_INTERFACE_PUBLIC
68  bool set_chained_mode(bool chained_mode) final;
69 
70  CONTROLLER_INTERFACE_PUBLIC
71  bool is_in_chained_mode() const final;
72 
73 protected:
76 
83  virtual std::vector<hardware_interface::StateInterface> on_export_state_interfaces();
84 
87 
94  virtual std::vector<hardware_interface::CommandInterface> on_export_reference_interfaces();
95 
97 
108  virtual bool on_set_chained_mode(bool chained_mode);
109 
111 
118  const rclcpp::Time & time, const rclcpp::Duration & period) = 0;
119 
121 
131  virtual return_type update_and_write_commands(
132  const rclcpp::Time & time, const rclcpp::Duration & period) = 0;
133 
135  std::vector<std::string> exported_state_interface_names_;
136  std::vector<hardware_interface::StateInterface::SharedPtr> ordered_exported_state_interfaces_;
137  std::unordered_map<std::string, hardware_interface::StateInterface::SharedPtr>
138  exported_state_interfaces_;
139  // BEGIN (Handle export change): for backward compatibility
140  std::vector<double> state_interfaces_values_;
141  // END
142 
144  std::vector<std::string> exported_reference_interface_names_;
145  // BEGIN (Handle export change): for backward compatibility
146  std::vector<double> reference_interfaces_;
147  // END
148  std::vector<hardware_interface::CommandInterface::SharedPtr>
149  ordered_exported_reference_interfaces_;
150  std::unordered_map<std::string, hardware_interface::CommandInterface::SharedPtr>
151  exported_reference_interfaces_;
152 
153 private:
155  bool in_chained_mode_ = false;
156 };
157 
158 } // namespace controller_interface
159 
160 #endif // CONTROLLER_INTERFACE__CHAINABLE_CONTROLLER_INTERFACE_HPP_
Definition: chainable_controller_interface.hpp:38
virtual return_type update_and_write_commands(const rclcpp::Time &time, const rclcpp::Duration &period)=0
Execute calculations of the controller and update command interfaces.
virtual return_type update_reference_from_subscribers(const rclcpp::Time &time, const rclcpp::Duration &period)=0
Update reference from input topics when not in chained mode.
virtual std::vector< hardware_interface::CommandInterface > on_export_reference_interfaces()
Definition: chainable_controller_interface.cpp:237
std::vector< std::string > exported_reference_interface_names_
Storage of values for reference interfaces.
Definition: chainable_controller_interface.hpp:144
virtual bool on_set_chained_mode(bool chained_mode)
Virtual method that each chainable controller should implement to switch chained mode.
Definition: chainable_controller_interface.cpp:221
CONTROLLER_INTERFACE_PUBLIC bool is_in_chained_mode() const final
Get information if a controller is currently in chained mode.
Definition: chainable_controller_interface.cpp:219
CONTROLLER_INTERFACE_PUBLIC return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) final
Definition: chainable_controller_interface.cpp:29
virtual std::vector< hardware_interface::StateInterface > on_export_state_interfaces()
Definition: chainable_controller_interface.cpp:224
std::vector< std::string > exported_state_interface_names_
Storage of values for state interfaces.
Definition: chainable_controller_interface.hpp:135
CONTROLLER_INTERFACE_PUBLIC bool set_chained_mode(bool chained_mode) final
Definition: chainable_controller_interface.cpp:193
CONTROLLER_INTERFACE_PUBLIC bool is_chainable() const final
Get information if a controller is chainable.
Definition: chainable_controller_interface.cpp:27
CONTROLLER_INTERFACE_PUBLIC std::vector< hardware_interface::CommandInterface::SharedPtr > export_reference_interfaces() final
Definition: chainable_controller_interface.cpp:113
CONTROLLER_INTERFACE_PUBLIC std::vector< hardware_interface::StateInterface::ConstSharedPtr > export_state_interfaces() final
Definition: chainable_controller_interface.cpp:49
Definition: controller_interface_base.hpp:99