diff --git a/hardware_interface/include/hardware_interface/resource_manager.hpp b/hardware_interface/include/hardware_interface/resource_manager.hpp index 258c32a40c..c964a2d256 100644 --- a/hardware_interface/include/hardware_interface/resource_manager.hpp +++ b/hardware_interface/include/hardware_interface/resource_manager.hpp @@ -80,8 +80,12 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager * \param[in] urdf string containing the URDF. * \param[in] validate_interfaces boolean argument indicating whether the exported * interfaces ought to be validated. Defaults to true. + * \param[in] load_and_initialize_components boolean argument indicating whether to load and + * initialize the components present in the parsed URDF. Defaults to true. */ - void load_urdf(const std::string & urdf, bool validate_interfaces = true); + void load_urdf( + const std::string & urdf, bool validate_interfaces = true, + bool load_and_initialize_components = true); /** * @brief if the resource manager load_urdf(...) function has been called this returns true. diff --git a/hardware_interface/src/resource_manager.cpp b/hardware_interface/src/resource_manager.cpp index 925068d65d..2297e2ffe1 100644 --- a/hardware_interface/src/resource_manager.cpp +++ b/hardware_interface/src/resource_manager.cpp @@ -676,7 +676,8 @@ ResourceManager::ResourceManager( } // CM API: Called in "callback/slow"-thread -void ResourceManager::load_urdf(const std::string & urdf, bool validate_interfaces) +void ResourceManager::load_urdf( + const std::string & urdf, bool validate_interfaces, bool load_and_initialize_components) { is_urdf_loaded__ = true; const std::string system_type = "system"; @@ -684,24 +685,27 @@ void ResourceManager::load_urdf(const std::string & urdf, bool validate_interfac const std::string actuator_type = "actuator"; const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf); - for (const auto & individual_hardware_info : hardware_info) + if (load_and_initialize_components) { - if (individual_hardware_info.type == actuator_type) + for (const auto & individual_hardware_info : hardware_info) { - std::lock_guard guard(resource_interfaces_lock_); - std::lock_guard guard_claimed(claimed_command_interfaces_lock_); - resource_storage_->load_and_initialize_actuator(individual_hardware_info); - } - if (individual_hardware_info.type == sensor_type) - { - std::lock_guard guard(resource_interfaces_lock_); - resource_storage_->load_and_initialize_sensor(individual_hardware_info); - } - if (individual_hardware_info.type == system_type) - { - std::lock_guard guard(resource_interfaces_lock_); - std::lock_guard guard_claimed(claimed_command_interfaces_lock_); - resource_storage_->load_and_initialize_system(individual_hardware_info); + if (individual_hardware_info.type == actuator_type) + { + std::lock_guard guard(resource_interfaces_lock_); + std::lock_guard guard_claimed(claimed_command_interfaces_lock_); + resource_storage_->load_and_initialize_actuator(individual_hardware_info); + } + if (individual_hardware_info.type == sensor_type) + { + std::lock_guard guard(resource_interfaces_lock_); + resource_storage_->load_and_initialize_sensor(individual_hardware_info); + } + if (individual_hardware_info.type == system_type) + { + std::lock_guard guard(resource_interfaces_lock_); + std::lock_guard guard_claimed(claimed_command_interfaces_lock_); + resource_storage_->load_and_initialize_system(individual_hardware_info); + } } }