Ask Your Question
0

[ROS2] How to implement a sync service client in a node?

asked 2020-02-04 15:43:38 -0600

mschickler gravatar image

In ROS1, it was possible to make a (synchronous) service call from a callback.

In ROS2, in a derived node class, if I do the following:

  1. create a service client using "create_client"
  2. within a callback function (e.g. a timer callback) call async_send_request() on the client and then:
  3. call get() on the future that is returned

It will block forever. Instead, I must register a callback when I call async_send_request() in order to handle the response.

An async design does have its advantages, so I am wondering, is it the intent of ROS2 to force asynchronous service message handling in a node or is there a way to do a sync call that I haven't uncovered yet?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-02-04 16:20:45 -0600

You're right, this is something I also would like as well. Dealing with all the async stuff for a simple sync application where I'm willing to wait makes the application-level code less clean.

I think your best bet right now is to create a sync_service wrapper to deal with all the async and waiting for you. Then you can use that in your code to interact with it like a synchronous operation.

Right now, that's not "batteries included".

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

3 followers

Stats

Asked: 2020-02-04 15:43:38 -0600

Seen: 23 times

Last updated: Feb 04