Skip to content

Commit

Permalink
Fix issue BehaviorTree#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Faconti committed Nov 22, 2018
1 parent c8092e3 commit af22b2a
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions include/behaviortree_cpp/decorators/blackboard_precondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,40 @@ class BlackboardPreconditionNode : public DecoratorNode
}

private:
virtual BT::NodeStatus tick() override
virtual BT::NodeStatus tick() override;
};

//----------------------------------------------------

template<typename T> inline
NodeStatus BlackboardPreconditionNode<T>::tick()
{
std::string key;
T expected_value;
T current_value;

getParam("key", key);
setStatus(NodeStatus::RUNNING);

// check if the key is present in the blackboard
if ( !blackboard() || !(blackboard()->contains(key)) )
{
std::string key;
T expected;
T value;

setStatus(NodeStatus::RUNNING);

if (blackboard() && //blackboard not null
getParam("key", key) && // parameter key provided
getParam("expected", expected) && // parameter expected provided
blackboard()->get(key, value) && // value found in blackboard
(value == expected ||
initializationParameters().at("expected") == "*")) // is expected value or "*"
{
return child_node_->executeTick();
}
else
{
return NodeStatus::FAILURE;
}
return NodeStatus::FAILURE;
}
};

if( initializationParameters().at("expected") == "*" )
{
return child_node_->executeTick();
}

bool same = ( getParam("expected", expected_value) &&
blackboard()->get(key, current_value) &&
current_value == expected_value ) ;

return same ? child_node_->executeTick() :
NodeStatus::FAILURE;
}

}

#endif

0 comments on commit af22b2a

Please sign in to comment.