Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
single_trigger_controller::SingleTriggerController Class Reference

A general purpose controller which can be used to trigger command interfaces. More...

#include <single_trigger_controller.hpp>

Inheritance diagram for single_trigger_controller::SingleTriggerController:

Public Member Functions

 SingleTriggerController ()
 
controller_interface::InterfaceConfiguration command_interface_configuration () const override
 Sets the command interface configuration to INDIVIDUAL.
 
controller_interface::InterfaceConfiguration state_interface_configuration () const override
 Sets the state interface configuration to INDIVIDUAL.
 
CallbackReturn on_init () override
 Called on initialization to the unconfigured state.
 
CallbackReturn on_configure (const rclcpp_lifecycle::State &previous_state) override
 Called on the transistion from the unconfigured to the inactive state.
 
CallbackReturn on_activate (const rclcpp_lifecycle::State &previous_state) override
 Called on the transistion from the inactive to the active state.
 
CallbackReturn on_deactivate (const rclcpp_lifecycle::State &previous_state) override
 Called on the transistion from the active to the inactive state.
 
controller_interface::return_type update (const rclcpp::Time &time, const rclcpp::Duration &period) override
 Realtime update method called when in active state.
 

Protected Attributes

InterfacesNames command_interface_types_
 vector of string holding all command interface names as configured from the parameters.
 
InterfacesNames state_interface_types_
 vector of string holding all state interface names as configured from the parameters.
 
MapOfReferencesToCommandInterfaces command_interfaces_map_
 map containing a reference to the actual hardwares command interfaces
 
MapOfReferencesToStateInterfaces state_interfaces_map_
 map containing a reference to the actual hardwares state interfaces
 
rclcpp::Subscription< CmdType >::SharedPtr command_subscriber_ {}
 Subscriber object for the '~/commands' topic.
 
std::shared_ptr< rclcpp::Publisher< StateType > > state_publisher_ {}
 Publisher object to the '~/states' topic.
 
std::shared_ptr< realtime_tools::RealtimePublisher< StateType > > realtime_state_publisher_ {}
 Realtime publisher wrapper of the state_publisher_.
 
StateType state_msg_
 Message object holding the states to be published.
 
std::shared_ptr< single_trigger_controller_parameters::ParamListener > param_listener_ {}
 parameter listerner object.
 
single_trigger_controller_parameters::Params params_
 Parameter structure holding controller configuration parameters.
 

Private Member Functions

void store_command_interface_types ()
 Stores all configured command interfaces in command_interface_types_.
 
void store_state_interface_types ()
 Stores all configured state interfaces in state_interface_types_.
 
void initialize_state_msg ()
 Initializes the state message state_msg_ with NaN values for each configured state interface.
 
void update_states ()
 Publishes current state values.
 
controller_interface::return_type update_commands (const CmdType &commands)
 Callback method for received command msg. Calls apply_command() for each command interface.
 
template<typename T >
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.
 
template<typename T >
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.
 
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.
 
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_interfaces_map_
 
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 name.
 
bool update_dynamic_map_parameters ()
 Update the controller parameters.
 

Detailed Description

A general purpose controller which can be used to trigger command interfaces.

This controller is a derivative of the ros2_control GpioCommandController. The key differences between this controller and the GpioCommandController is two-fold:

  1. Besides GPIO interfaces, this controller allows Joint interfaces to be used, enabling the user to utilize the controller in broader applications and simplifying the URDF description.
  2. The GpioCommandController wirtes the latest received command to the configured state interfaces on every update cycle. On the contrary, the SingleTriggerController only writes to the command interfaces once in the subscription callback when a new command has been received. The user can for example leverage this by clearing the command interface (writing NaN to it) in the hardware interface once the latest trigger has been handled.

The controller subscribes and publishes to the same topics as the GpioCommandController.

Constructor & Destructor Documentation

◆ SingleTriggerController()

single_trigger_controller::SingleTriggerController::SingleTriggerController ( )

Member Function Documentation

◆ apply_command()

void single_trigger_controller::SingleTriggerController::apply_command ( const CmdType commands,
std::size_t  index,
std::size_t  command_interface_index 
) const
private

calls the set_value() method for the hardwares command interface references from the command_interfaces_map_

Parameters
commands
index
command_interface_index

◆ apply_state_value()

void single_trigger_controller::SingleTriggerController::apply_state_value ( StateType state_msg,
std::size_t  index,
std::size_t  interface_index 
) const
private

retrieves the state values from the hardware and populates the state_msg with the result.

calls the get_optional() method of each state interface from the state_interfaces_map_ for the state referenced by the index and interface_index.

Parameters
state_msg
index
interface_index

◆ check_if_configured_interfaces_matches_received()

template<typename T >
bool single_trigger_controller::SingleTriggerController::check_if_configured_interfaces_matches_received ( const InterfacesNames interfaces_from_params,
const T &  configured_interfaces 
)
private

performs checks on the configured interfaces vs received interfaces.

Template Parameters
T
Parameters
interfaces_from_params
configured_interfaces
Returns
std::unordered_map<std::string, std::reference_wrapper<T>>

◆ command_interface_configuration()

controller_interface::InterfaceConfiguration single_trigger_controller::SingleTriggerController::command_interface_configuration ( ) const
override

Sets the command interface configuration to INDIVIDUAL.

See ControllerInterfaceBase::command_interface_configuration()

Returns
controller_interface::InterfaceConfiguration

◆ create_map_of_references_to_interfaces()

template<typename T >
std::unordered_map< std::string, std::reference_wrapper< T > > single_trigger_controller::SingleTriggerController::create_map_of_references_to_interfaces ( const InterfacesNames interfaces_from_params,
std::vector< T > &  configured_interfaces 
)
private

Create a map of references to the hardware components interfaces.

Template Parameters
T
Parameters
interfaces_from_params
configured_interfaces
Returns
std::unordered_map<std::string, std::reference_wrapper<T>>

◆ get_state_interfaces_names()

InterfacesNames single_trigger_controller::SingleTriggerController::get_state_interfaces_names ( const std::string &  name) const
private

Gets the all qualified state interface names from the state_interface_types_ for the joint matching name.

Parameters
name
Returns
InterfacesNames

◆ initialize_state_msg()

void single_trigger_controller::SingleTriggerController::initialize_state_msg ( )
private

Initializes the state message state_msg_ with NaN values for each configured state interface.

For example the state message could look like this:

{
header:
{
stamp: 12345678
},
interface_groups: ['j1', 'gpio1'],
interface_values:
[
{
interface_names: ['home'],
values: [NaN]
},
{
interface_names: ['ai0', 'ai1'],
values: [NaN, NaN]
}
]
}

◆ on_activate()

CallbackReturn single_trigger_controller::SingleTriggerController::on_activate ( const rclcpp_lifecycle::State &  previous_state)
override

Called on the transistion from the inactive to the active state.

Populates command_interfaces_map_ and state_interfaces_map_ by invoking create_map_of_references_to_interfaces() for both command and state interfaces.

Initializes an empty state message by calling initialize_state_msg().

Parameters
previous_state
Returns
CallbackReturn

◆ on_configure()

CallbackReturn single_trigger_controller::SingleTriggerController::on_configure ( const rclcpp_lifecycle::State &  previous_state)
override

Called on the transistion from the unconfigured to the inactive state.

Stores all configured command and state interfaces using the store_command_interface_types() and store_state_interface_types() methods.

Creates a subscription to the '~/commands' topic if command interfaces are configured. Creates a realtime publisher to the '~/states' topic is state interfaces are configured.

◆ on_deactivate()

CallbackReturn single_trigger_controller::SingleTriggerController::on_deactivate ( const rclcpp_lifecycle::State &  previous_state)
override

Called on the transistion from the active to the inactive state.

Parameters
previous_state
Returns
CallbackReturn

◆ on_init()

CallbackReturn single_trigger_controller::SingleTriggerController::on_init ( )
override

Called on initialization to the unconfigured state.

Retrieves and stores the parameters supplied to the controller in params_

Returns
hardware_interface::CallbackReturn

◆ state_interface_configuration()

controller_interface::InterfaceConfiguration single_trigger_controller::SingleTriggerController::state_interface_configuration ( ) const
override

Sets the state interface configuration to INDIVIDUAL.

See ControllerInterfaceBase::state_interface_configuration()

Returns
controller_interface::InterfaceConfiguration

◆ store_command_interface_types()

void single_trigger_controller::SingleTriggerController::store_command_interface_types ( )
private

Stores all configured command interfaces in command_interface_types_.

◆ store_state_interface_types()

void single_trigger_controller::SingleTriggerController::store_state_interface_types ( )
private

Stores all configured state interfaces in state_interface_types_.

◆ update()

controller_interface::return_type single_trigger_controller::SingleTriggerController::update ( const rclcpp::Time &  time,
const rclcpp::Duration &  period 
)
override

Realtime update method called when in active state.

Only publishes the states by invoking update_states().

Parameters
time
period
Returns
controller_interface::return_type

◆ update_commands()

controller_interface::return_type single_trigger_controller::SingleTriggerController::update_commands ( const CmdType commands)
private

Callback method for received command msg. Calls apply_command() for each command interface.

Sets all command interaces to 0.0 if an empty command message is received.

Parameters
commands
Returns
controller_interface::return_type

◆ update_dynamic_map_parameters()

bool single_trigger_controller::SingleTriggerController::update_dynamic_map_parameters ( )
private

Update the controller parameters.

Only called in on_configure() to update the parameters in case they have been changed.

Returns
true

◆ update_states()

void single_trigger_controller::SingleTriggerController::update_states ( )
private

Publishes current state values.

Loops over all interface groups and command interfaces and calls the apply_state_value(). Then publishes the result using the realtime_state_publisher_.

Member Data Documentation

◆ command_interface_types_

InterfacesNames single_trigger_controller::SingleTriggerController::command_interface_types_
protected

vector of string holding all command interface names as configured from the parameters.

Looks like this for example:

['j1/home', 'gpio1/ao0', 'gpio1/ao1']

◆ command_interfaces_map_

MapOfReferencesToCommandInterfaces single_trigger_controller::SingleTriggerController::command_interfaces_map_
protected

map containing a reference to the actual hardwares command interfaces

◆ command_subscriber_

rclcpp::Subscription<CmdType>::SharedPtr single_trigger_controller::SingleTriggerController::command_subscriber_ {}
protected

Subscriber object for the '~/commands' topic.

◆ param_listener_

std::shared_ptr<single_trigger_controller_parameters::ParamListener> single_trigger_controller::SingleTriggerController::param_listener_ {}
protected

parameter listerner object.

◆ params_

single_trigger_controller_parameters::Params single_trigger_controller::SingleTriggerController::params_
protected

Parameter structure holding controller configuration parameters.

◆ realtime_state_publisher_

std::shared_ptr<realtime_tools::RealtimePublisher<StateType> > single_trigger_controller::SingleTriggerController::realtime_state_publisher_ {}
protected

Realtime publisher wrapper of the state_publisher_.

◆ state_interface_types_

InterfacesNames single_trigger_controller::SingleTriggerController::state_interface_types_
protected

vector of string holding all state interface names as configured from the parameters.

Looks like this for example:

['j1/home', 'gpio1/ai0', 'gpio1/ai1']

◆ state_interfaces_map_

MapOfReferencesToStateInterfaces single_trigger_controller::SingleTriggerController::state_interfaces_map_
protected

map containing a reference to the actual hardwares state interfaces

◆ state_msg_

StateType single_trigger_controller::SingleTriggerController::state_msg_
protected

Message object holding the states to be published.

◆ state_publisher_

std::shared_ptr<rclcpp::Publisher<StateType> > single_trigger_controller::SingleTriggerController::state_publisher_ {}
protected

Publisher object to the '~/states' topic.


The documentation for this class was generated from the following files: