ROS2 Service Client freezes when calling twice
Service clients seem to freeze, if you are calling them more then just one time in ROS2.
I slightly modified the demo example from here:
https://github.com/ros2/examples/blob...
If I just remove the break
like that:
future = cli.call_async(req)
while rclpy.ok():
rclpy.spin_once(node)
if future.done():
try:
result = future.result()
except Exception as e:
node.get_logger().info('Service call failed %r' % (e,))
else:
node.get_logger().info(
'Result of add_two_ints: for %d + %d = %d' %
(req.a, req.b, result.sum))
node.destroy_node()
rclpy.shutdown()
This way the loop is called multiple times and should print the service response multiple times as well. This ends in the result that I get the client output twice:
[INFO] [minimal_client_async]: Result of add_two_ints: for 41 + 1 = 42
[INFO] [minimal_client_async]: Result of add_two_ints: for 41 + 1 = 42
And the service server output appears only once:
[INFO] [minimal_service]: Incoming request
a: 41 b: 1
If I now additionally move the service call itself future = cli.call_async(req)
inside the loop, I am expecting the request to be sent multiple times. (Yes, I know that Services are not made to be called frequently, it's just to keep the example simple.)
while rclpy.ok():
future = cli.call_async(req)
rclpy.spin_once(node)
if future.done():
try:
result = future.result()
except Exception as e:
node.get_logger().info('Service call failed %r' % (e,))
else:
node.get_logger().info(
'Result of add_two_ints: for %d + %d = %d' %
(req.a, req.b, result.sum))
node.destroy_node()
rclpy.shutdown()
This results in printing from the client only once:
[INFO] [minimal_client_async]: Result of add_two_ints: for 41 + 1 = 42
But the service server seems anyway to be requested frequently, because it is continuously printing to the terminal:
[INFO] [minimal_service]: Incoming request
a: 41 b: 1
[INFO] [minimal_service]: Incoming request
a: 41 b: 1
[INFO] [minimal_service]: Incoming request
a: 41 b: 1
[INFO] [minimal_service]: Incoming request
a: 41 b: 1
...
I would just like to call a service multiple times from the client. For example I would like to use a button to stop my robot by calling the service, if the button is pressed (which might result in sending cmd_vel: 0) and as soon as it is released again, the robot should be able to move on. Any ideas on how to solve this?
I am using Ubuntu 18.04 in a VM with ROS2 Eloquent installed.
It is easy to reproduce this by using the service examples from here: