Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipe error codes #3251

Merged
merged 65 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
94aaaf8
issue with finding key
Oct 19, 2022
589460b
passed up codes to bt_navigator
Oct 20, 2022
d798049
Merge branch 'main' into pipe_error_codes
Oct 25, 2022
a955def
lint fix
Oct 26, 2022
4b8293f
updates
Oct 26, 2022
0656fe4
Merge branch 'main' into controller_exceptions
Nov 3, 2022
cbdac4c
adding error_code_id back in
Nov 3, 2022
7cd843a
error codes names in params
Nov 3, 2022
d37581f
bump error codes
Nov 3, 2022
def6e6d
lint
Nov 3, 2022
bb258ca
spelling
Nov 3, 2022
281f5ce
test fix
Nov 3, 2022
1af29e6
update behavior trees
Nov 7, 2022
2ae9b95
cleanup
Nov 7, 2022
bbc9c86
Update bt_action_server_impl.hpp
jwallace42 Nov 7, 2022
be05124
code review
Nov 8, 2022
5298bcf
lint
Nov 8, 2022
9a7c876
code review
Nov 8, 2022
e21a6be
log fix
Nov 8, 2022
9beff9a
error code for waypoint follower
Nov 8, 2022
fcffaf8
clean up
Nov 8, 2022
850ac8e
remove waypoint error test, too flaky on CI
Nov 9, 2022
69e3d5e
lint and code review
Nov 11, 2022
2d7fd05
rough imp for waypoint changes
Nov 11, 2022
02590bb
lint
Nov 11, 2022
f2c39f7
code review
Nov 11, 2022
abccb13
Merge branch 'main' into pipe_error_codes
Nov 11, 2022
117f2fb
build fix
Nov 12, 2022
0516f6b
clean up
Nov 13, 2022
7f57e86
revert
Nov 13, 2022
33d44fb
space
Nov 13, 2022
d08d61c
remove
Nov 13, 2022
77fc5d3
try to make github happ
Nov 13, 2022
72fcadc
stop gap
Nov 13, 2022
3fd3c05
loading in param file
Nov 14, 2022
18b88c7
working tests :)
Nov 14, 2022
6554022
lint
Nov 14, 2022
153f9ce
fixed cmake
Nov 14, 2022
6c4c602
lint
Nov 14, 2022
b69225f
lint
Nov 14, 2022
c0b8b7a
trigger build
Nov 14, 2022
6d956ff
added invalid plugin error
Nov 14, 2022
240eb27
added test for piping up error codes
Nov 14, 2022
18d5993
clean up
Nov 14, 2022
ea70be7
test waypoint follower
Nov 14, 2022
a6f73dc
only launch what is needed
Nov 15, 2022
b970f4a
waypoint test
Nov 15, 2022
7b5e7d8
revert lines for robot navigator
Nov 15, 2022
cf999b9
fix test
Nov 15, 2022
6b372ad
waypoint test
Nov 15, 2022
ba0f85b
switched to uint16
Nov 15, 2022
d28d3c5
clean up
Nov 15, 2022
b0d59f3
code review
Nov 15, 2022
75b072f
todo to note
Nov 15, 2022
9c16e44
lint
Nov 16, 2022
aef8370
remove comment
Nov 16, 2022
4f2d8c9
Update nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server…
jwallace42 Nov 16, 2022
6cf5859
Merge branch 'main' into pipe_error_codes
Nov 17, 2022
3c07fb2
rename error_codes
Nov 17, 2022
2f31427
error code for navigate to pose
Nov 17, 2022
7b098e4
error codes for navigate through poses.
Nov 17, 2022
c9dcc79
error codes for navigate through poses
Nov 17, 2022
fb7b98c
message update for waypoint follower
Nov 17, 2022
4d6a78d
rename to error code
Nov 17, 2022
ff14a74
update node xml
Nov 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ class BtActionServer
*/
void executeCallback();

/**
* @brief updates the action server result to the highest priority error code posted on the
* blackboard
* @param result the action server result to be updated
*/
void populateErrorCode(typename std::shared_ptr<typename ActionT::Result> result);

// Action name
std::string action_name_;

Expand All @@ -211,6 +218,9 @@ class BtActionServer
// Libraries to pull plugins (BT Nodes) from
std::vector<std::string> plugin_lib_names_;

// Error code id names
std::vector<std::string> error_code_names_;

// A regular, non-spinning ROS node that we can use for calls to the action client
rclcpp::Node::SharedPtr client_node_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <set>
#include <exception>
#include <vector>
#include <limits>

#include "nav2_msgs/action/navigate_to_pose.hpp"
#include "nav2_behavior_tree/bt_action_server.hpp"
Expand Down Expand Up @@ -59,6 +60,24 @@ BtActionServer<ActionT>::BtActionServer(
if (!node->has_parameter("default_server_timeout")) {
node->declare_parameter("default_server_timeout", 20);
}

std::vector<std::string> error_code_names = {
"follow_path_error_code",
"compute_path_error_code"
};

if (!node->has_parameter("error_code_names")) {
std::string error_codes_str;
for (const auto & error_code : error_code_names) {
error_codes_str += error_code + "\n";
}
RCLCPP_WARN_STREAM(
logger_, "Error_code parameters were not set. Using default values of: "
<< error_codes_str
<< "Make sure these match your BT and there are not other sources of error codes you want "
"reported to your application");
node->declare_parameter("error_code_names", error_code_names);
}
}

template<class ActionT>
Expand Down Expand Up @@ -104,6 +123,9 @@ bool BtActionServer<ActionT>::on_configure()
node->get_parameter("default_server_timeout", timeout);
default_server_timeout_ = std::chrono::milliseconds(timeout);

// Get error code id names to grab off of the blackboard
error_code_names_ = node->get_parameter("error_code_names").as_string_array();

// Create the class that registers our custom nodes and executes the BT
bt_ = std::make_unique<nav2_behavior_tree::BehaviorTreeEngine>(plugin_lib_names_);

Expand Down Expand Up @@ -226,6 +248,9 @@ void BtActionServer<ActionT>::executeCallback()
// Give server an opportunity to populate the result message or simple give
// an indication that the action is complete.
auto result = std::make_shared<typename ActionT::Result>();

populateErrorCode(result);
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved

on_completion_callback_(result, rc);

switch (rc) {
Expand All @@ -246,6 +271,30 @@ void BtActionServer<ActionT>::executeCallback()
}
}

template<class ActionT>
void BtActionServer<ActionT>::populateErrorCode(
typename std::shared_ptr<typename ActionT::Result> result)
{
int highest_priority_error_code = std::numeric_limits<int>::max();
for (const auto & error_code : error_code_names_) {
try {
int current_error_code = blackboard_->get<int>(error_code);
if (current_error_code != 0 && current_error_code < highest_priority_error_code) {
highest_priority_error_code = current_error_code;
}
} catch (...) {
RCLCPP_ERROR(
logger_,
"Failed to get error code: %s from blackboard",
error_code.c_str());
}
}

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

} // namespace nav2_behavior_tree

#endif // NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_IMPL_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ComputePathThroughPosesAction
"Mapped name to the planner plugin type to use"),
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathThroughPoses node"),
BT::OutputPort<ActionResult::_error_code_type>(
"compute_path_through_poses_error_code", "The compute path through poses error code"),
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
"error_code_id", "The compute path through poses error code"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ComputePathToPoseAction : public BtActionNode<nav2_msgs::action::ComputePa
"Mapped name to the planner plugin type to use"),
BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathToPose node"),
BT::OutputPort<ActionResult::_error_code_type>(
"compute_path_to_pose_error_code", "The compute path to pose error code"),
"error_code_id", "The compute path to pose error code"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class FollowPathAction : public BtActionNode<nav2_msgs::action::FollowPath>
BT::InputPort<std::string>("controller_id", ""),
BT::InputPort<std::string>("goal_checker_id", ""),
BT::OutputPort<ActionResult::_error_code_type>(
"follow_path_error_code", "The follow path error code"),
"error_code_id", "The follow path error code"),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace nav2_behavior_tree
*/
class NavigateThroughPosesAction : public BtActionNode<nav2_msgs::action::NavigateThroughPoses>
{
using Action = nav2_msgs::action::NavigateThroughPoses;
using ActionResult = Action::Result;
using ActionGoal = Action::Goal;

public:
/**
* @brief A constructor for nav2_behavior_tree::NavigateThroughPosesAction
Expand All @@ -47,6 +51,21 @@ class NavigateThroughPosesAction : public BtActionNode<nav2_msgs::action::Naviga
*/
void on_tick() override;

/**
* @brief Function to perform some user-defined operation upon successful completion of the action
*/
BT::NodeStatus on_success() override;

/**
* @brief Function to perform some user-defined operation upon abortion of the action
*/
BT::NodeStatus on_aborted() override;

/**
* @brief Function to perform some user-defined operation upon cancellation of the action
*/
BT::NodeStatus on_cancelled() override;

/**
* @brief Creates list of BT ports
* @return BT::PortsList Containing basic ports along with node-specific ports
Expand All @@ -57,6 +76,8 @@ class NavigateThroughPosesAction : public BtActionNode<nav2_msgs::action::Naviga
{
BT::InputPort<geometry_msgs::msg::PoseStamped>("goals", "Destinations to plan through"),
BT::InputPort<std::string>("behavior_tree", "Behavior tree to run"),
BT::OutputPort<ActionResult::_error_code_type>(
"navigate_through_poses_error_code", "The navigate through poses error code"),
Copy link
Member

@SteveMacenski SteveMacenski Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we decide all these to be error_code_id for the port IDs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's also going to need to be documentation updates for the new ports + migration guide

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named navigate_to_pose_error_code + navigate_through_poses_error_code

I just copied this.

});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace nav2_behavior_tree
*/
class NavigateToPoseAction : public BtActionNode<nav2_msgs::action::NavigateToPose>
{
using Action = nav2_msgs::action::NavigateToPose;
using ActionResult = Action::Result;
using ActionGoal = Action::Goal;

public:
/**
* @brief A constructor for nav2_behavior_tree::NavigateToPoseAction
Expand All @@ -47,6 +51,21 @@ class NavigateToPoseAction : public BtActionNode<nav2_msgs::action::NavigateToPo
*/
void on_tick() override;

/**
* @brief Function to perform some user-defined operation upon successful completion of the action
*/
BT::NodeStatus on_success() override;

/**
* @brief Function to perform some user-defined operation upon abortion of the action
*/
BT::NodeStatus on_aborted() override;

/**
* @brief Function to perform some user-defined operation upon cancellation of the action
*/
BT::NodeStatus on_cancelled() override;

/**
* @brief Creates list of BT ports
* @return BT::PortsList Containing basic ports along with node-specific ports
Expand All @@ -57,6 +76,8 @@ class NavigateToPoseAction : public BtActionNode<nav2_msgs::action::NavigateToPo
{
BT::InputPort<geometry_msgs::msg::PoseStamped>("goal", "Destination to plan to"),
BT::InputPort<std::string>("behavior_tree", "Behavior tree to run"),
BT::OutputPort<ActionResult::_error_code_type>(
"navigate_to_pose_error_code", "Navigate to pose error code"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

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

BT::NodeStatus ComputePathThroughPosesAction::on_aborted()
{
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
setOutput("compute_path_through_poses_error_code", result_.result->error_code);
setOutput("error_code_id", result_.result->error_code);
return BT::NodeStatus::FAILURE;
}

Expand All @@ -59,7 +59,7 @@ BT::NodeStatus ComputePathThroughPosesAction::on_cancelled()
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
// Set empty error code, action was cancelled
setOutput("compute_path_through_poses_error_code", ActionGoal::NONE);
setOutput("error_code_id", ActionGoal::NONE);
return BT::NodeStatus::SUCCESS;
}

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

BT::NodeStatus ComputePathToPoseAction::on_aborted()
{
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
setOutput("compute_path_to_pose_error_code", result_.result->error_code);
setOutput("error_code_id", result_.result->error_code);
return BT::NodeStatus::FAILURE;
}

Expand All @@ -58,7 +58,7 @@ BT::NodeStatus ComputePathToPoseAction::on_cancelled()
nav_msgs::msg::Path empty_path;
setOutput("path", empty_path);
// Set empty error code, action was cancelled
setOutput("compute_path_to_pose_error_code", ActionGoal::NONE);
setOutput("error_code_id", ActionGoal::NONE);
return BT::NodeStatus::SUCCESS;
}

Expand Down
6 changes: 3 additions & 3 deletions nav2_behavior_tree/plugins/action/follow_path_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ void FollowPathAction::on_tick()

BT::NodeStatus FollowPathAction::on_success()
{
setOutput("follow_path_error_code", ActionGoal::NONE);
setOutput("error_code_id", ActionGoal::NONE);
return BT::NodeStatus::SUCCESS;
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ void NavigateThroughPosesAction::on_tick()
getInput("behavior_tree", goal_.behavior_tree);
}

BT::NodeStatus NavigateThroughPosesAction::on_success()
{
setOutput("navigate_through_poses_error_code", ActionGoal::NONE);
return BT::NodeStatus::SUCCESS;
}

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

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


} // namespace nav2_behavior_tree

#include "behaviortree_cpp_v3/bt_factory.h"
Expand Down
24 changes: 21 additions & 3 deletions nav2_behavior_tree/plugins/action/navigate_to_pose_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ NavigateToPoseAction::NavigateToPoseAction(
const std::string & xml_tag_name,
const std::string & action_name,
const BT::NodeConfiguration & conf)
: BtActionNode<nav2_msgs::action::NavigateToPose>(xml_tag_name, action_name, conf)
{
}
: BtActionNode<Action>(xml_tag_name, action_name, conf)
{}

void NavigateToPoseAction::on_tick()
{
Expand All @@ -39,6 +38,25 @@ void NavigateToPoseAction::on_tick()
getInput("behavior_tree", goal_.behavior_tree);
}

BT::NodeStatus NavigateToPoseAction::on_success()
{
setOutput("navigate_to_pose_error_code", ActionGoal::NONE);
return BT::NodeStatus::SUCCESS;
}

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

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

} // namespace nav2_behavior_tree

#include "behaviortree_cpp_v3/bt_factory.h"
Expand Down
Loading