Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4e02d25
include ZMQ publisher for Groot
gramss Aug 13, 2020
1d64cd3
fix Groot crashing finding custom nodes in monitor mode
gramss Aug 13, 2020
8ac97cb
refactor buildTreeFromText to createTreeFromText as in BT.CPP v3
gramss Aug 13, 2020
bbdcc72
forward XML to createTreeFromText from BT.CPP v3 factory function
gramss Aug 13, 2020
837c257
Add createTreeFromFile forware to BT-factory function
gramss Aug 13, 2020
b297828
fix createTreeFromFile args..
gramss Aug 13, 2020
a941a33
add personal copyright
gramss Aug 18, 2020
822d0c8
move creating ZMQ Publisher from run to dedicated function
gramss Aug 18, 2020
1f7cb77
Add parameter for Groot Monitoring - default true. Also cleanup ZMQ
gramss Aug 18, 2020
f17810d
Move haltAllActions() Implementation from .hpp to .cpp
gramss Aug 18, 2020
79e4750
update Copyright in hpp of BT-engine
gramss Aug 18, 2020
20e79fa
make linters happy.. :)
gramss Aug 19, 2020
c9e7508
Update Groot parameter naming and chg default=0
gramss Sep 12, 2020
7d86c3f
rename resetZMQGrootMonitor -> resetGrootMonitor
gramss Sep 12, 2020
b5fcbf6
add parameter to nav2_params.yaml - default = false
gramss Sep 12, 2020
c408caf
add ZMQ params and logic for server/pub ports
gramss Sep 25, 2020
86946b9
Fix RewrittenYaml ignoring Integers
gramss Sep 26, 2020
b18d244
add launch based tests for params and ZMQ
gramss Sep 26, 2020
ba11e36
Activate Dijkstra and A* switching tests, thanks to RewrittenYaml
gramss Sep 26, 2020
85791c7
add pyzmq==19.0.2 via pip3 to CI test_workspace
gramss Sep 26, 2020
68c273f
make flake8 linter happy
gramss Sep 26, 2020
b6666eb
make cpp linters happy
gramss Sep 26, 2020
570a98f
add personal copyright
gramss Sep 27, 2020
6e17e5b
add GoalUpdated BT node description in order to view the full default BT
gramss Sep 27, 2020
5c8ca63
make linter happy (unused import)
gramss Oct 13, 2020
7b2b071
remove unused groot-port replacement functions in test_system_launch.py
gramss Oct 14, 2020
7ea5163
add groot parameters to params.md
gramss Oct 14, 2020
06c4858
get reloading BTs to work nicely with Groot
gramss Oct 15, 2020
851aa01
pretty space for smac :)
gramss Oct 15, 2020
3fb4b7a
switch from unsinged to uint16_t
gramss Oct 15, 2020
dd5effd
fix converting string into float or int
gramss Oct 15, 2020
40876b2
Revert "add pyzmq==19.0.2 via pip3 to CI test_workspace"
gramss Sep 26, 2020
af3569e
Switch to 4 spaces indent and other linter stuff for RewrittenYaml
gramss Nov 12, 2020
d5b9918
removed prints in test_system_launch.py
gramss Nov 12, 2020
261cb03
linter stuff
gramss Nov 12, 2020
21b8537
add python-zmq as test_depend in package.xml (instead of .CI_conf)
gramss Nov 12, 2020
266208f
enable groot monitoring by default
gramss Nov 12, 2020
eaf2244
remove ZMQ from naming (function / variable)
gramss Nov 12, 2020
556b548
remove variable zmq ports from testing scripts
gramss Nov 12, 2020
d476432
remove default ports in BT_engine, as they are set through (def-)params
gramss Nov 12, 2020
9df3258
Remove complete test for "dynamic" ZMQ ports testing
gramss Nov 12, 2020
8ffcde2
fix python-zmq depend location
gramss Dec 4, 2020
ca70aca
fix style
gramss Dec 4, 2020
201bd0f
swap missing Groot to default True
gramss Dec 5, 2020
00ff004
fix rosdep zmq + flake8 fixes in system_tests
gramss Dec 6, 2020
1901dd8
remove debug logs + c_str()
gramss Dec 7, 2020
8318930
remove final debug_log
gramss Dec 9, 2020
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
3 changes: 3 additions & 0 deletions doc/parameters/param_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
| Parameter | Default | Description |
| ----------| --------| ------------|
| default_bt_xml_filename | N/A | path to the default behavior tree XML description |
| enable_groot_monitoring | True | enable Groot live monitoring of the behavior tree |
| groot_zmq_publisher_port | 1666 | change port of the zmq publisher needed for groot |
| groot_zmq_server_port | 1667 | change port of the zmq server needed for groot |
| plugin_lib_names | ["nav2_compute_path_to_pose_action_bt_node", "nav2_follow_path_action_bt_node", "nav2_back_up_action_bt_node", "nav2_spin_action_bt_node", "nav2_wait_action_bt_node", "nav2_clear_costmap_service_bt_node", "nav2_is_stuck_condition_bt_node", "nav2_goal_reached_condition_bt_node", "nav2_initial_pose_received_condition_bt_node", "nav2_goal_updated_condition_bt_node", "nav2_reinitialize_global_localization_service_bt_node", "nav2_rate_controller_bt_node", "nav2_distance_controller_bt_node", "nav2_recovery_node_bt_node", "nav2_pipeline_sequence_bt_node", "nav2_round_robin_node_bt_node", "nav2_transform_available_condition_bt_node"] | list of behavior tree node shared libraries |
| transform_tolerance | 0.1 | TF transform tolerance |
| global_frame | "map" | Reference frame |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2018 Intel Corporation
// Copyright (c) 2020 Florian Gramss
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -22,6 +23,8 @@
#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp_v3/xml_parsing.h"
#include "behaviortree_cpp_v3/loggers/bt_zmq_publisher.h"


namespace nav2_behavior_tree
{
Expand All @@ -40,28 +43,29 @@ class BehaviorTreeEngine
std::function<bool()> cancelRequested,
std::chrono::milliseconds loopTimeout = std::chrono::milliseconds(10));

BT::Tree buildTreeFromText(
BT::Tree createTreeFromText(
const std::string & xml_string,
BT::Blackboard::Ptr blackboard);

BT::Tree createTreeFromFile(
const std::string & file_path,
BT::Blackboard::Ptr blackboard);

void addGrootMonitoring(
BT::Tree * tree,
uint16_t publisher_port,
uint16_t server_port,
uint16_t max_msg_per_second = 25);

void resetGrootMonitor();

// In order to re-run a Behavior Tree, we must be able to reset all nodes to the initial state
void haltAllActions(BT::TreeNode * root_node)
{
// this halt signal should propagate through the entire tree.
root_node->halt();

// but, just in case...
auto visitor = [](BT::TreeNode * node) {
if (node->status() == BT::NodeStatus::RUNNING) {
node->halt();
}
};
BT::applyRecursiveVisitor(root_node, visitor);
}
void haltAllActions(BT::TreeNode * root_node);

protected:
// The factory that will be used to dynamically construct the behavior tree
BT::BehaviorTreeFactory factory_;
std::unique_ptr<BT::PublisherZMQ> groot_monitor_;
};

} // namespace nav2_behavior_tree
Expand Down
2 changes: 2 additions & 0 deletions nav2_behavior_tree/nav2_tree_nodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<input_port name="parent">Parent frame for transform</input_port>
</Condition>

<Condition ID="GoalUpdated"/>

<!-- ############################### CONTROL NODES ################################ -->
<Control ID="PipelineSequence"/>

Expand Down
52 changes: 46 additions & 6 deletions nav2_behavior_tree/src/behavior_tree_engine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2018 Intel Corporation
// Copyright (c) 2020 Florian Gramss
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,8 +22,6 @@
#include "rclcpp/rclcpp.hpp"
#include "behaviortree_cpp_v3/utils/shared_library.h"

using namespace std::chrono_literals;

namespace nav2_behavior_tree
{

Expand Down Expand Up @@ -62,13 +61,54 @@ BehaviorTreeEngine::run(
}

BT::Tree
BehaviorTreeEngine::buildTreeFromText(
BehaviorTreeEngine::createTreeFromText(
const std::string & xml_string,
BT::Blackboard::Ptr blackboard)
{
BT::XMLParser p(factory_);
p.loadFromText(xml_string);
return p.instantiateTree(blackboard);
return factory_.createTreeFromText(xml_string, blackboard);
}

BT::Tree
BehaviorTreeEngine::createTreeFromFile(
const std::string & file_path,
BT::Blackboard::Ptr blackboard)
{
return factory_.createTreeFromFile(file_path, blackboard);
}

void
BehaviorTreeEngine::addGrootMonitoring(
BT::Tree * tree,
uint16_t publisher_port,
uint16_t server_port,
uint16_t max_msg_per_second)
{
// This logger publish status changes using ZeroMQ. Used by Groot
groot_monitor_ = std::make_unique<BT::PublisherZMQ>(
*tree, max_msg_per_second, publisher_port,
server_port);
}

void
BehaviorTreeEngine::resetGrootMonitor()
{
groot_monitor_.reset();
}

// In order to re-run a Behavior Tree, we must be able to reset all nodes to the initial state
void
BehaviorTreeEngine::haltAllActions(BT::TreeNode * root_node)
{
// this halt signal should propagate through the entire tree.
root_node->halt();

// but, just in case...
auto visitor = [](BT::TreeNode * node) {
if (node->status() == BT::NodeStatus::RUNNING) {
node->halt();
}
};
BT::applyRecursiveVisitor(root_node, visitor);
}

} // namespace nav2_behavior_tree
3 changes: 3 additions & 0 deletions nav2_bringup/bringup/params/nav2_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bt_navigator:
global_frame: map
robot_base_frame: base_link
odom_topic: /odom
enable_groot_monitoring: True
groot_zmq_publisher_port: 1666
groot_zmq_server_port: 1667
default_bt_xml_filename: "navigate_w_replanning_and_recovery.xml"
plugin_lib_names:
- nav2_compute_path_to_pose_action_bt_node
Expand Down
31 changes: 24 additions & 7 deletions nav2_bt_navigator/src/bt_navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <utility>
#include <vector>
#include <set>
#include <exception>

#include "nav2_util/geometry_utils.hpp"
#include "nav2_util/robot_utils.hpp"
Expand Down Expand Up @@ -67,6 +68,9 @@ BtNavigator::BtNavigator()
declare_parameter("global_frame", std::string("map"));
declare_parameter("robot_base_frame", std::string("base_link"));
declare_parameter("odom_topic", std::string("odom"));
declare_parameter("enable_groot_monitoring", true);
declare_parameter("groot_zmq_publisher_port", 1666);
declare_parameter("groot_zmq_server_port", 1667);
}

BtNavigator::~BtNavigator()
Expand Down Expand Up @@ -138,9 +142,13 @@ BtNavigator::loadBehaviorTree(const std::string & bt_xml_filename)
{
// Use previous BT if it is the existing one
if (current_bt_xml_filename_ == bt_xml_filename) {
RCLCPP_DEBUG(get_logger(), "BT will not be reloaded as the given xml is already loaded");
return true;
}

// if a new tree is created, than the ZMQ Publisher must be destroyed
Comment thread
gramss marked this conversation as resolved.
bt_->resetGrootMonitor();

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

Expand All @@ -153,13 +161,21 @@ BtNavigator::loadBehaviorTree(const std::string & bt_xml_filename)
std::istreambuf_iterator<char>(xml_file),
std::istreambuf_iterator<char>());

RCLCPP_DEBUG(get_logger(), "Behavior Tree file: '%s'", bt_xml_filename.c_str());
RCLCPP_DEBUG(get_logger(), "Behavior Tree XML: %s", xml_string.c_str());

// Create the Behavior Tree from the XML input
tree_ = bt_->buildTreeFromText(xml_string, blackboard_);
tree_ = bt_->createTreeFromText(xml_string, blackboard_);
Comment thread
SteveMacenski marked this conversation as resolved.
current_bt_xml_filename_ = bt_xml_filename;

// get parameter for monitoring with Groot via ZMQ Publisher
if (get_parameter("enable_groot_monitoring").as_bool()) {
uint16_t zmq_publisher_port = get_parameter("groot_zmq_publisher_port").as_int();
uint16_t zmq_server_port = get_parameter("groot_zmq_server_port").as_int();
// optionally add max_msg_per_second = 25 (default) here
try {
bt_->addGrootMonitoring(&tree_, zmq_publisher_port, zmq_server_port);
} catch (const std::logic_error & e) {
RCLCPP_ERROR(get_logger(), "ZMQ already enabled, Error: %s", e.what());
}
}
return true;
}

Expand Down Expand Up @@ -214,6 +230,7 @@ BtNavigator::on_cleanup(const rclcpp_lifecycle::State & /*state*/)
current_bt_xml_filename_.clear();
blackboard_.reset();
bt_->haltAllActions(tree_.rootNode());
bt_->resetGrootMonitor();
bt_.reset();

RCLCPP_INFO(get_logger(), "Completed Cleaning up");
Expand Down Expand Up @@ -246,15 +263,15 @@ BtNavigator::navigateToPose()
return action_server_->is_cancel_requested();
};

auto bt_xml_filename = action_server_->get_current_goal()->behavior_tree;
std::string bt_xml_filename = action_server_->get_current_goal()->behavior_tree;

// Empty id in request is default for backward compatibility
bt_xml_filename = bt_xml_filename.empty() ? default_bt_xml_filename_ : bt_xml_filename;

if (!loadBehaviorTree(bt_xml_filename)) {
RCLCPP_ERROR(
get_logger(), "BT file not found: %s. Navigation canceled",
bt_xml_filename.c_str(), current_bt_xml_filename_.c_str());
get_logger(), "BT file not found: %s. Navigation canceled.",
bt_xml_filename.c_str());
action_server_->terminate_current();
return;
}
Expand Down
Loading