reactive_sequence.cpp
Go to the documentation of this file.
00001 /* Copyright (C) 2019 Davide Faconti, Eurecat -  All Rights Reserved
00002 *
00003 *   Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
00004 *   to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
00005 *   and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
00006 *   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00007 *
00008 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00009 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00010 *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00011 */
00012 
00013 #include "behaviortree_cpp/controls/reactive_sequence.h"
00014 
00015 namespace BT
00016 {
00017 
00018 NodeStatus ReactiveSequence::tick()
00019 {
00020     size_t success_count = 0;
00021     size_t running_count = 0;
00022 
00023     for (size_t index = 0; index < childrenCount(); index++)
00024     {
00025         TreeNode* current_child_node = children_nodes_[index];
00026         const NodeStatus child_status = current_child_node->executeTick();
00027 
00028         switch (child_status)
00029         {
00030             case NodeStatus::RUNNING:
00031             {
00032                 running_count++;
00033                 haltChildren(index+1);
00034                 return NodeStatus::RUNNING;
00035             }
00036 
00037             case NodeStatus::FAILURE:
00038             {
00039                 haltChildren(0);
00040                 return NodeStatus::FAILURE;
00041             }
00042             case NodeStatus::SUCCESS:
00043             {
00044                 success_count++;
00045             }break;
00046 
00047             case NodeStatus::IDLE:
00048             {
00049                 throw LogicError("A child node must never return IDLE");
00050             }
00051         }   // end switch
00052     } //end for
00053 
00054     if( success_count == childrenCount())
00055     {
00056         haltChildren(0);
00057         return NodeStatus::SUCCESS;
00058     }
00059     return NodeStatus::RUNNING;
00060 }
00061 
00062 
00063 }


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 20:17:15