Service call from python hangs
Hi,
I am trying to call an existing service (/reinitialise_global_localization from AMCL). I tried creating a client node, but the client gets to request and hangs. I am not sure what is wrong.
The code is given below. It prints '1', then '2', and then, nothing. There are no errors.
If possible, I would like to find a solution like https://answers.ros.org/question/2016... but I can't seem to translate that to ros2 either.
Thanks
import rclpy
from rclpy.node import Node
from std_srvs.srv import Empty
class MinimalClientAsync(Node):
def __init__(self):
print("1")
super().__init__('minimal_client_async')
self.cli = self.create_client(Empty, 'reinitialize_global_localization')
while not self.cli.wait_for_service(timeout_sec=1.0):
self.get_logger().info('service not available, waiting again...')
print("2")
self.req = Empty.Request()
def send_request(self):
print("3")
self.future = self.cli.call_async(self.req)
rclpy.spin_until_future_complete(self, self.future)
return self.future.result()
def main(args=None):
rclpy.init(args=args)
minimal_client = MinimalClientAsync()
rclpy.spin_once(minimal_client)
print ("4")
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_client.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()