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

fix issue #61, remove registerNodesIntoFactory #62

Closed
wants to merge 1 commit into from
Closed
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 @@ -65,6 +65,9 @@ class TreeExecutionServer
// pointer to the global blackboard
BT::Blackboard::Ptr globalBlackboard();

// reference to the factory, to allow users to register custom nodes
BT::BehaviorTreeFactory& factory();

protected:
/**
* @brief Callback invoked after the tree is created.
Expand All @@ -75,16 +78,6 @@ class TreeExecutionServer
virtual void onTreeCreated(BT::Tree& tree)
{}

/**
* @brief registerNodesIntoFactory is a callback invoked after the
* plugins were registered into the BT::BehaviorTreeFactory.
* It can be used to register additional custom nodes manually.
*
* @param factory The factory to use to register nodes
*/
virtual void registerNodesIntoFactory(BT::BehaviorTreeFactory& factory)
{}

/**
* @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
2 changes: 2 additions & 0 deletions behaviortree_ros2/src/bt_executor_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bt_server:
plugins: {
type: string_array,
default_value: [],
read_only: true,
description: "List of 'package_name/subfolder' containing BehaviorTree plugins to load into the factory",
validation: {
unique<>: null,
Expand All @@ -34,6 +35,7 @@ bt_server:
ros_plugins_timeout: {
type: int,
default_value: 1000,
read_only: true,
description: "Timeout (ms) used in BT::RosNodeParams",
validation: {
bounds<>: [1, 10000]
Expand Down
3 changes: 0 additions & 3 deletions behaviortree_ros2/src/bt_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ void LoadRosPlugins(BT::BehaviorTreeFactory& factory, const std::string& directo
void RegisterBehaviorTrees(bt_server::Params& params, BT::BehaviorTreeFactory& factory,
rclcpp::Node::SharedPtr node)
{
// clear the factory and load/reload it with the Behaviors and Trees specified by the user in their [bt_action_server] config yaml
factory.clearRegisteredBehaviorTrees();

BT::RosNodeParams ros_params;
ros_params.nh = node;
ros_params.server_timeout = std::chrono::milliseconds(params.ros_plugins_timeout);
Expand Down
14 changes: 5 additions & 9 deletions behaviortree_ros2/src/tree_execution_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ TreeExecutionServer::TreeExecutionServer(const rclcpp::NodeOptions& options)

// register the users Plugins and BehaviorTree.xml files into the factory
RegisterBehaviorTrees(p_->params, p_->factory, p_->node);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @kenyoshizoe pointed out we can't load the Tree.xml files that are pass in via parameters before the statically linked behaviors are loaded.

registerNodesIntoFactory(p_->factory);
}

rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
Expand Down Expand Up @@ -143,14 +142,6 @@ void TreeExecutionServer::execute(
BT::NodeStatus status = BT::NodeStatus::RUNNING;
auto action_result = std::make_shared<ExecuteTree::Result>();

// Before executing check if we have new Behaviors or Subtrees to reload
if(p_->param_listener->is_old(p_->params))
{
p_->params = p_->param_listener->get_params();
RegisterBehaviorTrees(p_->params, p_->factory, p_->node);
registerNodesIntoFactory(p_->factory);
}

// Loop until something happens with ROS or the node completes
try
{
Expand Down Expand Up @@ -262,4 +253,9 @@ BT::Blackboard::Ptr TreeExecutionServer::globalBlackboard()
return p_->global_blackboard;
}

BT::BehaviorTreeFactory& TreeExecutionServer::factory()
{
return p_->factory;
}

} // namespace BT
13 changes: 5 additions & 8 deletions behaviortree_ros2/tree_execution_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ Furthermore, the user can customize it to:

- Register custom BT Nodes directly (static linking).
- Attach additional loggers. The **Groot2** publisher will be attached by default.
- Use the "global blackboard", a new idiom/pattern explained in [this tutorial](https://github.com/BehaviorTree/BehaviorTree.CPP/blob/master/examples/t19_global_blackboard.cpp).
- Use the "global blackboard", a new idiom/pattern explained in [this tutorial](https://github.com/BehaviorTree/BehaviorTree.CPP/blob/master/examples/t16_global_blackboard.cpp).
- Customize the feedback of the `rclcpp_action::Server`.

## Customization points
If you want to register manually a custom Node or an enum,
you can access the factory directly using the public method `TreeExecutionServer::factory()`.

## Virtual methods

These are the virtual method of `TreeExecutionServer` that can be overridden by the user.

Expand All @@ -31,12 +34,6 @@ Callback invoked when a tree is created; this happens after `rclcpp_action::Serv

It can be used, for instance, to initialize a logger or the global blackboard.

### void registerNodesIntoFactory(BT::BehaviorTreeFactory& factory)

Called at the beginning, after all the plugins have been loaded.

It can be used to register programmatically more BT.CPP Nodes.

### std::optional<BT::NodeStatus> onLoopAfterTick(BT::NodeStatus status)

Used to do something after the tree was ticked, in its execution loop.
Expand Down
Loading