behavior_tree.h
Go to the documentation of this file.
00001 /* Copyright (C) 2015-2018 Michele Colledanchise -  All Rights Reserved
00002  * Copyright (C) 2018-2019 Davide Faconti, Eurecat -  All Rights Reserved
00003 *
00004 *   Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
00005 *   to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
00006 *   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:
00007 *   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00008 *
00009 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00010 *   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,
00011 *   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.
00012 */
00013 
00014 #ifndef BEHAVIOR_TREE_H
00015 #define BEHAVIOR_TREE_H
00016 
00017 #include "behaviortree_cpp/controls/parallel_node.h"
00018 #include "behaviortree_cpp/controls/reactive_sequence.h"
00019 #include "behaviortree_cpp/controls/reactive_fallback.h"
00020 #include "behaviortree_cpp/controls/fallback_node.h"
00021 #include "behaviortree_cpp/controls/sequence_node.h"
00022 #include "behaviortree_cpp/controls/sequence_star_node.h"
00023 
00024 #include "behaviortree_cpp/action_node.h"
00025 #include "behaviortree_cpp/condition_node.h"
00026 
00027 #include "behaviortree_cpp/decorators/inverter_node.h"
00028 #include "behaviortree_cpp/decorators/retry_node.h"
00029 #include "behaviortree_cpp/decorators/repeat_node.h"
00030 #include "behaviortree_cpp/decorators/subtree_node.h"
00031 
00032 #include "behaviortree_cpp/actions/always_success_node.h"
00033 #include "behaviortree_cpp/actions/always_failure_node.h"
00034 #include "behaviortree_cpp/actions/set_blackboard_node.h"
00035 
00036 #include "behaviortree_cpp/decorators/force_success_node.h"
00037 #include "behaviortree_cpp/decorators/force_failure_node.h"
00038 #include "behaviortree_cpp/decorators/blackboard_precondition.h"
00039 #include "behaviortree_cpp/decorators/timeout_node.h"
00040 
00041 namespace BT
00042 {
00043 
00044 //Call the visitor for each node of the tree, given a root.
00045 void applyRecursiveVisitor(const TreeNode* root_node,
00046                            const std::function<void(const TreeNode*)>& visitor);
00047 
00048 //Call the visitor for each node of the tree, given a root.
00049 void applyRecursiveVisitor(TreeNode* root_node, const std::function<void(TreeNode*)>& visitor);
00050 
00054 void printTreeRecursively(const TreeNode* root_node);
00055 
00058 void haltAllActions(TreeNode* root_node);
00059 
00060 
00061 typedef std::vector<std::pair<uint16_t, uint8_t>> SerializedTreeStatus;
00062 
00071 void buildSerializedStatusSnapshot(const TreeNode* root_node,
00072                                    SerializedTreeStatus& serialized_buffer);
00073 
00076 template <typename T>
00077 inline NodeType getType()
00078 {
00079     // clang-format off
00080     if( std::is_base_of<ActionNodeBase, T>::value )        return NodeType::ACTION;
00081     if( std::is_base_of<ConditionNode, T>::value )         return NodeType::CONDITION;
00082     if( std::is_base_of<DecoratorSubtreeNode, T>::value )  return NodeType::SUBTREE;
00083     if( std::is_base_of<DecoratorNode, T>::value )         return NodeType::DECORATOR;
00084     if( std::is_base_of<ControlNode, T>::value )           return NodeType::CONTROL;
00085     return NodeType::UNDEFINED;
00086     // clang-format on
00087 }
00088 }
00089 
00090 #endif   // BEHAVIOR_TREE_H


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