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

Throttle and switch to DEBUG bt loop rate warning #4430

Merged
merged 1 commit into from
Jun 14, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class BehaviorTreeEngine
* @param plugin_libraries vector of BT plugin library names to load
*/
explicit BehaviorTreeEngine(
const std::vector<std::string> & plugin_libraries);
const std::vector<std::string> & plugin_libraries,
rclcpp::Node::SharedPtr node);
virtual ~BehaviorTreeEngine() {}

/**
Expand Down Expand Up @@ -93,6 +94,9 @@ class BehaviorTreeEngine
protected:
// The factory that will be used to dynamically construct the behavior tree
BT::BehaviorTreeFactory factory_;

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

} // namespace nav2_behavior_tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool BtActionServer<ActionT>::on_configure()
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_);
bt_ = std::make_unique<nav2_behavior_tree::BehaviorTreeEngine>(plugin_lib_names_, client_node_);

// Create the blackboard that will be shared by all of the nodes in the tree
blackboard_ = BT::Blackboard::create();
Expand Down
8 changes: 6 additions & 2 deletions nav2_behavior_tree/src/behavior_tree_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ namespace nav2_behavior_tree
{

BehaviorTreeEngine::BehaviorTreeEngine(
const std::vector<std::string> & plugin_libraries)
const std::vector<std::string> & plugin_libraries, rclcpp::Node::SharedPtr node)
{
BT::SharedLibrary loader;
for (const auto & p : plugin_libraries) {
factory_.registerFromPlugin(loader.getOSName(p));
}

// clock for throttled debug log
clock_ = node->get_clock();

// FIXME: the next two line are needed for back-compatibility with BT.CPP 3.8.x
// Note that the can be removed, once we migrate from BT.CPP 4.5.x to 4.6+
BT::ReactiveSequence::EnableException(false);
Expand Down Expand Up @@ -62,8 +65,9 @@ BehaviorTreeEngine::run(
onLoop();

if (!loopRate.sleep()) {
RCLCPP_WARN(
RCLCPP_DEBUG_THROTTLE(
rclcpp::get_logger("BehaviorTreeEngine"),
*clock_, 1000,
"Behavior Tree tick rate %0.2f was exceeded!",
1.0 / (loopRate.period().count() * 1.0e-9));
}
Expand Down
Loading