Skip to content

Commit af22b2a

Browse files
author
Davide Faconti
committed
Fix issue #16
1 parent c8092e3 commit af22b2a

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

include/behaviortree_cpp/decorators/blackboard_precondition.h

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,40 @@ class BlackboardPreconditionNode : public DecoratorNode
3535
}
3636

3737
private:
38-
virtual BT::NodeStatus tick() override
38+
virtual BT::NodeStatus tick() override;
39+
};
40+
41+
//----------------------------------------------------
42+
43+
template<typename T> inline
44+
NodeStatus BlackboardPreconditionNode<T>::tick()
45+
{
46+
std::string key;
47+
T expected_value;
48+
T current_value;
49+
50+
getParam("key", key);
51+
setStatus(NodeStatus::RUNNING);
52+
53+
// check if the key is present in the blackboard
54+
if ( !blackboard() || !(blackboard()->contains(key)) )
3955
{
40-
std::string key;
41-
T expected;
42-
T value;
43-
44-
setStatus(NodeStatus::RUNNING);
45-
46-
if (blackboard() && //blackboard not null
47-
getParam("key", key) && // parameter key provided
48-
getParam("expected", expected) && // parameter expected provided
49-
blackboard()->get(key, value) && // value found in blackboard
50-
(value == expected ||
51-
initializationParameters().at("expected") == "*")) // is expected value or "*"
52-
{
53-
return child_node_->executeTick();
54-
}
55-
else
56-
{
57-
return NodeStatus::FAILURE;
58-
}
56+
return NodeStatus::FAILURE;
5957
}
60-
};
58+
59+
if( initializationParameters().at("expected") == "*" )
60+
{
61+
return child_node_->executeTick();
62+
}
63+
64+
bool same = ( getParam("expected", expected_value) &&
65+
blackboard()->get(key, current_value) &&
66+
current_value == expected_value ) ;
67+
68+
return same ? child_node_->executeTick() :
69+
NodeStatus::FAILURE;
70+
}
71+
6172
}
6273

6374
#endif

0 commit comments

Comments
 (0)