Skip to content

Commit

Permalink
add try to lock mutex and print to not to obsruct RT thread
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jul 23, 2024
1 parent c2336ae commit 0ce923d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,12 @@ void ControllerManager::read(const rclcpp::Time & time, const rclcpp::Duration &

void ControllerManager::manage_switch()
{
std::lock_guard<std::mutex> guard(switch_params_.mutex);
std::unique_lock<std::mutex> guard(switch_params_.mutex, std::try_to_lock);
if (!guard.owns_lock())
{
RCLCPP_WARN(get_logger(), "Unable to lock switch mutex. Retrying in next cycle.");
return;
}
// Ask hardware interfaces to change mode
if (!resource_manager_->perform_command_mode_switch(
activate_command_interface_request_, deactivate_command_interface_request_))
Expand Down

0 comments on commit 0ce923d

Please sign in to comment.