@@ -1297,7 +1297,6 @@ controller_interface::return_type ControllerManager::switch_controller(
1297
1297
}
1298
1298
1299
1299
// start the atomic controller switching
1300
- std::unique_lock<std::mutex> switch_params_guard (switch_params_.mutex );
1301
1300
switch_params_.strictness = strictness;
1302
1301
switch_params_.activate_asap = activate_asap;
1303
1302
if (timeout == rclcpp::Duration{0 , 0 })
@@ -1310,9 +1309,9 @@ controller_interface::return_type ControllerManager::switch_controller(
1310
1309
switch_params_.timeout = timeout.to_chrono <std::chrono::nanoseconds>();
1311
1310
}
1312
1311
switch_params_.do_switch = true ;
1313
-
1314
1312
// wait until switch is finished
1315
1313
RCLCPP_DEBUG (get_logger (), " Requested atomic controller switch from realtime loop" );
1314
+ std::unique_lock<std::mutex> switch_params_guard (switch_params_.mutex , std::defer_lock);
1316
1315
if (!switch_params_.cv .wait_for (
1317
1316
switch_params_guard, switch_params_.timeout , [this ] { return !switch_params_.do_switch ; }))
1318
1317
{
@@ -2156,7 +2155,12 @@ void ControllerManager::read(const rclcpp::Time & time, const rclcpp::Duration &
2156
2155
2157
2156
void ControllerManager::manage_switch ()
2158
2157
{
2159
- std::lock_guard<std::mutex> guard (switch_params_.mutex );
2158
+ std::unique_lock<std::mutex> guard (switch_params_.mutex , std::try_to_lock);
2159
+ if (!guard.owns_lock ())
2160
+ {
2161
+ RCLCPP_DEBUG (get_logger (), " Unable to lock switch mutex. Retrying in next cycle." );
2162
+ return ;
2163
+ }
2160
2164
// Ask hardware interfaces to change mode
2161
2165
if (!resource_manager_->perform_command_mode_switch (
2162
2166
activate_command_interface_request_, deactivate_command_interface_request_))
0 commit comments