FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adds onLoopBeforeTick callback to BT::TreeExecutionServer. by b-adkins · Pull Request #101 · BehaviorTree/BehaviorTree.ROS2 · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .hpp  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ class TreeExecutionServer
virtual void registerNodesIntoFactory(BT::BehaviorTreeFactory& factory)
{}

/**
* @brief onLoopBeforeTick invoked at each loop, before tree.tickOnce().
* It can be overridden to avoid ticking the tree without blocking the
* rest of the execute loop.
*
* Consider whether it's better to inject a preTickCallback to the root node
* or another node of the behavior tree.
*
* @return False to skip the tick.
*/
virtual bool onLoopBeforeTick()
{
return true;
}

/**
* @brief onLoopAfterTick invoked at each loop, after tree.tickOnce().
* If it returns a valid NodeStatus, the tree will stop and return that status.
Expand Down
31 changes: 17 additions & 14 deletions behaviortree_ros2/src/tree_execution_server.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,24 @@ void TreeExecutionServer::execute(
return;
}

// tick the tree once and publish the action feedback
status = p_->tree.tickExactlyOnce();

if(const auto res = onLoopAfterTick(status); res.has_value())
{
stop_action(res.value(), "Action Server aborted by onLoopAfterTick()");
goal_handle->abort(action_result);
return;
}

if(const auto res = onLoopFeedback(); res.has_value())
if(onLoopBeforeTick())
{
auto feedback = std::make_shared<ExecuteTree::Feedback>();
feedback->message = res.value();
goal_handle->publish_feedback(feedback);
// tick the tree once and publish the action feedback
status = p_->tree.tickExactlyOnce();

if(const auto res = onLoopAfterTick(status); res.has_value())
{
stop_action(res.value(), "Action Server aborted by onLoopAfterTick()");
goal_handle->abort(action_result);
return;
}

if(const auto res = onLoopFeedback(); res.has_value())
{
auto feedback = std::make_shared<ExecuteTree::Feedback>();
feedback->message = res.value();
goal_handle->publish_feedback(feedback);
}
}

const auto now = std::chrono::steady_clock::now();
Expand Down

Back | FazBrowse Home | New Git URL