[ROS2] Calling a service repeatedly from a subscriber callback

asked 2021-04-07 19:53:45 -0500

andrew_103 gravatar image

I'm having trouble implementing an async service call in my subscriber callback. I found a previous post about doing so here:


However, the example in the answer here only prints the data being received by the subscriber and nothing else before performing the service call, then looks for the response elsewhere. What I'm trying to accomplish in my callback is, in short, the following:

def subscriber_callback(self):
    for element in msg.list_of_vals:
        while True:
           while True:
               # break on response
           # break when response is desired value

I still call rclpy.spin(node) in my main() function and when I run this, it hangs on rclpy.spin_once. I realize this is probably because rclpy is already spinning from the main() function, but how else would I get the node started? I tried creating an internal spin() function like in the posted link, but it hangs again on rclpy.spin_once.

Any thoughts or help would be greatly appreciated. I could be going in the complete wrong direction with how I'm approaching this, so I'm open to all suggestions.

I'm using ROS2 Dashing with Python

edit retag flag offensive close merge delete