Skip to content

Commit 0777d96

Browse files
authored
Merge branch 'master' into feat/abs_pos_and_torque_interfaces
2 parents 0c6fb82 + 2c691e0 commit 0777d96

6 files changed

Lines changed: 35 additions & 23 deletions

File tree

controller_manager/doc/userdoc.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ robot_description [std_msgs::msg::String]
7979
Parameters
8080
-----------
8181

82-
enforce_command_limits (optional; bool; default: ``false`` for Jazzy and earlier distro and ``true`` for Rolling and newer distros)
83-
Enforces the joint limits to the joint command interfaces.
84-
If the command is outside the limits, the command is clamped to be within the limits depending on the type of configured joint limits in the URDF.
85-
If the command is within the limits, the command is passed through without any changes.
86-
8782
<controller_name>.type
8883
Name of a plugin exported using ``pluginlib`` for a controller.
8984
This is a class from which controller's instance with name "``controller_name``" is created.

controller_manager/include/controller_manager/controller_manager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ class ControllerManager : public rclcpp::Node
673673
std::string robot_description_;
674674
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr robot_description_subscription_;
675675
rclcpp::TimerBase::SharedPtr robot_description_notification_timer_;
676-
bool enforce_command_limits_;
677676

678677
controller_manager::MovingAverageStatistics periodicity_stats_;
679678

controller_manager/src/controller_manager.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void ControllerManager::init_controller_manager()
490490
// Get parameters needed for RT "update" loop to work
491491
if (is_resource_manager_initialized())
492492
{
493-
if (enforce_command_limits_)
493+
if (params_->enforce_command_limits)
494494
{
495495
resource_manager_->import_joint_limiters(robot_description_);
496496
}
@@ -556,12 +556,8 @@ void ControllerManager::init_controller_manager()
556556
RCLCPP_INFO(get_logger(), "Shutting down the controller manager.");
557557
}));
558558

559-
// Declare the enforce_command_limits parameter such a way that it is enabled by default for
560-
// rolling and newer alone
561-
enforce_command_limits_ =
562-
this->get_parameter_or("enforce_command_limits", RCLCPP_VERSION_MAJOR >= 29 ? true : false);
563559
RCLCPP_INFO_EXPRESSION(
564-
get_logger(), enforce_command_limits_, "Enforcing command limits is enabled...");
560+
get_logger(), params_->enforce_command_limits, "Enforcing command limits is enabled...");
565561
}
566562

567563
void ControllerManager::initialize_parameters()
@@ -615,7 +611,7 @@ void ControllerManager::robot_description_callback(const std_msgs::msg::String &
615611

616612
void ControllerManager::init_resource_manager(const std::string & robot_description)
617613
{
618-
if (enforce_command_limits_)
614+
if (params_->enforce_command_limits)
619615
{
620616
resource_manager_->import_joint_limiters(robot_description_);
621617
}

controller_manager/src/controller_manager_parameters.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ controller_manager:
66
description: "The frequency of controller manager's real-time update loop. This loop reads states from hardware, updates controllers and writes commands to hardware."
77
}
88

9+
enforce_command_limits: {
10+
type: bool,
11+
default_value: true,
12+
read_only: true,
13+
description: "If true, the controller manager will enforce command limits defined in the robot description. If false, no limits will be enforced. If true, when the command is outside the limits, the command is clamped to be within the limits depending on the type of configured joint limits defined in the robot description. If the command is within the limits, the command is passed through without any changes.",
14+
}
15+
916
hardware_components_initial_state:
1017
unconfigured: {
1118
type: string_array,
@@ -28,6 +35,7 @@ controller_manager:
2835
shutdown_on_initial_state_failure: {
2936
type: bool,
3037
default_value: false,
38+
read_only: true,
3139
description: "Specifies whether the controller manager should shut down if setting the desired initial state fails during startup.",
3240
}
3341

hardware_interface/include/hardware_interface/types/statistics_types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "libstatistics_collector/moving_average_statistics/moving_average.hpp"
2424
#include "libstatistics_collector/moving_average_statistics/types.hpp"
25-
#ifndef _WIN32
25+
#if !defined(_WIN32) && !defined(__APPLE__)
2626
#include "realtime_tools/mutex.hpp"
2727
#define DEFAULT_MUTEX realtime_tools::prio_inherit_mutex
2828
#else

hardware_interface/src/resource_manager.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,32 @@ std::string interfaces_to_string(
9191
return ss.str();
9292
};
9393

94-
void get_hardware_related_interfaces(
94+
void find_common_hardware_interfaces(
9595
const std::vector<std::string> & hw_command_itfs,
9696
const std::vector<std::string> & start_stop_interfaces_list,
9797
std::vector<std::string> & hw_interfaces)
9898
{
9999
hw_interfaces.clear();
100-
for (const auto & interface : start_stop_interfaces_list)
100+
101+
// decide which input vector is shorter.
102+
const auto & shorter_vec = hw_command_itfs.size() < start_stop_interfaces_list.size()
103+
? hw_command_itfs
104+
: start_stop_interfaces_list;
105+
const auto & longer_vec =
106+
&shorter_vec == &hw_command_itfs ? start_stop_interfaces_list : hw_command_itfs;
107+
108+
// reserve exactly the worst-case result size (all of the smaller one).
109+
hw_interfaces.reserve(shorter_vec.size());
110+
111+
// build a hash set from the smaller vector.
112+
std::unordered_set<std::string> lookup(shorter_vec.begin(), shorter_vec.end());
113+
114+
// iterate through the larger vector; test membership in constant time.
115+
for (const auto & name : longer_vec)
101116
{
102-
if (
103-
std::find(hw_command_itfs.begin(), hw_command_itfs.end(), interface) != hw_command_itfs.end())
117+
if (lookup.find(name) != lookup.end())
104118
{
105-
hw_interfaces.push_back(interface);
119+
hw_interfaces.push_back(name);
106120
}
107121
}
108122
}
@@ -1933,8 +1947,8 @@ bool ResourceManager::prepare_command_mode_switch(
19331947
for (auto & component : components)
19341948
{
19351949
const auto & hw_command_itfs = hardware_info_map.at(component.get_name()).command_interfaces;
1936-
get_hardware_related_interfaces(hw_command_itfs, start_interfaces, start_interfaces_buffer);
1937-
get_hardware_related_interfaces(hw_command_itfs, stop_interfaces, stop_interfaces_buffer);
1950+
find_common_hardware_interfaces(hw_command_itfs, start_interfaces, start_interfaces_buffer);
1951+
find_common_hardware_interfaces(hw_command_itfs, stop_interfaces, stop_interfaces_buffer);
19381952
if (start_interfaces_buffer.empty() && stop_interfaces_buffer.empty())
19391953
{
19401954
RCLCPP_DEBUG(
@@ -2023,8 +2037,8 @@ bool ResourceManager::perform_command_mode_switch(
20232037
for (auto & component : components)
20242038
{
20252039
const auto & hw_command_itfs = hardware_info_map.at(component.get_name()).command_interfaces;
2026-
get_hardware_related_interfaces(hw_command_itfs, start_interfaces, start_interfaces_buffer);
2027-
get_hardware_related_interfaces(hw_command_itfs, stop_interfaces, stop_interfaces_buffer);
2040+
find_common_hardware_interfaces(hw_command_itfs, start_interfaces, start_interfaces_buffer);
2041+
find_common_hardware_interfaces(hw_command_itfs, stop_interfaces, stop_interfaces_buffer);
20282042
if (start_interfaces_buffer.empty() && stop_interfaces_buffer.empty())
20292043
{
20302044
RCLCPP_DEBUG(

0 commit comments

Comments
 (0)