Ros里面延迟几秒和检测超时的写法

bool Node::WaitWorkStateForSeconds(int second) {
    
    
  ros::Time last_time = ros::Time::now();
  ros::Time attemp_end = last_time + ros::Duration(second);

  ros::Rate update_rate(100);

  while (ros::ok()) {
    
    
    if (is_service_done == true) {
    
    
      LOG(INFO) << "The Work successed";
      return true;
    } else if (ros::Time::now() > attemp_end) {
    
    
      LOG(INFO) << "The Work failed, timeout! ";
      return false;
    } else {
    
    
      LOG(INFO) << "Wait for state! ";
    }

    // ros::spinOnce();
    update_rate.sleep();
  }
  return false;
}

猜你喜欢

转载自blog.csdn.net/windxf/article/details/112169543
今日推荐