Skip to content

Commit d5c2c99

Browse files
authored
Avoid running joint limit enforcement during initialization (#2188)
1 parent 495d2b7 commit d5c2c99

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

hardware_interface/include/hardware_interface/resource_manager.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ class ResourceManager
527527
mutable std::recursive_mutex resource_interfaces_lock_;
528528
mutable std::recursive_mutex claimed_command_interfaces_lock_;
529529
mutable std::recursive_mutex resources_lock_;
530+
mutable std::recursive_mutex joint_limiters_lock_;
530531

531532
private:
532533
bool validate_storage(const std::vector<hardware_interface::HardwareInfo> & hardware_info) const;

hardware_interface/src/resource_manager.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,11 @@ class ResourceStorage
740740
const std::string interface_name = joint_name + "/" + interface_type;
741741
if (interface_map.find(interface_name) != interface_map.end())
742742
{
743-
// If the command interface is not claimed, then the value is not set
744-
if (is_command_itf && !claimed_command_interface_map_.at(interface_name))
743+
// If the command interface is not claimed, then the value is not set (or) if the
744+
// interface doesn't exist, then value is not set
745+
if (
746+
is_command_itf && (claimed_command_interface_map_.count(interface_name) == 0 ||
747+
!claimed_command_interface_map_.at(interface_name)))
745748
{
746749
value = std::nullopt;
747750
}
@@ -1446,6 +1449,7 @@ bool ResourceManager::load_and_initialize_components(
14461449

14471450
void ResourceManager::import_joint_limiters(const std::string & urdf)
14481451
{
1452+
std::lock_guard<std::recursive_mutex> guard(joint_limiters_lock_);
14491453
const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf);
14501454
resource_storage_->import_joint_limiters(hardware_info);
14511455
}
@@ -2072,6 +2076,12 @@ return_type ResourceManager::set_component_state(
20722076
// CM API: Called in "update"-thread
20732077
bool ResourceManager::enforce_command_limits(const rclcpp::Duration & period)
20742078
{
2079+
std::unique_lock<std::recursive_mutex> limiters_guard(joint_limiters_lock_, std::try_to_lock);
2080+
if (!limiters_guard.owns_lock())
2081+
{
2082+
return false;
2083+
}
2084+
20752085
bool enforce_result = false;
20762086
// Joint Limiters operations
20772087
for (auto & [hw_name, limiters] : resource_storage_->joint_limiters_interface_)

0 commit comments

Comments
 (0)