Skip to content

Commit d748f56

Browse files
Merge branch 'master' into isolate/start_stop_interfaces
2 parents 9bf94a7 + 9cda965 commit d748f56

File tree

5 files changed

+81
-20
lines changed

5 files changed

+81
-20
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,10 @@ void ControllerManager::init_controller_manager()
499499
// Get parameters needed for RT "update" loop to work
500500
if (is_resource_manager_initialized())
501501
{
502-
resource_manager_->import_joint_limiters(robot_description_);
502+
if (enforce_command_limits_)
503+
{
504+
resource_manager_->import_joint_limiters(robot_description_);
505+
}
503506
init_services();
504507
}
505508
else
@@ -621,7 +624,10 @@ void ControllerManager::robot_description_callback(const std_msgs::msg::String &
621624

622625
void ControllerManager::init_resource_manager(const std::string & robot_description)
623626
{
624-
resource_manager_->import_joint_limiters(robot_description_);
627+
if (enforce_command_limits_)
628+
{
629+
resource_manager_->import_joint_limiters(robot_description_);
630+
}
625631
if (!resource_manager_->load_and_initialize_components(robot_description, update_rate_))
626632
{
627633
RCLCPP_WARN(
@@ -2880,11 +2886,7 @@ controller_interface::return_type ControllerManager::update(
28802886
// To publish the activity of the failing controllers and the fallback controllers
28812887
publish_activity();
28822888
}
2883-
2884-
if (enforce_command_limits_)
2885-
{
2886-
resource_manager_->enforce_command_limits(period);
2887-
}
2889+
resource_manager_->enforce_command_limits(period);
28882890

28892891
// there are controllers to (de)activate
28902892
if (switch_params_.do_switch)

doc/introspection.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@ Data Visualization
7070

7171
Data can be visualized with any tools that display ROS topics, but we recommend `PlotJuggler <https://plotjuggler.io/>`_ for viewing high resolution live data, or data in bags.
7272

73-
1. Open ``PlotJuggler`` running ``ros2 run plotjuggler plotjuggler``.
73+
1. Open ``PlotJuggler`` by running ``ros2 run plotjuggler plotjuggler`` from the command line.
74+
7475
.. image:: images/plotjuggler.png
75-
2. Visualize the data:
76-
- Importing from the ros2bag
77-
- Subscribing to the ROS2 topics live with the ``ROS2 Topic Subscriber`` option under ``Streaming`` header.
76+
:alt: PlotJuggler
77+
78+
2. Visualize the data by importing from the ros2bag file or subscribing to the ROS2 topics live with the ``ROS2 Topic Subscriber`` option under ``Streaming`` header.
79+
7880
3. Choose the topics ``~/introspection_data/names`` and ``~/introspection_data/values`` from the popup window.
81+
7982
.. image:: images/plotjuggler_select_topics.png
80-
4. Now, select the variables that are of your interest and drag them to the plot.
83+
:alt: PlotJuggler Select Topics
84+
85+
4. Then, select the variables that are of your interest and drag them to the plot.
86+
8187
.. image:: images/plotjuggler_visualizing_data.png
88+
:alt: PlotJuggler Visualizing Data

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class Handle
319319
// END
320320
}
321321

322-
std::shared_mutex & get_mutex() { return handle_mutex_; }
322+
std::shared_mutex & get_mutex() const { return handle_mutex_; }
323323

324324
HandleDataType get_data_type() const { return data_type_; }
325325

hardware_interface/src/resource_manager.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,9 @@ class ResourceStorage
756756
}
757757
else
758758
{
759-
value = interface_map.at(interface_name)->get_value();
759+
auto itf_handle = interface_map.at(interface_name);
760+
std::shared_lock<std::shared_mutex> lock(itf_handle->get_mutex());
761+
value = itf_handle->get_optional(lock).value();
760762
}
761763
}
762764
};
@@ -778,7 +780,9 @@ class ResourceStorage
778780
const std::string interface_name = limited_command.joint_name + "/" + interface_type;
779781
if (data.has_value() && interface_map.find(interface_name) != interface_map.end())
780782
{
781-
interface_map.at(interface_name)->set_value(data.value());
783+
auto itf_handle = interface_map.at(interface_name);
784+
std::unique_lock<std::shared_mutex> lock(itf_handle->get_mutex());
785+
std::ignore = itf_handle->set_value(lock, data.value());
782786
}
783787
};
784788
// update the command data of the limiters
@@ -966,7 +970,8 @@ class ResourceStorage
966970
interface_name.c_str());
967971
continue;
968972
}
969-
const auto limiter_fn = [&, interface_name](double value, bool & is_limited) -> double
973+
const auto limiter_fn = [this, joint_name, interface_name, desired_period, &limiters](
974+
double value, bool & is_limited) -> double
970975
{
971976
is_limited = false;
972977
joint_limits::JointInterfacesCommandLimiterData data;
@@ -994,10 +999,14 @@ class ResourceStorage
994999
}
9951000
data.limited = data.command;
9961001
is_limited = limiters[joint_name]->enforce(data.actual, data.limited, desired_period);
997-
RCLCPP_ERROR_THROTTLE(
998-
get_logger(), *rm_clock_, 1000,
999-
"Command '%s' for joint '%s' is out of limits. Command limited to %f - %d",
1000-
interface_name.c_str(), joint_name.c_str(), value, is_limited);
1002+
if (is_limited)
1003+
{
1004+
RCLCPP_ERROR_THROTTLE(
1005+
get_logger(), *rm_clock_, 1000,
1006+
"Command of at least one joint is out of limits (throttled log). %s with desired "
1007+
"period : %f sec.",
1008+
data.to_string().c_str(), desired_period.seconds());
1009+
}
10011010
if (
10021011
interface_name == hardware_interface::HW_IF_POSITION &&
10031012
data.limited.position.has_value())

joint_limits/include/joint_limits/data_structures.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,41 @@ struct JointControlInterfacesData
6464
bool has_acceleration() const { return acceleration.has_value(); }
6565

6666
bool has_jerk() const { return jerk.has_value(); }
67+
68+
std::string to_string() const
69+
{
70+
std::string str;
71+
if (has_position())
72+
{
73+
str += "position: " + std::to_string(position.value()) + ", ";
74+
}
75+
if (has_velocity())
76+
{
77+
str += "velocity: " + std::to_string(velocity.value()) + ", ";
78+
}
79+
if (has_effort())
80+
{
81+
str += "effort: " + std::to_string(effort.value()) + ", ";
82+
}
83+
if (has_acceleration())
84+
{
85+
str += "acceleration: " + std::to_string(acceleration.value()) + ", ";
86+
}
87+
if (has_jerk())
88+
{
89+
str += "jerk: " + std::to_string(jerk.value());
90+
}
91+
// trim the last comma and space
92+
if (!str.empty() && str.back() == ' ')
93+
{
94+
str.pop_back();
95+
}
96+
if (!str.empty() && str.back() == ',')
97+
{
98+
str.pop_back();
99+
}
100+
return str;
101+
}
67102
};
68103

69104
struct JointInterfacesCommandLimiterData
@@ -77,6 +112,14 @@ struct JointInterfacesCommandLimiterData
77112
bool has_actual_data() const { return actual.has_data(); }
78113

79114
bool has_command_data() const { return command.has_data(); }
115+
116+
bool has_limited_data() const { return limited.has_data(); }
117+
118+
std::string to_string() const
119+
{
120+
return "Joint : '" + joint_name + "', (actual: [" + actual.to_string() + "], command : [" +
121+
command.to_string() + "], limited: [" + limited.to_string() + "])";
122+
}
80123
};
81124

82125
} // namespace joint_limits

0 commit comments

Comments
 (0)