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

Skip to content

Commit 5726798

Browse files
committed
rebased master
2 parents 081c554 + dce278e commit 5726798

23 files changed

+623
-106
lines changed

3rdparty/coroutine/coroutine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
using ::std::string;
3939
using ::std::wstring;
4040

41-
#ifdef _MSC_VER
41+
#ifdef _WIN32
4242
#include <Windows.h>
4343
#else
4444
#if defined(__APPLE__) && defined(__MACH__)
@@ -60,7 +60,7 @@ enum class ResumeResult
6060
YIELD = 0
6161
};
6262

63-
#ifdef _MSC_VER
63+
#ifdef _WIN32
6464

6565
struct Routine
6666
{

CMakeLists.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")
2424
option(BUILD_EXAMPLES "Build tutorials and examples" ON)
2525
option(BUILD_UNIT_TESTS "Build the unit tests" ON)
2626
option(BUILD_TOOLS "Build commandline tools" ON)
27+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
2728

2829
#############################################################
2930
# Find packages
@@ -38,7 +39,7 @@ if( ZMQ_FOUND )
3839
message(STATUS "ZeroMQ found.")
3940
add_definitions( -DZMQ_FOUND )
4041
list(APPEND BT_SOURCE src/loggers/bt_zmq_publisher.cpp)
41-
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES zmq)
42+
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${ZMQ_LIBRARIES})
4243
else()
4344
message(WARNING "ZeroMQ NOT found. Skipping the build of [PublisherZMQ] and [bt_recorder].")
4445
endif()
@@ -85,7 +86,7 @@ elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
8586
list(APPEND BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${catkin_LIBRARIES})
8687
set(BUILD_TOOL_INCLUDE_DIRS ${catkin_INCLUDE_DIRS})
8788

88-
else()
89+
elseif(BUILD_UNIT_TESTS)
8990
find_package(GTest)
9091

9192
if(NOT GTEST_FOUND)
@@ -152,9 +153,12 @@ list(APPEND BT_SOURCE
152153
src/controls/reactive_fallback.cpp
153154
src/controls/sequence_node.cpp
154155
src/controls/sequence_star_node.cpp
156+
155157
src/controls/latched_sequence.cpp
156158
src/controls/latched_fallback.cpp
157159

160+
src/controls/switch_node.cpp
161+
158162
src/loggers/bt_cout_logger.cpp
159163
src/loggers/bt_file_logger.cpp
160164
src/loggers/bt_minitrace_logger.cpp
@@ -167,7 +171,11 @@ list(APPEND BT_SOURCE
167171

168172
if (UNIX)
169173
list(APPEND BT_SOURCE src/shared_library_UNIX.cpp )
170-
add_library(${BEHAVIOR_TREE_LIBRARY} SHARED ${BT_SOURCE} )
174+
if (BUILD_SHARED_LIBS)
175+
add_library(${BEHAVIOR_TREE_LIBRARY} SHARED ${BT_SOURCE})
176+
else()
177+
add_library(${BEHAVIOR_TREE_LIBRARY} STATIC ${BT_SOURCE})
178+
endif()
171179
endif()
172180

173181
if (WIN32)
@@ -176,6 +184,10 @@ if (WIN32)
176184
add_library(${BEHAVIOR_TREE_LIBRARY} STATIC ${BT_SOURCE} )
177185
endif()
178186

187+
if( ZMQ_FOUND )
188+
list(APPEND BUILD_TOOL_INCLUDE_DIRS ${ZMQ_INCLUDE_DIRS})
189+
endif()
190+
179191
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PUBLIC
180192
${BEHAVIOR_TREE_EXTERNAL_LIBRARIES})
181193

@@ -200,7 +212,9 @@ endif()
200212

201213
######################################################
202214
# Test
203-
add_subdirectory(tests)
215+
if (BUILD_UNIT_TESTS)
216+
add_subdirectory(tests)
217+
endif()
204218

205219
######################################################
206220
# INSTALL
@@ -209,8 +223,9 @@ set(PROJECT_CONFIG ${PROJECT_NAMESPACE}Config)
209223

210224
INSTALL(TARGETS ${BEHAVIOR_TREE_LIBRARY}
211225
EXPORT ${PROJECT_CONFIG}
212-
ARCHIVE DESTINATION ${BEHAVIOR_TREE_BIN_DESTINATION}
226+
ARCHIVE DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION}
213227
LIBRARY DESTINATION ${BEHAVIOR_TREE_LIB_DESTINATION}
228+
RUNTIME DESTINATION ${BEHAVIOR_TREE_BIN_DESTINATION}
214229
)
215230

216231
INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
@@ -235,5 +250,3 @@ if( BUILD_EXAMPLES )
235250
add_subdirectory(sample_nodes)
236251
add_subdirectory(examples)
237252
endif()
238-
239-

docs/images/ReactiveFallback.png

-392 Bytes
Loading

docs/images/ReactiveSequence.png

-509 Bytes
Loading

docs/images/SequenceNode.png

29 Bytes
Loading

docs/images/SequenceStar.png

-3.66 KB
Loading

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ endif()
4242

4343
add_executable(t10_include_trees t10_include_trees.cpp )
4444
target_link_libraries(t10_include_trees ${BEHAVIOR_TREE_LIBRARY} bt_sample_nodes )
45+
46+
47+
add_executable(t11_runtime_ports t11_runtime_ports.cpp )
48+
target_link_libraries(t11_runtime_ports ${BEHAVIOR_TREE_LIBRARY} bt_sample_nodes )

examples/t11_runtime_ports.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "behaviortree_cpp_v3/bt_factory.h"
2+
using namespace BT;
3+
4+
// clang-format off
5+
static const char* xml_text = R"(
6+
<root main_tree_to_execute = "MainTree" >
7+
<BehaviorTree ID="MainTree">
8+
<Sequence name="root">
9+
<ThinkRuntimePort text="{the_answer}"/>
10+
<SayRuntimePort message="{the_answer}" />
11+
</Sequence>
12+
</BehaviorTree>
13+
</root>
14+
)";
15+
// clang-format on
16+
17+
class ThinkRuntimePort: public BT::SyncActionNode
18+
{
19+
public:
20+
ThinkRuntimePort(const std::string& name,
21+
const BT::NodeConfiguration& config)
22+
: BT::SyncActionNode(name, config)
23+
{
24+
}
25+
26+
BT::NodeStatus tick() override {
27+
setOutput("text", "The answer is 42" );
28+
return NodeStatus::SUCCESS;
29+
}
30+
};
31+
32+
class SayRuntimePort : public BT::SyncActionNode
33+
{
34+
public:
35+
SayRuntimePort(const std::string& name, const BT::NodeConfiguration& config)
36+
: BT::SyncActionNode(name, config)
37+
{
38+
}
39+
40+
// You must override the virtual function tick()
41+
BT::NodeStatus tick() override
42+
{
43+
auto msg = getInput<std::string>("message");
44+
if (!msg){
45+
throw BT::RuntimeError( "missing required input [message]: ", msg.error() );
46+
}
47+
std::cout << "Robot says: " << msg.value() << std::endl;
48+
return BT::NodeStatus::SUCCESS;
49+
}
50+
};
51+
52+
53+
int main()
54+
{
55+
BehaviorTreeFactory factory;
56+
57+
//-------- register ports that might be defined at runtime --------
58+
// more verbose way
59+
PortsList think_ports = {BT::OutputPort<std::string>("text")};
60+
factory.registerBuilder(CreateManifest<ThinkRuntimePort>("ThinkRuntimePort", think_ports),
61+
CreateBuilder<ThinkRuntimePort>());
62+
// less verbose way
63+
PortsList say_ports = {BT::InputPort<std::string>("message")};
64+
factory.registerNodeType<SayRuntimePort>("SayRuntimePort", say_ports);
65+
66+
auto tree = factory.createTreeFromText(xml_text);
67+
tree.root_node->executeTick();
68+
return 0;
69+
}
70+
71+

include/behaviortree_cpp_v3/behavior_tree.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "behaviortree_cpp_v3/controls/fallback_node.h"
2121
#include "behaviortree_cpp_v3/controls/sequence_node.h"
2222
#include "behaviortree_cpp_v3/controls/sequence_star_node.h"
23+
#include "behaviortree_cpp_v3/controls/switch_node.h"
2324

2425
#include "behaviortree_cpp_v3/action_node.h"
2526
#include "behaviortree_cpp_v3/condition_node.h"
@@ -72,14 +73,15 @@ void buildSerializedStatusSnapshot(const TreeNode* root_node,
7273
SerializedTreeStatus& serialized_buffer);
7374

7475
/// Simple way to extract the type of a TreeNode at COMPILE TIME.
75-
/// Useful to avoid the cost of without dynamic_cast or the virtual method TreeNode::type().
76+
/// Useful to avoid the cost of dynamic_cast or the virtual method TreeNode::type().
7677
template <typename T>
7778
inline NodeType getType()
7879
{
7980
// clang-format off
8081
if( std::is_base_of<ActionNodeBase, T>::value ) return NodeType::ACTION;
8182
if( std::is_base_of<ConditionNode, T>::value ) return NodeType::CONDITION;
82-
if( std::is_base_of<DecoratorSubtreeNode, T>::value ) return NodeType::SUBTREE;
83+
if( std::is_base_of<SubtreeNode, T>::value ) return NodeType::SUBTREE;
84+
if( std::is_base_of<SubtreeWrapperNode, T>::value ) return NodeType::SUBTREE;
8385
if( std::is_base_of<DecoratorNode, T>::value ) return NodeType::DECORATOR;
8486
if( std::is_base_of<ControlNode, T>::value ) return NodeType::CONTROL;
8587
return NodeType::UNDEFINED;

0 commit comments

Comments
 (0)