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

Skip to content

Commit 34509f8

Browse files
author
Davide Faconti
committed
changed funtor signature
1 parent c043fd4 commit 34509f8

File tree

10 files changed

+31
-32
lines changed

10 files changed

+31
-32
lines changed

examples/t04_blackboard.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ const std::string xml_text = R"(
4141

4242
// Write into the blackboard key: [GoalPose]
4343
// Use this function signature to create a SimpleAction that needs the blackboard
44-
NodeStatus CalculateGoalPose(const Blackboard::Ptr& blackboard)
44+
NodeStatus CalculateGoalPose(TreeNode& self)
4545
{
4646
const Pose2D mygoal = { 1, 2, M_PI};
4747

4848
// RECOMMENDED: check if the blackboard is nullptr
49-
if( blackboard )
49+
if( self.blackboard() )
5050
{
5151
// store it in the blackboard
52-
blackboard->set("GoalPose", mygoal);
52+
self.blackboard()->set("GoalPose", mygoal);
5353
}
5454

5555
printf("[CalculateGoalPose]\n");

include/behavior_tree_core/action_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ActionNodeBase : public LeafNode
4747
class SimpleActionNode : public ActionNodeBase
4848
{
4949
public:
50-
typedef std::function<NodeStatus(const Blackboard::Ptr&)> TickFunctor;
50+
typedef std::function<NodeStatus(TreeNode&)> TickFunctor;
5151

5252
// Constructor: you must provide the function to call when tick() is invoked
5353
SimpleActionNode(const std::string& name, TickFunctor tick_functor);

include/behavior_tree_core/condition_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ConditionNode : public LeafNode
4949
class SimpleConditionNode : public ConditionNode
5050
{
5151
public:
52-
typedef std::function<NodeStatus(const Blackboard::Ptr&)> TickFunctor;
52+
typedef std::function<NodeStatus(TreeNode&)> TickFunctor;
5353

5454
// Constructor: you must provide the function to call when tick() is invoked
5555
SimpleConditionNode(const std::string& name, TickFunctor tick_functor);

include/behavior_tree_core/decorator_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DecoratorNode : public TreeNode
4747
class SimpleDecoratorNode : public DecoratorNode
4848
{
4949
public:
50-
typedef std::function<NodeStatus(NodeStatus,const Blackboard::Ptr&)> TickFunctor;
50+
typedef std::function<NodeStatus(NodeStatus, TreeNode&)> TickFunctor;
5151

5252
// Constructor: you must provide the function to call when tick() is invoked
5353
SimpleDecoratorNode(const std::string& name, TickFunctor tick_functor);

sample_nodes/crossdoor_nodes.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,66 @@ BT_REGISTER_NODES(factory)
88
}
99

1010

11-
NodeStatus CrossDoor::IsDoorOpen(const Blackboard::Ptr &blackboard)
11+
NodeStatus CrossDoor::IsDoorOpen(TreeNode &self)
1212
{
1313
SleepMS(500);
14-
bool door_open = blackboard->get<bool>("door_open");
14+
bool door_open = self.blackboard()->get<bool>("door_open");
1515

1616
return door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
1717
}
1818

19-
NodeStatus CrossDoor::IsDoorLocked(const Blackboard::Ptr &blackboard)
19+
NodeStatus CrossDoor::IsDoorLocked(TreeNode &self)
2020
{
2121
SleepMS(500);
22-
bool door_locked = blackboard->get<bool>("door_locked");
22+
bool door_locked = self.blackboard()->get<bool>("door_locked");
2323

2424
return door_locked ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
2525
}
2626

27-
NodeStatus CrossDoor::UnlockDoor(const Blackboard::Ptr &blackboard)
27+
NodeStatus CrossDoor::UnlockDoor(TreeNode &self)
2828
{
2929
SleepMS(2000);
30-
blackboard->set("door_locked", false);
30+
self.blackboard()->set("door_locked", false);
3131

3232
return NodeStatus::SUCCESS;
3333
}
3434

35-
NodeStatus CrossDoor::PassThroughDoor(const Blackboard::Ptr &blackboard)
35+
NodeStatus CrossDoor::PassThroughDoor(TreeNode &self)
3636
{
3737
SleepMS(1000);
38-
bool door_open = blackboard->get<bool>("door_open");
38+
bool door_open = self.blackboard()->get<bool>("door_open");
3939

4040
return door_open ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
4141
}
4242

43-
NodeStatus CrossDoor::PassThroughWindow(const Blackboard::Ptr &blackboard)
43+
NodeStatus CrossDoor::PassThroughWindow(TreeNode &self)
4444
{
4545
SleepMS(1000);
4646
return NodeStatus::SUCCESS;
4747
}
4848

49-
NodeStatus CrossDoor::OpenDoor(const Blackboard::Ptr &blackboard)
49+
NodeStatus CrossDoor::OpenDoor(TreeNode &self)
5050
{
5151
SleepMS(2000);
52-
bool door_locked = blackboard->get<bool>("door_locked");
52+
bool door_locked = self.blackboard()->get<bool>("door_locked");
5353

5454
if (door_locked)
5555
{
5656
return NodeStatus::FAILURE;
5757
}
5858

59-
blackboard->set("door_open", true);
59+
self.blackboard()->set("door_open", true);
6060
return NodeStatus::SUCCESS;
6161
}
6262

63-
NodeStatus CrossDoor::CloseDoor(const Blackboard::Ptr &blackboard)
63+
NodeStatus CrossDoor::CloseDoor(TreeNode &self)
6464
{
65-
bool door_open = blackboard->get<bool>("door_open");
65+
bool door_open = self.blackboard()->get<bool>("door_open");
6666

6767
if (door_open)
6868
{
6969
SleepMS(1500);
70-
blackboard->set("door_open", false);
70+
self.blackboard()->set("door_open", false);
7171
}
7272
return NodeStatus::SUCCESS;
7373
}

sample_nodes/crossdoor_nodes.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ inline void SleepMS(int ms)
1010
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
1111
}
1212

13-
BT::NodeStatus IsDoorOpen(const Blackboard::Ptr& blackboard);
13+
BT::NodeStatus IsDoorOpen(TreeNode &self);
1414

15-
BT::NodeStatus IsDoorLocked(const Blackboard::Ptr& blackboard);
15+
BT::NodeStatus IsDoorLocked(TreeNode &self);
1616

17-
BT::NodeStatus UnlockDoor(const Blackboard::Ptr& blackboard);
17+
BT::NodeStatus UnlockDoor(TreeNode &self);
1818

19-
BT::NodeStatus PassThroughDoor(const Blackboard::Ptr& blackboard);
19+
BT::NodeStatus PassThroughDoor(TreeNode &self);
2020

21-
BT::NodeStatus PassThroughWindow(const Blackboard::Ptr& blackboard);
21+
BT::NodeStatus PassThroughWindow(TreeNode &self);
2222

23-
BT::NodeStatus OpenDoor(const Blackboard::Ptr& blackboard);
23+
BT::NodeStatus OpenDoor(TreeNode &self);
2424

25-
BT::NodeStatus CloseDoor(const Blackboard::Ptr& blackboard);
25+
BT::NodeStatus CloseDoor(TreeNode &self);
2626

2727
void RegisterNodes(BT::BehaviorTreeFactory& factory);
2828

sample_nodes/dummy_nodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class SaySomething: public BT::ActionNodeBase
6060

6161
// It is mandatory to define this static method.
6262
// If you don't, BehaviorTreeFactory::registerNodeType will not compile.
63-
//
6463
static const BT::NodeParameters& requiredNodeParameters()
6564
{
6665
static BT::NodeParameters params = {{"message",""}};

src/action_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ NodeStatus SimpleActionNode::tick()
3737
prev_status = NodeStatus::RUNNING;
3838
}
3939

40-
NodeStatus status = tick_functor_( blackboard() );
40+
NodeStatus status = tick_functor_( *this );
4141
if (status != prev_status)
4242
{
4343
setStatus(status);

src/condition_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SimpleConditionNode::SimpleConditionNode(const std::string &name,
3434

3535
NodeStatus SimpleConditionNode::tick()
3636
{
37-
return tick_functor_(blackboard());
37+
return tick_functor_(*this);
3838
}
3939

4040
}

src/decorator_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ SimpleDecoratorNode::SimpleDecoratorNode(const std::string &name,
6565

6666
NodeStatus SimpleDecoratorNode::tick()
6767
{
68-
return tick_functor_( child()->executeTick(), blackboard() );
68+
return tick_functor_( child()->executeTick(), *this );
6969
}
7070

7171
}

0 commit comments

Comments
 (0)