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

Behavior tree execution on launch #71

Closed
wants to merge 3 commits 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
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 @@ -101,6 +105,16 @@ void TreeExecutionServer::executeRegistration()
// load trees (XML) from multiple directories
RegisterBehaviorTrees(p_->params, p_->factory, node_);

// 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);
}

p_->factory_initialized_ = true;
}

Expand Down
Loading