15#ifndef HARDWARE_INTERFACE__RESOURCE_MANAGER_HPP_
16#define HARDWARE_INTERFACE__RESOURCE_MANAGER_HPP_
20#include <unordered_map>
23#include "hardware_interface/actuator.hpp"
24#include "hardware_interface/hardware_component_info.hpp"
25#include "hardware_interface/hardware_info.hpp"
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
28#include "hardware_interface/loaned_command_interface.hpp"
29#include "hardware_interface/loaned_state_interface.hpp"
30#pragma GCC diagnostic pop
31#include "hardware_interface/sensor.hpp"
32#include "hardware_interface/system.hpp"
33#include "hardware_interface/system_interface.hpp"
34#include "hardware_interface/types/hardware_interface_return_values.hpp"
35#include "hardware_interface/types/resource_manager_params.hpp"
36#include "rclcpp/duration.hpp"
37#include "rclcpp/executor.hpp"
38#include "rclcpp/node_interfaces/node_logging_interface.hpp"
39#include "rclcpp/time.hpp"
44class ControllerManager;
49 std::vector<std::string> failed_hardware_names;
57 rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface,
58 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_interface);
61 explicit ResourceManager(rclcpp::Clock::SharedPtr clock, rclcpp::Logger logger);
79 const std::string & urdf,
80 rclcpp::node_interfaces::NodeClockInterface::SharedPtr clock_interface,
81 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_interface,
82 bool activate_all =
false,
const unsigned int update_rate = 100);
100 const std::string & urdf, rclcpp::Clock::SharedPtr clock, rclcpp::Logger logger,
101 bool activate_all =
false,
const unsigned int update_rate = 100);
137 [[deprecated(
"Use load_and_initialize_components(const ResourceManagerParams & params) instead")]]
139 const std::string & urdf,
const unsigned int update_rate = 100);
220 const std::string & controller_name, std::vector<StateInterface::ConstSharedPtr> & interfaces);
230 const std::string & controller_name);
273 const std::string & controller_name,
274 const std::vector<hardware_interface::CommandInterface::SharedPtr> & interfaces);
284 const std::string & controller_name);
324 const std::string & controller_name,
const std::vector<std::string> & interfaces);
419 "Use import_component(std::unique_ptr<ActuatorInterface> actuator, "
420 "const HardwareComponentParams & params) instead")]]
422 std::unique_ptr<ActuatorInterface> actuator,
const HardwareInfo & hardware_info);
438 "Use import_component(std::unique_ptr<SensorInterface> sensor, "
439 "const HardwareComponentParams & params) instead")]]
441 std::unique_ptr<SensorInterface> sensor,
const HardwareInfo & hardware_info);
508 "Use import_component(std::unique_ptr<SystemInterface> system, "
509 "const HardwareComponentParams & params) instead")]]
511 std::unique_ptr<SystemInterface> system,
const HardwareInfo & hardware_info);
537 const std::vector<std::string> & start_interfaces,
538 const std::vector<std::string> & stop_interfaces);
554 const std::vector<std::string> & start_interfaces,
555 const std::vector<std::string> & stop_interfaces);
571 const std::string & component_name, rclcpp_lifecycle::State & target_state);
618 const std::string & get_robot_description()
const;
631 rclcpp::Clock::SharedPtr
get_clock()
const;
633 bool components_are_loaded_and_initialized_ =
false;
635 mutable std::recursive_mutex resource_interfaces_lock_;
636 mutable std::recursive_mutex claimed_command_interfaces_lock_;
637 mutable std::recursive_mutex resources_lock_;
638 mutable std::recursive_mutex joint_limiters_lock_;
641 bool validate_storage(
const std::vector<hardware_interface::HardwareInfo> & hardware_info)
const;
643 void release_command_interface(
const std::string & key);
649 rclcpp::Clock::SharedPtr clock, rclcpp::Logger logger,
const std::string & urdf = std::string(),
650 bool activate_all =
false,
unsigned int update_rate = 100);
652 std::unordered_map<std::string, bool> claimed_command_interface_map_;
654 std::unique_ptr<ResourceStorage> resource_storage_;
Definition loaned_command_interface.hpp:30
Definition loaned_state_interface.hpp:29
Definition resource_manager.hpp:53
void make_controller_reference_interfaces_available(const std::string &controller_name)
Add controller's reference interface to available list.
Definition resource_manager.cpp:1681
std::string get_state_interface_data_type(const std::string &name) const
Gets the data type of the state interface.
Definition resource_manager.cpp:1586
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.
Definition resource_manager.cpp:1664
std::vector< std::string > command_interface_keys() const
Returns all registered command interfaces keys.
Definition resource_manager.cpp:1815
virtual bool load_and_initialize_components(const std::string &urdf, const unsigned int update_rate=100)
Load resources from on a given URDF.
Definition resource_manager.cpp:1432
bool command_interface_exists(const std::string &key) const
Checks whether a command interface is registered under the given key.
Definition resource_manager.cpp:2525
bool command_interface_is_claimed(const std::string &key) const
Checks whether a command interface is already claimed.
Definition resource_manager.cpp:1773
return_type set_component_state(const std::string &component_name, rclcpp_lifecycle::State &target_state)
Sets state of hardware component.
Definition resource_manager.cpp:2201
bool are_components_initialized() const
if the resource manager load_and_initialize_components(...) function has been called this returns tru...
Definition resource_manager.cpp:1539
void set_on_component_state_switch_callback(std::function< void()> callback)
A method to register a callback to be called when the component state changes.
Definition resource_manager.cpp:2539
bool shutdown_components()
Shutdown all hardware components, irrespective of their state.
Definition resource_manager.cpp:1415
void remove_controller_exported_state_interfaces(const std::string &controller_name)
Remove controllers exported state interfaces from resource manager.
Definition resource_manager.cpp:1652
void import_component(std::unique_ptr< ActuatorInterface > actuator, const HardwareInfo &hardware_info)
Import a hardware component which is not listed in the URDF.
Definition resource_manager.cpp:1858
void make_controller_exported_state_interfaces_available(const std::string &controller_name)
Add controller's exported state interfaces to available list.
Definition resource_manager.cpp:1618
size_t sensor_components_size() const
Return the number of loaded sensor components.
Definition resource_manager.cpp:2515
std::vector< std::string > state_interface_keys() const
Returns all registered state interfaces keys.
Definition resource_manager.cpp:1558
size_t system_components_size() const
Return the number of loaded system components.
Definition resource_manager.cpp:2520
std::vector< std::string > get_controller_reference_interface_names(const std::string &controller_name)
Get list of reference interface of a controller.
Definition resource_manager.cpp:1674
bool command_interface_is_available(const std::string &interface) const
Checks whether a command interface is available under the given name.
Definition resource_manager.cpp:1834
void import_controller_exported_state_interfaces(const std::string &controller_name, std::vector< StateInterface::ConstSharedPtr > &interfaces)
Add controllers' exported state interfaces to resource manager.
Definition resource_manager.cpp:1602
void make_controller_exported_state_interfaces_unavailable(const std::string &controller_name)
Remove controller's exported state interface to available list.
Definition resource_manager.cpp:1630
std::vector< std::string > get_cached_controllers_to_hardware(const std::string &hardware_name)
Return cached controllers for a specific hardware.
Definition resource_manager.cpp:1766
std::string get_command_interface_data_type(const std::string &name) const
Gets the data type of the command interface.
Definition resource_manager.cpp:1843
bool state_interface_is_available(const std::string &name) const
Checks whether a state interface is available under the given key.
Definition resource_manager.cpp:1577
std::vector< std::string > get_controller_exported_state_interface_names(const std::string &controller_name)
Get list of exported tate interface of a controller.
Definition resource_manager.cpp:1611
bool state_interface_exists(const std::string &key) const
Checks whether a state interface is registered under the given key.
Definition resource_manager.cpp:2532
void make_controller_reference_interfaces_unavailable(const std::string &controller_name)
Remove controller's reference interface to available list.
Definition resource_manager.cpp:1693
size_t actuator_components_size() const
Return the number size_t of loaded actuator components.
Definition resource_manager.cpp:2510
rclcpp::Clock::SharedPtr get_clock() const
Gets the clock for the resource manager.
Definition resource_manager.cpp:2553
HardwareReadWriteStatus read(const rclcpp::Time &time, const rclcpp::Duration &period)
Reads all loaded hardware components.
Definition resource_manager.cpp:2307
std::vector< std::string > available_command_interfaces() const
Returns all available command interfaces keys.
Definition resource_manager.cpp:1827
void remove_controller_reference_interfaces(const std::string &controller_name)
Remove controllers reference interfaces from resource manager.
Definition resource_manager.cpp:1715
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.
Definition resource_manager.cpp:1933
void import_joint_limiters(const std::string &urdf)
Import joint limiters from the URDF.
Definition resource_manager.cpp:1532
bool enforce_command_limits(const rclcpp::Duration &period)
Definition resource_manager.cpp:2286
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.
Definition resource_manager.cpp:2085
std::vector< std::string > available_state_interfaces() const
Returns all available state interfaces keys.
Definition resource_manager.cpp:1570
rclcpp::Logger get_logger() const
Gets the logger for the resource manager.
Definition resource_manager.cpp:2551
LoanedCommandInterface claim_command_interface(const std::string &key)
Claim a command interface given its key.
Definition resource_manager.cpp:1785
void cache_controller_to_hardware(const std::string &controller_name, const std::vector< std::string > &interfaces)
Cache mapping between hardware and controllers using it.
Definition resource_manager.cpp:1726
LoanedStateInterface claim_state_interface(const std::string &key)
Claim a state interface given its key.
Definition resource_manager.cpp:1545
HardwareReadWriteStatus write(const rclcpp::Time &time, const rclcpp::Duration &period)
Write all loaded hardware components.
Definition resource_manager.cpp:2406
const std::unordered_map< std::string, HardwareComponentInfo > & get_components_status()
Return status for all components.
Definition resource_manager.cpp:1914
Definition actuator.hpp:22
Parameters required for the initialization of a specific hardware component plugin....
Definition hardware_component_params.hpp:32
This structure stores information about hardware defined in a robot's URDF.
Definition hardware_info.hpp:252
Definition resource_manager.hpp:47
Parameters required for the construction and initial setup of a ResourceManager. This struct is typic...
Definition resource_manager_params.hpp:30