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

Populate error_msg for all action result messages (#4341) #4460

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
de921ed
Populate error_msg in action result messages (#4341)
aosmw Jun 22, 2024
a130061
FollowWaypoints - Add usage of error_code and error_msg (#4341)
aosmw Jun 22, 2024
6589ea9
nav2_simple_commander: use error_code and error_msg (#4341)
aosmw Jun 23, 2024
cdefa04
Create and populate BT::OutputPort(s) for error_msg (#4341)
aosmw Jun 26, 2024
6d845dc
Add error_msg handling to nav2_bt_navigators (#4341)
aosmw Jun 26, 2024
1cd7133
nav2_simple_command track LastActionError (#4341)
aosmw Jun 26, 2024
ef9ec90
Restore output format of planner server message (#4341)
aosmw Jun 26, 2024
39d703f
Fix opennav_docking error_msg/code usage (#4341)
aosmw Jun 26, 2024
35e910c
Fix error_msg type -> BT::OutputPort<std::string> (#4341)
aosmw Jul 10, 2024
b43400d
report index of failed initializeGoalPoses (#4341)
aosmw Jul 10, 2024
fa5da01
Add error_msg to (un)dock_robot bt (#4341)
aosmw Jul 10, 2024
b3f7f08
fix dock/undock use of error_msg (#4341)
aosmw Jul 11, 2024
4b4b3e0
Improve comment to populate error_msg if goal not accepted (#4341)
aosmw Jul 11, 2024
9755fbe
change robot_navigator api to (get|set|clear)TaskError() (#4341)
aosmw Jul 11, 2024
0be3f5b
remove exceptions from navigator onLoop (#4341)
aosmw Jul 11, 2024
0ff7a1c
change error code to GOAL_TRANSFORMATION_ERROR (#4341)
aosmw Jul 11, 2024
81c0baf
check getCurrentPose in initialiseGoalPoses (#4341)
aosmw Jul 11, 2024
7ce8ce8
change error_code_names_ to error_code_name_prefixes_ (#4341)
aosmw Jul 11, 2024
45a116e
add error_msg port to default behavior xml files (#4341)
aosmw Jul 11, 2024
f96d524
Fix 'basic_string::_M_construct null not valid' exception(#4341)
aosmw Aug 10, 2024
bb30727
fix error_code_name_prefixes: in nav2_system_param.yml (#4341)
aosmw Aug 10, 2024
8f06de7
Add error_msg handling to builtin nav2_behaviors plugins (#4341)
aosmw Aug 23, 2024
0ce9235
simple_action_server improve "Aborting handle" log (#4341)
aosmw Aug 23, 2024
f98e8ef
Add vim temporary files to .gitignore
aosmw Aug 23, 2024
523193a
Fix include what you use (#4341)
aosmw Aug 23, 2024
2958f47
Fix cpplint and uncrustify (#4341)
aosmw Aug 23, 2024
47c41e9
nav2_waypoint_follower do is_premppt_requested() before is_cancel_req…
aosmw Aug 23, 2024
28a09b5
fix behavior tree xml Backup backup_code_error_msg (#4341)
aosmw Aug 28, 2024
75750bd
Fix internal error tracking of navigators (#4341)
aosmw Aug 28, 2024
c3122e1
fix halt() in ComputePathToPose ComputePathThroughPoses (#4341)
aosmw Aug 28, 2024
73575f8
fix NavigateToPose onLoop current_path blackboard existance logic (#4…
aosmw Aug 28, 2024
03da1be
nav2_msgs MissedWaypoint interface change, add error_msg (#4341)
aosmw Aug 28, 2024
43bfff0
Fix waypoint_follower error_msg handling (#4341)
aosmw Aug 28, 2024
a7fb2a4
Fix cpplint uncrustify (#4341)
aosmw Aug 28, 2024
92bb31c
Add tool to help check for error_code and error_msg in behavior trees…
aosmw Aug 29, 2024
cb0feca
controller_server: Remove redundant logging (#4341)
aosmw Sep 7, 2024
cdb4086
timed_behaviour: pass through on_run_result.error_msg (#4341)
aosmw Sep 7, 2024
d046817
nav2_waypoint_follower - revert logic swap experiment (#4341)
aosmw Sep 7, 2024
9f80a86
nav2_waypoint_follower: clear error_msg when clearing error_code (#4341)
aosmw Sep 7, 2024
fb2c3f9
Remove tool to check behaviour tree error_msg compliance (#4341)
aosmw Sep 7, 2024
cb1b3a2
nav2_simple_commander: improve goal request rejection error reporting…
aosmw Sep 7, 2024
1c5f38d
nav2_system_tests: ensure error_msg not empty (#4341)
aosmw Sep 7, 2024
83ddf35
nav2_system_tests: behaviour_tree error_code, error_msg checks (#4341)
aosmw Sep 7, 2024
ec2ff07
nav2_system_tests: behaviour_tree error_code, error_msg checks (#4341)
aosmw Sep 13, 2024
52eecbf
doc: fix hint on how to run bt_navigator tests with ctest.
aosmw Oct 3, 2024
f76ec0a
nav2_system_tests: log error_code and error_msg. (#4341)
aosmw Oct 3, 2024
47a8538
lint: remove tab (#4341)
aosmw Oct 4, 2024
b305e08
add result->error_msg for new CONTROLLER_TIMED_OUT (#4341)
aosmw Oct 4, 2024
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
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ cmake-build-debug/

# doxygen docs
doc/html/
# Vim Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Vim Persistent undo
[._]*.un~

# Vim Session
Session.vim

# Vim Temporary
.netrwhist

Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ 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_;
// Error code name prefixes
std::vector<std::string> error_code_name_prefixes_;

// 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 @@ -73,34 +73,41 @@ BtActionServer<ActionT>::BtActionServer(
node->declare_parameter("wait_for_service_timeout", 1000);
}

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

if (!node->has_parameter("error_code_names")) {
if (node->has_parameter("error_code_names")) {
RCLCPP_ERROR(logger_, "parameter 'error_code_names' has been replaced by "
" 'error_code_name_prefixes'. Please update");
}

if (!node->has_parameter("error_code_name_prefixes")) {
const rclcpp::ParameterValue value = node->declare_parameter(
"error_code_names",
"error_code_name_prefixes",
rclcpp::PARAMETER_STRING_ARRAY);
if (value.get_type() == rclcpp::PARAMETER_NOT_SET) {
std::string error_codes_str;
for (const auto & error_code : error_code_names) {
error_codes_str += " " + error_code;
std::string error_code_name_prefixes_str;
for (const auto & error_code_name_prefix : error_code_name_prefixes) {
error_code_name_prefixes_str += " " + error_code_name_prefix;
}
RCLCPP_WARN_STREAM(
logger_, "Error_code parameters were not set. Using default values of:"
<< error_codes_str + "\n"
logger_, "error_code_name_prefixes parameters were not set. Using default values of:"
<< error_code_name_prefixes_str + "\n"
<< "Make sure these match your BT and there are not other sources of error codes you"
"reported to your application");
rclcpp::Parameter error_code_names_param("error_code_names", error_code_names);
node->set_parameter(error_code_names_param);
rclcpp::Parameter error_code_name_prefixes_param("error_code_name_prefixes",
error_code_name_prefixes);
node->set_parameter(error_code_name_prefixes_param);
} else {
error_code_names = value.get<std::vector<std::string>>();
std::string error_codes_str;
for (const auto & error_code : error_code_names) {
error_codes_str += " " + error_code;
error_code_name_prefixes = value.get<std::vector<std::string>>();
std::string error_code_name_prefixes_str;
for (const auto & error_code_name_prefix : error_code_name_prefixes) {
error_code_name_prefixes_str += " " + error_code_name_prefix;
}
RCLCPP_INFO_STREAM(logger_, "Error_code parameters were set to:" << error_codes_str);
RCLCPP_INFO_STREAM(logger_, "Error_code parameters were set to:"
<< error_code_name_prefixes_str);
}
}
}
Expand Down Expand Up @@ -172,7 +179,7 @@ bool BtActionServer<ActionT>::on_configure()
node->get_parameter("always_reload_bt_xml", always_reload_bt_xml_);

// Get error code id names to grab off of the blackboard
error_code_names_ = node->get_parameter("error_code_names").as_string_array();
error_code_name_prefixes_ = node->get_parameter("error_code_name_prefixes").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_, client_node_);
Expand Down Expand Up @@ -270,7 +277,11 @@ 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
// if the goal is not accepted
auto result = std::make_shared<typename ActionT::Result>();
populateErrorCode(result);
action_server_->terminate_current(result);
cleanErrorCodes();
return;
}
Expand Down Expand Up @@ -318,7 +329,8 @@ void BtActionServer<ActionT>::executeCallback()

case nav2_behavior_tree::BtStatus::FAILED:
action_server_->terminate_current(result);
RCLCPP_ERROR(logger_, "Goal failed");
RCLCPP_ERROR(logger_, "Goal failed error_code:%d error_msg:'%s'", result->error_code,
result->error_msg.c_str());
break;

case nav2_behavior_tree::BtStatus::CANCELED:
Expand All @@ -335,30 +347,40 @@ 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_) {
std::string highest_priority_error_msg = "";
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
std::string name;
for (const auto & error_code_name_prefix : error_code_name_prefixes_) {
try {
int current_error_code = blackboard_->get<int>(error_code);
name = error_code_name_prefix + "_error_code";
int current_error_code = blackboard_->get<int>(name);
if (current_error_code != 0 && current_error_code < highest_priority_error_code) {
highest_priority_error_code = current_error_code;
name = error_code_name_prefix + "_error_msg";
highest_priority_error_msg = blackboard_->get<std::string>(name);
}
} catch (...) {
RCLCPP_DEBUG(
logger_,
"Failed to get error code: %s from blackboard",
error_code.c_str());
"Failed to get error code name: %s from blackboard",
name.c_str());
}
}

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

template<class ActionT>
void BtActionServer<ActionT>::cleanErrorCodes()
{
for (const auto & error_code : error_code_names_) {
blackboard_->set<unsigned short>(error_code, 0); //NOLINT
std::string name;
for (const auto & error_code_name_prefix : error_code_name_prefixes_) {
name = error_code_name_prefix + "_error_code";
blackboard_->set<unsigned short>(name, 0); //NOLINT
name = error_code_name_prefix + "_error_msg";
blackboard_->set<std::string>(name, "");
}
}

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<std::string>(
"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<std::string>(
"error_msg", "The back up behavior server error msg"),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class ComputePathThroughPosesAction
*/
BT::NodeStatus on_cancelled() override;

/**
* \brief Override required by the a BT action. Cancel the action and set the path output
*/
void halt() override;

/**
* @brief Creates list of BT ports
* @return BT::PortsList Containing basic ports along with node-specific ports
Expand All @@ -86,6 +91,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<std::string>(
"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<std::string>(
"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<std::string>(
"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<std::string>(
"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<std::string>(
"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<std::string>(
"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<std::string>(
"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<std::string>(
"error_msg", "The spin behavior error msg"),
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
9 changes: 9 additions & 0 deletions nav2_behavior_tree/nav2_tree_nodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<input_port name="server_name">Server name</input_port>
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="error_code_id">"Back up error code"</output_port>
<output_port name="error_msg">"Back up error message"</output_port>
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
</Action>

<Action ID="DriveOnHeading">
Expand All @@ -23,6 +24,7 @@
<input_port name="server_name">Server name</input_port>
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="error_code_id">"Drive on heading error code"</output_port>
<output_port name="error_msg">"Drive on heading error message"</output_port>
</Action>

<Action ID="CancelControl">
Expand Down Expand Up @@ -80,6 +82,7 @@
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="path">Path created by ComputePathToPose node</output_port>
<output_port name="error_code_id">"Compute path to pose error code"</output_port>
<output_port name="error_msg">"Compute path to pose error message"</output_port>
</Action>

<Action ID="ComputePathThroughPoses">
Expand All @@ -90,6 +93,7 @@
<input_port name="planner_id">Mapped name to the planner plugin type to use</input_port>
<output_port name="path">Path created by ComputePathToPose node</output_port>
<output_port name="error_code_id">"Compute path through poses error code"</output_port>
<output_port name="error_msg">"Compute path through poses error message"</output_port>
</Action>

<Action ID="RemovePassedGoals">
Expand Down Expand Up @@ -126,6 +130,7 @@
<input_port name="service_name">Service name</input_port>
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="error_code_id">Follow Path error code</output_port>
<output_port name="error_msg">Follow Path error message</output_port>
</Action>

<Action ID="NavigateToPose">
Expand All @@ -134,6 +139,7 @@
<input_port name="server_timeout">Server timeout</input_port>
<input_port name="behavior_tree">Behavior tree to run</input_port>
<output_port name="error_code_id">Navigate to pose error code</output_port>
<output_port name="error_msg">Navigate to pose error message</output_port>
</Action>

<Action ID="NavigateThroughPoses">
Expand All @@ -142,6 +148,7 @@
<input_port name="server_timeout">Server timeout</input_port>
<input_port name="behavior_tree">Behavior tree to run</input_port>
<output_port name="error_code_id">Navigate through poses error code</output_port>
<output_port name="error_msg">Navigate through poses error message</output_port>
</Action>

<Action ID="ReinitializeGlobalLocalization">
Expand Down Expand Up @@ -202,6 +209,7 @@
<input_port name="server_name">Server name</input_port>
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="error_code_id">Spin error code</output_port>
<output_port name="error_msg">Spin error message</output_port>
</Action>

<Action ID="Wait">
Expand All @@ -216,6 +224,7 @@
<input_port name="server_name">Service name</input_port>
<input_port name="server_timeout">Server timeout</input_port>
<output_port name="error_code_id">Assisted teleop error code</output_port>
<output_port name="error_msg">Assisted teleop error message</output_port>
</Action>

<!-- ############################### CONDITION NODES ############################## -->
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
Loading
Loading