diff --git a/controller_manager/src/controller_manager.cpp b/controller_manager/src/controller_manager.cpp index 2f5406f0d..0e53879ab 100644 --- a/controller_manager/src/controller_manager.cpp +++ b/controller_manager/src/controller_manager.cpp @@ -604,17 +604,29 @@ bool ControllerManager::switchController(const std::vector& start_c // wait until switch is finished ROS_DEBUG("Request atomic controller switch from realtime loop"); + auto start_time = std::chrono::system_clock::now(); + bool timed_out = false; while (ros::ok() && switch_params_.do_switch) { if (!ros::ok()) { return false; } - std::this_thread::sleep_for(std::chrono::microseconds(100)); + std::chrono::duration diff = std::chrono::system_clock::now() - start_time; + if (diff.count() < timeout+1.0 || timeout == 0){ + std::this_thread::sleep_for(std::chrono::microseconds(100)); + } else { + ROS_DEBUG("Timed out while switching controllers. Exiting..."); + timed_out = true; + break; + } } start_request_.clear(); stop_request_.clear(); - + if(timed_out){ + ROS_DEBUG("Exited wait until switch is finished loop using non-ROS-time timeout"); + return false; + } ROS_DEBUG("Successfully switched controllers"); return true; }