示例#1
0
 inline void_result spin()
 {
   for(;;)
   {
     void_result ret = spin_once();
     if(!ret) return ret;
   }
   return success();
 }
示例#2
0
void teleop::spin(void)
{
  while (ros::ok())
  {
    ros::Rate rate(_rate_ms);
    spin_once();
    ros::spinOnce();
    rate.sleep();
  }
}
示例#3
0
void red_ball_tracker::spin(void)
{
  while (ros::ok())
  {
    ros::Rate rate(50);
    spin_once();
    ros::spinOnce();
    rate.sleep();
  }
}
示例#4
0
 /** \brief Start the listener. This method does not return.
     
     Spinning a group node is required for receiving messages
     whether you plan to access the messages synchronously OR
     asynchronously: something still must listen to the underlying
     network.
 */
 void 
 GroupNodeImpl::spin()
 {
   //event_thread_ = NULL;
   bool continue_spinning = true;
   while (ok() && continue_spinning) {
     continue_spinning = spin_once();
   }
   
 }
示例#5
0
  FutureReturnCode
  spin_until_future_complete(
    std::shared_future<ResponseT> & future,
    std::chrono::duration<int64_t, TimeT> timeout = std::chrono::duration<int64_t, TimeT>(-1))
  {
    // TODO(wjwwood): does not work recursively; can't call spin_node_until_future_complete
    // inside a callback executed by an executor.

    // Check the future before entering the while loop.
    // If the future is already complete, don't try to spin.
    std::future_status status = future.wait_for(std::chrono::seconds(0));
    if (status == std::future_status::ready) {
      return FutureReturnCode::SUCCESS;
    }

    auto end_time = std::chrono::steady_clock::now();
    std::chrono::nanoseconds timeout_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
      timeout);
    if (timeout_ns > std::chrono::nanoseconds::zero()) {
      end_time += timeout_ns;
    }
    std::chrono::nanoseconds timeout_left = timeout_ns;

    while (rclcpp::utilities::ok()) {
      // Do one item of work.
      spin_once(timeout_left);
      // Check if the future is set, return SUCCESS if it is.
      status = future.wait_for(std::chrono::seconds(0));
      if (status == std::future_status::ready) {
        return FutureReturnCode::SUCCESS;
      }
      // If the original timeout is < 0, then this is blocking, never TIMEOUT.
      if (timeout_ns < std::chrono::nanoseconds::zero()) {
        continue;
      }
      // Otherwise check if we still have time to wait, return TIMEOUT if not.
      auto now = std::chrono::steady_clock::now();
      if (now >= end_time) {
        return FutureReturnCode::TIMEOUT;
      }
      // Subtract the elapsed time from the original timeout.
      timeout_left = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - now);
    }

    // The future did not complete before ok() returned false, return INTERRUPTED.
    return FutureReturnCode::INTERRUPTED;
  }