Skip to content

Commit 7fc9387

Browse files
committed
Fix logic for simpler reviewing
1 parent b9246f0 commit 7fc9387

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vector>
2424

2525
#include "controller_interface/controller_interface_base.hpp"
26+
#include "controller_manager/controller_manager_parameters.hpp"
2627
#include "controller_manager_msgs/msg/hardware_component_state.hpp"
2728
#include "hardware_interface/helpers.hpp"
2829
#include "hardware_interface/introspection.hpp"
@@ -32,8 +33,6 @@
3233
#include "rclcpp/version.h"
3334
#include "rclcpp_lifecycle/state.hpp"
3435

35-
#include "controller_manager/controller_manager_parameters.hpp"
36-
3736
namespace // utility
3837
{
3938
static constexpr const char * kControllerInterfaceNamespace = "controller_interface";
@@ -546,7 +545,20 @@ void ControllerManager::init_controller_manager()
546545
init_resource_manager(robot_description_);
547546
}
548547

549-
if (!is_resource_manager_initialized())
548+
if (
549+
is_resource_manager_initialized() && !(resource_manager_->get_joint_limiters_imported()) &&
550+
params_->enforce_command_limits)
551+
{
552+
try
553+
{
554+
resource_manager_->import_joint_limiters(robot_description_);
555+
}
556+
catch (const std::exception & e)
557+
{
558+
RCLCPP_ERROR(get_logger(), "Error importing joint limiters: %s", e.what());
559+
}
560+
}
561+
else if (!is_resource_manager_initialized())
550562
{
551563
// The RM failed to initialize after receiving the robot description, or no description was
552564
// received at all. This is a critical error. Don't finalize controller manager, instead keep
@@ -598,15 +610,6 @@ void ControllerManager::init_controller_manager()
598610
diagnostics_updater_.add(
599611
"Controller Manager Activity", this,
600612
&ControllerManager::controller_manager_diagnostic_callback);
601-
602-
INITIALIZE_ROS2_CONTROL_INTROSPECTION_REGISTRY(
603-
this, hardware_interface::DEFAULT_INTROSPECTION_TOPIC,
604-
hardware_interface::DEFAULT_REGISTRY_KEY);
605-
START_ROS2_CONTROL_INTROSPECTION_PUBLISHER_THREAD(hardware_interface::DEFAULT_REGISTRY_KEY);
606-
INITIALIZE_ROS2_CONTROL_INTROSPECTION_REGISTRY(
607-
this, hardware_interface::CM_STATISTICS_TOPIC, hardware_interface::CM_STATISTICS_KEY);
608-
START_ROS2_CONTROL_INTROSPECTION_PUBLISHER_THREAD(hardware_interface::CM_STATISTICS_KEY);
609-
610613
// Add on_shutdown callback to stop the controller manager
611614
rclcpp::Context::SharedPtr context = this->get_node_base_interface()->get_context();
612615
preshutdown_cb_handle_ =

hardware_interface/include/hardware_interface/resource_manager.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ class ResourceManager
558558

559559
const std::string & get_robot_description() const;
560560

561+
bool get_joint_limiters_imported() const;
562+
561563
protected:
562564
/// Gets the logger for the resource manager
563565
/**
@@ -598,6 +600,7 @@ class ResourceManager
598600

599601
// Structure to store read and write status so it is not initialized in the real-time loop
600602
HardwareReadWriteStatus read_write_status;
603+
mutable bool joint_limiters_imported_ = false;
601604
};
602605

603606
} // namespace hardware_interface

hardware_interface/src/resource_manager.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ class ResourceStorage
733733
}
734734
}
735735

736-
void import_joint_limiters(const std::vector<HardwareInfo> & hardware_infos)
736+
bool import_joint_limiters(const std::vector<HardwareInfo> & hardware_infos)
737737
{
738738
for (const auto & hw_info : hardware_infos)
739739
{
@@ -782,6 +782,7 @@ class ResourceStorage
782782
joint_limiters_interface_[hw_info.name].insert({joint_name, std::move(limits_interface)});
783783
}
784784
}
785+
return true;
785786
}
786787

787788
template <typename T>
@@ -1561,9 +1562,15 @@ void ResourceManager::import_joint_limiters(const std::string & urdf)
15611562
{
15621563
std::lock_guard<std::recursive_mutex> guard(joint_limiters_lock_);
15631564
const auto hardware_info = hardware_interface::parse_control_resources_from_urdf(urdf);
1564-
resource_storage_->import_joint_limiters(hardware_info);
1565+
bool success = resource_storage_->import_joint_limiters(hardware_info);
1566+
if (success)
1567+
{
1568+
joint_limiters_imported_ = true;
1569+
}
15651570
}
15661571

1572+
bool ResourceManager::get_joint_limiters_imported() const { return joint_limiters_imported_; }
1573+
15671574
bool ResourceManager::are_components_initialized() const
15681575
{
15691576
return components_are_loaded_and_initialized_;

0 commit comments

Comments
 (0)