Skip to content

Commit 3325745

Browse files
committed
Merge branch 'master' of github.com:BehaviorTree/BehaviorTree.CPP
2 parents 26d0e3c + 0dd404b commit 3325745

File tree

9 files changed

+43
-35
lines changed

9 files changed

+43
-35
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

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/tree_node.h

Lines changed: 4 additions & 3 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>
@@ -343,9 +344,9 @@ inline Result TreeNode::getInput(const std::string& key, T& destination) const
343344

344345
std::unique_lock<std::mutex> entry_lock(config_.blackboard->entryMutex());
345346
const Any* val = config_.blackboard->getAny(static_cast<std::string>(remapped_key));
346-
if (val && val->empty() == false)
347+
if (val && !val->empty())
347348
{
348-
if (std::is_same<T, std::string>::value == false &&
349+
if (!std::is_same_v<T, std::string> &&
349350
val->type() == typeid(std::string))
350351
{
351352
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/controls/fallback_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
#include "behaviortree_cpp/controls/fallback_node.h"
15-
#include "behaviortree_cpp/action_node.h"
15+
1616
namespace BT
1717
{
1818
FallbackNode::FallbackNode(const std::string& name) :

src/decorators/repeat_node.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
namespace BT
1717
{
18-
constexpr const char* RepeatNode::NUM_CYCLES;
1918

2019
RepeatNode::RepeatNode(const std::string& name, int NTries) :
2120
DecoratorNode(name, {}),

tests/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ if( BTCPP_ENABLE_COROUTINES AND BT_COROUTINES_FOUND )
2828
LIST( APPEND BT_TESTS gtest_coroutines.cpp)
2929
endif()
3030

31-
#if(ament_cmake_FOUND OR catkin_FOUND)
32-
# # This test requires gmock. Since we don't have a uniform way to include
33-
# # gmock for non-users, it is turned of when build without ros.
34-
# list(APPEND BT_TESTS gtest_async_action_node.cpp)
35-
#endif()
36-
3731

3832
if(ament_cmake_FOUND AND BUILD_TESTING)
3933

@@ -81,4 +75,14 @@ elseif(BTCPP_UNIT_TESTS)
8175

8276
endif()
8377

78+
# if(BUILD_TESTING AND (ament_cmake_FOUND OR catkin_FOUND))
79+
# # This test requires gmock. Since we don't have a uniform way to include
80+
# # gmock for non-users, it is turned of when build without ros.
81+
# list(APPEND BT_TESTS gtest_async_action_node.cpp)
82+
# target_link_libraries(${BEHAVIOR_TREE_LIBRARY}_test
83+
# ${BEHAVIOR_TREE_LIBRARY}
84+
# gmock
85+
# )
86+
# endif()
87+
8488
target_compile_definitions(${BEHAVIOR_TREE_LIBRARY}_test PRIVATE BT_TEST_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}")

tests/gtest_async_action_node.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <gmock/gmock.h>
1414

1515
// The mocked version of the base.
16-
struct MockedAsyncActionNode : public BT::AsyncActionNode
16+
struct MockedThreadedAction : public BT::ThreadedAction
1717
{
18-
using BT::AsyncActionNode::AsyncActionNode;
18+
using BT::ThreadedAction::ThreadedAction;
1919
MOCK_METHOD0(tick, BT::NodeStatus());
2020

2121
// Tick while the node is running.
@@ -29,25 +29,25 @@ struct MockedAsyncActionNode : public BT::AsyncActionNode
2929
}
3030

3131
// Expose the setStatus method.
32-
using BT::AsyncActionNode::setStatus;
32+
using BT::ThreadedAction::setStatus;
3333
};
3434

3535
// The fixture taking care of the node-setup.
36-
struct MockedAsyncActionFixture : public testing::Test
36+
struct MockedThreadedActionFixture : public testing::Test
3737
{
3838
BT::NodeConfig config;
39-
MockedAsyncActionNode sn;
40-
MockedAsyncActionFixture() : sn("node", config)
39+
MockedThreadedAction sn;
40+
MockedThreadedActionFixture() : sn("node", config)
4141
{}
4242
};
4343

4444
// Parameters for the terminal node states.
4545
struct NodeStatusFixture : public testing::WithParamInterface<BT::NodeStatus>,
46-
public MockedAsyncActionFixture
46+
public MockedThreadedActionFixture
4747
{
4848
};
4949

50-
INSTANTIATE_TEST_CASE_P(/**/, NodeStatusFixture,
50+
INSTANTIATE_TEST_SUITE_P(/**/, NodeStatusFixture,
5151
testing::Values(BT::NodeStatus::SUCCESS,
5252
BT::NodeStatus::FAILURE));
5353

@@ -67,7 +67,7 @@ TEST_P(NodeStatusFixture, normal_routine)
6767
ASSERT_EQ(sn.spinUntilDone(), state);
6868
}
6969

70-
TEST_F(MockedAsyncActionFixture, no_halt)
70+
TEST_F(MockedThreadedActionFixture, no_halt)
7171
{
7272
// Test verifies that halt returns immediately, if the node is idle. It
7373
// further checks if the halt-flag is resetted correctly.
@@ -83,7 +83,7 @@ TEST_F(MockedAsyncActionFixture, no_halt)
8383
ASSERT_FALSE(sn.isHaltRequested());
8484
}
8585

86-
TEST_F(MockedAsyncActionFixture, halt)
86+
TEST_F(MockedThreadedActionFixture, halt)
8787
{
8888
// Test verifies that calling halt() is blocking.
8989
bool release = false;
@@ -120,7 +120,7 @@ TEST_F(MockedAsyncActionFixture, halt)
120120
ASSERT_EQ(sn.status(), state);
121121
}
122122

123-
TEST_F(MockedAsyncActionFixture, exception)
123+
TEST_F(MockedThreadedActionFixture, exception)
124124
{
125125
// Verifies that we can recover from the exceptions in the tick method:
126126
// 1) catch the exception, 2) re-raise it in the caller thread.

0 commit comments

Comments
 (0)