Synchronous Service Call question (ROS2 Basic Python, Real Robot Roject, Part 2)

I’m working on Part 2 of the ROS2 Basic (Python) real robot project.

During simulation, the service call to find the wall completes successfully on the server side. However on the client side, the service call response does not appear to be received and therefore the node which called the service is stuck.

The last three lines of my service server callback function are:

response.wallfound = True
self.get_logger().info('Completed service call (server)')

return response

The second to last line of code is executed since the Completed service call (server) message is shown in the terminal window. So, I’m presuming the return response line is executed as well and the server sends a service call response and completes successfully on the server side.

The service client node has the following lines of code:

super().__init__('wall_follower')
client_find_wall = self.create_client(FindWall, 'find_wall')

req = FindWall.Request()
response = client_find_wall.call(req)

self.get_logger().info('Completed service call (client)')

The second to last line does a synchronous call to the wall find service and triggers the service server to complete the find wall service successfully (see above).
However, the last line of code is never executed… so the program is stuck.

Why is the client not receiving the service response from the server ?

Below is the code used to launch the client and server nodes.

rclpy.init(args=args)
control_node = WallFollower()
executor = MultiThreadedExecutor(num_threads=8)
executor.add_node(control_node)
try:
    executor.spin()
finally:
    executor.shutdown()
    control_node.destroy_node()
rclpy.shutdown()
rclpy.init(args=args)
control_node = WallFinder()
executor = MultiThreadedExecutor(num_threads=8)
executor.add_node(control_node)
try:
    executor.spin()
finally:
    executor.shutdown()
    control_node.destroy_node()
rclpy.shutdown()

Hi,

Try using the asynchronous call:

response = client_find_wall.call_async(req)

I find bookmarking the rclpy and rclcpp API websites useful:
https://docs.ros2.org/foxy/api/rclpy/api/services.html

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.