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

How to cancel ros2 action with ros2 cpp action client

asked 2022-03-09 10:15:58 -0500

anadgopi1994 gravatar image

Pleas provide ros2 cpp example client to cancel actions

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2022-03-10 15:13:49 -0500

updated 2022-03-11 01:19:22 -0500

gvdhoorn gravatar image

As you wish https://github.com/ros-planning/navig...

  auto future_cancel = action_client_->async_cancel_goal(goal_handle_);
  if (callback_group_executor_.spin_until_future_complete(future_cancel, server_timeout_) !=
    rclcpp::FutureReturnCode::SUCCESS)
  {
    RCLCPP_ERROR(
      node_->get_logger(),
      "Failed to cancel action server for %s", action_name_.c_str());
  }
}
edit flag offensive delete link more

Comments

I think there is something weird around. According with your code we need the goal_handle_ to cancel the action. Ok, sounds good. But it turns out that you get that goal_handle_ value only after the future of the response of the original request is resolved.

https://github.com/ros-planning/navig...

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2022-09-07 15:42:14 -0500 )edit
0

answered 2022-09-07 15:42:29 -0500

updated 2022-09-07 15:59:15 -0500

I even wonder if you can cancel some specific action goal using the rclcpp_action API nowadays (Sept 2022).

The problem is that the "async_cancel_goal" requires a goal handle, but the "send_goal" function only provides a "future goal handle". You will get the required "goal handle" only after the response from the server is received. Too late to cancel.

see: https://github.com/ros2/rclcpp/blob/3...

I would say that is still an open issue in the rclcpp repo: https://github.com/ros2/rclcpp/issues...

By the moment, cancelling everything is an alternative:

  client_ptr->async_cancel_all_goals();
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-03-09 10:15:58 -0500

Seen: 931 times

Last updated: Sep 07 '22