1717
1818#include < memory>
1919#include < string>
20+ #include < optional>
2021#include < rclcpp/executors.hpp>
2122#include < rclcpp/allocator/allocator_common.hpp>
2223#include " behaviortree_cpp/action_node.h"
@@ -156,8 +157,15 @@ class RosActionNode : public BT::ActionNodeBase
156157 }
157158
158159 /* * Callback invoked when something goes wrong.
160+ * The result is provided if it is available.
159161 * It must return either SUCCESS or FAILURE.
160162 */
163+ virtual BT::NodeStatus onFailure (ActionNodeErrorCode error,
164+ const std::optional<WrappedResult>&)
165+ {
166+ return onFailure (error);
167+ }
168+
161169 virtual BT::NodeStatus onFailure (ActionNodeErrorCode /* error*/ )
162170 {
163171 return NodeStatus::FAILURE;
@@ -394,7 +402,7 @@ inline NodeStatus RosActionNode<T>::tick()
394402
395403 if (!setGoal (goal))
396404 {
397- return CheckStatus (onFailure (INVALID_GOAL));
405+ return CheckStatus (onFailure (INVALID_GOAL, {} ));
398406 }
399407
400408 typename ActionClient::SendGoalOptions goal_options;
@@ -437,7 +445,7 @@ inline NodeStatus RosActionNode<T>::tick()
437445 // Check if server is ready
438446 if (!action_client->action_server_is_ready ())
439447 {
440- return onFailure (SERVER_UNREACHABLE);
448+ return onFailure (SERVER_UNREACHABLE, {} );
441449 }
442450
443451 future_goal_handle_ = action_client->async_send_goal (goal, goal_options);
@@ -464,7 +472,7 @@ inline NodeStatus RosActionNode<T>::tick()
464472 {
465473 if ((now () - time_goal_sent_) > timeout)
466474 {
467- return CheckStatus (onFailure (SEND_GOAL_TIMEOUT));
475+ return CheckStatus (onFailure (SEND_GOAL_TIMEOUT, {} ));
468476 }
469477 else
470478 {
@@ -495,11 +503,11 @@ inline NodeStatus RosActionNode<T>::tick()
495503 {
496504 if (result_.code == rclcpp_action::ResultCode::ABORTED)
497505 {
498- return CheckStatus (onFailure (ACTION_ABORTED));
506+ return CheckStatus (onFailure (ACTION_ABORTED, result_ ));
499507 }
500508 else if (result_.code == rclcpp_action::ResultCode::CANCELED)
501509 {
502- return CheckStatus (onFailure (ACTION_CANCELLED));
510+ return CheckStatus (onFailure (ACTION_CANCELLED, result_ ));
503511 }
504512 else
505513 {
0 commit comments