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

Skip to content

Commit ed16076

Browse files
committed
Merge branch 'ver_3' of https://github.com/BehaviorTree/BehaviorTree.CPP into ver_3
2 parents ed89df3 + a836f36 commit ed16076

40 files changed

+842
-449
lines changed

CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")
1515

1616
option(BUILD_EXAMPLES "Build tutorials and examples" ON)
1717
option(BUILD_UNIT_TESTS "Build the unit tests" ON)
18+
option(BUILD_TOOLS "Build commandline tools" ON)
1819

1920
#############################################################
2021
# Find packages
@@ -73,6 +74,12 @@ elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
7374
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${catkin_LIBRARIES})
7475
set(BUILD_TOOL_INCLUDE_DIRS ${catkin_INCLUDE_DIRS})
7576

77+
find_package(backward_ros QUIET)
78+
if (backward_ros_FOUND)
79+
message(STATUS "backward_ros found, using it.")
80+
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${catkin_LIBRARIES} ${backward_ros_LIBRARIES})
81+
endif()
82+
7683
else()
7784
find_package(GTest)
7885

@@ -113,8 +120,9 @@ list(APPEND BT_SOURCE
113120
src/decorators/timeout_node.cpp
114121

115122
src/controls/fallback_node.cpp
116-
src/controls/fallback_star_node.cpp
117123
src/controls/parallel_node.cpp
124+
src/controls/reactive_sequence.cpp
125+
src/controls/reactive_fallback.cpp
118126
src/controls/sequence_node.cpp
119127
src/controls/sequence_star_node.cpp
120128

@@ -124,8 +132,11 @@ list(APPEND BT_SOURCE
124132

125133
3rdparty/tinyXML2/tinyxml2.cpp
126134
3rdparty/minitrace/minitrace.cpp
127-
3rdparty/backward-cpp/backward.cpp
128135
)
136+
if (NOT backward_ros_FOUND)
137+
list(APPEND BT_SOURCE
138+
3rdparty/backward-cpp/backward.cpp)
139+
endif()
129140

130141
######################################################
131142

@@ -245,9 +256,11 @@ install(EXPORT ${PROJECT_CONFIG}
245256

246257
######################################################
247258
# EXAMPLES and TOOLS
259+
if(BUILD_TOOLS)
260+
add_subdirectory(tools)
261+
endif()
248262

249263
if( BUILD_EXAMPLES )
250-
add_subdirectory(tools)
251264
add_subdirectory(sample_nodes)
252265
add_subdirectory(examples)
253266
endif()

docs/FallbackNode.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ in other frameworks.
55

66
Its purpose is to try different strategies, until we find one that "works".
77

8-
Currently the framework provides two kinds of nodes:
9-
10-
- FallbackNode
11-
- FallbackStarNode
12-
138
They share the following rules:
149

1510
- Before ticking the first child, the node status becomes __RUNNING__.

examples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ target_link_libraries(t02_basic_ports ${BEHAVIOR_TREE_LIBRARY} dummy_nodes )
1717
add_executable(t03_generic_ports t03_generic_ports.cpp )
1818
target_link_libraries(t03_generic_ports ${BEHAVIOR_TREE_LIBRARY} movebase_node dummy_nodes )
1919

20-
add_executable(t04_sequence_star t04_sequence_star.cpp )
21-
target_link_libraries(t04_sequence_star ${BEHAVIOR_TREE_LIBRARY} movebase_node dummy_nodes )
20+
add_executable(t04_reactive_sequence t04_reactive_sequence.cpp )
21+
target_link_libraries(t04_reactive_sequence ${BEHAVIOR_TREE_LIBRARY} movebase_node dummy_nodes )
2222

2323
add_executable(t05_crossdoor t05_crossdoor.cpp )
2424
target_link_libraries(t05_crossdoor ${BEHAVIOR_TREE_LIBRARY} crossdoor_nodes )

examples/t03_generic_ports.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ static const char* xml_text = R"(
103103
104104
<root main_tree_to_execute = "MainTree" >
105105
<BehaviorTree ID="MainTree">
106-
<SequenceStar name="root">
106+
<Sequence name="root">
107107
<CalculateGoal goal="{GoalPosition}" />
108108
<PrintTarget target="{GoalPosition}" />
109109
<SetBlackboard output_key="OtherGoal" value="-1;3" />
110110
<PrintTarget target="{OtherGoal}" />
111-
</SequenceStar>
111+
</Sequence>
112112
</BehaviorTree>
113113
</root>
114114
)";

examples/t04_sequence_star.cpp renamed to examples/t04_reactive_sequence.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ static const char* xml_text_sequence = R"(
3131
</root>
3232
)";
3333

34-
static const char* xml_text_sequence_star = R"(
34+
static const char* xml_text_reactive = R"(
3535
3636
<root main_tree_to_execute = "MainTree" >
3737
3838
<BehaviorTree ID="MainTree">
39-
<SequenceStar name="root">
39+
<ReactiveSequence name="root">
4040
<BatteryOK/>
41-
<SaySomething message="mission started..." />
42-
<MoveBase goal="1;2;3"/>
43-
<SaySomething message="mission completed!" />
44-
</SequenceStar>
41+
<Sequence>
42+
<SaySomething message="mission started..." />
43+
<MoveBase goal="1;2;3"/>
44+
<SaySomething message="mission completed!" />
45+
</Sequence>
46+
</ReactiveSequence>
4547
</BehaviorTree>
4648
4749
</root>
@@ -71,7 +73,7 @@ int main()
7173
// 1) When Sequence is used, BatteryOK is executed at __each__ tick()
7274
// 2) When SequenceStar is used, those ConditionNodes are executed only __once__.
7375

74-
for (auto& xml_text : {xml_text_sequence, xml_text_sequence_star})
76+
for (auto& xml_text : {xml_text_sequence, xml_text_reactive})
7577
{
7678
std::cout << "\n------------ BUILDING A NEW TREE ------------" << std::endl;
7779

gtest/gtest_decorator.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
#include "behaviortree_cpp/behavior_tree.h"
1717

1818
using BT::NodeStatus;
19+
using std::chrono::milliseconds;
1920

2021
struct DeadlineTest : testing::Test
2122
{
2223
BT::TimeoutNode root;
2324
BT::AsyncActionTest action;
2425

25-
DeadlineTest() : root("deadline", 300), action("action")
26+
DeadlineTest() : root("deadline", 300)
27+
, action("action", milliseconds(500) )
2628
{
2729
root.setChild(&action);
2830
}
@@ -62,26 +64,45 @@ struct RetryTest : testing::Test
6264
}
6365
};
6466

67+
struct TimeoutAndRetry : testing::Test
68+
{
69+
BT::TimeoutNode timeout_root;
70+
BT::RetryNode retry;
71+
BT::SyncActionTest action;
72+
73+
TimeoutAndRetry() :
74+
timeout_root("deadline", 9)
75+
, retry("retry", 1000)
76+
, action("action")
77+
{
78+
timeout_root.setChild(&retry);
79+
retry.setChild(&action);
80+
}
81+
~TimeoutAndRetry()
82+
{
83+
haltAllActions(&timeout_root);
84+
}
85+
};
86+
6587
/****************TESTS START HERE***************************/
6688

6789
TEST_F(DeadlineTest, DeadlineTriggeredTest)
6890
{
69-
action.setTime(4);
70-
7191
BT::NodeStatus state = root.executeTick();
72-
// deadline in 300 ms
92+
// deadline in 300 ms, action requires 500 ms
93+
7394
ASSERT_EQ(NodeStatus::RUNNING, action.status());
7495
ASSERT_EQ(NodeStatus::RUNNING, state);
7596

76-
std::this_thread::sleep_for(std::chrono::milliseconds(450));
97+
std::this_thread::sleep_for(std::chrono::milliseconds(400));
7798
state = root.executeTick();
7899
ASSERT_EQ(NodeStatus::FAILURE, state);
79100
ASSERT_EQ(NodeStatus::IDLE, action.status());
80101
}
81102

82103
TEST_F(DeadlineTest, DeadlineNotTriggeredTest)
83104
{
84-
action.setTime(2);
105+
action.setTime( milliseconds(200) );
85106
// deadline in 300 ms
86107

87108
BT::NodeStatus state = root.executeTick();
@@ -168,5 +189,18 @@ TEST_F(RepeatTest, RepeatTestA)
168189
root.executeTick();
169190
ASSERT_EQ(NodeStatus::FAILURE, root.status());
170191
ASSERT_EQ(3, action.tickCount() );
192+
}
171193

194+
// https://github.com/BehaviorTree/BehaviorTree.CPP/issues/57
195+
TEST_F(TimeoutAndRetry, Issue57)
196+
{
197+
action.setBoolean( false );
198+
199+
auto t1 = std::chrono::high_resolution_clock::now();
200+
201+
while( std::chrono::high_resolution_clock::now() < t1 + std::chrono::seconds(2) )
202+
{
203+
ASSERT_NE( timeout_root.executeTick(), BT::NodeStatus::IDLE );
204+
std::this_thread::sleep_for( std::chrono::microseconds(50) );
205+
}
172206
}

0 commit comments

Comments
 (0)