Skip to content

Commit

Permalink
Adding behavior tree on launch (initial commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
marj3220 committed May 10, 2024
1 parent 69cb36a commit 82aea49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions behaviortree_ros2/bt_executor_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ List of 'package_name/subfolder' containing SubTrees to load into the BehaviorTr

*Constraints:*
- contains no duplicates

## tree_on_initialization

The name of the behavior tree to launch on intialization. Defaults to no behavior tree launched on initialization

* Type: `string`
* Default Value: ""
* Read only: True
6 changes: 6 additions & 0 deletions behaviortree_ros2/src/bt_executor_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ bt_server:
unique<>: null,
}
}
tree_on_initialization: {
type: string,
default_value: "",
read_only: true,
description: "The name of the behavior tree to launch on intialization. Defaults to no behavior tree launched on initialization"
}
14 changes: 14 additions & 0 deletions behaviortree_ros2/src/tree_execution_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct TreeExecutionServer::Pimpl
rclcpp_action::Server<ExecuteTree>::SharedPtr action_server;
std::thread action_thread;

rclcpp_action::Client<ExecuteTree>::SharedPtr client_server;

std::shared_ptr<bt_server::ParamListener> param_listener;
bt_server::Params params;

Expand Down Expand Up @@ -71,6 +73,8 @@ TreeExecutionServer::TreeExecutionServer(const rclcpp::Node::SharedPtr& node)
handle_accepted(std::move(goal_handle));
});

p_->client_server = rclcpp_action::create_client<ExecuteTree>(node, action_name);

// we use a wall timer to run asynchronously executeRegistration();
rclcpp::VoidCallbackType callback = [this]() {
if(!p_->factory_initialized_)
Expand Down Expand Up @@ -102,6 +106,16 @@ void TreeExecutionServer::executeRegistration()
RegisterBehaviorTrees(p_->params, p_->factory, node_);

p_->factory_initialized_ = true;

// launch initalization behavior tree if set
if(!p_->params.tree_on_initialization.empty())
{
auto goal_msg = ExecuteTree::Goal();
goal_msg.target_tree = p_->params.tree_on_initialization;

auto send_goal_options = rclcpp_action::Client<ExecuteTree>::SendGoalOptions();
p_->client_server->async_send_goal(goal_msg, send_goal_options);
}
}

rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
Expand Down

0 comments on commit 82aea49

Please sign in to comment.