Skip to content

Commit 544e661

Browse files
authored
[RM] Fix crash for missing urdf in resource manager (#1301) (#1316)
1 parent a3bf280 commit 544e661

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

hardware_interface/include/hardware_interface/resource_manager.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager
8080
* \param[in] urdf string containing the URDF.
8181
* \param[in] validate_interfaces boolean argument indicating whether the exported
8282
* interfaces ought to be validated. Defaults to true.
83+
* \param[in] load_and_initialize_components boolean argument indicating whether to load and
84+
* initialize the components present in the parsed URDF. Defaults to true.
8385
*/
84-
void load_urdf(const std::string & urdf, bool validate_interfaces = true);
86+
void load_urdf(
87+
const std::string & urdf, bool validate_interfaces = true,
88+
bool load_and_initialize_components = true);
8589

8690
/**
8791
* @brief if the resource manager load_urdf(...) function has been called this returns true.

hardware_interface/src/resource_manager.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -676,32 +676,36 @@ ResourceManager::ResourceManager(
676676
}
677677

678678
// CM API: Called in "callback/slow"-thread
679-
void ResourceManager::load_urdf(const std::string & urdf, bool validate_interfaces)
679+
void ResourceManager::load_urdf(
680+
const std::string & urdf, bool validate_interfaces, bool load_and_initialize_components)
680681
{
681682
is_urdf_loaded__ = true;
682683
const std::string system_type = "system";
683684
const std::string sensor_type = "sensor";
684685
const std::string actuator_type = "actuator";
685686

686687
const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf);
687-
for (const auto & individual_hardware_info : hardware_info)
688+
if (load_and_initialize_components)
688689
{
689-
if (individual_hardware_info.type == actuator_type)
690+
for (const auto & individual_hardware_info : hardware_info)
690691
{
691-
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
692-
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
693-
resource_storage_->load_and_initialize_actuator(individual_hardware_info);
694-
}
695-
if (individual_hardware_info.type == sensor_type)
696-
{
697-
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
698-
resource_storage_->load_and_initialize_sensor(individual_hardware_info);
699-
}
700-
if (individual_hardware_info.type == system_type)
701-
{
702-
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
703-
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
704-
resource_storage_->load_and_initialize_system(individual_hardware_info);
692+
if (individual_hardware_info.type == actuator_type)
693+
{
694+
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
695+
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
696+
resource_storage_->load_and_initialize_actuator(individual_hardware_info);
697+
}
698+
if (individual_hardware_info.type == sensor_type)
699+
{
700+
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
701+
resource_storage_->load_and_initialize_sensor(individual_hardware_info);
702+
}
703+
if (individual_hardware_info.type == system_type)
704+
{
705+
std::lock_guard<std::recursive_mutex> guard(resource_interfaces_lock_);
706+
std::lock_guard<std::recursive_mutex> guard_claimed(claimed_command_interfaces_lock_);
707+
resource_storage_->load_and_initialize_system(individual_hardware_info);
708+
}
705709
}
706710
}
707711

0 commit comments

Comments
 (0)