Skip to content

Commit

Permalink
Create and populate BT::OutputPort(s) for error_msg (#4341)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Wake <[email protected]>
  • Loading branch information
aosmw committed Jun 26, 2024
1 parent face00d commit f79f5c0
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ template<class ActionT>
void BtActionServer<ActionT>::executeCallback()
{
if (!on_goal_received_callback_(action_server_->get_current_goal())) {
action_server_->terminate_current();
// Give server an opportunity to populate the result message
auto result = std::make_shared<typename ActionT::Result>();
populateErrorCode(result);
action_server_->terminate_current(result);
cleanErrorCodes();
return;
}
Expand Down Expand Up @@ -333,6 +336,7 @@ void BtActionServer<ActionT>::populateErrorCode(
typename std::shared_ptr<typename ActionT::Result> result)
{
int highest_priority_error_code = std::numeric_limits<int>::max();
std::string highest_priority_error_msg = "";
for (const auto & error_code : error_code_names_) {
try {
int current_error_code = blackboard_->get<int>(error_code);
Expand All @@ -349,6 +353,7 @@ void BtActionServer<ActionT>::populateErrorCode(

if (highest_priority_error_code != std::numeric_limits<int>::max()) {
result->error_code = highest_priority_error_code;
result->error_msg = highest_priority_error_msg;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class AssistedTeleopAction : public BtActionNode<nav2_msgs::action::AssistedTele
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for running assisted teleop"),
BT::InputPort<bool>("is_recovery", false, "If true the recovery count will be incremented"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The assisted teleop behavior server error code")
"error_code_id", "The assisted teleop behavior server error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The assisted teleop behavior server error msg"),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class BackUpAction : public BtActionNode<nav2_msgs::action::BackUp>
BT::InputPort<double>("backup_speed", 0.025, "Speed at which to backup"),
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for reversing"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The back up behavior server error code")
"error_code_id", "The back up behavior server error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The back up behavior server error msg"),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class ComputePathThroughPosesAction
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathThroughPoses node"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The compute path through poses error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The compute path through poses error msg"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class ComputePathToPoseAction : public BtActionNode<nav2_msgs::action::ComputePa
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathToPose node"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The compute path to pose error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The compute path to pose error msg"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class DriveOnHeadingAction : public BtActionNode<nav2_msgs::action::DriveOnHeadi
BT::InputPort<double>("speed", 0.025, "Speed at which to travel"),
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for driving on heading"),
BT::OutputPort<Action::Result::_error_code_type>(
"error_code_id", "The drive on heading behavior server error code")
"error_code_id", "The drive on heading behavior server error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The drive on heading behavior server error msg"),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class FollowPathAction : public BtActionNode<nav2_msgs::action::FollowPath>
BT::InputPort<std::string>("progress_checker_id", ""),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The follow path error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The follow path error msg"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class NavigateThroughPosesAction : public BtActionNode<nav2_msgs::action::Naviga
BT::InputPort<std::string>("behavior_tree", "Behavior tree to run"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The navigate through poses error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The navigate through poses error msg"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class NavigateToPoseAction : public BtActionNode<nav2_msgs::action::NavigateToPo
BT::InputPort<std::string>("behavior_tree", "Behavior tree to run"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "Navigate to pose error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "Navigate to pose error msg"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class SmoothPathAction : public nav2_behavior_tree::BtActionNode<nav2_msgs::acti
"was_completed", "True if smoothing was not interrupted by time limit"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The smooth path error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The smooth path error msg"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class SpinAction : public BtActionNode<nav2_msgs::action::Spin>
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for spinning"),
BT::InputPort<bool>("is_recovery", true, "True if recovery"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_code_id", "The spin behavior error code")
"error_code_id", "The spin behavior error code"),
BT::OutputPort<ActionResult::_error_code_type>(
"error_msg", "The spin behavior error msg"),
});
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/assisted_teleop_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ void AssistedTeleopAction::on_tick()
BT::NodeStatus AssistedTeleopAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus AssistedTeleopAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return is_recovery_ ? BT::NodeStatus::FAILURE : BT::NodeStatus::SUCCESS;
}

BT::NodeStatus AssistedTeleopAction::on_cancelled()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/back_up_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,21 @@ void BackUpAction::on_tick()
BT::NodeStatus BackUpAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus BackUpAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus BackUpAction::on_cancelled()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BT::NodeStatus ComputePathThroughPosesAction::on_success()
setOutput("path", result_.result->path);
// Set empty error code, action was successful
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand All @@ -51,6 +52,7 @@ BT::NodeStatus ComputePathThroughPosesAction::on_aborted()
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

Expand All @@ -60,6 +62,7 @@ BT::NodeStatus ComputePathThroughPosesAction::on_cancelled()
setOutput("path", empty_path);
// Set empty error code, action was cancelled
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ BT::NodeStatus ComputePathToPoseAction::on_success()
setOutput("path", result_.result->path);
// Set empty error code, action was successful
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand All @@ -50,6 +51,7 @@ BT::NodeStatus ComputePathToPoseAction::on_aborted()
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

Expand All @@ -59,6 +61,7 @@ BT::NodeStatus ComputePathToPoseAction::on_cancelled()
setOutput("path", empty_path);
// Set empty error code, action was cancelled
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/drive_on_heading_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,21 @@ void DriveOnHeadingAction::on_tick()
BT::NodeStatus DriveOnHeadingAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus DriveOnHeadingAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus DriveOnHeadingAction::on_cancelled()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/follow_path_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ void FollowPathAction::on_tick()
BT::NodeStatus FollowPathAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus FollowPathAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus FollowPathAction::on_cancelled()
{
// Set empty error code, action was cancelled
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ void NavigateThroughPosesAction::on_tick()
BT::NodeStatus NavigateThroughPosesAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus NavigateThroughPosesAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus NavigateThroughPosesAction::on_cancelled()
{
// Set empty error code, action was cancelled
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/navigate_to_pose_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ void NavigateToPoseAction::on_tick()
BT::NodeStatus NavigateToPoseAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus NavigateToPoseAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus NavigateToPoseAction::on_cancelled()
{
// Set empty error code, action was cancelled
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/smooth_path_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ BT::NodeStatus SmoothPathAction::on_success()
setOutput("was_completed", result_.result->was_completed);
// Set empty error code, action was successful
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus SmoothPathAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus SmoothPathAction::on_cancelled()
{
// Set empty error code, action was cancelled
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions nav2_behavior_tree/plugins/action/spin_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,21 @@ void SpinAction::on_tick()
BT::NodeStatus SpinAction::on_success()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

BT::NodeStatus SpinAction::on_aborted()
{
setOutput("error_code_id", result_.result->error_code);
setOutput("error_msg", result_.result->error_msg);
return BT::NodeStatus::FAILURE;
}

BT::NodeStatus SpinAction::on_cancelled()
{
setOutput("error_code_id", ActionResult::NONE);
setOutput("error_msg", "");
return BT::NodeStatus::SUCCESS;
}

Expand Down

0 comments on commit f79f5c0

Please sign in to comment.