Skip to content

Commit 4c5a65a

Browse files
committed
Merge branch 'bt_server' of github.com:BehaviorTree/BehaviorTree.ROS2 into bt_server
2 parents 70b5d74 + dbf6bc0 commit 4c5a65a

8 files changed

+200
-76
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This repository contains useful wrappers to use ROS2 and BehaviorTree.CPP togeth
55

66
In particular, it provides a standard way to implement:
77

8+
- Behavior Tree Executor with ROS Action interface.
89
- Action clients.
910
- Service Clients.
1011
- Topic Subscribers.
@@ -15,6 +16,12 @@ Our main goals are:
1516
- to minimize the amount of boilerplate.
1617
- to make asynchronous Actions non-blocking.
1718

19+
# Documentation
20+
21+
- [ROS Behavior Wrappers](behaviortree_ros2/ros_behavior_wrappers.md)
22+
- [TreeExecutionServer](behaviortree_ros2/tree_execution_server.md)
23+
- [Sample Behaviors](btcpp_ros2_samples/README.md)
24+
1825
Note that this library is compatible **only** with:
1926

2027
- **BT.CPP** 4.1 or newer.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Bt Server Parameters
2+
3+
Default Config
4+
```yaml
5+
bt_server:
6+
ros__parameters:
7+
action_name: bt_execution
8+
behavior_trees: '{}'
9+
groot2_port: 1667.0
10+
plugins: '{}'
11+
ros_plugins_timeout: 1000.0
12+
tick_frequency: 100.0
13+
14+
```
15+
16+
## action_name
17+
18+
The name the Action Server takes requests from
19+
20+
* Type: `string`
21+
* Default Value: "bt_execution"
22+
* Read only: True
23+
24+
## tick_frequency
25+
26+
Frequency in Hz to tick() the Behavior tree at
27+
28+
* Type: `int`
29+
* Default Value: 100
30+
* Read only: True
31+
32+
*Constraints:*
33+
- parameter must be within bounds 1
34+
35+
## groot2_port
36+
37+
Server port value to publish Groot2 messages on
38+
39+
* Type: `int`
40+
* Default Value: 1667
41+
* Read only: True
42+
43+
*Constraints:*
44+
- parameter must be within bounds 1
45+
46+
## plugins
47+
48+
List of 'package_name/subfolder' containing BehaviorTree plugins to load into the factory
49+
50+
* Type: `string_array`
51+
* Default Value: {}
52+
53+
*Constraints:*
54+
- contains no duplicates
55+
56+
## ros_plugins_timeout
57+
58+
Timeout (ms) used in BT::RosNodeParams
59+
60+
* Type: `int`
61+
* Default Value: 1000
62+
63+
*Constraints:*
64+
- parameter must be within bounds 1
65+
66+
## behavior_trees
67+
68+
List of 'package_name/subfolder' containing SubTrees to load into the BehaviorTree factory
69+
70+
* Type: `string_array`
71+
* Default Value: {}
72+
73+
*Constraints:*
74+
- contains no duplicates
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ROS Behavior Wrappers
2+
3+
A base class is used to implement each Behavior type for a ROS Action, Service or Topic Publisher / Subscriber.
4+
5+
Users are expected to create a derived class and can implement the following methods.
6+
7+
# ROS Action Behavior Wrapper
8+
9+
### bool setGoal(Goal& goal)
10+
11+
Required callback that allows the user to set the goal message.
12+
Return false if the request should not be sent. In that case, RosActionNode::onFailure(INVALID_GOAL) will be called.
13+
14+
### BT::NodeStatus onResultReceived(const WrappedResult& result)
15+
16+
Required callback invoked when the result is received by the server.
17+
It is up to the user to define if the action returns SUCCESS or FAILURE.
18+
19+
### BT::NodeStatus onFeedback(const std::shared_ptr<const Feedback> feedback)
20+
21+
Optional callback invoked when the feedback is received.
22+
It generally returns RUNNING, but the user can also use this callback to cancel the current action and return SUCCESS or FAILURE.
23+
24+
### BT::NodeStatus onFailure(ActionNodeErrorCode error)
25+
26+
Optional callback invoked when something goes wrong.
27+
It must return either SUCCESS or FAILURE.
28+
29+
### void onHalt()
30+
31+
Optional callback executed when the node is halted.
32+
Note that cancelGoal() is done automatically.
33+
34+
# ROS Service Behavior Wrapper
35+
36+
### setRequest(typename Request::SharedPtr& request)
37+
38+
Required callback that allows the user to set the request message (ServiceT::Request).
39+
40+
### BT::NodeStatus onResponseReceived(const typename Response::SharedPtr& response)
41+
42+
Required callback invoked when the response is received by the server.
43+
It is up to the user to define if this returns SUCCESS or FAILURE.
44+
45+
### BT::NodeStatus onFailure(ServiceNodeErrorCode error)
46+
47+
Optional callback invoked when something goes wrong; you can override it.
48+
It must return either SUCCESS or FAILURE.
49+
50+
# ROS Topic Publisher Wrapper
51+
52+
### bool setMessage(TopicT& msg)
53+
54+
Required callback invoked in tick to allow the user to pass the message to be published.
55+
56+
# ROS Topic Subscriber Wrapper
57+
58+
### NodeStatus onTick(const std::shared_ptr<TopicT>& last_msg)
59+
60+
Required callback invoked in the tick. You must return either SUCCESS of FAILURE.
61+
62+
### bool latchLastMessage()
63+
64+
Optional callback to latch the message that has been processed.
65+
If returns false and no new message is received, before next call there will be no message to process.
66+
If returns true, the next call will process the same message again, if no new message received.

behaviortree_ros2/tree_execution_server.md

+5-73
Original file line numberDiff line numberDiff line change
@@ -67,77 +67,9 @@ sent as feedback to the `rclcpp_action::Client`.
6767

6868
## ROS Parameters
6969

70-
Default Config
71-
72-
```yaml
73-
bt_action_server:
74-
ros__parameters:
75-
action_name: bt_execution
76-
behavior_tick_frequency: 100.0
77-
behavior_trees: '{}'
78-
groot2_port: 1667.0
79-
ros_plugins_timeout: 1000,
80-
plugins: '{}'
81-
```
82-
83-
### action_name
84-
85-
The name the Action Server takes requests from
86-
87-
* Type: `string`
88-
* Default Value: "bt_execution"
89-
* Read only: True
90-
91-
### behavior_tick_frequency
92-
93-
Frequency in Hz to tick() the Behavior tree at
94-
95-
* Type: `int`
96-
* Default Value: 100
97-
* Read only: True
98-
99-
*Constraints:*
100-
- parameter must be within bounds 1
101-
102-
### groot2_port
103-
104-
Server port value to publish Groot2 messages on
105-
106-
* Type: `int`
107-
* Default Value: 1667
108-
* Read only: True
109-
110-
*Constraints:*
111-
- parameter must be within bounds 1
112-
113-
### ros_plugins_timeout
70+
Documentation for the parameters used by the `TreeExecutionServer` can be found [here](bt_executor_parameters.md).
11471

115-
Timeout, in milliseconds, to use with ROS Plugins (see BT::RosNodeParams)
116-
117-
* Type: `int`
118-
* Default Value: {}
119-
120-
*Constraints:*
121-
- parameter must be within 1 and 10000
122-
123-
### plugins
124-
125-
List of 'package_name/subfolder' containing BehaviorTree plugins to load into the factory.
126-
127-
These are plugins created using either the macro `BT_RegisterNodesFromPlugin` or `BT_RegisterRosNodeFromPlugin`.
128-
129-
* Type: `string_array`
130-
* Default Value: {}
131-
132-
*Constraints:*
133-
- contains no duplicates
134-
135-
### behavior_trees
136-
137-
List of 'package_name/subfolder' containing SubTrees to load into the BehaviorTree factory
138-
139-
* Type: `string_array`
140-
* Default Value: {}
141-
142-
*Constraints:*
143-
- contains no duplicates
72+
If the parameter documentation needs updating you can regenerate it with:
73+
```bash
74+
generate_parameter_library_markdown --input_yaml src/bt_executor_parameters.yaml --output_markdown_file bt_executor_parameters.md
75+
```

btcpp_ros2_samples/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ install(TARGETS
7373
RUNTIME DESTINATION share/${PROJECT_NAME}/bt_plugins
7474
)
7575

76+
######################################################
77+
# INSTALL Behavior.xml's, ROS config and launch files
78+
79+
install(DIRECTORY
80+
behavior_trees
81+
config
82+
launch
83+
DESTINATION share/${PROJECT_NAME}/
84+
)
85+
7686

7787
ament_export_dependencies(behaviortree_ros2 btcpp_ros2_interfaces)
7888

btcpp_ros2_samples/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Sample Behaviors
2+
3+
For documentation on sample behaviors included in this package please see the BehaviorTree.CPP [ROS 2 Integration documentation](https://www.behaviortree.dev/docs/ros2_integration). Documentation of the derived class methods can methods for each ROS interface type can be found [here](../behaviortree_ros2/ros_behavior_wrappers.md).
4+
5+
# TreeExecutionServer Sample
6+
7+
Documentation on the TreeExecutionServer used in this example can be found [here](../behaviortree_ros2/tree_execution_server.md).
8+
9+
To start the sample Execution Server that load a list of plugins and BehaviorTrees from `yaml` file:
10+
``` bash
11+
ros2 launch btcpp_ros2_samples sample_bt_executor.launch.xml
12+
```
13+
14+
> *NOTE:* For documentation on the `yaml` parameters please see [bt_executor_parameters.md](../behaviortree_ros2/bt_executor_parameters.md).
15+
16+
As the Server starts up it will print out the name of the ROS Action followed by the plugins and BehaviorTrees it was able to load.
17+
```
18+
[bt_action_server]: Starting Action Server: behavior_server
19+
[bt_action_server]: Loaded Plugin: libdummy_nodes_dyn.so
20+
[bt_action_server]: Loaded Plugin: libmovebase_node_dyn.so
21+
[bt_action_server]: Loaded Plugin: libcrossdoor_nodes_dyn.so
22+
[bt_action_server]: Loaded Plugin: libsleep_plugin.so
23+
[bt_action_server]: Loaded BehaviorTree: door_closed.xml
24+
[bt_action_server]: Loaded BehaviorTree: cross_door.xml
25+
```
26+
27+
To call the Action Server from the command line:
28+
``` bash
29+
ros2 action send_goal /behavior_server btcpp_ros2_interfaces/action/ExecuteTree "{target_tree: CrossDoor}"
30+
```
31+
32+
You can also try a Behavior that is a ROS Action or Service client itself.
33+
```bash
34+
ros2 action send_goal /behavior_server btcpp_ros2_interfaces/action/ExecuteTree "{target_tree: SleepActionSample}"
35+
```

btcpp_ros2_samples/launch/sample_bt_executor.launch.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<launch>
22
<arg name="sleep_server" default="true"/>
33

4-
<node pkg="btcpp_ros2_samples" exec="simple_bt_executor" output="screen">
5-
<param from="$(find-pkg-share btcpp_ros2_samples)/config/simple_bt_executor.yaml"/>
4+
<node pkg="btcpp_ros2_samples" exec="sample_bt_executor" output="screen">
5+
<param from="$(find-pkg-share btcpp_ros2_samples)/config/sample_bt_executor.yaml"/>
66
</node>
77

88
<group if="$(var sleep_server)">

btcpp_ros2_samples/src/sample_bt_executor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <behaviortree_ros2/tree_execution_server.hpp>
1515
#include <behaviortree_cpp/loggers/bt_cout_logger.h>
1616

17-
// Example that shows how to customize ActionServerBT.
17+
// Example that shows how to customize TreeExecutionServer.
1818
// Here, we simply add an extra logger
1919
class MyActionServer : public BT::TreeExecutionServer
2020
{

0 commit comments

Comments
 (0)