reactive_fallback.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_fallback.h"
00014 
00015 namespace BT
00016 {
00017 
00018 NodeStatus ReactiveFallback::tick()
00019 {
00020     size_t failure_count = 0;
00021 
00022     for (size_t index = 0; index < childrenCount(); index++)
00023     {
00024         TreeNode* current_child_node = children_nodes_[index];
00025         const NodeStatus child_status = current_child_node->executeTick();
00026 
00027         switch (child_status)
00028         {
00029             case NodeStatus::RUNNING:
00030             {
00031                 haltChildren(index+1);
00032                 return NodeStatus::RUNNING;
00033             }
00034 
00035             case NodeStatus::FAILURE:
00036             {
00037                 failure_count++;
00038             }break;
00039 
00040             case NodeStatus::SUCCESS:
00041             {
00042                 haltChildren(0);
00043                 return NodeStatus::SUCCESS;
00044             }
00045 
00046             case NodeStatus::IDLE:
00047             {
00048                 throw LogicError("A child node must never return IDLE");
00049             }
00050         }   // end switch
00051     } //end for
00052 
00053     if( failure_count == childrenCount() )
00054     {
00055         haltChildren(0);
00056         return NodeStatus::FAILURE;
00057     }
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