Skip to content
Merged
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
19 changes: 13 additions & 6 deletions plansys2_bt_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This example shows how to use Behavior Trees to carry out the tasks that an acti

See https://github.com/IntelligentRoboticsLabs/ros2_planning_system/pull/27 for details.

## Prerequisites
```bash
sudo apt-get install ros-humble-turtlebot3*
```

## How to run

### In terminal 1:
Expand All @@ -16,7 +21,7 @@ See https://github.com/IntelligentRoboticsLabs/ros2_planning_system/pull/27 for
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/humble/share/turtlebot3_gazebo/models
export TURTLEBOT3_MODEL=waffle
source /usr/share/gazebo/setup.sh
source $HOME/dev_ws/install/setup.bash
source install/setup.bash
ros2 launch nav2_bringup tb3_simulation_launch.py headless:=False
```

Expand All @@ -32,7 +37,7 @@ ros2 topic pub --once /initialpose geometry_msgs/msg/PoseWithCovarianceStamped "
### In terminal 2:

```bash
source $HOME/dev_ws/install/setup.bash
source install/setup.bash
ros2 launch plansys2_bt_example plansys2_bt_example_launch.py
```

Expand All @@ -41,7 +46,7 @@ ros2 launch plansys2_bt_example plansys2_bt_example_launch.py
There are two options in this example. First option is to use the plansys2 terminal. Secondly you can use the custom assemble controller. Both options are shown below.

```bash
source $HOME/dev_ws/install/setup.bash
source install/setup.bash

# before you run the commands below, it seems the starting location must be different to prevent an error
ros2 topic pub --times 3 /goal_pose geometry_msgs/PoseStamped "{header: {stamp: {sec: 0}, frame_id: 'map'}, pose: {position: {x: -0.4, y: 0.4, z: 0.01}, orientation: {w: 0.0}}}"
Expand Down Expand Up @@ -70,21 +75,23 @@ set predicate (piece_at steering_wheel_1 steering_wheels_zone)
set goal (and(piece_at wheel_1 assembly_zone))
run
```
You can also paste commands above into a file (e.g. commands.txt), start the plansys2_terminal and enter the following:
You can also paste the problem above into a file (e.g. problem.txt), start the plansys2_terminal and enter the following:

```text
source commands.txt
source problem.txt
```
Or use a custom controller:

```bash
source $HOME/dev_ws/install/setup.bash
source install/setup.bash
$HOME/dev_ws/build/plansys2_bt_example/assemble_controller_node
```
NOTE: this problem domain is different from example entered in the plansys2 terminal.

### In terminal 4 (optional):

NOTE: this is not working right now due to the upgrade to BT.CPP v4

To monitor the behaviortree in Groot, type the following to connect it to the plansys2 executor:
```bash
$HOME/dev_ws/build/groot/Groot --mode monitor --publisher_port 2666 --server_port 2667 --autoconnect
Expand Down
4 changes: 2 additions & 2 deletions plansys2_bt_example/behavior_trees_xml/move.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<root main_tree_to_execute = "MainTree" >
<root BTCPP_format="4" main_tree_to_execute = "MainTree" >
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<Move name="move" goal="${arg2}"/>
<Move name="move" goal="{arg2}" />
</Sequence>
</BehaviorTree>
</root>
2 changes: 1 addition & 1 deletion plansys2_bt_example/behavior_trees_xml/recharge.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<root main_tree_to_execute = "MainTree" >
<root BTCPP_format="4" main_tree_to_execute = "MainTree" >
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<Recharge name="recharge"/>
Expand Down
4 changes: 2 additions & 2 deletions plansys2_bt_example/behavior_trees_xml/transport.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<root main_tree_to_execute = "MainTree" >
<root BTCPP_format="4" main_tree_to_execute = "MainTree" >
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<OpenGripper name="open_gripper"/>
<ApproachObject name="approach_object"/>
<CloseGripper name="close_gripper"/>
<Move name="move" goal="${arg3}"/>
<Move name="move" goal="{arg3}"/>
<OpenGripper name="open_gripper"/>
</Sequence>
</BehaviorTree>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <string>

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/behavior_tree.h"
#include "behaviortree_cpp/bt_factory.h"

namespace plansys2_bt_example
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <string>

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/behavior_tree.h"
#include "behaviortree_cpp/bt_factory.h"

namespace plansys2_bt_example
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "nav2_msgs/action/navigate_to_pose.hpp"

#include "plansys2_bt_actions/BTActionNode.hpp"
#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/behavior_tree.h"
#include "behaviortree_cpp/bt_factory.h"

namespace plansys2_bt_tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <string>

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/behavior_tree.h"
#include "behaviortree_cpp/bt_factory.h"

namespace plansys2_bt_example
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <string>

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/behavior_tree.h"
#include "behaviortree_cpp/bt_factory.h"

namespace plansys2_bt_example
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "plansys2_bt_example/behavior_tree_nodes/ApproachObject.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp/behavior_tree.h"

namespace plansys2_bt_example
{
Expand Down Expand Up @@ -50,7 +50,7 @@ ApproachObject::tick()

} // namespace plansys2_bt_example

#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/bt_factory.h"
BT_REGISTER_NODES(factory)
{
factory.registerNodeType<plansys2_bt_example::ApproachObject>("ApproachObject");
Expand Down
4 changes: 2 additions & 2 deletions plansys2_bt_example/src/behavior_tree_nodes/CloseGripper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "plansys2_bt_example/behavior_tree_nodes/CloseGripper.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp/behavior_tree.h"

namespace plansys2_bt_example
{
Expand Down Expand Up @@ -50,7 +50,7 @@ CloseGripper::tick()

} // namespace plansys2_bt_example

#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/bt_factory.h"
BT_REGISTER_NODES(factory)
{
factory.registerNodeType<plansys2_bt_example::CloseGripper>("CloseGripper");
Expand Down
12 changes: 8 additions & 4 deletions plansys2_bt_example/src/behavior_tree_nodes/Move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "geometry_msgs/msg/pose2_d.hpp"
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp/behavior_tree.h"

#include "rclcpp_lifecycle/lifecycle_node.hpp"

Expand All @@ -36,7 +36,9 @@ Move::Move(
: plansys2::BtActionNode<nav2_msgs::action::NavigateToPose>(xml_tag_name, action_name, conf)
{
rclcpp_lifecycle::LifecycleNode::SharedPtr node;
config().blackboard->get("node", node);
if (!config().blackboard->get("node", node)) {
RCLCPP_ERROR(node_->get_logger(), "Failed to get 'node' from the blackboard");
}

try {
node->declare_parameter<std::vector<std::string>>("waypoints");
Expand Down Expand Up @@ -76,7 +78,9 @@ Move::on_tick()
{
if (status() == BT::NodeStatus::IDLE) {
rclcpp_lifecycle::LifecycleNode::SharedPtr node;
config().blackboard->get("node", node);
if (!config().blackboard->get("node", node)) {
RCLCPP_ERROR(node_->get_logger(), "Failed to get 'node' from the blackboard");
}

std::string goal;
getInput<std::string>("goal", goal);
Expand Down Expand Up @@ -112,7 +116,7 @@ Move::on_success()

} // namespace plansys2_bt_tests

#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/bt_factory.h"
BT_REGISTER_NODES(factory)
{
BT::NodeBuilder builder =
Expand Down
4 changes: 2 additions & 2 deletions plansys2_bt_example/src/behavior_tree_nodes/OpenGripper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "plansys2_bt_example/behavior_tree_nodes/OpenGripper.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp/behavior_tree.h"

namespace plansys2_bt_example
{
Expand Down Expand Up @@ -50,7 +50,7 @@ OpenGripper::tick()

} // namespace plansys2_bt_example

#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/bt_factory.h"
BT_REGISTER_NODES(factory)
{
factory.registerNodeType<plansys2_bt_example::OpenGripper>("OpenGripper");
Expand Down
4 changes: 2 additions & 2 deletions plansys2_bt_example/src/behavior_tree_nodes/Recharge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "plansys2_bt_example/behavior_tree_nodes/Recharge.hpp"

#include "behaviortree_cpp_v3/behavior_tree.h"
#include "behaviortree_cpp/behavior_tree.h"

namespace plansys2_bt_example
{
Expand Down Expand Up @@ -50,7 +50,7 @@ Recharge::tick()

} // namespace plansys2_bt_example

#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp/bt_factory.h"
BT_REGISTER_NODES(factory)
{
factory.registerNodeType<plansys2_bt_example::Recharge>("Recharge");
Expand Down