From cd6f00ed5aad26ca500d9574aeef33134c79bd32 Mon Sep 17 00:00:00 2001 From: Ephson24 Date: Tue, 14 Mar 2023 15:55:07 +0100 Subject: [PATCH] Fixed skipping issue when using ReactiveSequence continuously | Created two tests: SkippingLogic.RepeatedSkippingReactiveSequence and SkippingLogic.RepeatedNoSkippingReactiveSequence --- src/controls/reactive_sequence.cpp | 2 +- tests/gtest_skipping.cpp | 117 +++++++++++++++++++++++++++++ tests/script_parser_test.cpp | 1 + 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/controls/reactive_sequence.cpp b/src/controls/reactive_sequence.cpp index bd36d522f..670466033 100644 --- a/src/controls/reactive_sequence.cpp +++ b/src/controls/reactive_sequence.cpp @@ -60,7 +60,7 @@ NodeStatus ReactiveSequence::tick() } // end switch } //end for - if (success_count == childrenCount()) + //if (success_count == childrenCount()) { resetChildren(); } diff --git a/tests/gtest_skipping.cpp b/tests/gtest_skipping.cpp index b25572252..3797cea37 100644 --- a/tests/gtest_skipping.cpp +++ b/tests/gtest_skipping.cpp @@ -3,6 +3,7 @@ #include "behaviortree_cpp/basic_types.h" #include "behaviortree_cpp/bt_factory.h" #include "test_helper.hpp" +#include "../sample_nodes/dummy_nodes.h" using namespace BT; @@ -114,3 +115,119 @@ TEST(SkippingLogic, ReactiveSingleChild) tree.tickWhileRunning(); } + +enum DeviceType { BATT=1, CONTROLLER=2 }; +BT::NodeStatus checkLevel2(BT::TreeNode &self) +{ + double percent = self.getInput("percentage").value(); + DeviceType devType; + auto res = self.getInput("deviceType", devType); + if(!res) { + throw std::runtime_error(res.error()); + } + + if(devType == DeviceType::BATT) + { + self.setOutput("isLowBattery", (percent < 25)); + } + std::cout << "Device: " << devType << " Level: " << percent << std::endl; + return BT::NodeStatus::SUCCESS; +} + +TEST(SkippingLogic, RepeatedSkippingReactiveSequence) +{ + BehaviorTreeFactory factory; + std::array counters; + RegisterTestTick(factory, "Test", counters); + + //! setting the battery level = 50 + const std::string xml_text = R"( + + + + +