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

Skip to content

Commit f0978ea

Browse files
committed
Merge branch 'master' into ros2
2 parents 874c742 + e05ad94 commit f0978ea

31 files changed

+633
-214
lines changed

CHANGELOG.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
Changelog for package behaviortree_cpp
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
2.5.0 (2018-12-12)
6+
------------------
7+
* Introducing SyncActionNode that is more self explaining and less ambiguous
8+
* fix potential problem related to ControlNode::haltChildren()
9+
* Adding example/test of navigation and recovery behavior. Related to issue #36
10+
* Contributors: Davide Faconti
11+
12+
2.4.4 (2018-12-12)
13+
------------------
14+
* adding virtual TreeNode::onInit() [issue #33]
15+
* fix issue #34 : if you don't implement convertFromString, it will compile but it may throw
16+
* Pretty demangled names and obsolate comments removed
17+
* bug fixes
18+
* more comments
19+
* [enhancement #32]: add CoroActionNode and rename ActionNode as "AsynActionNode"
20+
The name ActionNode was confusing and it has been deprecated.
21+
* Update README.md
22+
* removed old file
23+
* Fix issue #31 : convertFromString mandatory for TreeNode::getParam, not Blackboard::get
24+
* Cherry piking changes from PR #19 which solve issue #2 CONAN support
25+
* Contributors: Davide Faconti
26+
527
2.4.3 (2018-12-07)
628
------------------
729
* Merge branch 'master' into ros2

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ set(BT_TESTS
164164
gtest/gtest_fallback.cpp
165165
gtest/gtest_factory.cpp
166166
gtest/gtest_decorator.cpp
167+
gtest/gtest_blackboard.cpp
168+
gtest/navigation_test.cpp
167169
)
168170

169171
if(ament_cmake_FOUND AND BUILD_TESTING)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
![License MIT](https://img.shields.io/dub/l/vibe-d.svg)
2-
![Version](https://img.shields.io/badge/version-v2.4-green.svg)
2+
![Version](https://img.shields.io/badge/version-v2.5-green.svg)
33
[![Build Status](https://travis-ci.org/BehaviorTree/BehaviorTree.CPP.svg?branch=master)](https://travis-ci.org/BehaviorTree/BehaviorTree.CPP)
44

55
Question? [![Join the chat at https://gitter.im/BehaviorTree-ROS/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/BehaviorTree-ROS/Lobby?utm_source=badge&utm_medium=badge&utm_content=badge)

docs/getting_started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ a long calculation.
3434
To create a custom TreeNode, you should inherit from the proper class.
3535

3636
For instance, to create your own synchronous Action, you should inherit from the
37-
class __ActionNodeBase__.
37+
class __SyncActionNode__.
3838

3939
Alternatively, we provided a mechanism to create a TreeNode passing a
4040
__function pointer__ to a wrapper (dependency injection).

docs/tutorial_A_create_trees.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@ You can find the source code here: **sample_nodes/dummy_nodes.h**.
1515
The default (and recommended) way to create a TreeNode is by inheritance.
1616

1717
``` c++
18-
// Example of custom ActionNodeBase (synchronous Action)
19-
class ApproachObject: public BT::ActionNodeBase
18+
// Example of custom SyncActionNode (synchronous Action)
19+
class ApproachObject: public BT::SyncActionNode
2020
{
2121
public:
2222
ApproachObject(const std::string& name):
23-
BT::ActionNodeBase(name) {}
23+
BT::SyncActionNode(name) {}
2424

2525
// You must override this virtual function
2626
BT::NodeStatus tick() override
2727
{
28-
std::cout << "ApproachObject: " << this->name() << std::endl;
29-
return BT::NodeStatus::SUCCESS;
30-
}
31-
32-
// You must override this virtual function
33-
virtual void halt() override
34-
{
35-
// Do nothing. This is used by asynchronous nodes only.
28+
std::cout << "ApproachObject: " << this->name() << std::endl;
29+
return BT::NodeStatus::SUCCESS;
3630
}
3731
};
3832
```

docs/tutorial_B_node_parameters.md

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ read from file.
77

88
To create a TreeNodes that accepts NodeParameters, you must follow these rules:
99

10-
- Inherit from either ActionNodeBase, ActionNode, ConditionNode or DecoratorNode.
10+
- Inherit from either ActionNode, ConditionNode or DecoratorNode.
1111

1212
- You must provide a constructor with the following signature:
1313

@@ -27,7 +27,7 @@ Check the [tutorial 6](tutorial_G_legacy.md) for details.
2727

2828
## Example: an Action requiring the parameter "message"
2929

30-
`SaySomething` is a simple synchronous ActionNodeBase which will print the
30+
`SaySomething` is a simple SyncActionNode which will print the
3131
string passed in the NodeParameter called "message".
3232

3333
Please note:
@@ -41,12 +41,12 @@ Please note:
4141
`tick()` method.
4242

4343
``` c++ hl_lines="5 9 18"
44-
class SaySomething: public ActionNodeBase
44+
class SaySomething: public SyncActionNode
4545
{
4646
public:
4747
// There must be a constructor with this signature
4848
SaySomething(const std::string& name, const NodeParameters& params):
49-
ActionNodeBase(name, params) {}
49+
SyncActionNode(name, params) {}
5050

5151
// It is mandatory to define this static method.
5252
static const NodeParameters& requiredNodeParameters()
@@ -57,20 +57,18 @@ public:
5757

5858
virtual NodeStatus tick() override
5959
{
60-
std::string msg;
61-
if( getParam("message", msg) == false )
62-
{
63-
// if getParam failed, use the default value
64-
msg = requiredNodeParameters().at("message");
65-
}
66-
std::cout << "Robot says: " << msg << std::endl;
67-
return BT::NodeStatus::SUCCESS;
68-
}
69-
virtual void halt() override {}
60+
std::string msg;
61+
if( getParam("message", msg) == false )
62+
{
63+
// if getParam failed, use the default value
64+
msg = requiredNodeParameters().at("message");
65+
}
66+
std::cout << "Robot says: " << msg << std::endl;
67+
return BT::NodeStatus::SUCCESS;
68+
}
7069
};
7170
```
7271

73-
7472
## Example: conversion to user defined C++ types
7573

7674
In the next example we have a user defined type `Pose2D`.
@@ -146,36 +144,36 @@ public:
146144
return params;
147145
}
148146

149-
virtual NodeStatus tick() override
150-
{
151-
Pose2D goal;
147+
virtual NodeStatus tick() override
148+
{
149+
Pose2D goal;
152150
if( getParam<Pose2D>("goal", goal) == false )
153151
{
154152
auto default_goal = requiredNodeParameters().at("goal");
155153
goal = BT::convertFromString<Pose2D>( default_goal_value );
156154
}
157155
158-
printf("[ MoveBase: STARTED ]. goal: x=%.f y=%.1f theta=%.2f\n",
159-
goal.x, goal.y, goal.theta);
156+
printf("[ MoveBase: STARTED ]. goal: x=%.f y=%.1f theta=%.2f\n",
157+
goal.x, goal.y, goal.theta);
160158

161-
halt_requested_ = false;
159+
halt_requested_ = false;
162160
163-
int count = 0;
164-
// "compute" for 250 milliseconds or until halt_requested_
165-
while( !halt_requested_ && count++ < 25)
166-
{
167-
SleepMilliseconds(10);
168-
}
169-
170-
std::cout << "[ MoveBase: FINISHED ]" << std::endl;
171-
return halt_requested_ ? NodeStatus::FAILURE :
172-
NodeStatus::SUCCESS;
173-
}
174-
175-
virtual void halt() override
176-
{
177-
halt_requested_ = true;
178-
}
161+
int count = 0;
162+
// "compute" for 250 milliseconds or until halt_requested_
163+
while( !halt_requested_ && count++ < 25)
164+
{
165+
SleepMilliseconds(10);
166+
}
167+
168+
std::cout << "[ MoveBase: FINISHED ]" << std::endl;
169+
return halt_requested_ ? NodeStatus::FAILURE :
170+
NodeStatus::SUCCESS;
171+
}
172+
173+
virtual void halt() override
174+
{
175+
halt_requested_ = true;
176+
}
179177
private:
180178
bool halt_requested_;
181179
};

gtest/gtest_blackboard.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* Copyright (C) 2018 Davide Faconti - All Rights Reserved
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4+
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
*/
12+
13+
#include <gtest/gtest.h>
14+
#include "action_test_node.h"
15+
#include "condition_test_node.h"
16+
#include "behaviortree_cpp/behavior_tree.h"
17+
#include "behaviortree_cpp/blackboard/blackboard_local.h"
18+
19+
using namespace BT;
20+
21+
class InitTestNode: public SyncActionNode
22+
{
23+
public:
24+
InitTestNode(bool try_to_access_bb, const std::string& name):
25+
SyncActionNode(name),
26+
_value(0)
27+
{
28+
if( try_to_access_bb )
29+
{
30+
// this should throw
31+
blackboard()->set(KEY(), 33);
32+
}
33+
}
34+
35+
void onInit() {
36+
blackboard()->get(KEY(), _value);
37+
}
38+
39+
NodeStatus tick()
40+
{
41+
_value *= 2;
42+
blackboard()->set(KEY(), _value);
43+
return NodeStatus::SUCCESS;
44+
}
45+
46+
static const char* KEY() { return "my_entry"; }
47+
48+
private:
49+
int _value;
50+
};
51+
52+
53+
54+
55+
/****************TESTS START HERE***************************/
56+
57+
TEST(BlackboardTest, CheckOInit)
58+
{
59+
auto bb = Blackboard::create<BlackboardLocal>();
60+
const auto KEY = InitTestNode::KEY();
61+
62+
EXPECT_THROW( InitTestNode(true,"init_test"), std::logic_error );
63+
64+
InitTestNode node(false,"init_test");
65+
node.setBlackboard(bb);
66+
67+
bb->set(KEY, 11 );
68+
69+
// this should read and write "my_entry", respectively in onInit() and tick()
70+
node.executeTick();
71+
72+
ASSERT_EQ( bb->get<int>(KEY), 22 );
73+
74+
// check that onInit is executed only once
75+
bb->set(KEY, 1 );
76+
77+
// since this value is read in OnInit(), the node will not notice the change in bb
78+
node.setStatus( NodeStatus::IDLE );
79+
node.executeTick();
80+
ASSERT_EQ( bb->get<int>(KEY), 44 );
81+
}

gtest/gtest_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ TEST(BehaviorTreeFactory, VerifyLargeTree)
8787

8888
std::vector<BT::TreeNode::Ptr> nodes;
8989

90-
BT::TreeNode::Ptr root_node = parser.instantiateTree(nodes);
90+
BT::TreeNode::Ptr root_node = parser.instantiateTree(nodes, Blackboard::Ptr());
9191

9292
BT::printTreeRecursively(root_node.get());
9393

@@ -133,7 +133,7 @@ TEST(BehaviorTreeFactory, Subtree)
133133

134134
std::vector<BT::TreeNode::Ptr> nodes;
135135

136-
BT::TreeNode::Ptr root_node = parser.instantiateTree(nodes);
136+
BT::TreeNode::Ptr root_node = parser.instantiateTree(nodes, Blackboard::Ptr());
137137
BT::printTreeRecursively(root_node.get());
138138

139139
ASSERT_EQ(root_node->name(), "root_selector");

gtest/include/action_test_node.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66
namespace BT
77
{
8-
class SyncActionTest : public ActionNodeBase
8+
class SyncActionTest : public SyncActionNode
99
{
1010
public:
1111
SyncActionTest(const std::string& name);
1212

1313
BT::NodeStatus tick() override;
1414

15-
virtual void halt() override
16-
{
17-
}
18-
1915
void setBoolean(bool boolean_value);
2016

2117
int tickCount() const
@@ -33,7 +29,7 @@ class SyncActionTest : public ActionNodeBase
3329
int tick_count_;
3430
};
3531

36-
class AsyncActionTest : public ActionNode
32+
class AsyncActionTest : public AsyncActionNode
3733
{
3834
public:
3935
AsyncActionTest(const std::string& name);

0 commit comments

Comments
 (0)