Skip to content

Commit 8b8b7df

Browse files
committed
async thread name: By default component name, truncated to 15 chars
1 parent 2014c57 commit 8b8b7df

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

controller_interface/src/controller_interface_base.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ return_type ControllerInterfaceBase::init(
107107
auto_declare<int>("async_parameters.execution_rate", impl_->ctrl_itf_params_.update_rate);
108108
auto_declare<bool>("async_parameters.wait_until_initial_trigger", true);
109109
auto_declare<bool>("async_parameters.print_warnings", true);
110+
auto_declare<std::string>("async_parameters.thread_name", "");
111+
110112
}
111113
catch (const std::exception & e)
112114
{
@@ -265,6 +267,9 @@ const rclcpp_lifecycle::State & ControllerInterfaceBase::configure()
265267
"instead.");
266268
}
267269
async_params.initialize(impl_->node_, "async_parameters.");
270+
if (async_params.thread_name.empty()) {
271+
async_params.thread_name = get_node()->get_name();
272+
}
268273
if (async_params.scheduling_policy == realtime_tools::AsyncSchedulingPolicy::DETACHED)
269274
{
270275
RCLCPP_ERROR(

hardware_interface/include/hardware_interface/hardware_info.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ struct HardwareAsyncParams
358358
std::vector<int> cpu_affinity_cores = {};
359359
/// Whether to print warnings when the async thread doesn't meet its deadline
360360
bool print_warnings = true;
361+
/// Custom name for the async worker thread
362+
std::string thread_name = "";
361363
};
362364

363365
/// This structure stores information about hardware defined in a robot's URDF.

hardware_interface/src/component_parser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ constexpr const auto kThreadPriorityAttribute = "thread_priority";
7676
constexpr const auto kAffinityCoresAttribute = "affinity";
7777
constexpr const auto kSchedulingPolicyAttribute = "scheduling_policy";
7878
constexpr const auto kPrintWarningsAttribute = "print_warnings";
79+
constexpr const auto kThreadNameAttribute = "thread_name";
7980

8081
} // namespace
8182

@@ -766,6 +767,11 @@ HardwareInfo parse_resource_from_xml(
766767
hardware.async_params.scheduling_policy =
767768
to_lower_case(get_attribute_value(async_it, kSchedulingPolicyAttribute, kAsyncTag));
768769
}
770+
if (async_it->FindAttribute(kThreadNameAttribute))
771+
{
772+
hardware.async_params.thread_name =
773+
get_attribute_value(async_it, kThreadNameAttribute, kAsyncTag);
774+
}
769775
if (async_it->FindAttribute(kThreadPriorityAttribute))
770776
{
771777
hardware.async_params.thread_priority = parse_thread_priority_attribute(async_it);

hardware_interface/src/hardware_component_interface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ CallbackReturn HardwareComponentInterface::init(
8181
async_thread_params.logger = get_logger();
8282
async_thread_params.exec_rate = params.hardware_info.rw_rate;
8383
async_thread_params.print_warnings = info_.async_params.print_warnings;
84+
if (!info_.async_params.thread_name.empty()) {
85+
async_thread_params.thread_name = info_.async_params.thread_name;
86+
} else {
87+
async_thread_params.thread_name = info_.name;
88+
}
8489
RCLCPP_INFO(
8590
get_logger(), "Starting async handler with scheduler priority: %d and policy : %s",
8691
info_.async_params.thread_priority,

0 commit comments

Comments
 (0)