Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion nav2_amcl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>nav2_amcl</name>
<version>1.3.10</version>
<version>1.3.11</version>
<description>
<p>
amcl is a probabilistic localization system for a robot moving in
Expand Down
9 changes: 9 additions & 0 deletions nav2_behavior_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ list(APPEND plugin_libs nav2_compute_path_to_pose_action_bt_node)
add_library(nav2_compute_path_through_poses_action_bt_node SHARED plugins/action/compute_path_through_poses_action.cpp)
list(APPEND plugin_libs nav2_compute_path_through_poses_action_bt_node)

add_library(nav2_concatenate_paths_action_bt_node SHARED plugins/action/concatenate_paths_action.cpp)
list(APPEND plugin_libs nav2_concatenate_paths_action_bt_node)

add_library(nav2_controller_cancel_bt_node SHARED plugins/action/controller_cancel_node.cpp)
list(APPEND plugin_libs nav2_controller_cancel_bt_node)

Expand Down Expand Up @@ -140,6 +143,9 @@ list(APPEND plugin_libs nav2_is_battery_low_condition_bt_node)
add_library(nav2_are_error_codes_active_condition_bt_node SHARED plugins/condition/are_error_codes_present_condition.cpp)
list(APPEND plugin_libs nav2_are_error_codes_active_condition_bt_node)

add_library(nav2_are_poses_near_condition_bt_node SHARED plugins/condition/are_poses_near_condition.cpp)
list(APPEND plugin_libs nav2_are_poses_near_condition_bt_node)

add_library(nav2_would_a_controller_recovery_help_condition_bt_node SHARED plugins/condition/would_a_controller_recovery_help_condition.cpp)
list(APPEND plugin_libs nav2_would_a_controller_recovery_help_condition_bt_node)

Expand Down Expand Up @@ -185,6 +191,9 @@ list(APPEND plugin_libs nav2_navigate_through_poses_action_bt_node)
add_library(nav2_remove_passed_goals_action_bt_node SHARED plugins/action/remove_passed_goals_action.cpp)
list(APPEND plugin_libs nav2_remove_passed_goals_action_bt_node)

add_library(nav2_get_current_pose_action_bt_node SHARED plugins/action/get_current_pose_action.cpp)
list(APPEND plugin_libs nav2_get_current_pose_action_bt_node)

add_library(nav2_get_pose_from_path_action_bt_node SHARED plugins/action/get_pose_from_path_action.cpp)
list(APPEND plugin_libs nav2_get_pose_from_path_action_bt_node)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "behaviortree_cpp/behavior_tree.h"
#include "behaviortree_cpp/bt_factory.h"
#include "behaviortree_cpp/loggers/groot2_publisher.h"
#include "behaviortree_cpp/xml_parsing.h"

#include "rclcpp/rclcpp.hpp"
Expand Down Expand Up @@ -85,6 +86,18 @@ class BehaviorTreeEngine
const std::string & file_path,
BT::Blackboard::Ptr blackboard);

/**
* @brief Add Groot2 monitor to publish BT status changes
* @param tree BT to monitor
* @param server_port Groot2 Server port, first of the pair (server_port, publisher_port)
*/
void addGrootMonitoring(BT::Tree * tree, uint16_t server_port);

/**
* @brief Reset groot monitor
*/
void resetGrootMonitor();

/**
* @brief Function to explicitly reset all BT nodes to initial state
* @param tree Tree to halt
Expand All @@ -97,6 +110,9 @@ class BehaviorTreeEngine

// Clock
rclcpp::Clock::SharedPtr clock_;

// Groot2 monitor
std::unique_ptr<BT::Groot2Publisher> groot_monitor_;
};

} // namespace nav2_behavior_tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include <chrono>

#include "behaviortree_cpp/action_node.h"
#include "behaviortree_cpp/json_export.h"
#include "nav2_util/node_utils.hpp"
#include "rclcpp_action/rclcpp_action.hpp"
#include "nav2_behavior_tree/bt_utils.hpp"
#include "nav2_behavior_tree/json_utils.hpp"

namespace nav2_behavior_tree
{
Expand Down Expand Up @@ -59,6 +61,7 @@ class BtActionNode : public BT::ActionNodeBase
auto bt_loop_duration =
config().blackboard->template get<std::chrono::milliseconds>("bt_loop_duration");
getInputOrBlackboard("server_timeout", server_timeout_);
getInputOrBlackboard("cancel_timeout", cancel_timeout_);
wait_for_service_timeout_ =
config().blackboard->template get<std::chrono::milliseconds>("wait_for_service_timeout");

Expand Down Expand Up @@ -321,7 +324,7 @@ class BtActionNode : public BT::ActionNodeBase
"Failed to cancel action server for %s", action_name_.c_str());
}

if (callback_group_executor_.spin_until_future_complete(future_result, server_timeout_) !=
if (callback_group_executor_.spin_until_future_complete(future_result, cancel_timeout_) !=
rclcpp::FutureReturnCode::SUCCESS)
{
RCLCPP_ERROR(
Expand Down Expand Up @@ -474,6 +477,9 @@ class BtActionNode : public BT::ActionNodeBase
// new action goal is sent or canceled
std::chrono::milliseconds server_timeout_;

// The timeout value when cancelling actions during halt
std::chrono::milliseconds cancel_timeout_;

// The timeout value for BT loop execution
std::chrono::milliseconds max_timeout_;

Expand Down
14 changes: 14 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 @@ -87,6 +87,13 @@ class BtActionServer
*/
bool on_cleanup();

/**
* @brief Enable (or disable) Groot2 monitoring of BT
* @param enable Groot2 monitoring
* @param server_port Groot2 Server port, first of the pair (server_port, publisher_port)
*/
void setGrootMonitoring(const bool enable, const unsigned server_port);

/**
* @brief Replace current BT with another one
* @param bt_xml_filename The file containing the new BT, uses default filename if empty
Expand Down Expand Up @@ -248,12 +255,19 @@ class BtActionServer
// Default timeout value while waiting for response from a server
std::chrono::milliseconds default_server_timeout_;

// Default timeout value when cancelling actions during node halt
std::chrono::milliseconds default_cancel_timeout_;

// The timeout value for waiting for a service to response
std::chrono::milliseconds wait_for_service_timeout_;

// should the BT be reloaded even if the same xml filename is requested?
bool always_reload_bt_xml_ = false;

// Parameters for Groot2 monitoring
bool enable_groot_monitoring_ = false;
int groot_server_port_ = 1667;

// User-provided callbacks
OnGoalReceivedCallback on_goal_received_callback_;
OnLoopCallback on_loop_callback_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ BtActionServer<ActionT>::BtActionServer(
if (!node->has_parameter("default_server_timeout")) {
node->declare_parameter("default_server_timeout", 20);
}
if (!node->has_parameter("default_cancel_timeout")) {
node->declare_parameter("default_cancel_timeout", 20);
}
if (!node->has_parameter("action_server_result_timeout")) {
node->declare_parameter("action_server_result_timeout", 900.0);
}
Expand Down Expand Up @@ -164,6 +167,9 @@ bool BtActionServer<ActionT>::on_configure()
int default_server_timeout;
node->get_parameter("default_server_timeout", default_server_timeout);
default_server_timeout_ = std::chrono::milliseconds(default_server_timeout);
int default_cancel_timeout;
node->get_parameter("default_cancel_timeout", default_cancel_timeout);
default_cancel_timeout_ = std::chrono::milliseconds(default_cancel_timeout);
int wait_for_service_timeout;
node->get_parameter("wait_for_service_timeout", wait_for_service_timeout);
wait_for_service_timeout_ = std::chrono::milliseconds(wait_for_service_timeout);
Expand All @@ -181,6 +187,7 @@ bool BtActionServer<ActionT>::on_configure()
// Put items on the blackboard
blackboard_->set<rclcpp::Node::SharedPtr>("node", client_node_); // NOLINT
blackboard_->set<std::chrono::milliseconds>("server_timeout", default_server_timeout_); // NOLINT
blackboard_->set<std::chrono::milliseconds>("cancel_timeout", default_cancel_timeout_); // NOLINT
blackboard_->set<std::chrono::milliseconds>("bt_loop_duration", bt_loop_duration_); // NOLINT
blackboard_->set<std::chrono::milliseconds>(
"wait_for_service_timeout",
Expand Down Expand Up @@ -217,10 +224,18 @@ bool BtActionServer<ActionT>::on_cleanup()
current_bt_xml_filename_.clear();
blackboard_.reset();
bt_->haltAllActions(tree_);
bt_->resetGrootMonitor();
bt_.reset();
return true;
}

template<class ActionT>
void BtActionServer<ActionT>::setGrootMonitoring(const bool enable, const unsigned server_port)
{
enable_groot_monitoring_ = enable;
groot_server_port_ = server_port;
}

template<class ActionT>
bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filename)
{
Expand All @@ -233,6 +248,9 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
return true;
}

// Reset any existing Groot2 monitoring
bt_->resetGrootMonitor();

// Read the input BT XML from the specified file into a string
std::ifstream xml_file(filename);

Expand All @@ -248,6 +266,7 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
auto & blackboard = subtree->blackboard;
blackboard->set("node", client_node_);
blackboard->set<std::chrono::milliseconds>("server_timeout", default_server_timeout_);
blackboard->set<std::chrono::milliseconds>("cancel_timeout", default_cancel_timeout_);
blackboard->set<std::chrono::milliseconds>("bt_loop_duration", bt_loop_duration_);
blackboard->set<std::chrono::milliseconds>(
"wait_for_service_timeout",
Expand All @@ -261,6 +280,14 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
topic_logger_ = std::make_unique<RosTopicLogger>(client_node_, tree_);

current_bt_xml_filename_ = filename;

if (enable_groot_monitoring_) {
bt_->addGrootMonitoring(&tree_, groot_server_port_);
RCLCPP_DEBUG(
logger_, "Enabling Groot2 monitoring for %s: %d",
action_name_.c_str(), groot_server_port_);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include <chrono>

#include "behaviortree_cpp/action_node.h"
#include "behaviortree_cpp/json_export.h"
#include "nav2_util/node_utils.hpp"
#include "rclcpp/rclcpp.hpp"
#include "nav2_behavior_tree/bt_utils.hpp"
#include "nav2_behavior_tree/json_utils.hpp"

namespace nav2_behavior_tree
{
Expand Down
34 changes: 34 additions & 0 deletions nav2_behavior_tree/include/nav2_behavior_tree/bt_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ namespace BT
template<>
inline geometry_msgs::msg::Point convertFromString(const StringView key)
{
// if string starts with "json:{", try to parse it as json
if (StartWith(key, "json:")) {
auto new_key = key;
new_key.remove_prefix(5);
return convertFromJSON<geometry_msgs::msg::Point>(new_key);
}

// three real numbers separated by semicolons
auto parts = BT::splitString(key, ';');
if (parts.size() != 3) {
Expand All @@ -63,6 +70,13 @@ inline geometry_msgs::msg::Point convertFromString(const StringView key)
template<>
inline geometry_msgs::msg::Quaternion convertFromString(const StringView key)
{
// if string starts with "json:{", try to parse it as json
if (StartWith(key, "json:")) {
auto new_key = key;
new_key.remove_prefix(5);
return convertFromJSON<geometry_msgs::msg::Quaternion>(new_key);
}

// four real numbers separated by semicolons
auto parts = BT::splitString(key, ';');
if (parts.size() != 4) {
Expand All @@ -85,6 +99,13 @@ inline geometry_msgs::msg::Quaternion convertFromString(const StringView key)
template<>
inline geometry_msgs::msg::PoseStamped convertFromString(const StringView key)
{
// if string starts with "json:{", try to parse it as json
if (StartWith(key, "json:")) {
auto new_key = key;
new_key.remove_prefix(5);
return convertFromJSON<geometry_msgs::msg::PoseStamped>(new_key);
}

// 7 real numbers separated by semicolons
auto parts = BT::splitString(key, ';');
if (parts.size() != 9) {
Expand Down Expand Up @@ -143,6 +164,13 @@ inline std::vector<geometry_msgs::msg::PoseStamped> convertFromString(const Stri
template<>
inline nav_msgs::msg::Path convertFromString(const StringView key)
{
// if string starts with "json:{", try to parse it as json
if (StartWith(key, "json:")) {
auto new_key = key;
new_key.remove_prefix(5);
return convertFromJSON<nav_msgs::msg::Path>(new_key);
}

// 9 real numbers separated by semicolons
auto parts = BT::splitString(key, ';');
if ((parts.size() - 2) % 9 != 0) {
Expand Down Expand Up @@ -176,6 +204,12 @@ inline nav_msgs::msg::Path convertFromString(const StringView key)
template<>
inline std::chrono::milliseconds convertFromString<std::chrono::milliseconds>(const StringView key)
{
// if string starts with "json:{", try to parse it as json
if (StartWith(key, "json:")) {
auto new_key = key;
new_key.remove_prefix(5);
return convertFromJSON<std::chrono::milliseconds>(new_key);
}
return std::chrono::milliseconds(std::stoul(key.data()));
}

Expand Down
Loading