Skip to content

Commit

Permalink
docs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarqRazz committed May 4, 2024
1 parent bb435f4 commit dbf6bc0
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 85 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This repository contains useful wrappers to use ROS2 and BehaviorTree.CPP togeth

In particular, it provides a standard way to implement:

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

# Documentation

- [ROS Behavior Wrappers](behaviortree_ros2/ros_behavior_wrappers.md)
- [TreeExecutionServer](behaviortree_ros2/tree_execution_server.md)
- [Sample Behaviors](btcpp_ros2_samples/README.md)

Note that this library is compatible **only** with:

- **BT.CPP** 4.1 or newer.
Expand Down
66 changes: 66 additions & 0 deletions behaviortree_ros2/ros_behavior_wrappers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ROS Behavior Wrappers

A base class is used to implement each Behavior type for a ROS Action, Service or Topic Publisher / Subscriber.

Users are expected to create a derived class and can implement the following methods.

# ROS Action Behavior Wrapper

### bool setGoal(Goal& goal)

Required callback that allows the user to set the goal message.
Return false if the request should not be sent. In that case, RosActionNode::onFailure(INVALID_GOAL) will be called.

### BT::NodeStatus onResultReceived(const WrappedResult& result)

Required callback invoked when the result is received by the server.
It is up to the user to define if the action returns SUCCESS or FAILURE.

### BT::NodeStatus onFeedback(const std::shared_ptr<const Feedback> feedback)

Optional callback invoked when the feedback is received.
It generally returns RUNNING, but the user can also use this callback to cancel the current action and return SUCCESS or FAILURE.

### BT::NodeStatus onFailure(ActionNodeErrorCode error)

Optional callback invoked when something goes wrong.
It must return either SUCCESS or FAILURE.

### void onHalt()

Optional callback executed when the node is halted.
Note that cancelGoal() is done automatically.

# ROS Service Behavior Wrapper

### setRequest(typename Request::SharedPtr& request)

Required callback that allows the user to set the request message (ServiceT::Request).

### BT::NodeStatus onResponseReceived(const typename Response::SharedPtr& response)

Required callback invoked when the response is received by the server.
It is up to the user to define if this returns SUCCESS or FAILURE.

### BT::NodeStatus onFailure(ServiceNodeErrorCode error)

Optional callback invoked when something goes wrong; you can override it.
It must return either SUCCESS or FAILURE.

# ROS Topic Publisher Wrapper

### bool setMessage(TopicT& msg)

Required callback invoked in tick to allow the user to pass the message to be published.

# ROS Topic Subscriber Wrapper

### NodeStatus onTick(const std::shared_ptr<TopicT>& last_msg)

Required callback invoked in the tick. You must return either SUCCESS of FAILURE.

### bool latchLastMessage()

Optional callback to latch the message that has been processed.
If returns false and no new message is received, before next call there will be no message to process.
If returns true, the next call will process the same message again, if no new message received.
78 changes: 5 additions & 73 deletions behaviortree_ros2/tree_execution_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,77 +67,9 @@ sent as feedback to the `rclcpp_action::Client`.

## ROS Parameters

Default Config

```yaml
bt_action_server:
ros__parameters:
action_name: bt_execution
behavior_tick_frequency: 100.0
behavior_trees: '{}'
groot2_port: 1667.0
ros_plugins_timeout: 1000,
plugins: '{}'
```
### action_name
The name the Action Server takes requests from
* Type: `string`
* Default Value: "bt_execution"
* Read only: True

### behavior_tick_frequency

Frequency in Hz to tick() the Behavior tree at

* Type: `int`
* Default Value: 100
* Read only: True

*Constraints:*
- parameter must be within bounds 1

### groot2_port

Server port value to publish Groot2 messages on

* Type: `int`
* Default Value: 1667
* Read only: True

*Constraints:*
- parameter must be within bounds 1

### ros_plugins_timeout
Documentation for the parameters used by the `TreeExecutionServer` can be found [here](bt_executor_parameters.md).

Timeout, in milliseconds, to use with ROS Plugins (see BT::RosNodeParams)

* Type: `int`
* Default Value: {}

*Constraints:*
- parameter must be within 1 and 10000

### plugins

List of 'package_name/subfolder' containing BehaviorTree plugins to load into the factory.

These are plugins created using either the macro `BT_RegisterNodesFromPlugin` or `BT_RegisterRosNodeFromPlugin`.

* Type: `string_array`
* Default Value: {}

*Constraints:*
- contains no duplicates

### behavior_trees

List of 'package_name/subfolder' containing SubTrees to load into the BehaviorTree factory

* Type: `string_array`
* Default Value: {}

*Constraints:*
- contains no duplicates
If the parameter documentation needs updating you can regenerate it with:
```bash
generate_parameter_library_markdown --input_yaml src/bt_executor_parameters.yaml --output_markdown_file bt_executor_parameters.md
```
21 changes: 9 additions & 12 deletions btcpp_ros2_samples/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Sample Behaviors

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) .
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).

# TreeExecutionServer Documentation and Example
# TreeExecutionServer Sample

This package also includes an example Behavior Tree Executor that is designed to make building, combining and executing [BehaviorTree.CPP](https://www.behaviortree.dev/docs/intro) based Behaviors easy and reusable.
This Executor includes an Action Server that is able to register plugins or directly linked Behaviors and Trees/Subtrees so that a user can execute any known BehaviorTree by simply sending the name of it to the server.
Documentation on the TreeExecutionServer used in this example can be found [here](../behaviortree_ros2/tree_execution_server.md).

The `TreeExecutionServer` class offers several overridable methods that that can be used to meet your specific needs. Please see [tree_execution_server.hpp](../behaviortree_ros2/include/behaviortree_ros2/tree_execution_server.hpp) for descriptions and requirements of each virtual method. You can also refer to [sample_bt_executor.cpp](src/sample_bt_executor.cpp) for a working example of the `TreeExecutionServer`.

A launch file is included that starts the Execution Server and loads a list of plugins and BehaviorTrees from `yaml` file:
To start the sample Execution Server that load a list of plugins and BehaviorTrees from `yaml` file:
``` bash
ros2 launch btcpp_ros2_samples sample_bt_executor.launch.xml
```
Expand All @@ -18,21 +15,21 @@ ros2 launch btcpp_ros2_samples sample_bt_executor.launch.xml
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.
```
[bt_action_server]: Starting Action Server: bt_action_server
[bt_action_server]: Starting Action Server: behavior_server
[bt_action_server]: Loaded Plugin: libdummy_nodes_dyn.so
[bt_action_server]: Loaded Plugin: libmovebase_node_dyn.so
[bt_action_server]: Loaded Plugin: libcrossdoor_nodes_dyn.so
[bt_action_server]: Loaded ROS Plugin: libsleep_plugin.so
[bt_action_server]: Loaded Plugin: libsleep_plugin.so
[bt_action_server]: Loaded BehaviorTree: door_closed.xml
[bt_action_server]: Loaded Beha viorTree: cross_door.xml
[bt_action_server]: Loaded BehaviorTree: cross_door.xml
```

To call the Action Server from the command line:
``` bash
ros2 action send_goal /bt_action_server btcpp_ros2_interfaces/action/ExecuteTree "{target_tree: CrossDoor}"
ros2 action send_goal /behavior_server btcpp_ros2_interfaces/action/ExecuteTree "{target_tree: CrossDoor}"
```

You can also try a Behavior that is a ROS Action or Service client itself.
```bash
ros2 action send_goal /bt_action_server btcpp_ros2_interfaces/action/ExecuteTree "{target_tree: SleepActionSample}"
ros2 action send_goal /behavior_server btcpp_ros2_interfaces/action/ExecuteTree "{target_tree: SleepActionSample}"
```

0 comments on commit dbf6bc0

Please sign in to comment.