Ask Your Question
0

How to call spin_some or spin_until_future_complete in member functions

asked 2020-06-05 05:44:38 -0500

MrCheesecake gravatar image

updated 2020-06-05 05:48:05 -0500

Hi together,

my coding style of ROS2 is to put all stuff into an object and member functions. Now I wonder how to use spin_some or spin_until_future_complete inside a member function of my object? I tried with this, but that doesn't work.

Here is how I create the object:

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<myNode>());
  rclcpp::shutdown();
  return 0;
}

Example for a service call I want to make:

auto request = std::make_shared<std_srvs::srv::SetBool::Request>();
request->data = true;

auto result = client_->async_send_request(request);
 if (rclcpp::spin_until_future_complete(this, result) != rclcpp::executor::FutureReturnCode::SUCCESS)
{
  RCLCPP_ERROR(this->get_logger(), "Failed");
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-05 05:56:49 -0500

MrCheesecake gravatar image

Ok, I did a little bit more of research and had a look into the node class reference here: http://docs.ros2.org/dashing/api/rclc...

I found the function get_node_base_interface() which is what spin_some and spin_until_future_complete need.

example:

auto request = std::make_shared<std_srvs::srv::SetBool::Request>();
request->data = true;

auto result = client_->async_send_request(request);
if (rclcpp::spin_until_future_complete(this->get_node_base_interface(), result) 
    != rclcpp::executor::FutureReturnCode::SUCCESS)
{
  RCLCPP_ERROR(this->get_logger(), "Failed");
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-06-05 05:44:38 -0500

Seen: 374 times

Last updated: Jun 05 '20