File tree Expand file tree Collapse file tree 10 files changed +37
-37
lines changed Expand file tree Collapse file tree 10 files changed +37
-37
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ class DecoratorNode : public TreeNode
31
31
{
32
32
return NodeType::DECORATOR;
33
33
}
34
+
35
+ NodeStatus executeTick () override ;
34
36
};
35
37
36
38
/* *
Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ inline NodeStatus ForceFailureDecorator::tick()
42
42
case NodeStatus::FAILURE:
43
43
case NodeStatus::SUCCESS:
44
44
{
45
- child_node_->setStatus (NodeStatus::IDLE);
46
45
return NodeStatus::FAILURE;
47
46
}
48
47
Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ inline NodeStatus ForceSuccessDecorator::tick()
42
42
case NodeStatus::FAILURE:
43
43
case NodeStatus::SUCCESS:
44
44
{
45
- child_node_->setStatus (NodeStatus::IDLE);
46
45
return NodeStatus::SUCCESS;
47
46
}
48
47
Original file line number Diff line number Diff line change @@ -41,8 +41,11 @@ class RepeatNode : public DecoratorNode
41
41
bool read_parameter_from_blackboard_;
42
42
static constexpr const char * NUM_CYCLES = " num_cycles" ;
43
43
44
- virtual BT::NodeStatus tick () override ;
44
+ virtual NodeStatus tick () override ;
45
+
46
+ void halt () override ;
45
47
};
48
+
46
49
}
47
50
48
51
#endif
Original file line number Diff line number Diff line change @@ -67,4 +67,16 @@ NodeStatus SimpleDecoratorNode::tick()
67
67
{
68
68
return tick_functor_ (child ()->executeTick (), *this );
69
69
}
70
+
71
+ NodeStatus DecoratorNode::executeTick ()
72
+ {
73
+ NodeStatus status = TreeNode::executeTick ();
74
+ NodeStatus child_status =child ()->status ();
75
+ if ( child_status == NodeStatus::SUCCESS || child_status == NodeStatus::FAILURE )
76
+ {
77
+ child ()->setStatus (NodeStatus::IDLE);
78
+ }
79
+ return status;
80
+ }
81
+
70
82
}
Original file line number Diff line number Diff line change @@ -30,23 +30,18 @@ NodeStatus InverterNode::tick()
30
30
{
31
31
case NodeStatus::SUCCESS:
32
32
{
33
- setStatus (NodeStatus::FAILURE);
34
- child_node_->setStatus (NodeStatus::IDLE);
33
+ return NodeStatus::FAILURE;
35
34
}
36
- break ;
37
35
38
36
case NodeStatus::FAILURE:
39
37
{
40
- setStatus (NodeStatus::SUCCESS);
41
- child_node_->setStatus (NodeStatus::IDLE);
38
+ return NodeStatus::SUCCESS;
42
39
}
43
- break ;
44
40
45
41
case NodeStatus::RUNNING:
46
42
{
47
- setStatus ( NodeStatus::RUNNING) ;
43
+ return NodeStatus::RUNNING;
48
44
}
49
- break ;
50
45
51
46
default :
52
47
{
Original file line number Diff line number Diff line change @@ -61,33 +61,35 @@ NodeStatus RepeatNode::tick()
61
61
try_index_++;
62
62
if (try_index_ >= num_cycles_)
63
63
{
64
- setStatus (NodeStatus::SUCCESS);
65
64
try_index_ = 0 ;
65
+ return (NodeStatus::SUCCESS);
66
66
}
67
- child_node_->setStatus (NodeStatus::IDLE);
68
67
}
69
68
break ;
70
69
71
70
case NodeStatus::FAILURE:
72
71
{
73
72
try_index_ = 0 ;
74
- setStatus (NodeStatus::FAILURE);
75
- child_node_->setStatus (NodeStatus::IDLE);
73
+ return (NodeStatus::FAILURE);
76
74
}
77
- break ;
78
75
79
76
case NodeStatus::RUNNING:
80
77
{
81
- setStatus (NodeStatus::RUNNING);
78
+ return (NodeStatus::RUNNING);
82
79
}
83
- break ;
84
80
85
81
default :
86
82
{
87
83
// TODO throw?
88
84
}
89
85
}
90
-
91
86
return status ();
92
87
}
88
+
89
+ void RepeatNode::halt ()
90
+ {
91
+ try_index_ = 0 ;
92
+ DecoratorNode::halt ();
93
+ }
94
+
93
95
}
Original file line number Diff line number Diff line change @@ -65,28 +65,24 @@ NodeStatus RetryNode::tick()
65
65
case NodeStatus::SUCCESS:
66
66
{
67
67
try_index_ = 0 ;
68
- setStatus (NodeStatus::SUCCESS);
69
- child_node_->setStatus (NodeStatus::IDLE);
68
+ return (NodeStatus::SUCCESS);
70
69
}
71
- break ;
72
70
73
71
case NodeStatus::FAILURE:
74
72
{
75
73
try_index_++;
76
74
if (try_index_ >= max_attempts_)
77
75
{
78
76
try_index_ = 0 ;
79
- setStatus (NodeStatus::FAILURE);
77
+ return (NodeStatus::FAILURE);
80
78
}
81
- child_node_->setStatus (NodeStatus::IDLE);
82
79
}
83
80
break ;
84
81
85
82
case NodeStatus::RUNNING:
86
83
{
87
- setStatus (NodeStatus::RUNNING);
84
+ return (NodeStatus::RUNNING);
88
85
}
89
- break ;
90
86
91
87
default :
92
88
{
@@ -96,4 +92,5 @@ NodeStatus RetryNode::tick()
96
92
97
93
return status ();
98
94
}
95
+
99
96
}
Original file line number Diff line number Diff line change @@ -14,14 +14,6 @@ BT::NodeStatus BT::DecoratorSubtreeNode::tick()
14
14
{
15
15
setStatus (NodeStatus::RUNNING);
16
16
}
17
- auto status = child_node_->executeTick ();
18
- setStatus (status);
19
-
20
- // reset child if completed
21
- if ( status == NodeStatus::SUCCESS || status == NodeStatus::FAILURE)
22
- {
23
- child_node_->setStatus (NodeStatus::IDLE);
24
- }
25
- return status;
17
+ return child_node_->executeTick ();
26
18
}
27
19
Original file line number Diff line number Diff line change @@ -54,7 +54,6 @@ NodeStatus TimeoutNode::tick()
54
54
if (!aborted && child ()->status () == NodeStatus::RUNNING)
55
55
{
56
56
child ()->halt ();
57
- child ()->setStatus (NodeStatus::IDLE);
58
57
child_halted_ = true ;
59
58
}
60
59
});
@@ -70,12 +69,12 @@ NodeStatus TimeoutNode::tick()
70
69
auto child_status = child ()->executeTick ();
71
70
if (child_status != NodeStatus::RUNNING)
72
71
{
73
- child ()->setStatus (NodeStatus::IDLE);
74
72
timer ().cancel (timer_id_);
75
73
}
76
74
setStatus (child_status);
77
75
}
78
76
79
77
return status ();
80
78
}
79
+
81
80
}
You can’t perform that action at this time.
0 commit comments