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

Is it possible to query the result of the action server?

asked 2023-03-23 05:10:13 -0600

Acwok gravatar image

Hello,

I'd like to use polling instead of callbacks.
Is it possible to query the result of the action server as it was the case in ROS1 with action_client->get_state() ?
I can't find an equivalent in ROS2 Humble.

Clement

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-03-23 06:58:41 -0600

GuimingChen gravatar image

updated 2023-03-23 13:31:15 -0600

In ROS 2 Humble, when you send out a goal with "async_send_goal", assign the returned future goal handle to a variable. When you need to query for the result, you can just call "async_get_result" or "async_result" (deprecated). For example:

auto future_goal_handle = client_ptr_->async_send_goal(goal_msg, send_goal_options);
rclcpp::spin_until_future_complete(node, future_goal_handle);
auto result = client_ptr_-> async_get_result(future_goal_handle.get());
if (result.get().code == rclcpp_action::ResultCode::SUCCEEDED)
{
    return true;
}

Note that the "result" you get is a WrappedResult, so if you want the result message, you need to do something like:

result.get().result

You can also query for goal status through the client goal handle with "get_status" if you are comparing with action_client->get_state() instead.

edit flag offensive delete link more

Comments

Thank you @GuimingChen!

Acwok gravatar image Acwok  ( 2023-03-23 07:16:17 -0600 )edit

@GuimingChen The execution get stucked at auto result = client_ptr_-> async_get_result(future_goal_handle.get()); :( The action is well executed though

Acwok gravatar image Acwok  ( 2023-03-23 10:14:40 -0600 )edit

hmm... interesting, I thought this should return immediately since it is a std::shared_future. Did it give you any error message? Can you print something in the server side to check which status the goal is currently in when it got stucked? You can try access the goal status in handle accepted callback.

GuimingChen gravatar image GuimingChen  ( 2023-03-23 10:31:16 -0600 )edit

No, there is no error, it just block at the async_get_result() call.
On the server side, the _execute() callback is correctly executed, I can see the message "Goal succeeded" in the terminal.

void SpacecraftController::change_si_state_execute(const std::shared_ptr<GoalHandleChangeSIState> goal_handle)
{
    RCLCPP_INFO(this->get_logger(), "Executing goal");
    const auto goal = goal_handle->get_goal();

    auto result = std::make_shared<ChangeSIState::Result>();
    if (emitSiCmd(*goal))
    {
        result->nb_si_handled = goal->si_list.size();
        goal_handle->succeed(result);
        RCLCPP_INFO(this->get_logger(), "Goal succeeded");
    }
}
Acwok gravatar image Acwok  ( 2023-03-23 10:45:07 -0600 )edit

The goal status in the _accepted() callback is is_active=1, is_executing=1 and is_canceling=0

Acwok gravatar image Acwok  ( 2023-03-23 10:54:59 -0600 )edit

The goal status at the end of the _execute() callback is is_active=0, is_executing=0 and is_cancelling=0

Acwok gravatar image Acwok  ( 2023-03-23 10:59:11 -0600 )edit

Actually there is an error if I kill the blocking node with CTRL+C:

[ERROR] [1679587180.654655117] [rclcpp]: caught std::exception exception when uninstalling signal handlers in rclcpp::~SignalHandler: Invalid argument cannot publish data, at ./src/rmw_publish.cpp:62 during '__function__' [ERROR] [1679587180.656454559] [sequencer.rclcpp]: Error in destruction of rcl subscription handle: Failed to delete datareader, at ./src/subscription.cpp:52, at ./src/rcl/subscription.c:183 cannot publish data, at ./src/rmw_publish.cpp:62 during '__function__' Fail in delete datareader, at ./src/rmw_service.cpp:104 during '__function__' [ros2run]: Segmentation fault

Acwok gravatar image Acwok  ( 2023-03-23 11:00:51 -0600 )edit

I tried

auto future_goal_handle = action_client->async_send_goal(goal_msg, send_goal_options);
RCLCPP_INFO(node->get_logger(), "Goal handle valid =%d", future_goal_handle.valid());
RCLCPP_INFO(node->get_logger(), "Goal status =%d", future_goal_handle.get().get()->get_status());

future_goal_handle.valid() returns 1
future_goal_handle.get() blocks the execution

Acwok gravatar image Acwok  ( 2023-03-23 11:25:55 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2023-03-23 05:10:13 -0600

Seen: 455 times

Last updated: Mar 23 '23