Skip to content

Commit

Permalink
ros2 service Use new client api (#77)
Browse files Browse the repository at this point in the history
* Use new client api
* try_shutdown() -> shutdown()
  • Loading branch information
sloretz committed Mar 27, 2018
1 parent ffcacbb commit f11e2c3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ros2service/ros2service/verb/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ def requester(service_type, service_name, values, period):
while True:
print('requester: making request: %r\n' % request)
last_call = time.time()
cli.call(request)
cli.wait_for_future()
if cli.response is not None:
print('response:\n%r\n' % cli.response)
future = cli.call_async(request)
rclpy.spin_until_future_complete(node, future)
if future.result() is not None:
print('response:\n%r\n' % future.result())
else:
raise RuntimeError('Exception while calling service: %r' % future.exception())
if period is None or not rclpy.ok():
break
time_until_next_period = (last_call + period) - time.time()
if time_until_next_period > 0:
time.sleep(time_until_next_period)

node.destroy_node()
rclpy.try_shutdown() # avoid duplicate shutdown from shutdown within cli.wait_for_future()
rclpy.shutdown()

0 comments on commit f11e2c3

Please sign in to comment.