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 <string>
19 #include <vector>
20 
21 #include "controller_interface/controller_interface_base.hpp"
22 #include "controller_interface/visibility_control.h"
23 #include "hardware_interface/handle.hpp"
24 
25 namespace controller_interface
26 {
29 
36 {
37 public:
38  CONTROLLER_INTERFACE_PUBLIC
40 
41  CONTROLLER_INTERFACE_PUBLIC
42  virtual ~ChainableControllerInterface() = default;
43 
53  CONTROLLER_INTERFACE_PUBLIC
54  return_type update(const rclcpp::Time & time, const rclcpp::Duration & period) final;
55 
56  CONTROLLER_INTERFACE_PUBLIC
57  bool is_chainable() const final;
58 
59  CONTROLLER_INTERFACE_PUBLIC
60  std::vector<hardware_interface::StateInterface> export_state_interfaces() final;
61 
62  CONTROLLER_INTERFACE_PUBLIC
63  std::vector<hardware_interface::CommandInterface> export_reference_interfaces() final;
64 
65  CONTROLLER_INTERFACE_PUBLIC
66  bool set_chained_mode(bool chained_mode) final;
67 
68  CONTROLLER_INTERFACE_PUBLIC
69  bool is_in_chained_mode() const final;
70 
71 protected:
74 
81  virtual std::vector<hardware_interface::StateInterface> on_export_state_interfaces();
82 
85 
92  virtual std::vector<hardware_interface::CommandInterface> on_export_reference_interfaces();
93 
95 
106  virtual bool on_set_chained_mode(bool chained_mode);
107 
109 
116  const rclcpp::Time & time, const rclcpp::Duration & period) = 0;
117 
119 
129  virtual return_type update_and_write_commands(
130  const rclcpp::Time & time, const rclcpp::Duration & period) = 0;
131 
133  std::vector<std::string> exported_state_interface_names_;
134  std::vector<double> state_interfaces_values_;
135 
137  std::vector<std::string> exported_reference_interface_names_;
138  std::vector<double> reference_interfaces_;
139 
140 private:
142  bool in_chained_mode_ = false;
143 };
144 
145 } // namespace controller_interface
146 
147 #endif // CONTROLLER_INTERFACE__CHAINABLE_CONTROLLER_INTERFACE_HPP_
Definition: chainable_controller_interface.hpp:36
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:140
std::vector< std::string > exported_reference_interface_names_
Storage of values for reference interfaces.
Definition: chainable_controller_interface.hpp:137
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:124
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:122
CONTROLLER_INTERFACE_PUBLIC std::vector< hardware_interface::StateInterface > export_state_interfaces() final
Definition: chainable_controller_interface.cpp:48
CONTROLLER_INTERFACE_PUBLIC return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) final
Definition: chainable_controller_interface.cpp:28
virtual std::vector< hardware_interface::StateInterface > on_export_state_interfaces()
Definition: chainable_controller_interface.cpp:127
CONTROLLER_INTERFACE_PUBLIC std::vector< hardware_interface::CommandInterface > export_reference_interfaces() final
Definition: chainable_controller_interface.cpp:72
std::vector< std::string > exported_state_interface_names_
Storage of values for state interfaces.
Definition: chainable_controller_interface.hpp:133
CONTROLLER_INTERFACE_PUBLIC bool set_chained_mode(bool chained_mode) final
Definition: chainable_controller_interface.cpp:96
CONTROLLER_INTERFACE_PUBLIC bool is_chainable() const final
Get information if a controller is chainable.
Definition: chainable_controller_interface.cpp:26
Definition: controller_interface_base.hpp:67