15#ifndef SINGLE_TRIGGER_CONTROLLER__GPIO_COMMAND_CONTROLLER_HPP_
16#define SINGLE_TRIGGER_CONTROLLER__GPIO_COMMAND_CONTROLLER_HPP_
20#include <unordered_map>
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"
30#include "single_trigger_controller/single_trigger_controller_parameters.hpp"
34 using CmdType = control_msgs::msg::DynamicInterfaceGroupValues;
35 using StateType = control_msgs::msg::DynamicInterfaceGroupValues;
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>>;
132 controller_interface::return_type
update(
133 const rclcpp::Time &time,
const rclcpp::Duration &period)
override;
200 template <
typename T>
202 const InterfacesNames &interfaces_from_params, std::vector<T> &configured_interfaces);
212 template <
typename T>
214 const InterfacesNames &interfaces_from_params,
const T &configured_interfaces);
227 StateType &state_msg, std::size_t index, std::size_t interface_index)
const;
238 const CmdType &commands, std::size_t index,
239 std::size_t command_interface_index)
const;
319 std::shared_ptr<single_trigger_controller_parameters::ParamListener>
param_listener_{};
325 single_trigger_controller_parameters::Params
params_;
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