Skip to content

Commit 82aea49

Browse files
committed
Adding behavior tree on launch (initial commit)
1 parent 69cb36a commit 82aea49

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

behaviortree_ros2/bt_executor_parameters.md

+8
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ List of 'package_name/subfolder' containing SubTrees to load into the BehaviorTr
7272

7373
*Constraints:*
7474
- contains no duplicates
75+
76+
## tree_on_initialization
77+
78+
The name of the behavior tree to launch on intialization. Defaults to no behavior tree launched on initialization
79+
80+
* Type: `string`
81+
* Default Value: ""
82+
* Read only: True

behaviortree_ros2/src/bt_executor_parameters.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ bt_server:
4747
unique<>: null,
4848
}
4949
}
50+
tree_on_initialization: {
51+
type: string,
52+
default_value: "",
53+
read_only: true,
54+
description: "The name of the behavior tree to launch on intialization. Defaults to no behavior tree launched on initialization"
55+
}

behaviortree_ros2/src/tree_execution_server.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ struct TreeExecutionServer::Pimpl
3333
rclcpp_action::Server<ExecuteTree>::SharedPtr action_server;
3434
std::thread action_thread;
3535

36+
rclcpp_action::Client<ExecuteTree>::SharedPtr client_server;
37+
3638
std::shared_ptr<bt_server::ParamListener> param_listener;
3739
bt_server::Params params;
3840

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

76+
p_->client_server = rclcpp_action::create_client<ExecuteTree>(node, action_name);
77+
7478
// we use a wall timer to run asynchronously executeRegistration();
7579
rclcpp::VoidCallbackType callback = [this]() {
7680
if(!p_->factory_initialized_)
@@ -102,6 +106,16 @@ void TreeExecutionServer::executeRegistration()
102106
RegisterBehaviorTrees(p_->params, p_->factory, node_);
103107

104108
p_->factory_initialized_ = true;
109+
110+
// launch initalization behavior tree if set
111+
if(!p_->params.tree_on_initialization.empty())
112+
{
113+
auto goal_msg = ExecuteTree::Goal();
114+
goal_msg.target_tree = p_->params.tree_on_initialization;
115+
116+
auto send_goal_options = rclcpp_action::Client<ExecuteTree>::SendGoalOptions();
117+
p_->client_server->async_send_goal(goal_msg, send_goal_options);
118+
}
105119
}
106120

107121
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr

0 commit comments

Comments
 (0)