BehaviorTree/BehaviorTree.CPP

Question about internal loop vs. counter management for Repeater node

Lecrapouille opened this issue · 0 comments

Hello !

I read the code source of the repeater node.

NodeStatus RepeatNode::tick()
{
...
  bool do_loop = repeat_count_ < num_cycles_ || num_cycles_ == -1;
  setStatus(NodeStatus::RUNNING);

  while(do_loop)
  {

Why do you use an internal loop instead of using a counter forcing the Repeater node to be ticked "num_cycles_" times ?

My naive implementation would be:

        Status status = m_child->tick();
        if (status == Status::RUNNING)
        {
            return Status::RUNNING;
        }
        else if (status == Status::FAILURE)
        {
            return Status::FAILURE;
        }
        
        if ((m_num_cycles > 0) && (++m_counter == m_num_cycles))
        {
            m_counter = m_num_cycles;
            return Status::SUCCESS;
        }
        
        return Status::RUNNING;

I guess with your method, you do not have the timestamp of the tree between each iteration ? I think the last method is more in the spirit of BT: blocking less each node and each iteration scheduled by a fixed time stamp ?