Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adbfd5e

Browse files
author
Davide Faconti
committed
fix issue BehaviorTree#72 with sibling subtrees
1 parent f590d0f commit adbfd5e

File tree

4 files changed

+101
-51
lines changed

4 files changed

+101
-51
lines changed

CMakeLists.txt

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -184,54 +184,9 @@ export(TARGETS ${PROJECT_NAME}
184184
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_CONFIG}.cmake")
185185

186186
######################################################
187-
# TESTS
188-
189-
set(BT_TESTS
190-
gtest/src/action_test_node.cpp
191-
gtest/src/condition_test_node.cpp
192-
gtest/gtest_tree.cpp
193-
gtest/gtest_sequence.cpp
194-
gtest/gtest_parallel.cpp
195-
gtest/gtest_fallback.cpp
196-
gtest/gtest_factory.cpp
197-
gtest/gtest_decorator.cpp
198-
gtest/gtest_blackboard.cpp
199-
gtest/gtest_coroutines.cpp
200-
gtest/navigation_test.cpp
201-
)
202-
203-
if(ament_cmake_FOUND AND BUILD_TESTING)
204-
205-
find_package(ament_cmake_gtest REQUIRED)
206-
207-
ament_add_gtest_executable(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
208-
target_link_libraries(${BEHAVIOR_TREE_LIBRARY}_test ${BEHAVIOR_TREE_LIBRARY}
209-
crossdoor_nodes dummy_nodes
210-
${ament_LIBRARIES})
211-
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include)
212-
include_directories($<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty>)
213-
214-
elseif(catkin_FOUND AND CATKIN_ENABLE_TESTING)
215-
216-
catkin_add_gtest(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
217-
target_link_libraries(${BEHAVIOR_TREE_LIBRARY}_test ${BEHAVIOR_TREE_LIBRARY}
218-
crossdoor_nodes dummy_nodes
219-
${catkin_LIBRARIES})
220-
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include)
221-
222-
elseif(GTEST_FOUND AND BUILD_UNIT_TESTS)
223-
224-
enable_testing()
225-
226-
add_executable(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
227-
target_link_libraries(${PROJECT_NAME}_test ${BEHAVIOR_TREE_LIBRARY}
228-
crossdoor_nodes dummy_nodes
229-
${GTEST_LIBRARIES}
230-
${GTEST_MAIN_LIBRARIES})
231-
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include ${GTEST_INCLUDE_DIRS})
232-
233-
add_test(BehaviorTreeCoreTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BEHAVIOR_TREE_LIBRARY}_test)
234-
endif()
187+
# Test
188+
189+
add_subdirectory(gtest)
235190

236191
######################################################
237192
# INSTALL

gtest/CMakeLists.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
######################################################
2+
# TESTS
3+
4+
include_directories(include)
5+
6+
set(BT_TESTS
7+
src/action_test_node.cpp
8+
src/condition_test_node.cpp
9+
gtest_tree.cpp
10+
gtest_sequence.cpp
11+
gtest_parallel.cpp
12+
gtest_fallback.cpp
13+
gtest_factory.cpp
14+
gtest_decorator.cpp
15+
gtest_blackboard.cpp
16+
gtest_coroutines.cpp
17+
navigation_test.cpp
18+
gtest_subtree.cpp
19+
)
20+
21+
if(ament_cmake_FOUND AND BUILD_TESTING)
22+
23+
find_package(ament_cmake_gtest REQUIRED)
24+
25+
ament_add_gtest_executable(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
26+
target_link_libraries(${BEHAVIOR_TREE_LIBRARY}_test ${BEHAVIOR_TREE_LIBRARY}
27+
crossdoor_nodes dummy_nodes
28+
${ament_LIBRARIES})
29+
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include)
30+
include_directories($<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty>)
31+
32+
elseif(catkin_FOUND AND CATKIN_ENABLE_TESTING)
33+
34+
catkin_add_gtest(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
35+
target_link_libraries(${BEHAVIOR_TREE_LIBRARY}_test ${BEHAVIOR_TREE_LIBRARY}
36+
crossdoor_nodes dummy_nodes
37+
${catkin_LIBRARIES})
38+
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include)
39+
40+
elseif(GTEST_FOUND AND BUILD_UNIT_TESTS)
41+
42+
enable_testing()
43+
44+
add_executable(${BEHAVIOR_TREE_LIBRARY}_test ${BT_TESTS})
45+
target_link_libraries(${PROJECT_NAME}_test ${BEHAVIOR_TREE_LIBRARY}
46+
crossdoor_nodes dummy_nodes
47+
${GTEST_LIBRARIES}
48+
${GTEST_MAIN_LIBRARIES})
49+
target_include_directories(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE gtest/include ${GTEST_INCLUDE_DIRS})
50+
51+
add_test(BehaviorTreeCoreTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BEHAVIOR_TREE_LIBRARY}_test)
52+
53+
endif()

gtest/gtest_subtree.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <gtest/gtest.h>
2+
#include "behaviortree_cpp/bt_factory.h"
3+
#include "../sample_nodes/dummy_nodes.h"
4+
5+
using namespace BT;
6+
7+
TEST(SubTree, SiblingPorts_Issue_72)
8+
{
9+
10+
static const char* xml_text = R"(
11+
12+
<root main_tree_to_execute = "MainTree" >
13+
14+
<BehaviorTree ID="MainTree">
15+
<Sequence>
16+
<SetBlackboard value="hello" output_key="myParam" />
17+
<SubTree ID="mySubtree" param="myParam" />
18+
<SetBlackboard value="world" output_key="myParam" />
19+
<SubTree ID="mySubtree" param="myParam" />
20+
</Sequence>
21+
</BehaviorTree>
22+
23+
<BehaviorTree ID="mySubtree">
24+
<SaySomething ID="AlwaysSuccess" message="{param}" />
25+
</BehaviorTree>
26+
</root> )";
27+
28+
BehaviorTreeFactory factory;
29+
factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
30+
31+
Tree tree = factory.createTreeFromText(xml_text);
32+
33+
for( auto& bb: tree.blackboard_stack)
34+
{
35+
bb->debugMessage();
36+
std::cout << "-----" << std::endl;
37+
}
38+
39+
auto ret = tree.root_node->executeTick();
40+
41+
ASSERT_EQ(ret, NodeStatus::SUCCESS );
42+
ASSERT_EQ(tree.blackboard_stack.size(), 3 );
43+
}

src/xml_parsing.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,13 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
612612

613613
if( node->type() == NodeType::SUBTREE )
614614
{
615-
auto parent_bb = output_tree.blackboard_stack.back();
616-
auto new_bb = Blackboard::create(parent_bb);
615+
auto new_bb = Blackboard::create(blackboard);
617616

618617
for (auto remap_el = element->FirstChildElement("remap"); remap_el != nullptr;
619618
remap_el = remap_el->NextSiblingElement("remap"))
620619
{
621620
new_bb->addSubtreeRemapping( remap_el->Attribute("internal"),
622-
remap_el->Attribute("external") );
621+
remap_el->Attribute("external") );
623622
}
624623

625624
for (const XMLAttribute* attr = element->FirstAttribute(); attr != nullptr; attr = attr->Next())

0 commit comments

Comments
 (0)