@@ -18,31 +18,43 @@ namespace BT
1818constexpr const char * RepeatNode::NUM_CYCLES;
1919
2020RepeatNode::RepeatNode (const std::string& name, unsigned int NTries)
21- : DecoratorNode(name, {{NUM_CYCLES, std::to_string (NTries)}}), NTries_(NTries), TryIndx_(0 )
21+ : DecoratorNode(name, {{NUM_CYCLES, std::to_string (NTries)}}),
22+ num_cycles_ (NTries),
23+ try_index_ (0 ),
24+ refresh_parameter_ (false )
2225{
2326}
2427
2528RepeatNode::RepeatNode (const std::string& name, const NodeParameters& params)
26- : DecoratorNode(name, params), NTries_(1 ), TryIndx_(0 )
29+ : DecoratorNode(name, params),
30+ try_index_ (0 ),
31+ refresh_parameter_(false )
2732{
28- auto param = getParam<int >(NUM_CYCLES);
29- if (param)
33+ if ( !getParam (NUM_CYCLES, num_cycles_) )
3034 {
31- NTries_ = param. value ( );
35+ throw std::runtime_error ( " Missing parameter [num_cycles] in RepeatNode " );
3236 }
37+ refresh_parameter_ = isBlackboardPattern ( params.begin ()->second );
3338}
3439
3540NodeStatus RepeatNode::tick ()
3641{
42+ if ( refresh_parameter_ )
43+ {
44+ // Read it at every tick. Since it points to the blackboard,
45+ // it may change dynamically
46+ getParam (RepeatNode::NUM_CYCLES, num_cycles_);
47+ }
48+
3749 setStatus (NodeStatus::RUNNING);
3850 NodeStatus child_state = child_node_->executeTick ();
3951
4052 switch (child_state)
4153 {
4254 case NodeStatus::SUCCESS:
4355 {
44- TryIndx_ ++;
45- if (TryIndx_ >= NTries_ )
56+ try_index_ ++;
57+ if (try_index_ >= num_cycles_ )
4658 {
4759 setStatus (NodeStatus::SUCCESS);
4860 child_node_->setStatus (NodeStatus::IDLE);
@@ -52,7 +64,7 @@ NodeStatus RepeatNode::tick()
5264
5365 case NodeStatus::FAILURE:
5466 {
55- TryIndx_ = 0 ;
67+ try_index_ = 0 ;
5668 setStatus (NodeStatus::FAILURE);
5769 child_node_->setStatus (NodeStatus::IDLE);
5870 }
0 commit comments