Modulo 5.0.0
Loading...
Searching...
No Matches
ControllerInterface.hpp
1#pragma once
2
3#include "modulo_controllers/BaseControllerInterface.hpp"
4
5namespace modulo_controllers {
6
11public:
17
22 CallbackReturn on_init() override;
23
30 CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) final;
31
38 CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) final;
39
45 CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) final;
46
53 controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) final;
54
59 controller_interface::InterfaceConfiguration state_interface_configuration() const final;
60
65 controller_interface::InterfaceConfiguration command_interface_configuration() const final;
66
67protected:
75
82
89
96
101 virtual controller_interface::return_type read_state_interfaces();
102
108 virtual controller_interface::return_type write_command_interfaces(const rclcpp::Duration& period);
109
118 virtual controller_interface::return_type
119 evaluate(const rclcpp::Time& time, const std::chrono::nanoseconds& period) = 0;
120
126 void add_state_interface(const std::string& name, const std::string& interface);
127
133 void add_command_interface(const std::string& name, const std::string& interface);
134
141 std::unordered_map<std::string, double> get_state_interfaces(const std::string& name) const;
142
150 double get_state_interface(const std::string& name, const std::string& interface) const;
151
159 double get_command_interface(const std::string& name, const std::string& interface) const;
160
167 void set_command_interface(const std::string& name, const std::string& interface, double value);
168
169 std::string hardware_name_;
170
171private:
179 void add_interface(
180 const std::string& name, const std::string& interface, std::vector<std::string>& list, const std::string& type);
181
182 using controller_interface::ControllerInterfaceBase::command_interfaces_;
183 using controller_interface::ControllerInterfaceBase::state_interfaces_;
184
185 std::unordered_map<std::string, std::unordered_map<std::string, double>>
186 state_interface_data_;
187 std::vector<double> command_interface_data_;
188 std::unordered_map<std::string, std::unordered_map<std::string, unsigned int>>
189 command_interface_indices_;
190 std::vector<std::string> state_interface_names_;
191 std::vector<std::string> command_interface_names_;
192 bool claim_all_state_interfaces_;
193
194 // TODO make missed_locks an internal parameter
195 unsigned int missed_locks_;
196 bool on_init_called_;
197};
198
199}// namespace modulo_controllers
Base controller class to combine ros2_control, control libraries and modulo.
T get_parameter_value(const std::string &name) const
Get a parameter value by name.
virtual CallbackReturn add_interfaces()
Add interfaces like parameters, signals, services, and predicates to the controller.
controller_interface::InterfaceConfiguration command_interface_configuration() const final
Configure the command interfaces.
virtual controller_interface::return_type write_command_interfaces(const rclcpp::Duration &period)
Write the command interfaces.
virtual CallbackReturn on_configure()
Configure the controller.
virtual controller_interface::return_type evaluate(const rclcpp::Time &time, const std::chrono::nanoseconds &period)=0
The control logic callback.
virtual controller_interface::return_type read_state_interfaces()
Read the state interfaces.
std::unordered_map< std::string, double > get_state_interfaces(const std::string &name) const
Get a map containing the state interfaces by name of the parent tag.
CallbackReturn on_init() override
Declare parameters.
void add_state_interface(const std::string &name, const std::string &interface)
Add a state interface to the controller by name.
double get_command_interface(const std::string &name, const std::string &interface) const
Get the value of a command interface by name.
virtual CallbackReturn on_activate()
Activate the controller.
double get_state_interface(const std::string &name, const std::string &interface) const
Get the value of a state interface by name.
controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) final
Read the state interfaces, perform control evaluation and write the command interfaces.
void set_command_interface(const std::string &name, const std::string &interface, double value)
Set the value of a command interface by name.
std::string hardware_name_
The hardware name provided by a parameter.
virtual CallbackReturn on_deactivate()
Deactivate the controller.
void add_command_interface(const std::string &name, const std::string &interface)
Add a command interface to the controller by name.
controller_interface::InterfaceConfiguration state_interface_configuration() const final
Configure the state interfaces.