Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
single_trigger_controller.hpp
Go to the documentation of this file.
1// Copyright 2022 ICUBE Laboratory, University of Strasbourg
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 SINGLE_TRIGGER_CONTROLLER__GPIO_COMMAND_CONTROLLER_HPP_
16#define SINGLE_TRIGGER_CONTROLLER__GPIO_COMMAND_CONTROLLER_HPP_
17
18#include <memory>
19#include <string>
20#include <unordered_map>
21#include <vector>
22
23#include "control_msgs/msg/dynamic_interface_group_values.hpp"
24#include "controller_interface/controller_interface.hpp"
25#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
26#include "rclcpp_lifecycle/state.hpp"
27#include "realtime_tools/realtime_publisher.hpp"
28#include "realtime_tools/realtime_thread_safe_box.hpp"
29
30#include "single_trigger_controller/single_trigger_controller_parameters.hpp"
31
33{
34 using CmdType = control_msgs::msg::DynamicInterfaceGroupValues;
35 using StateType = control_msgs::msg::DynamicInterfaceGroupValues;
36 using CallbackReturn = controller_interface::CallbackReturn;
37 using InterfacesNames = std::vector<std::string>;
38 using MapOfReferencesToCommandInterfaces = std::unordered_map<
39 std::string, std::reference_wrapper<hardware_interface::LoanedCommandInterface>>;
41 std::unordered_map<std::string, std::reference_wrapper<hardware_interface::LoanedStateInterface>>;
43 std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>>;
44
59 class SingleTriggerController : public controller_interface::ControllerInterface
60 {
61 public:
63
71 controller_interface::InterfaceConfiguration command_interface_configuration() const override;
72
80 controller_interface::InterfaceConfiguration state_interface_configuration() const override;
81
89 CallbackReturn on_init() override;
90
100 CallbackReturn on_configure(const rclcpp_lifecycle::State &previous_state) override;
101
102
114 CallbackReturn on_activate(const rclcpp_lifecycle::State &previous_state) override;
115
121 CallbackReturn on_deactivate(const rclcpp_lifecycle::State &previous_state) override;
122
132 controller_interface::return_type update(
133 const rclcpp::Time &time, const rclcpp::Duration &period) override;
134
135 private:
136
141
146
173
181 void update_states();
182
190 controller_interface::return_type update_commands(const CmdType &commands);
191
200 template <typename T>
201 std::unordered_map<std::string, std::reference_wrapper<T>> create_map_of_references_to_interfaces(
202 const InterfacesNames &interfaces_from_params, std::vector<T> &configured_interfaces);
203
212 template <typename T>
214 const InterfacesNames &interfaces_from_params, const T &configured_interfaces);
215
227 StateType &state_msg, std::size_t index, std::size_t interface_index) const;
228
237 void apply_command(
238 const CmdType &commands, std::size_t index,
239 std::size_t command_interface_index) const;
240
241
248 InterfacesNames get_state_interfaces_names(const std::string &name) const;
249
258
259 protected:
269
279
285
291
296 rclcpp::Subscription<CmdType>::SharedPtr command_subscriber_{};
297
302 std::shared_ptr<rclcpp::Publisher<StateType>> state_publisher_{};
303
307 std::shared_ptr<realtime_tools::RealtimePublisher<StateType>> realtime_state_publisher_{};
308
314
319 std::shared_ptr<single_trigger_controller_parameters::ParamListener> param_listener_{};
320
325 single_trigger_controller_parameters::Params params_;
326
327 };
328
329} // namespace single_trigger_controller
330
331#endif // SINGLE_TRIGGER_CONTROLLER__GPIO_COMMAND_CONTROLLER_HPP_
A general purpose controller which can be used to trigger command interfaces.
Definition single_trigger_controller.hpp:60
std::shared_ptr< realtime_tools::RealtimePublisher< StateType > > realtime_state_publisher_
Realtime publisher wrapper of the state_publisher_.
Definition single_trigger_controller.hpp:307
SingleTriggerController()
Definition single_trigger_controller.cpp:40
void initialize_state_msg()
Initializes the state message state_msg_ with NaN values for each configured state interface.
Definition single_trigger_controller.cpp:209
controller_interface::return_type update_commands(const CmdType &commands)
Callback method for received command msg. Calls apply_command() for each command interface.
Definition single_trigger_controller.cpp:295
MapOfReferencesToCommandInterfaces command_interfaces_map_
map containing a reference to the actual hardwares command interfaces
Definition single_trigger_controller.hpp:284
void update_states()
Publishes current state values.
Definition single_trigger_controller.cpp:372
MapOfReferencesToStateInterfaces state_interfaces_map_
map containing a reference to the actual hardwares state interfaces
Definition single_trigger_controller.hpp:290
rclcpp::Subscription< CmdType >::SharedPtr command_subscriber_
Subscriber object for the '~/commands' topic.
Definition single_trigger_controller.hpp:296
single_trigger_controller_parameters::Params params_
Parameter structure holding controller configuration parameters.
Definition single_trigger_controller.hpp:325
CallbackReturn on_configure(const rclcpp_lifecycle::State &previous_state) override
Called on the transistion from the unconfigured to the inactive state.
Definition single_trigger_controller.cpp:58
void store_state_interface_types()
Stores all configured state interfaces in state_interface_types_.
Definition single_trigger_controller.cpp:188
CallbackReturn on_deactivate(const rclcpp_lifecycle::State &previous_state) override
Called on the transistion from the active to the inactive state.
Definition single_trigger_controller.cpp:143
controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) override
Realtime update method called when in active state.
Definition single_trigger_controller.cpp:148
controller_interface::InterfaceConfiguration command_interface_configuration() const override
Sets the command interface configuration to INDIVIDUAL.
Definition single_trigger_controller.cpp:104
InterfacesNames command_interface_types_
vector of string holding all command interface names as configured from the parameters.
Definition single_trigger_controller.hpp:268
InterfacesNames state_interface_types_
vector of string holding all state interface names as configured from the parameters.
Definition single_trigger_controller.hpp:278
void apply_state_value(StateType &state_msg, std::size_t index, std::size_t interface_index) const
retrieves the state values from the hardware and populates the state_msg with the result.
Definition single_trigger_controller.cpp:393
bool check_if_configured_interfaces_matches_received(const InterfacesNames &interfaces_from_params, const T &configured_interfaces)
performs checks on the configured interfaces vs received interfaces.
Definition single_trigger_controller.cpp:277
StateType state_msg_
Message object holding the states to be published.
Definition single_trigger_controller.hpp:313
InterfacesNames get_state_interfaces_names(const std::string &name) const
Gets the all qualified state interface names from the state_interface_types_ for the joint matching n...
Definition single_trigger_controller.cpp:238
std::unordered_map< std::string, std::reference_wrapper< T > > create_map_of_references_to_interfaces(const InterfacesNames &interfaces_from_params, std::vector< T > &configured_interfaces)
Create a map of references to the hardware components interfaces.
Definition single_trigger_controller.cpp:255
CallbackReturn on_init() override
Called on initialization to the unconfigured state.
Definition single_trigger_controller.cpp:42
CallbackReturn on_activate(const rclcpp_lifecycle::State &previous_state) override
Called on the transistion from the inactive to the active state.
Definition single_trigger_controller.cpp:123
std::shared_ptr< single_trigger_controller_parameters::ParamListener > param_listener_
parameter listerner object.
Definition single_trigger_controller.hpp:319
void apply_command(const CmdType &commands, std::size_t index, std::size_t command_interface_index) const
calls the set_value() method for the hardwares command interface references from the command_interfac...
Definition single_trigger_controller.cpp:345
controller_interface::InterfaceConfiguration state_interface_configuration() const override
Sets the state interface configuration to INDIVIDUAL.
Definition single_trigger_controller.cpp:113
void store_command_interface_types()
Stores all configured command interfaces in command_interface_types_.
Definition single_trigger_controller.cpp:165
bool update_dynamic_map_parameters()
Update the controller parameters.
Definition single_trigger_controller.cpp:155
std::shared_ptr< rclcpp::Publisher< StateType > > state_publisher_
Publisher object to the '~/states' topic.
Definition single_trigger_controller.hpp:302
Definition single_trigger_controller.hpp:33
std::unordered_map< std::string, std::reference_wrapper< hardware_interface::LoanedCommandInterface > > MapOfReferencesToCommandInterfaces
Definition single_trigger_controller.hpp:39
std::vector< std::string > InterfacesNames
Definition single_trigger_controller.hpp:37
std::unordered_map< std::string, std::reference_wrapper< hardware_interface::LoanedStateInterface > > MapOfReferencesToStateInterfaces
Definition single_trigger_controller.hpp:41
controller_interface::CallbackReturn CallbackReturn
Definition single_trigger_controller.hpp:36
control_msgs::msg::DynamicInterfaceGroupValues CmdType
Definition single_trigger_controller.hpp:34
std::vector< std::reference_wrapper< hardware_interface::LoanedStateInterface > > StateInterfaces
Definition single_trigger_controller.hpp:43
control_msgs::msg::DynamicInterfaceGroupValues StateType
Definition single_trigger_controller.hpp:35