From ca4153dd5a48086c8e09284a55dd46ad38667ea5 Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Wed, 16 Oct 2024 21:01:32 -0400 Subject: [PATCH 1/3] Add simple BT.CPP solutions to Problems 2 and 3 --- technologies/BehaviorTree.CPP/README.md | 2 +- .../pyrobosim_btcpp/trees/problem2.xml | 38 +++++++++++---- .../pyrobosim_btcpp/trees/problem3.xml | 48 +++++++++++++++++++ 3 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml diff --git a/technologies/BehaviorTree.CPP/README.md b/technologies/BehaviorTree.CPP/README.md index b98bea1..a59ee7d 100644 --- a/technologies/BehaviorTree.CPP/README.md +++ b/technologies/BehaviorTree.CPP/README.md @@ -34,7 +34,7 @@ For instance, consider this sample XML in [trees/navigation_demo.xml](pyrobosim_ NOTE: remember that the `name` attribute in the XML is optional and used for debugging only. -You can run the BeahviorTree with the command: +You can run the BehaviorTree with the command: ```bash ros2 run pyrobosim_btcpp btcpp_executor --ros-args -p tree:=trees/navigation_demo.xml diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem2.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem2.xml index f12f1a9..704c057 100644 --- a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem2.xml +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem2.xml @@ -2,16 +2,34 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml new file mode 100644 index 0000000..6181e37 --- /dev/null +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 6809fcc204496901aedaf0d166c9fe2cc3a1c32d Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Wed, 16 Oct 2024 21:14:26 -0400 Subject: [PATCH 2/3] WIP problem 4 --- .../pyrobosim_btcpp/trees/problem4.xml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml new file mode 100644 index 0000000..93b67d1 --- /dev/null +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 34b82999041760595cfc2dfbe078eab9f462fbd7 Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Sat, 19 Oct 2024 16:22:04 -0400 Subject: [PATCH 3/3] Add Problem 4 solution --- technologies/BehaviorTree.CPP/README.md | 2 +- .../nodes/get_current_location_node.hpp | 41 ++++ .../pyrobosim_btcpp/src/btcpp_executor.cpp | 2 + .../pyrobosim_btcpp/trees/problem4.xml | 28 --- .../trees/pyrobosim_btcpp_model.xml | 3 + .../trees/{ => solution}/problem1.xml | 0 .../trees/{ => solution}/problem2.xml | 0 .../trees/{ => solution}/problem3.xml | 12 +- .../trees/solution/problem4.xml | 175 ++++++++++++++++++ 9 files changed, 228 insertions(+), 35 deletions(-) delete mode 100644 technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml rename technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/{ => solution}/problem1.xml (100%) rename technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/{ => solution}/problem2.xml (100%) rename technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/{ => solution}/problem3.xml (82%) create mode 100644 technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem4.xml diff --git a/technologies/BehaviorTree.CPP/README.md b/technologies/BehaviorTree.CPP/README.md index a59ee7d..a50b6b5 100644 --- a/technologies/BehaviorTree.CPP/README.md +++ b/technologies/BehaviorTree.CPP/README.md @@ -9,7 +9,7 @@ We suggest creating your XML trees in the folder `technologies/BehaviorTree.CPP/ **Careful**: make sure to run this command in `/delib_ws` folder. ```bash -colcon build --symlink-install --packages-select pyrobosim_btcpp +colcon build --symlink-install --packages-up-to pyrobosim_btcpp ``` ## How to run diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/include/pyrobosim_btcpp/nodes/get_current_location_node.hpp b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/include/pyrobosim_btcpp/nodes/get_current_location_node.hpp index e69de29..712680d 100644 --- a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/include/pyrobosim_btcpp/nodes/get_current_location_node.hpp +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/include/pyrobosim_btcpp/nodes/get_current_location_node.hpp @@ -0,0 +1,41 @@ + +#pragma once + +#include +#include + +namespace BT +{ + +class GetCurrentLocation : public SyncActionNode +{ +public: + GetCurrentLocation(const std::string& name, const NodeConfig& config, rclcpp::Logger logger) + : SyncActionNode(name, config), logger_(logger) + {} + + static PortsList providedPorts() + { + return { OutputPort("location", "The robot's current location.") }; + } + + // You must override the virtual function tick() + NodeStatus tick() override + { + // Read a value from the blackboard + std::string current_location = ""; + if(!config().blackboard->get("@last_visited_location", current_location)) + { + RCLCPP_ERROR(logger_, "Robot location not available yet"); + return NodeStatus::FAILURE; + } + RCLCPP_INFO(logger_, "Robot location level: %s", current_location.c_str()); + setOutput("location", current_location); + return NodeStatus::SUCCESS; + } + +private: + rclcpp::Logger logger_; +}; + +} // namespace BT diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/src/btcpp_executor.cpp b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/src/btcpp_executor.cpp index 4bdeab0..30be81d 100644 --- a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/src/btcpp_executor.cpp +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/src/btcpp_executor.cpp @@ -13,6 +13,7 @@ // BTCPP nodes in this package #include "pyrobosim_btcpp/nodes/battery_nodes.hpp" +#include "pyrobosim_btcpp/nodes/get_current_location_node.hpp" #include "pyrobosim_btcpp/nodes/open_node.hpp" #include "pyrobosim_btcpp/nodes/close_node.hpp" #include "pyrobosim_btcpp/nodes/detect_object_node.hpp" @@ -72,6 +73,7 @@ int main(int argc, char** argv) factory.registerNodeType("IsBatteryLow", nh->get_logger()); factory.registerNodeType("IsBatteryFull", nh->get_logger()); + factory.registerNodeType("GetCurrentLocation", nh->get_logger()); factory.registerNodeType("Close", params); factory.registerNodeType("DetectObject", params); factory.registerNodeType("Navigate", params); diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml deleted file mode 100644 index 93b67d1..0000000 --- a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem4.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/pyrobosim_btcpp_model.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/pyrobosim_btcpp_model.xml index a33a602..ffd45ab 100644 --- a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/pyrobosim_btcpp_model.xml +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/pyrobosim_btcpp_model.xml @@ -16,6 +16,9 @@ Return SUCCESS if {@battery_level} below this value + + + Robot name diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem1.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem1.xml similarity index 100% rename from technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem1.xml rename to technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem1.xml diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem2.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem2.xml similarity index 100% rename from technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem2.xml rename to technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem2.xml diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem3.xml similarity index 82% rename from technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml rename to technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem3.xml index 6181e37..453282a 100644 --- a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/problem3.xml +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem3.xml @@ -2,40 +2,40 @@ - + - + - + - + - + - + diff --git a/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem4.xml b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem4.xml new file mode 100644 index 0000000..a19d553 --- /dev/null +++ b/technologies/BehaviorTree.CPP/pyrobosim_btcpp/trees/solution/problem4.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +