Configuring Action Server 'Ready' state in ROS2 Galactic

asked 2022-05-30 08:26:12 -0500

Hi all, I'm trying to implement nested actions (a higher-level action server sends a lower-level action server to perform some action). Specifically, the use case is a global planner that outputs waypoints, and a local planner that outputs a Twist to physically control a robot.

Waypoints from the global planner should be followed sequentially, so the local planner action server should not be sent multiple goals at once. I've gotten around this for now by using state flags in the global planner action server. These are set when a goal is first sent and cleared when the goal is completed.

For example (pseudocode):

local_planner_state = FREE
while num_waypoints > 0:
  if local_planner_state==FREE:
    future = local_planner_action_client.send_async(goal) # register callback later
    local_planner_state = BUSY
// callback when future is done is defined elsewhere and sets local_planner_state back to FREE

I was thinking that this while-loop based system is inefficient as it has to check if the local planner is done every loop, instead of waiting on a callback or something similar.

I understand there is a wait_for_server function defined for action clients in rclpy. I've tried using that, but that returns true once the goal has been accepted (not completed).

Is there a way to configure action servers to only be able to process one goal at a time such that wait_for_server returns only when the goal has been completed?

edit retag flag offensive close merge delete