Add return code to CancelGoal service response (#710)
* Populate return code of CancelGoal service response Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Throw if there is an error processing a cancel goal request Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Make cancel callback signature consistent across cancel methods and add tests Refactored the callback signature for canceling one goal. Now it is the same as the other cancel methods. This makes it easier to communicate the error code to the user. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Address review Signed-off-by: Jacob Perron <jacob@openrobotics.org>
This commit is contained in:
parent
7ed130cf7a
commit
ecf35114b6
4 changed files with 165 additions and 38 deletions
|
@ -325,6 +325,9 @@ ServerBase::execute_cancel_request_received()
|
|||
pimpl_->action_server_.get(),
|
||||
&cancel_request,
|
||||
&cancel_response);
|
||||
if (RCL_RET_OK != ret) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret);
|
||||
}
|
||||
|
||||
RCLCPP_SCOPE_EXIT({
|
||||
ret = rcl_action_cancel_response_fini(&cancel_response);
|
||||
|
@ -335,6 +338,7 @@ ServerBase::execute_cancel_request_received()
|
|||
|
||||
auto response = std::make_shared<action_msgs::srv::CancelGoal::Response>();
|
||||
|
||||
response->return_code = cancel_response.msg.return_code;
|
||||
auto & goals = cancel_response.msg.goals_canceling;
|
||||
// For each canceled goal, call cancel callback
|
||||
for (size_t i = 0; i < goals.size; ++i) {
|
||||
|
@ -351,6 +355,12 @@ ServerBase::execute_cancel_request_received()
|
|||
}
|
||||
}
|
||||
|
||||
// If the user rejects all individual requests to cancel goals,
|
||||
// then we consider the top-level cancel request as rejected.
|
||||
if (goals.size >= 1u && 0u == response->goals_canceling.size()) {
|
||||
response->return_code = action_msgs::srv::CancelGoal::Response::ERROR_REJECTED;
|
||||
}
|
||||
|
||||
if (!response->goals_canceling.empty()) {
|
||||
// at least one goal state changed, publish a new status message
|
||||
publish_status();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue