ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[Humble] Service call does nothing after second call when calling a goal from the callback

asked 2023-02-02 13:50:05 -0500

rezenders gravatar image

Hello,

I have a node where I want to call an action with send_async_goal from within a service callback. I implemented it as shown below. It works, but only one time. When I call the service /task/request from the cmd line it returns the right result without a problem. But when I call the service a second time it does nothing, the service returns but the callback is not excuted.

I was trying to do something similar earlier but calling a service (async) inside another service, it was also working only one time, but in this situation the service was hanging instead of returning. I had to change the service call to be sync for it to work.

Any ideas?

class TaskBridge(Node):
    ...
    client_cb_group = MutuallyExclusiveCallbackGroup()
    self.mros_action_client = ActionClient(
        self, ControlQos, '/mros/objective',
        callback_group=client_cb_group)

    task_cb_group = MutuallyExclusiveCallbackGroup()
    self.task_request_service = self.create_service(
        Task,
        'task/request',
        self.task_request_cb,
        callback_group=task_cb_group
    )

   def task_request_cb(self, req, res):
       ...
       future = self.mros_action_client.send_goal_async(goal_msg, feedback_callback=self.feedback_callback)
       while rclpy.spin_until_future_complete(self, future, timeout_sec=1.0):
           self.get_logger().info("Waiting for future to complete")
       return future.result().accepted

def main():
    rclpy.init(args=sys.argv)

    task_bridge_node = TaskBridge()

    executor = MultiThreadedExecutor()
    rclpy.spin(task_bridge_node, executor=executor)

    task_bridge_node.destroy_node()
    rclpy.shutdown()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-03-14 10:01:24 -0500

rezenders gravatar image

Changed:

while rclpy.spin_until_future_complete(self, future, timeout_sec=1.0):

To:

while self.executor.spin_until_future_complete(future, timeout_sec=1.0)

And it worked

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-02-02 13:50:05 -0500

Seen: 142 times

Last updated: Mar 14 '23