Preempt action ros2

How to preempt action by the client in ros2 using c++?

I am trying to do:

void send_cancel()
{
auto goal_handle = this->goal_handle_future.get();
auto cancel_result_future = this->client_ptr_->async_cancel_goal(goal_handle); //this line show how to cancel the action
}

Is there any possibility to cancel at some point according to some feedback received at feedback_callback?

I found another reference here, but it is a different scenario using not_composable:

I found the solution. The send_cancel must always be called inside the wall_timer !!

void feedback_callback(
GoalHandleMove::SharedPtr,
const std::shared_ptr feedback)
{
RCLCPP_INFO(
this->get_logger(),
"Feedback received: " +
feedback->feedback);

  this->cont++;
  if(this->cont==2){
    this->timer_ = this->create_wall_timer(
    std::chrono::milliseconds(500),
    std::bind(&T3ActionClient::send_cancel, this));
  }

}

1 Like

Nice!

It’s really good that you found the solution for yourself. Keep pushing your ROS learning! @vinicius.marques

1 Like