ros2_control - galactic
Public Member Functions | List of all members
hardware_interface::ResourceManager Class Reference

Public Member Functions

 ResourceManager ()
 Default constructor for the Resource Manager.
 
 ResourceManager (const std::string &urdf, bool validate_interfaces=true)
 Constructor for the Resource Manager. More...
 
 ResourceManager (const ResourceManager &)=delete
 
void load_urdf (const std::string &urdf, bool validate_interfaces=true)
 Load resources from on a given URDF. More...
 
LoanedStateInterface claim_state_interface (const std::string &key)
 Claim a state interface given its key. More...
 
std::vector< std::string > state_interface_keys () const
 Returns all registered state interfaces keys. More...
 
bool state_interface_exists (const std::string &key) const
 Checks whether a state interface is registered under the given key. More...
 
bool command_interface_is_claimed (const std::string &key) const
 Checks whether a command interface is already claimed. More...
 
LoanedCommandInterface claim_command_interface (const std::string &key)
 Claim a command interface given its key. More...
 
std::vector< std::string > command_interface_keys () const
 Returns all registered command interfaces keys. More...
 
bool command_interface_exists (const std::string &key) const
 Checks whether a command interface is registered under the given key. More...
 
size_t actuator_components_size () const
 Return the number size_t of loaded actuator components. More...
 
void import_component (std::unique_ptr< ActuatorInterface > actuator)
 Import a hardware component which is not listed in the URDF. More...
 
size_t sensor_components_size () const
 Return the number of loaded sensor components. More...
 
void import_component (std::unique_ptr< SensorInterface > sensor)
 Import a hardware component which is not listed in the URDF. More...
 
size_t system_components_size () const
 Return the number of loaded system components. More...
 
void import_component (std::unique_ptr< SystemInterface > system)
 Import a hardware component which is not listed in the URDF. More...
 
void import_component (std::unique_ptr< ActuatorInterface > actuator, const HardwareInfo &hardware_info)
 Import a hardware component which is not listed in the URDF. More...
 
void import_component (std::unique_ptr< SensorInterface > sensor, const HardwareInfo &hardware_info)
 Import a hardware component which is not listed in the URDF. More...
 
void import_component (std::unique_ptr< SystemInterface > system, const HardwareInfo &hardware_info)
 Import a hardware component which is not listed in the URDF. More...
 
std::unordered_map< std::string, rclcpp_lifecycle::State > get_components_states ()
 Return status for all components. More...
 
bool prepare_command_mode_switch (const std::vector< std::string > &start_interfaces, const std::vector< std::string > &stop_interfaces)
 Prepare the hardware components for a new command interface mode. More...
 
bool perform_command_mode_switch (const std::vector< std::string > &start_interfaces, const std::vector< std::string > &stop_interfaces)
 Notify the hardware components that realtime hardware mode switching should occur. More...
 
void start_components ()
 Start all loaded hardware components.
 
void stop_components ()
 Stops all loaded hardware components.
 
void read ()
 Reads all loaded hardware components.
 
void write ()
 Write all loaded hardware components.
 

Constructor & Destructor Documentation

◆ ResourceManager()

hardware_interface::ResourceManager::ResourceManager ( const std::string &  urdf,
bool  validate_interfaces = true 
)
explicit

Constructor for the Resource Manager.

The implementation loads the specified urdf and initializes the hardware components listed within as well as populate their respective state and command interfaces.

If the interfaces ought to be validated, the constructor throws an exception in case the URDF lists interfaces which are not available.

Parameters
[in]urdfstring containing the URDF.
[in]validate_interfacesboolean argument indicating whether the exported interfaces ought to be validated. Defaults to true.

Member Function Documentation

◆ actuator_components_size()

size_t hardware_interface::ResourceManager::actuator_components_size ( ) const

Return the number size_t of loaded actuator components.

Returns
number of actuator components.

◆ claim_command_interface()

LoanedCommandInterface hardware_interface::ResourceManager::claim_command_interface ( const std::string &  key)

Claim a command interface given its key.

The resource is claimed as long as being in scope. Once the resource is going out of scope, the destructor returns and thus frees the resource to claimed by others.

Parameters
[in]keyString identifier which command interface to claim
Returns
command interface

◆ claim_state_interface()

LoanedStateInterface hardware_interface::ResourceManager::claim_state_interface ( const std::string &  key)

Claim a state interface given its key.

The resource is claimed as long as being in scope. Once the resource is going out of scope, the destructor returns.

Parameters
[in]keyString identifier which state interface to claim
Returns
state interface

◆ command_interface_exists()

bool hardware_interface::ResourceManager::command_interface_exists ( const std::string &  key) const

Checks whether a command interface is registered under the given key.

Parameters
[in]keystring identifying the interface to check.
Returns
true if interface exist, false otherwise.

◆ command_interface_is_claimed()

bool hardware_interface::ResourceManager::command_interface_is_claimed ( const std::string &  key) const

Checks whether a command interface is already claimed.

Any command interface can only be claimed by a single instance.

Note
the equivalent function does not exist for state interfaces. These are solely read-only and can thus be used by multiple instances.
Parameters
[in]keystring identifying the interface to check.
Returns
true if interface is already claimed, false if available.

◆ command_interface_keys()

std::vector< std::string > hardware_interface::ResourceManager::command_interface_keys ( ) const

Returns all registered command interfaces keys.

The keys are collected from each loaded hardware component.

Returns
vector of strings, containing all registered keys.

◆ get_components_states()

std::unordered_map< std::string, rclcpp_lifecycle::State > hardware_interface::ResourceManager::get_components_states ( )

Return status for all components.

Returns
map of hardware names and their states

◆ import_component() [1/6]

void hardware_interface::ResourceManager::import_component ( std::unique_ptr< ActuatorInterface actuator)

Import a hardware component which is not listed in the URDF.

Components which are initialized outside a URDF can be added post initialization.

Note
this might invalidate existing state and command interfaces and should thus not be called when a controller is running.
given that no hardware_info is available, the component has to be configured externally and prior to the call to import.
Parameters
[in]actuatorpointer to the actuator interface.

◆ import_component() [2/6]

void hardware_interface::ResourceManager::import_component ( std::unique_ptr< ActuatorInterface actuator,
const HardwareInfo hardware_info 
)

Import a hardware component which is not listed in the URDF.

Components which are initialized outside a URDF can be added post initialization. Nevertheless, there should still be HardwareInfo available for this component, either parsed from a URDF string (easiest) or filled manually.

Note
this might invalidate existing state and command interfaces and should thus not be called when a controller is running.
given that no hardware_info is available, the component has to be configured externally and prior to the call to import.
Parameters
[in]actuatorpointer to the actuator interface.
[in]

◆ import_component() [3/6]

void hardware_interface::ResourceManager::import_component ( std::unique_ptr< SensorInterface sensor)

Import a hardware component which is not listed in the URDF.

Components which are initialized outside a URDF can be added post initialization.

Note
this might invalidate existing state and command interfaces and should thus not be called when a controller is running.
given that no hardware_info is available, the component has to be configured externally and prior to the call to import.
Parameters
[in]sensorpointer to the sensor interface.

◆ import_component() [4/6]

void hardware_interface::ResourceManager::import_component ( std::unique_ptr< SensorInterface sensor,
const HardwareInfo hardware_info 
)

Import a hardware component which is not listed in the URDF.

Components which are initialized outside a URDF can be added post initialization. Nevertheless, there should still be HardwareInfo available for this component, either parsed from a URDF string (easiest) or filled manually.

Note
this might invalidate existing state and command interfaces and should thus not be called when a controller is running.
given that no hardware_info is available, the component has to be configured externally and prior to the call to import.
Parameters
[in]sensorpointer to the sensor interface.
[in]hardware_infohardware info

◆ import_component() [5/6]

void hardware_interface::ResourceManager::import_component ( std::unique_ptr< SystemInterface system)

Import a hardware component which is not listed in the URDF.

Components which are initialized outside a URDF can be added post initialization.

Note
this might invalidate existing state and command interfaces and should thus not be called when a controller is running.
given that no hardware_info is available, the component has to be configured externally and prior to the call to import.
Parameters
[in]systempointer to the system interface.

◆ import_component() [6/6]

void hardware_interface::ResourceManager::import_component ( std::unique_ptr< SystemInterface system,
const HardwareInfo hardware_info 
)

Import a hardware component which is not listed in the URDF.

Components which are initialized outside a URDF can be added post initialization. Nevertheless, there should still be HardwareInfo available for this component, either parsed from a URDF string (easiest) or filled manually.

Note
this might invalidate existing state and command interfaces and should thus not be called when a controller is running.
given that no hardware_info is available, the component has to be configured externally and prior to the call to import.
Parameters
[in]systempointer to the system interface.
[in]hardware_infohardware info

◆ load_urdf()

void hardware_interface::ResourceManager::load_urdf ( const std::string &  urdf,
bool  validate_interfaces = true 
)

Load resources from on a given URDF.

The resource manager can be post initialized with a given URDF. This is mainly used in conjunction with the default constructor in which the URDF might not be present at first initialization.

Parameters
[in]urdfstring containing the URDF.
[in]validate_interfacesboolean argument indicating whether the exported interfaces ought to be validated. Defaults to true.

◆ perform_command_mode_switch()

bool hardware_interface::ResourceManager::perform_command_mode_switch ( const std::vector< std::string > &  start_interfaces,
const std::vector< std::string > &  stop_interfaces 
)

Notify the hardware components that realtime hardware mode switching should occur.

Hardware components are asked to perform the command interface mode switching.

Note
this is intended for mode-switching when a hardware interface needs to change control mode depending on which command interface is claimed.
this is for realtime switching of the command interface.
Parameters
[in]start_interfacesvector of string identifiers for the command interfaces starting.
[in]stop_interfacesvector of string identifiers for the command interfacs stopping.
Returns
true if switch is performed, false if a component rejects switching.

◆ prepare_command_mode_switch()

bool hardware_interface::ResourceManager::prepare_command_mode_switch ( const std::vector< std::string > &  start_interfaces,
const std::vector< std::string > &  stop_interfaces 
)

Prepare the hardware components for a new command interface mode.

Hardware components are asked to prepare a new command interface claim.

Note
this is intended for mode-switching when a hardware interface needs to change control mode depending on which command interface is claimed.
this is for non-realtime preparing for and accepting new command resource combinations.
accept_command_resource_claim is called on all actuators and system components and hardware interfaces should return hardware_interface::return_type::SUCCESS by default
Parameters
[in]start_interfacesvector of string identifiers for the command interfaces starting.
[in]stop_interfacesvector of string identifiers for the command interfaces stopping.
Returns
true if switch can be prepared, false if a component rejects switch request.

◆ sensor_components_size()

size_t hardware_interface::ResourceManager::sensor_components_size ( ) const

Return the number of loaded sensor components.

Returns
number of sensor components.

◆ state_interface_exists()

bool hardware_interface::ResourceManager::state_interface_exists ( const std::string &  key) const

Checks whether a state interface is registered under the given key.

Returns
true if interface exist, false otherwise.

◆ state_interface_keys()

std::vector< std::string > hardware_interface::ResourceManager::state_interface_keys ( ) const

Returns all registered state interfaces keys.

The keys are collected from each loaded hardware component.

Returns
Vector of strings, containing all registered keys.

◆ system_components_size()

size_t hardware_interface::ResourceManager::system_components_size ( ) const

Return the number of loaded system components.

Returns
size_t number of system components.

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