ros2_control - rolling
|
Public Member Functions | |
ResourceManager (rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_interface) | |
Default constructor for the Resource Manager. | |
ResourceManager (const std::string &urdf, rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_interface, bool activate_all=false, const unsigned int update_rate=100) | |
Constructor for the Resource Manager. More... | |
ResourceManager (const ResourceManager &)=delete | |
virtual bool | load_and_initialize_components (const std::string &urdf, const unsigned int update_rate=100) |
Load resources from on a given URDF. More... | |
bool | are_components_initialized () const |
if the resource manager load_and_initialize_components(...) function has been called this returns true. We want to permit to loading the urdf later on, but we currently don't want to permit multiple calls to load_and_initialize_components (reloading/loading different 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... | |
std::vector< std::string > | available_state_interfaces () const |
Returns all available state interfaces keys. More... | |
bool | state_interface_is_available (const std::string &name) const |
Checks whether a state interface is available under the given key. More... | |
void | import_controller_exported_state_interfaces (const std::string &controller_name, std::vector< StateInterface::ConstSharedPtr > &interfaces) |
Add controllers' exported state interfaces to resource manager. More... | |
std::vector< std::string > | get_controller_exported_state_interface_names (const std::string &controller_name) |
Get list of exported tate interface of a controller. More... | |
void | make_controller_exported_state_interfaces_available (const std::string &controller_name) |
Add controller's exported state interfaces to available list. More... | |
void | make_controller_exported_state_interfaces_unavailable (const std::string &controller_name) |
Remove controller's exported state interface to available list. More... | |
void | remove_controller_exported_state_interfaces (const std::string &controller_name) |
Remove controllers exported state interfaces from resource manager. More... | |
void | import_controller_reference_interfaces (const std::string &controller_name, const std::vector< hardware_interface::CommandInterface::SharedPtr > &interfaces) |
Add controllers' reference interfaces to resource manager. More... | |
std::vector< std::string > | get_controller_reference_interface_names (const std::string &controller_name) |
Get list of reference interface of a controller. More... | |
void | make_controller_reference_interfaces_available (const std::string &controller_name) |
Add controller's reference interface to available list. More... | |
void | make_controller_reference_interfaces_unavailable (const std::string &controller_name) |
Remove controller's reference interface to available list. More... | |
void | remove_controller_reference_interfaces (const std::string &controller_name) |
Remove controllers reference interfaces from resource manager. More... | |
void | cache_controller_to_hardware (const std::string &controller_name, const std::vector< std::string > &interfaces) |
Cache mapping between hardware and controllers using it. More... | |
std::vector< std::string > | get_cached_controllers_to_hardware (const std::string &hardware_name) |
Return cached controllers for a specific hardware. 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... | |
std::vector< std::string > | available_command_interfaces () const |
Returns all available command interfaces keys. More... | |
bool | command_interface_is_available (const std::string &interface) const |
Checks whether a command interface is available under the given name. More... | |
size_t | actuator_components_size () const |
Return the number size_t of loaded actuator components. More... | |
size_t | sensor_components_size () const |
Return the number of loaded sensor components. More... | |
size_t | system_components_size () const |
Return the number of loaded system components. 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, HardwareComponentInfo > | get_components_status () |
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... | |
return_type | set_component_state (const std::string &component_name, rclcpp_lifecycle::State &target_state) |
Sets state of hardware component. More... | |
HardwareReadWriteStatus | read (const rclcpp::Time &time, const rclcpp::Duration &period) |
Reads all loaded hardware components. More... | |
HardwareReadWriteStatus | write (const rclcpp::Time &time, const rclcpp::Duration &period) |
Write all loaded hardware components. More... | |
bool | command_interface_exists (const std::string &key) const |
Checks whether a command interface is registered under the given key. More... | |
bool | state_interface_exists (const std::string &key) const |
Checks whether a state interface is registered under the given key. More... | |
Protected Member Functions | |
rclcpp::Logger | get_logger () const |
Gets the logger for the resource manager. More... | |
rclcpp::Clock::SharedPtr | get_clock () const |
Gets the clock for the resource manager. More... | |
|
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.
[in] | urdf | string containing the URDF. |
[in] | activate_all | boolean argument indicating if all resources should be immediately activated. Currently used only in tests. |
[in] | update_rate | Update rate of the controller manager to calculate calling frequency of async components. |
[in] | clock_interface | reference to the clock interface of the CM node for getting time used for triggering async components. |
size_t hardware_interface::ResourceManager::actuator_components_size | ( | ) | const |
Return the number size_t of loaded actuator components.
bool hardware_interface::ResourceManager::are_components_initialized | ( | ) | const |
if the resource manager load_and_initialize_components(...) function has been called this returns true. We want to permit to loading the urdf later on, but we currently don't want to permit multiple calls to load_and_initialize_components (reloading/loading different urdf).
std::vector< std::string > hardware_interface::ResourceManager::available_command_interfaces | ( | ) | const |
Returns all available command interfaces keys.
The keys are collected from the available list.
std::vector< std::string > hardware_interface::ResourceManager::available_state_interfaces | ( | ) | const |
Returns all available state interfaces keys.
The keys are collected from the available list.
void hardware_interface::ResourceManager::cache_controller_to_hardware | ( | const std::string & | controller_name, |
const std::vector< std::string > & | interfaces | ||
) |
Cache mapping between hardware and controllers using it.
Find mapping between controller and hardware based on interfaces controller with controller_name
is using and cache those for later usage.
[in] | controller_name | name of the controller which interfaces are provided. |
[in] | interfaces | list of interfaces controller with controller_name is using. |
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.
[in] | key | String identifier which command interface to claim |
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.
[in] | key | String identifier which state interface to claim |
bool hardware_interface::ResourceManager::command_interface_exists | ( | const std::string & | key | ) | const |
Checks whether a command interface is registered under the given key.
[in] | key | string identifying the interface to check. |
bool hardware_interface::ResourceManager::command_interface_is_available | ( | const std::string & | interface | ) | const |
Checks whether a command interface is available under the given name.
[in] | name | string identifying the interface to check. |
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.
[in] | key | string identifying the interface to check. |
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.
std::vector< std::string > hardware_interface::ResourceManager::get_cached_controllers_to_hardware | ( | const std::string & | hardware_name | ) |
Return cached controllers for a specific hardware.
Return list of cached controller names that use the hardware with name hardware_name
.
[in] | hardware_name | the name of the hardware for which cached controllers should be returned. |
hardware_name
.
|
protected |
Gets the clock for the resource manager.
std::unordered_map< std::string, HardwareComponentInfo > hardware_interface::ResourceManager::get_components_status | ( | ) |
Return status for all components.
std::vector< std::string > hardware_interface::ResourceManager::get_controller_exported_state_interface_names | ( | const std::string & | controller_name | ) |
Get list of exported tate interface of a controller.
Returns lists of stored exported state interfaces names for a controller.
[in] | controller_name | for which list of state interface names is returned. |
std::vector< std::string > hardware_interface::ResourceManager::get_controller_reference_interface_names | ( | const std::string & | controller_name | ) |
Get list of reference interface of a controller.
Returns lists of stored reference interfaces names for a controller.
[in] | controller_name | for which list of reference interface names is returned. |
|
protected |
Gets the logger for the resource manager.
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.
[in] | actuator | pointer to the actuator interface. |
[in] | hardware_info | hardware info |
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.
[in] | sensor | pointer to the sensor interface. |
[in] | hardware_info | hardware info |
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.
[in] | system | pointer to the system interface. |
[in] | hardware_info | hardware info |
void hardware_interface::ResourceManager::import_controller_exported_state_interfaces | ( | const std::string & | controller_name, |
std::vector< StateInterface::ConstSharedPtr > & | interfaces | ||
) |
Add controllers' exported state interfaces to resource manager.
Interface for transferring management of exported state interfaces to resource manager. When chaining controllers, state interfaces are used by the preceding controllers. Therefore, they should be managed in the same way as state interface of hardware.
[in] | controller_name | name of the controller which state interfaces are imported. |
[in] | interfaces | list of controller's state interfaces as StateInterfaces. |
void hardware_interface::ResourceManager::import_controller_reference_interfaces | ( | const std::string & | controller_name, |
const std::vector< hardware_interface::CommandInterface::SharedPtr > & | interfaces | ||
) |
Add controllers' reference interfaces to resource manager.
Interface for transferring management of reference interfaces to resource manager. When chaining controllers, reference interfaces are used as command interface of preceding controllers. Therefore, they should be managed in the same way as command interface of hardware.
[in] | controller_name | name of the controller which reference interfaces are imported. |
[in] | interfaces | list of controller's reference interfaces as CommandInterfaces. |
|
virtual |
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.
[in] | urdf | string containing the URDF. |
[in] | update_rate | update rate of the main control loop, i.e., of the controller manager. |
Reimplemented in gz_ros2_control::GZResourceManager, and gazebo_ros2_control::GazeboResourceManager.
void hardware_interface::ResourceManager::make_controller_exported_state_interfaces_available | ( | const std::string & | controller_name | ) |
Add controller's exported state interfaces to available list.
Adds state interfacess of a controller with given name to the available list. This method should be called when a controller gets activated with chained mode turned on. That means, the controller's exported state interfaces can be used by another controllers in chained architectures.
[in] | controller_name | name of the controller which interfaces should become available. |
void hardware_interface::ResourceManager::make_controller_exported_state_interfaces_unavailable | ( | const std::string & | controller_name | ) |
Remove controller's exported state interface to available list.
Removes interfaces of a controller with given name from the available list. This method should be called when a controller gets deactivated and its reference interfaces cannot be used by another controller anymore.
[in] | controller_name | name of the controller which interfaces should become unavailable. |
void hardware_interface::ResourceManager::make_controller_reference_interfaces_available | ( | const std::string & | controller_name | ) |
Add controller's reference interface to available list.
Adds interfaces of a controller with given name to the available list. This method should be called when a controller gets activated with chained mode turned on. That means, the controller's reference interfaces can be used by another controller in chained architectures.
[in] | controller_name | name of the controller which interfaces should become available. |
void hardware_interface::ResourceManager::make_controller_reference_interfaces_unavailable | ( | const std::string & | controller_name | ) |
Remove controller's reference interface to available list.
Removes interfaces of a controller with given name from the available list. This method should be called when a controller gets deactivated and its reference interfaces cannot be used by another controller anymore.
[in] | controller_name | name of the controller which interfaces should become unavailable. |
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.
prepare_command_mode_switch
is called just before this method with the same input arguments. [in] | start_interfaces | vector of string identifiers for the command interfaces starting. |
[in] | stop_interfaces | vector of string identifiers for the command interfaces stopping. |
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.
[in] | start_interfaces | vector of string identifiers for the command interfaces starting. |
[in] | stop_interfaces | vector of string identifiers for the command interfaces stopping. |
HardwareReadWriteStatus hardware_interface::ResourceManager::read | ( | const rclcpp::Time & | time, |
const rclcpp::Duration & | period | ||
) |
Reads all loaded hardware components.
Reads from all active hardware components.
Part of the real-time critical update loop. It is realtime-safe if used hardware interfaces are implemented adequately.
void hardware_interface::ResourceManager::remove_controller_exported_state_interfaces | ( | const std::string & | controller_name | ) |
Remove controllers exported state interfaces from resource manager.
Remove exported state interfaces from resource manager, i.e., resource storage. The interfaces will be deleted from all internal maps and lists.
[in] | controller_name | list of interface names that will be deleted from resource manager. |
void hardware_interface::ResourceManager::remove_controller_reference_interfaces | ( | const std::string & | controller_name | ) |
Remove controllers reference interfaces from resource manager.
Remove reference interfaces from resource manager, i.e., resource storage. The interfaces will be deleted from all internal maps and lists.
[in] | controller_name | list of interface names that will be deleted from resource manager. |
size_t hardware_interface::ResourceManager::sensor_components_size | ( | ) | const |
Return the number of loaded sensor components.
return_type hardware_interface::ResourceManager::set_component_state | ( | const std::string & | component_name, |
rclcpp_lifecycle::State & | target_state | ||
) |
Sets state of hardware component.
Set set of hardware component if possible. Takes care of all transitions needed to reach the target state. It implements the state machine from: https://design.ros2.org/articles/node_lifecycle.html
The method is not part of the real-time critical update loop.
[in] | component_name | component name to change state. |
[in] | target_state | target state to set for a hardware component. |
bool hardware_interface::ResourceManager::state_interface_exists | ( | const std::string & | key | ) | const |
Checks whether a state interface is registered under the given key.
bool hardware_interface::ResourceManager::state_interface_is_available | ( | const std::string & | name | ) | const |
Checks whether a state interface is available under the given key.
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.
size_t hardware_interface::ResourceManager::system_components_size | ( | ) | const |
Return the number of loaded system components.
HardwareReadWriteStatus hardware_interface::ResourceManager::write | ( | const rclcpp::Time & | time, |
const rclcpp::Duration & | period | ||
) |
Write all loaded hardware components.
Writes to all active hardware components.
Part of the real-time critical update loop. It is realtime-safe if used hardware interfaces are implemented adequately.