Skip to content

Commit f7d015d

Browse files
committed
added thread priority argument to be able to set the scheduler priority
1 parent c3e4ddf commit f7d015d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

controller_interface/src/controller_interface_base.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ return_type ControllerInterfaceBase::init(
3535
{
3636
auto_declare<int>("update_rate", cm_update_rate);
3737
auto_declare<bool>("is_async", false);
38+
auto_declare<bool>("thread_priority", 50);
3839
}
3940
catch (const std::exception & e)
4041
{
@@ -89,9 +90,16 @@ const rclcpp_lifecycle::State & ControllerInterfaceBase::configure()
8990
}
9091
if (is_async_)
9192
{
93+
const unsigned int thread_priority =
94+
static_cast<unsigned int>(get_node()->get_parameter("thread_priority").as_int());
95+
RCLCPP_INFO_STREAM(
96+
get_node()->get_logger(),
97+
"Starting async handler with scheduler priority: " << thread_priority);
9298
async_handler_ = std::make_unique<realtime_tools::AsyncFunctionHandler<return_type>>();
93-
async_handler_->init(std::bind(
94-
&ControllerInterfaceBase::update, this, std::placeholders::_1, std::placeholders::_2));
99+
async_handler_->init(
100+
std::bind(
101+
&ControllerInterfaceBase::update, this, std::placeholders::_1, std::placeholders::_2),
102+
thread_priority);
95103
async_handler_->start_thread();
96104
}
97105

0 commit comments

Comments
 (0)