Skip to content

Commit e5e60db

Browse files
committed
do not skip pre-post condition in substituted tick
1 parent 8e9a77e commit e5e60db

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

include/behaviortree_cpp/tree_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class TreeNode
354354

355355
std::string registration_ID_;
356356

357-
PreTickCallback pre_condition_callback_;
357+
PreTickCallback substitution_callback_;
358358

359359
PostTickCallback post_condition_callback_;
360360

src/tree_node.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@ NodeStatus TreeNode::executeTick()
2727
{
2828
auto new_status = status_;
2929

30-
// injected pre-callback
31-
if(status_ == NodeStatus::IDLE)
32-
{
33-
PreTickCallback callback;
34-
{
35-
std::unique_lock lk(callback_injection_mutex_);
36-
callback = pre_condition_callback_;
37-
}
38-
if(callback)
39-
{
40-
auto override_status = callback(*this);
41-
if(isStatusCompleted(override_status))
42-
{
43-
// return immediately and don't execute the actual tick()
44-
new_status = override_status;
45-
setStatus(new_status);
46-
return new_status;
47-
}
48-
}
49-
}
50-
5130
// a pre-condition may return the new status.
5231
// In this case it override the actual tick()
5332
if (auto precond = checkPreConditions())
@@ -56,8 +35,31 @@ NodeStatus TreeNode::executeTick()
5635
}
5736
else
5837
{
59-
//Call the actual tick
60-
new_status = tick();
38+
// injected pre-callback
39+
bool substituted = false;
40+
if(status_ == NodeStatus::IDLE)
41+
{
42+
PreTickCallback callback;
43+
{
44+
std::unique_lock lk(callback_injection_mutex_);
45+
callback = substitution_callback_;
46+
}
47+
if(callback)
48+
{
49+
auto override_status = callback(*this);
50+
if(isStatusCompleted(override_status))
51+
{
52+
// don't execute the actual tick()
53+
substituted = true;
54+
new_status = override_status;
55+
}
56+
}
57+
}
58+
59+
// Call the ACTUAL tick
60+
if(!substituted){
61+
new_status = tick();
62+
}
6163
}
6264

6365
checkPostConditions(new_status);
@@ -242,7 +244,7 @@ TreeNode::subscribeToStatusChange(TreeNode::StatusChangeCallback callback)
242244
void TreeNode::setPreTickFunction(PreTickCallback callback)
243245
{
244246
std::unique_lock lk(callback_injection_mutex_);
245-
pre_condition_callback_ = callback;
247+
substitution_callback_ = callback;
246248
}
247249

248250
void TreeNode::setPostTickFunction(PostTickCallback callback)

0 commit comments

Comments
 (0)