0
$\begingroup$

Rosanswers logo

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()

Originally posted by rezenders on ROS Answers with karma: 122 on 2023-02-02

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by rezenders with karma: 122 on 2023-03-14

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.