Skip to content

Commit 73f663f

Browse files
committed
2 parents bc2ce53 + e0927b6 commit 73f663f

27 files changed

+136
-230
lines changed

.github/workflows/cmake_windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ jobs:
4343

4444
- name: run test (Windows)
4545
working-directory: ${{github.workspace}}/build
46-
run: ./tests/Release/behaviortree_cpp_test
46+
run: ctest -C $BUILD_TYPE
4747

CMakeLists.txt

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,8 @@ endif()
6363
find_package(Threads)
6464
find_package(ZMQ)
6565

66-
list(APPEND BEHAVIOR_TREE_PUBLIC_LIBRARIES
67-
${CMAKE_THREAD_LIBS_INIT}
68-
${CMAKE_DL_LIBS}
69-
)
70-
7166
if( ZMQ_FOUND )
72-
message(STATUS "ZeroMQ found.")
67+
message(STATUS "ZeroMQ: found.")
7368
add_definitions( -DZMQ_FOUND )
7469
list(APPEND BT_SOURCE src/loggers/bt_zmq_publisher.cpp)
7570
else()
@@ -93,8 +88,6 @@ if ( ament_cmake_FOUND )
9388
message(STATUS "BehaviourTree is being built using AMENT.")
9489
message(STATUS "------------------------------------------")
9590

96-
set(BUILD_TOOL_INCLUDE_DIRS ${ament_INCLUDE_DIRS})
97-
9891
elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
9992

10093
set(catkin_FOUND 1)
@@ -112,9 +105,6 @@ elseif( CATKIN_DEVEL_PREFIX OR CATKIN_BUILD_BINARY_PACKAGE)
112105
CATKIN_DEPENDS roslib
113106
)
114107

115-
list(APPEND BEHAVIOR_TREE_PUBLIC_LIBRARIES ${catkin_LIBRARIES})
116-
set(BUILD_TOOL_INCLUDE_DIRS ${catkin_INCLUDE_DIRS})
117-
118108
elseif(BTCPP_UNIT_TESTS)
119109
if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
120110
find_package(GTest REQUIRED)
@@ -177,11 +167,8 @@ list(APPEND BT_SOURCE
177167
if(BTCPP_MANUAL_SELECTOR)
178168
find_package(Curses QUIET)
179169
if(CURSES_FOUND)
180-
list(APPEND BT_SOURCE
181-
src/controls/manual_node.cpp
182-
)
183-
list(APPEND BEHAVIOR_TREE_PUBLIC_LIBRARIES ${CURSES_LIBRARIES})
184-
add_definitions(-DNCURSES_FOUND)
170+
message(STATUS "NCurses: found.")
171+
list(APPEND BT_SOURCE src/controls/manual_node.cpp )
185172
else()
186173
message(WARNING "NCurses NOT found. Skipping the build of manual selector node.")
187174
endif()
@@ -206,15 +193,11 @@ else()
206193
add_library(${BEHAVIOR_TREE_LIBRARY} STATIC ${BT_SOURCE})
207194
endif()
208195

209-
if( ZMQ_FOUND )
210-
list(APPEND BUILD_TOOL_INCLUDE_DIRS ${ZMQ_INCLUDE_DIRS})
211-
endif()
212-
213196
target_link_libraries(${BEHAVIOR_TREE_LIBRARY}
214197
PUBLIC
215-
${BEHAVIOR_TREE_PUBLIC_LIBRARIES}
198+
${CMAKE_THREAD_LIBS_INIT}
199+
${CMAKE_DL_LIBS}
216200
PRIVATE
217-
$<BUILD_INTERFACE:${ZMQ_LIBRARIES}>
218201
$<BUILD_INTERFACE:foonathan::lexy>
219202
)
220203

@@ -225,22 +208,35 @@ target_include_directories(${BEHAVIOR_TREE_LIBRARY}
225208
PRIVATE
226209
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty>
227210
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lexy/include>
228-
$<BUILD_INTERFACE:${BUILD_TOOL_INCLUDE_DIRS}>
211+
$<BUILD_INTERFACE:${BTCPP_EXTRA_INCLUDE_DIRS}>
229212
)
230213

231-
if(DEFINED BT_COROUTINES_FOUND)
214+
if(ZMQ_FOUND)
232215
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PRIVATE
233-
$<BUILD_INTERFACE:${Boost_LIBRARIES}> )
234-
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PRIVATE
235-
$<BUILD_INTERFACE:${Boost_INCLUDE_DIRS}> )
216+
${ZMQ_LIBRARIES} )
217+
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PRIVATE
218+
${ZMQ_INCLUDE_DIRS} )
219+
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PRIVATE ZMQ_FOUND)
236220
endif()
237221

238-
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PRIVATE $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
222+
if(BT_COROUTINES_FOUND)
223+
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PRIVATE
224+
${Boost_LIBRARIES} )
225+
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PRIVATE
226+
${Boost_INCLUDE_DIRS} )
227+
endif()
239228

240-
if( ZMQ_FOUND )
241-
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PUBLIC ZMQ_FOUND)
229+
if(CURSES_FOUND)
230+
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PRIVATE
231+
${CURSES_LIBRARIES} )
232+
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PRIVATE
233+
${CURSES_INCLUDE_DIRS} )
234+
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PRIVATE NCURSES_FOUND)
242235
endif()
243236

237+
238+
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY} PRIVATE $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
239+
244240
if(MSVC)
245241
else()
246242
target_compile_options(${BEHAVIOR_TREE_LIBRARY} PRIVATE
@@ -255,7 +251,7 @@ if(ament_cmake_FOUND)
255251
$<BUILD_INTERFACE:${ament_index_cpp_INCLUDE_DIRS}> )
256252

257253
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PRIVATE
258-
$<BUILD_INTERFACE:ament_index_cpp::ament_index_cpp> )
254+
$<BUILD_INTERFACE:ament_index_cpp::ament_index_cpp> )
259255

260256
ament_export_dependencies(ament_index_cpp)
261257

@@ -267,6 +263,13 @@ if(ament_cmake_FOUND)
267263
ament_export_libraries(${BEHAVIOR_TREE_LIBRARY})
268264
ament_package()
269265
elseif(catkin_FOUND)
266+
267+
target_include_directories(${BEHAVIOR_TREE_LIBRARY} PRIVATE
268+
${catkin_INCLUDE_DIRS} )
269+
270+
target_link_libraries(${BEHAVIOR_TREE_LIBRARY} PRIVATE
271+
${catkin_LIBRARIES} )
272+
270273
set( BEHAVIOR_TREE_LIB_DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} )
271274
set( BEHAVIOR_TREE_INC_DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} )
272275
set( BEHAVIOR_TREE_BIN_DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} )

include/behaviortree_cpp/action_node.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class SimpleActionNode : public SyncActionNode
102102
* the result of the method isHaltRequested() and stop your execution accordingly.
103103
*
104104
* - in the overriden halt() method, you can do some cleanup, but do not forget to
105-
* invoke the base class method AsyncActionNode::halt();
105+
* invoke the base class method ThreadedAction::halt();
106106
*
107-
* - remember, with few exceptions, a halted AsyncAction must return NodeStatus::IDLE.
107+
* - remember, with few exceptions, a halted ThreadedAction must return NodeStatus::IDLE.
108108
*
109109
* For a complete example, look at __AsyncActionTest__ in action_test_node.h in the folder test.
110110
*
@@ -137,12 +137,12 @@ class ThreadedAction : public ActionNodeBase
137137
};
138138

139139
#ifdef USE_BTCPP3_OLD_NAMES
140-
using AsyncActionNode = ThreadedActionNode;
140+
using AsyncActionNode = ThreadedAction;
141141
#endif
142142

143143
/**
144-
* @brief The StatefulAsyncAction is the preferred way to implement asynchronous Actions.
145-
* It is actually easier to use correctly, when compared with AsyncAction
144+
* @brief The StatefulActionNode is the preferred way to implement asynchronous Actions.
145+
* It is actually easier to use correctly, when compared with ThreadedAction
146146
*
147147
* It is particularly useful when your code contains a request-reply pattern,
148148
* i.e. when the actions sends an asynchronous request, then checks periodically

include/behaviortree_cpp/basic_types.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ using enable_if_not = typename std::enable_if<!Predicate::value>::type*;
201201
*
202202
* */
203203
template <typename T>
204+
using Expected = nonstd::expected<T, std::string>;
204205
#ifdef USE_BTCPP3_OLD_NAMES
206+
// note: we also use the name Optional instead of expected because it is more intuitive
207+
// for users that are not up to date with "modern" C++
208+
template <typename T>
205209
using Optional = nonstd::expected<T, std::string>;
206-
#else
207-
using Expected = nonstd::expected<T, std::string>;
208210
#endif
209-
// note: we use the name Optional instead of expected because it is more intuitive
210-
// for users that are not up to date with "modern" C++
211211

212212
/** Usage: given a function/method like:
213213
*
@@ -292,7 +292,8 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction, StringView
292292
auto sname = static_cast<std::string>(name);
293293
if (!IsAllowedPortName(sname))
294294
{
295-
throw RuntimeError("The name of a port must start with an alphabetic character. "
295+
throw RuntimeError("The name of a port must not be `name` or `ID` "
296+
"and must start with an alphabetic character. "
296297
"Underscore is reserved.");
297298
}
298299

include/behaviortree_cpp/control_node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ControlNode : public TreeNode
4242

4343
virtual void halt() override;
4444

45+
/// same as resetChildren()
4546
void haltChildren();
4647

4748
[[deprecated("deprecated: please use explicitly haltChildren() or haltChild(i)")]] void
@@ -53,5 +54,9 @@ class ControlNode : public TreeNode
5354
{
5455
return NodeType::CONTROL;
5556
}
57+
58+
/// Set the status of all children to IDLE.
59+
/// also send a halt() signal to all RUNNING children
60+
void resetChildren();
5661
};
5762
} // namespace BT

include/behaviortree_cpp/controls/switch_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ inline NodeStatus SwitchNode<NUM_CASES>::tick()
126126
}
127127
else
128128
{
129-
haltChildren();
129+
resetChildren();
130130
running_child_ = -1;
131131
}
132132
return ret;

include/behaviortree_cpp/decorator_node.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DecoratorNode : public TreeNode
2424
/// The method used to interrupt the execution of this node
2525
virtual void halt() override;
2626

27-
/// Halt() the child node
27+
/// Same as resetChild()
2828
void haltChild();
2929

3030
virtual NodeType type() const override
@@ -33,6 +33,10 @@ class DecoratorNode : public TreeNode
3333
}
3434

3535
NodeStatus executeTick() override;
36+
37+
/// Set the status of the child to IDLE.
38+
/// also send a halt() signal to a RUNNING child
39+
void resetChild();
3640
};
3741

3842
/**

include/behaviortree_cpp/tree_node.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma once
1515

1616
#include <condition_variable>
17+
#include <exception>
1718
#include <mutex>
1819
#include <map>
1920

@@ -79,7 +80,7 @@ struct NodeConfig
7980

8081
#ifdef USE_BTCPP3_OLD_NAMES
8182
// back compatibility
82-
using NodeConfig = NodeConfig;
83+
using NodeConfiguration = NodeConfig;
8384
#endif
8485

8586
template <typename T>
@@ -247,7 +248,6 @@ class TreeNode
247248
node_ptr->config_ = config;
248249
return std::unique_ptr<DerivedT>(node_ptr);
249250
}
250-
return {};
251251
}
252252

253253
protected:
@@ -343,9 +343,9 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
343343

344344
std::unique_lock<std::mutex> entry_lock(config_.blackboard->entryMutex());
345345
const Any* val = config_.blackboard->getAny(static_cast<std::string>(remapped_key));
346-
if (val && val->empty() == false)
346+
if (val && !val->empty())
347347
{
348-
if (std::is_same<T, std::string>::value == false &&
348+
if (!std::is_same_v<T, std::string> &&
349349
val->type() == typeid(std::string))
350350
{
351351
destination = convertFromString<T>(val->cast<std::string>());

src/basic_types.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ PortDirection convertFromString<PortDirection>(StringView str)
253253
return PortDirection::INPUT;
254254
if (str == "Output" || str == "OUTPUT")
255255
return PortDirection::OUTPUT;
256-
return PortDirection::INOUT;
256+
if (str == "InOut" || str == "INOUT")
257+
return PortDirection::INOUT;
258+
throw RuntimeError(std::string("Cannot convert this to PortDirection: ") +
259+
static_cast<std::string>(str));
257260
}
258261

259262
std::ostream& operator<<(std::ostream& os, const NodeType& type)
@@ -287,7 +290,7 @@ std::vector<StringView> splitString(const StringView& strToSplit, char delimeter
287290
{
288291
new_pos = strToSplit.size();
289292
}
290-
StringView sv = {&strToSplit.data()[pos], new_pos - pos};
293+
const auto sv = StringView{&strToSplit.data()[pos], new_pos - pos};
291294
splitted_strings.push_back(sv);
292295
pos = new_pos + 1;
293296
}

src/control_node.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ size_t ControlNode::childrenCount() const
3131

3232
void ControlNode::halt()
3333
{
34-
haltChildren();
34+
resetChildren();
35+
}
36+
37+
void ControlNode::resetChildren()
38+
{
39+
for (auto child: children_nodes_)
40+
{
41+
if (child->status() == NodeStatus::RUNNING)
42+
{
43+
child->halt();
44+
}
45+
child->resetStatus();
46+
}
3547
}
3648

3749
const std::vector<TreeNode*>& ControlNode::children() const

0 commit comments

Comments
 (0)