Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding extra time counter to exit while loop so that controller manager doesn't freeze #458

Merged
merged 12 commits into from
Jun 16, 2021
16 changes: 14 additions & 2 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,29 @@ bool ControllerManager::switchController(const std::vector<std::string>& 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<double> 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;
}
Expand Down