BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
BT Namespace Reference

Namespaces

namespace  details
 The SwitchNode is equivalent to a switch statement, where a certain branch (child) is executed according to the value of a blackboard entry.
 

Classes

class  ActionNodeBase
 The ActionNodeBase is the base class to use to create any kind of action. A particular derived class is free to override executeTick() as needed. More...
 
class  AlwaysFailureNode
 
class  AlwaysSuccessNode
 
class  Any
 
struct  AnyTypeAllowed
 
class  BehaviorTreeException
 
class  BehaviorTreeFactory
 The BehaviorTreeFactory is used to create instances of a TreeNode at run-time. More...
 
class  Blackboard
 The Blackboard is the mechanism used by BehaviorTrees to exchange typed data. More...
 
class  ConditionNode
 The ConditionNode is a leaf node used to check a condition. More...
 
class  ConsumeQueue
 
class  ControlNode
 The ControlNode is the base class for nodes that can have multiple children. More...
 
class  CoroActionNode
 The CoroActionNode class is an a good candidate for asynchronous actions which need to communicate with an external service using an async request/reply interface. More...
 
class  DecoratorNode
 The DecoratorNode is the base class for nodes that have exactly one child. More...
 
class  DelayNode
 The delay node will introduce a delay and then tick the child returning the status of the child as it is upon completion The delay is in milliseconds and it is passed using the port "delay_msec". More...
 
class  EntryUpdatedAction
 The EntryUpdatedAction checks the Timestamp in an entry to determine if the value was updated since the last time. More...
 
class  EntryUpdatedDecorator
 The EntryUpdatedDecorator checks the Timestamp in an entry to determine if the value was updated since the last time (true, the first time). More...
 
class  FallbackNode
 The FallbackNode is used to try different strategies, until one succeeds. If any child returns RUNNING, previous children will NOT be ticked again. More...
 
class  FileLogger2
 The FileLogger2 is a logger that saves the tree as XML and all the transitions. Data is written to file in a separate thread, to minimize latency. More...
 
class  ForceFailureNode
 The ForceFailureNode always returns FAILURE when the child completes, regardless of whether the child returned SUCCESS or FAILURE. More...
 
class  ForceSuccessNode
 The ForceSuccessNode always returns SUCCESS when the child completes, regardless of whether the child returned SUCCESS or FAILURE. More...
 
class  Groot2Publisher
 The Groot2Publisher is used to create an interface between your BT.CPP executor and Groot2. More...
 
struct  has_static_method_metadata
 
struct  has_static_method_metadata< T, typename std::enable_if< std::is_same< decltype(T::metadata()), KeyValueVector >::value >::type >
 
struct  has_static_method_providedPorts
 
struct  has_static_method_providedPorts< T, typename std::enable_if< std::is_same< decltype(T::providedPorts()), PortsList >::value >::type >
 
class  IfThenElseNode
 IfThenElseNode must have exactly 2 or 3 children. This node is NOT reactive. More...
 
class  InverterNode
 The InverterNode returns SUCCESS if child fails of FAILURE is child succeeds. RUNNING status is propagated. More...
 
struct  is_shared_ptr
 
struct  is_shared_ptr< std::shared_ptr< U > >
 
class  JsonExporter
 
class  KeepRunningUntilFailureNode
 The KeepRunningUntilFailureNode keeps ticking the child as long as it returns SUCCESS, and returns RUNNING. More...
 
class  LeafNode
 
class  LockedPtr
 The LockedPtr class is used to share a pointer to an object and a mutex that protects the read/write access to that object. More...
 
class  LogicError
 
class  LoopNode
 The LoopNode class is used to pop_front elements from a std::deque. This element is copied into the port "value" and the child will be executed, as long as we have elements in the queue. More...
 
class  ManualSelectorNode
 Use a Terminal User Interface (ncurses) to select a certain child manually. More...
 
class  MinitraceLogger
 
struct  NodeConfig
 
class  NodeExecutionError
 
class  ParallelAllNode
 The ParallelAllNode execute all its children concurrently, but not in separate threads! More...
 
class  ParallelNode
 The ParallelNode execute all its children concurrently, but not in separate threads! More...
 
class  Parser
 The BehaviorTreeParser is a class used to read the model of a BehaviorTree from file or text and instantiate the corresponding tree using the BehaviorTreeFactory. More...
 
class  PolymorphicCastRegistry
 Registry for polymorphic shared_ptr cast relationships. More...
 
class  PopFromQueue
 
class  PortInfo
 
class  PreconditionNode
 The PreconditionNode evaluates a script condition before ticking its child. More...
 
struct  ProtectedQueue
 
class  QueueSize
 
class  ReactiveFallback
 The ReactiveFallback is similar to a ParallelNode. All the children are ticked from first to last: More...
 
class  ReactiveSequence
 The ReactiveSequence is similar to a ParallelNode. All the children are ticked from first to last: More...
 
class  RepeatNode
 The RepeatNode is used to execute a child several times, as long as it succeed. More...
 
class  RetryNode
 The RetryNode is used to execute a child several times if it fails. More...
 
class  RetryNodeTypo
 
class  RunOnceNode
 The RunOnceNode is used when you want to execute the child only once. If the child is asynchronous, we will tick until either SUCCESS or FAILURE is returned. More...
 
class  RuntimeError
 
class  scoped_demangled_name
 
class  ScriptCondition
 Execute a script, and if the result is true, return SUCCESS, FAILURE otherwise. More...
 
class  ScriptNode
 The ScriptNode executes a piece of script code to set or modify entries in the Blackboard. More...
 
class  SequenceNode
 The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING, previous children will NOT be ticked again. More...
 
class  SequenceWithMemory
 The SequenceWithMemory is used to tick children in an ordered sequence. If any child returns RUNNING, previous children are not ticked again. More...
 
class  SetBlackboardNode
 The SetBlackboard is action used to store a string into an entry of the Blackboard specified in "output_key". More...
 
class  SharedLibrary
 
class  Signal
 
class  SimpleActionNode
 The SimpleActionNode provides an easy to use SyncActionNode. The user should simply provide a callback with this signature. More...
 
class  SimpleConditionNode
 The SimpleConditionNode provides an easy to use ConditionNode. The user should simply provide a callback with this signature. More...
 
class  SimpleDecoratorNode
 The SimpleDecoratorNode provides an easy to use DecoratorNode. The user should simply provide a callback with this signature. More...
 
class  SleepNode
 Sleep for a certain amount of time. Consider also using the decorator <Delay> More...
 
class  SqliteLogger
 The SqliteLogger is a logger that will store the tree and all the status transitions in a SQLite database (single file). More...
 
struct  StampedValue
 
class  StatefulActionNode
 The StatefulActionNode is the preferred way to implement asynchronous Actions. It is actually easier to use correctly, when compared with ThreadedAction. More...
 
class  StatusChangeLogger
 
class  StdCoutLogger
 StdCoutLogger is a very simple logger that displays all the transitions on the console. More...
 
class  SubTreeNode
 The SubTreeNode is a way to wrap an entire Subtree, creating a separated BlackBoard. If you want to have data flow through ports, you need to explicitly remap the ports. More...
 
class  SwitchNode
 
class  SyncActionNode
 The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require an implementation of halt(). More...
 
class  TestNode
 The TestNode is a Node that can be configure to: More...
 
struct  TestNodeConfig
 
class  ThreadedAction
 The ThreadedAction executes the tick in a different thread. More...
 
struct  TickBacktraceEntry
 Information about a node in the tick backtrace. More...
 
class  TimeoutNode
 The TimeoutNode will halt() a running child if the latter has been RUNNING longer than a given time. The timeout is in milliseconds and it is passed using the port "msec". More...
 
class  TimerQueue
 
struct  Timestamp
 
class  Tree
 Struct used to store a tree. If this object goes out of scope, the tree is destroyed. More...
 
class  TreeNode
 Abstract base class for Behavior Tree Nodes. More...
 
struct  TreeNodeManifest
 This information is used mostly by the XMLParser. More...
 
class  TreeObserver
 The TreeObserver is used to collect statistics about which nodes are executed and their returned status. More...
 
class  TryCatchNode
 The TryCatch node executes children 1..N-1 as a Sequence ("try" block). More...
 
class  TypeInfo
 
class  UnsetBlackboardNode
 
class  WakeUpSignal
 
class  WhileDoElseNode
 WhileDoElse must have exactly 2 or 3 children. It is a REACTIVE node of IfThenElseNode. More...
 
class  XMLParser
 The XMLParser is a class used to read the model of a BehaviorTree from file or text and instantiate the corresponding tree using the BehaviorTreeFactory. More...
 

Typedefs

using StringView = std::string_view
 
using KeyValueVector = std::vector< std::pair< std::string, std::string > >
 
template<typename T >
using Expected = nonstd::expected< T, std::string >
 
using StringConverter = std::function< Any(StringView)>
 
using StringConvertersMap = std::unordered_map< const std::type_info *, StringConverter >
 
template<typename Predicate >
using enable_if = typename std::enable_if< Predicate::value >::type *
 
template<typename Predicate >
using enable_if_not = typename std::enable_if<!Predicate::value >::type *
 
using Result = Expected< std::monostate >
 
using PortsList = std::unordered_map< std::string, PortInfo >
 
using TimePoint = std::chrono::high_resolution_clock::time_point
 
using Duration = std::chrono::high_resolution_clock::duration
 
using SerializedTreeStatus = std::vector< std::pair< uint16_t, uint8_t > >
 
using AnyPtrLocked = LockedPtr< Any >
 
using NodeBuilder = std::function< std::unique_ptr< TreeNode >(const std::string &, const NodeConfig &)>
 The term "Builder" refers to the Builder Pattern (https://en.wikipedia.org/wiki/Builder_pattern)
 
template<typename T >
using SharedQueue = std::shared_ptr< std::deque< T > >
 
using SerializedTransition = std::array< uint8_t, 12 >
 
using EnumsTable = std::unordered_map< std::string, int >
 
using EnumsTablePtr = std::shared_ptr< EnumsTable >
 
using ScriptFunction = std::function< Any(Ast::Environment &env)>
 
using PortsRemapping = std::unordered_map< std::string, std::string >
 
using NonPortAttributes = std::unordered_map< std::string, std::string >
 
using ScriptingEnumsRegistry = std::unordered_map< std::string, int >
 
using NodeConfiguration = NodeConfig
 

Enumerations

enum class  NodeType {
  UNDEFINED = 0 , ACTION , CONDITION , CONTROL ,
  DECORATOR , SUBTREE
}
 Enumerates the possible types of nodes.
 
enum class  NodeStatus {
  IDLE = 0 , RUNNING = 1 , SUCCESS = 2 , FAILURE = 3 ,
  SKIPPED = 4
}
 
enum class  PortDirection { INPUT , OUTPUT , INOUT }
 
enum class  TimestampType { absolute , relative }
 
enum class  PreCond {
  FAILURE_IF = 0 , SUCCESS_IF , SKIP_IF , WHILE_TRUE ,
  COUNT_
}
 Pre-conditions that can be attached to any node via XML attributes. More...
 
enum class  PostCond {
  ON_HALTED = 0 , ON_FAILURE , ON_SUCCESS , ALWAYS ,
  COUNT_
}
 

Functions

bool isStatusActive (const NodeStatus &status)
 
bool isStatusCompleted (const NodeStatus &status)
 
bool StartWith (StringView str, StringView prefix)
 
bool StartWith (StringView str, char prefix)
 
Any convertFromJSON (StringView json_text, std::type_index type)
 convertFromJSON will parse a json string and use JsonExporter to convert its content to a given type. It will work only if the type was previously registered. May throw if it fails.
 
template<typename T >
convertFromJSON (StringView str)
 Same as the non template version, but with automatic casting.
 
template<typename T >
convertFromString (StringView str)
 
template<>
std::string convertFromString< std::string > (StringView str)
 
template<>
const char * convertFromString< const char * > (StringView str)
 
template<>
int8_t convertFromString< int8_t > (StringView str)
 
template<>
int16_t convertFromString< int16_t > (StringView str)
 
template<>
int32_t convertFromString< int32_t > (StringView str)
 
template<>
int64_t convertFromString< int64_t > (StringView str)
 
template<>
uint8_t convertFromString< uint8_t > (StringView str)
 
template<>
uint16_t convertFromString< uint16_t > (StringView str)
 
template<>
uint32_t convertFromString< uint32_t > (StringView str)
 
template<>
uint64_t convertFromString< uint64_t > (StringView str)
 
template<>
float convertFromString< float > (StringView str)
 
template<>
double convertFromString< double > (StringView str)
 
template<>
std::vector< int > convertFromString< std::vector< int > > (StringView str)
 
template<>
std::vector< double > convertFromString< std::vector< double > > (StringView str)
 
template<>
std::vector< bool > convertFromString< std::vector< bool > > (StringView str)
 
template<>
std::vector< std::string > convertFromString< std::vector< std::string > > (StringView str)
 
template<>
bool convertFromString< bool > (StringView str)
 
template<>
NodeStatus convertFromString< NodeStatus > (StringView str)
 
template<>
NodeType convertFromString< NodeType > (StringView str)
 
template<>
PortDirection convertFromString< PortDirection > (StringView str)
 
template<typename T >
StringConverter GetAnyFromStringFunctor ()
 
template<>
StringConverter GetAnyFromStringFunctor< void > ()
 
template<typename T >
constexpr bool IsConvertibleToString ()
 
Expected< std::string > toJsonString (const Any &value)
 
template<typename T >
std::string toStr (const T &value)
 toStr is the reverse operation of convertFromString.
 
template<>
std::string toStr< bool > (const bool &value)
 
template<>
std::string toStr< std::string > (const std::string &value)
 
template<>
std::string toStr< BT::NodeStatus > (const BT::NodeStatus &status)
 
std::string toStr (BT::NodeStatus status, bool colored)
 toStr converts NodeStatus to string. Optionally colored.
 
std::ostream & operator<< (std::ostream &os, const BT::NodeStatus &status)
 
template<>
std::string toStr< BT::NodeType > (const BT::NodeType &type)
 
std::ostream & operator<< (std::ostream &os, const BT::NodeType &type)
 
template<>
std::string toStr< BT::PortDirection > (const BT::PortDirection &direction)
 
std::ostream & operator<< (std::ostream &os, const BT::PortDirection &type)
 
std::vector< StringView > splitString (const StringView &strToSplit, char delimeter)
 
bool IsAllowedPortName (StringView str)
 
bool IsReservedAttribute (StringView str)
 
char findForbiddenChar (StringView name)
 
template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfoCreatePort (PortDirection direction, StringView name, StringView description={})
 
template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfoInputPort (StringView name, StringView description={})
 
template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfoOutputPort (StringView name, StringView description={})
 
template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfoBidirectionalPort (StringView name, StringView description={})
 
template<typename T = AnyTypeAllowed, typename DefaultT = T>
std::pair< std::string, PortInfoInputPort (StringView name, const DefaultT &default_value, StringView description)
 
template<typename T = AnyTypeAllowed, typename DefaultT = T>
std::pair< std::string, PortInfoBidirectionalPort (StringView name, const DefaultT &default_value, StringView description)
 
template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfoOutputPort (StringView name, StringView default_value, StringView description)
 
template<typename T >
PortsList getProvidedPorts (enable_if< has_static_method_providedPorts< T > >=nullptr)
 
void applyRecursiveVisitor (const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)
 
void applyRecursiveVisitor (TreeNode *root_node, const std::function< void(TreeNode *)> &visitor)
 
void printTreeRecursively (const TreeNode *root_node, std::ostream &stream=std::cout)
 
void buildSerializedStatusSnapshot (const TreeNode *root_node, SerializedTreeStatus &serialized_buffer)
 buildSerializedStatusSnapshot can be used to create a buffer that can be stored (or sent to a client application) to know the status of all the nodes of a tree. It is not "human readable".
 
template<typename T >
NodeType getType ()
 
const char * LibraryVersionString ()
 
int LibraryVersionNumber ()
 
nlohmann::json ExportBlackboardToJSON (const Blackboard &blackboard)
 ExportBlackboardToJSON will create a JSON that contains the current values of the blackboard. Complex types must be registered with JsonExporter::get()
 
void ImportBlackboardFromJSON (const nlohmann::json &json, Blackboard &blackboard)
 ImportBlackboardFromJSON will append elements to the blackboard, using the values parsed from the JSON file created using ExportBlackboardToJSON. Complex types must be registered with JsonExporter::get()
 
template<typename T , typename... Args>
NodeBuilder CreateBuilder (Args... args)
 
template<typename T >
TreeNodeManifest CreateManifest (const std::string &ID, PortsList portlist=getProvidedPorts< T >())
 
bool WildcardMatch (const std::string &str, StringView filter)
 
void BlackboardClone (const Blackboard &src, Blackboard &dst)
 BlackboardClone make a copy of the content of the blackboard.
 
std::vector< Blackboard::Ptr > BlackboardBackup (const BT::Tree &tree)
 BlackboardBackup uses Blackboard::cloneInto to backup all the blackboards of the tree.
 
void BlackboardRestore (const std::vector< Blackboard::Ptr > &backup, BT::Tree &tree)
 BlackboardRestore uses Blackboard::cloneInto to restore all the blackboards of the tree.
 
nlohmann::json ExportTreeToJSON (const BT::Tree &tree)
 ExportTreeToJSON it calls ExportBlackboardToJSON for all the blackboards in the tree.
 
void ImportTreeFromJSON (const nlohmann::json &json, BT::Tree &tree)
 ImportTreeFromJSON it calls ImportBlackboardFromJSON for all the blackboards in the tree.
 
template<>
SharedQueue< int > convertFromString< SharedQueue< int > > (StringView str)
 
template<>
SharedQueue< bool > convertFromString< SharedQueue< bool > > (StringView str)
 
template<>
SharedQueue< double > convertFromString< SharedQueue< double > > (StringView str)
 
template<>
SharedQueue< std::string > convertFromString< SharedQueue< std::string > > (StringView str)
 
Serialization::NodeType convertToFlatbuffers (BT::NodeType type)
 
Serialization::NodeStatus convertToFlatbuffers (BT::NodeStatus type)
 
Serialization::PortDirection convertToFlatbuffers (BT::PortDirection direction)
 
void CreateFlatbuffersBehaviorTree (flatbuffers::FlatBufferBuilder &builder, const BT::Tree &tree)
 
SerializedTransition SerializeTransition (uint16_t UID, Duration timestamp, NodeStatus prev_status, NodeStatus status)
 
template<typename T >
void RegisterJsonDefinition ()
 
Result ValidateScript (const std::string &script)
 ValidateScript will check if a certain string is valid.
 
Expected< ScriptFunction > ParseScript (const std::string &script)
 
Expected< AnyParseScriptAndExecute (Ast::Environment &env, const std::string &script)
 
template<>
std::string toStr< BT::PostCond > (const BT::PostCond &cond)
 
template<>
std::string toStr< BT::PreCond > (const BT::PreCond &cond)
 
template<typename T >
constexpr bool hasNodeNameCtor ()
 
template<typename T , typename... ExtraArgs>
constexpr bool hasNodeFullCtor ()
 
template<typename T >
void assignDefaultRemapping (NodeConfig &config)
 
char const * demangle_alloc (char const *name) noexcept
 
void demangle_free (char const *name) noexcept
 
std::string demangle (char const *name)
 
std::string demangle (const std::type_index &index)
 
std::string demangle (const std::type_info &info)
 
template<typename SRC , typename TO >
bool ValidCast (const SRC &val)
 
template<typename T >
bool isCastingSafe (const std::type_index &type, const T &val)
 
std::string StrCat ()
 
std::string StrCat (const std::string_view &a)
 
std::string StrCat (const std::string_view &a, const std::string_view &b)
 
std::string StrCat (const std::string_view &a, const std::string_view &b, const std::string_view &c)
 
template<typename... AV>
std::string StrCat (const std::string_view &a, const std::string_view &b, const std::string_view &c, const std::string_view &d, const AV &... args)
 
void StrAppend (std::string *destination, const std::string_view &a)
 
void StrAppend (std::string *destination, const std::string_view &a, const std::string_view &b)
 
void StrAppend (std::string *destination, const std::string_view &a, const std::string_view &b, const std::string_view &c)
 
template<typename... AV>
void StrAppend (std::string *destination, const std::string_view &a, const std::string_view &b, const std::string_view &c, const std::string_view &d, const AV &... args)
 
void VerifyXML (const std::string &xml_text, const std::unordered_map< std::string, NodeType > &registered_nodes)
 
std::string writeTreeNodesModelXML (const BehaviorTreeFactory &factory, bool include_builtin=false)
 writeTreeNodesModelXML generates an XMl that contains the manifests in the <TreeNodesModel>
 
std::string writeTreeXSD (const BehaviorTreeFactory &factory)
 writeTreeXSD generates an XSD for the nodes defined in the factory
 
std::string WriteTreeToXML (const Tree &tree, bool add_metadata, bool add_builtin_models)
 WriteTreeToXML create a string that contains the XML that corresponds to a given tree. When using this function with a logger, you should probably set both add_metadata and add_builtin_models to true.
 

Variables

constexpr const char * PLUGIN_SYMBOL = "BT_RegisterNodesFromPlugin"
 

Detailed Description

Template Action used in ex04_waypoints.cpp example.

Its purpose is to do make it easy to create while loops which consume the elements of a queue.

Note that modifying the queue is not thread safe, therefore the action that creates the queue or push elements into it, must be Synchronous.

When ticked, we pop_front from the "queue" and insert that value in "popped_item". Return FAILURE if the queue is empty, SUCCESS otherwise.

Typedef Documentation

◆ AnyPtrLocked

using BT::AnyPtrLocked = typedef LockedPtr<Any>

This type contains a pointer to Any, protected with a locked mutex as long as the object is in scope

◆ EnumsTable

using BT::EnumsTable = typedef std::unordered_map<std::string, int>

Simple map (string->nt), used to convert enums in the scripting language

◆ Expected

template<typename T >
using BT::Expected = typedef nonstd::expected<T, std::string>

Usage: given a function/method like this:

Expected<double> getAnswer();

User code can check result and error message like this:

auto res = getAnswer();
if( res )
{
    std::cout << "answer was: " << res.value() << std::endl;
}
else{
    std::cerr << "failed to get the answer: " << res.error() << std::endl;
}

◆ Result

using BT::Result = typedef Expected<std::monostate>

Usage: given a function/method like:

Result DoSomething();

User code can check result and error message like this:

auto res = DoSomething();
if( res )
{
    std::cout << "DoSomething() done " << std::endl;
}
else{
    std::cerr << "DoSomething() failed with message: " << res.error() << std::endl;
}

Enumeration Type Documentation

◆ NodeStatus

enum class BT::NodeStatus
strong

Enumerates the states every node can be in after execution during a particular time step. IMPORTANT: Your custom nodes should NEVER return IDLE.

◆ PreCond

enum class BT::PreCond
strong

Pre-conditions that can be attached to any node via XML attributes.

Pre-conditions are evaluated in the order defined by this enum (FAILURE_IF first, then SUCCESS_IF, then SKIP_IF, then WHILE_TRUE).

Important: FAILURE_IF, SUCCESS_IF, and SKIP_IF are evaluated only once when the node transitions from IDLE (or SKIPPED) to another state. They are NOT re-evaluated while the node is RUNNING.

  • _failureIf="<script>": If true when node is IDLE, return FAILURE immediately (node's tick() is not called).
  • _successIf="<script>": If true when node is IDLE, return SUCCESS immediately (node's tick() is not called).
  • _skipIf="<script>": If true when node is IDLE, return SKIPPED immediately (node's tick() is not called).
  • _while="<script>": Checked both on IDLE and RUNNING states.

    If false when IDLE, return SKIPPED. If false when RUNNING, halt the node and return SKIPPED. This is the only pre-condition that can interrupt a running node.

If you need a condition to be re-evaluated on every tick, use the <Precondition> decorator node with else="RUNNING" instead of these attributes.

Function Documentation

◆ BidirectionalPort() [1/2]

template<typename T = AnyTypeAllowed, typename DefaultT = T>
std::pair< std::string, PortInfo > BT::BidirectionalPort ( StringView  name,
const DefaultT &  default_value,
StringView  description 
)
inline

Syntactic sugar to invoke CreatePort<T>(PortDirection::INOUT,...) It also sets the PortInfo::defaultValue()

Parameters
namethe name of the port
default_valuedefault value of the port, either type T of BlackboardKey
descriptionoptional human-readable description

◆ BidirectionalPort() [2/2]

template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfo > BT::BidirectionalPort ( StringView  name,
StringView  description = {} 
)
inline

Syntactic sugar to invoke CreatePort<T>(PortDirection::INOUT,...)

Parameters
namethe name of the port
descriptionoptional human-readable description

◆ BlackboardBackup()

std::vector< Blackboard::Ptr > BT::BlackboardBackup ( const BT::Tree tree)

BlackboardBackup uses Blackboard::cloneInto to backup all the blackboards of the tree.

Parameters
treesource
Returns
destination (the backup)

◆ BlackboardClone()

void BT::BlackboardClone ( const Blackboard src,
Blackboard dst 
)

BlackboardClone make a copy of the content of the blackboard.

Parameters
srcsource
dstdestination

◆ BlackboardRestore()

void BT::BlackboardRestore ( const std::vector< Blackboard::Ptr > &  backup,
BT::Tree tree 
)

BlackboardRestore uses Blackboard::cloneInto to restore all the blackboards of the tree.

Parameters
backupa vector of blackboards
treethe destination

◆ buildSerializedStatusSnapshot()

void BT::buildSerializedStatusSnapshot ( const TreeNode root_node,
SerializedTreeStatus &  serialized_buffer 
)

buildSerializedStatusSnapshot can be used to create a buffer that can be stored (or sent to a client application) to know the status of all the nodes of a tree. It is not "human readable".

Parameters
root_node
serialized_bufferis the output.

◆ convertFromJSON()

Any BT::convertFromJSON ( StringView  json_text,
std::type_index  type 
)

convertFromJSON will parse a json string and use JsonExporter to convert its content to a given type. It will work only if the type was previously registered. May throw if it fails.

Parameters
json_texta valid JSON string
typeyou must specify the typeid()
Returns
the object, wrapped in Any.

◆ convertFromString()

template<typename T >
T BT::convertFromString ( StringView  str)
inline

convertFromString is used to convert a string into a custom type.

This function is invoked under the hood by TreeNode::getInput(), but only when the input port contains a string.

If you have a custom type, you need to implement the corresponding template specialization.

If the string starts with the prefix "json:", it will fall back to convertFromJSON()

◆ findForbiddenChar()

char BT::findForbiddenChar ( StringView  name)

Returns the first forbidden character found in the name, or '\0' if valid. Forbidden characters include: space, tab, newline, CR, < > & " ' / \ : * ? | . and control characters (ASCII 0-31, 127). UTF-8 multibyte sequences are allowed.

◆ getType()

template<typename T >
NodeType BT::getType ( )
inline

Simple way to extract the type of a TreeNode at COMPILE TIME. Useful to avoid the cost of dynamic_cast or the virtual method TreeNode::type().

◆ InputPort() [1/2]

template<typename T = AnyTypeAllowed, typename DefaultT = T>
std::pair< std::string, PortInfo > BT::InputPort ( StringView  name,
const DefaultT &  default_value,
StringView  description 
)
inline

Syntactic sugar to invoke CreatePort<T>(PortDirection::INPUT,...) It also sets the PortInfo::defaultValue()

Parameters
namethe name of the port
default_valuedefault value of the port, either type T of BlackboardKey
descriptionoptional human-readable description

◆ InputPort() [2/2]

template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfo > BT::InputPort ( StringView  name,
StringView  description = {} 
)
inline

Syntactic sugar to invoke CreatePort<T>(PortDirection::INPUT, ...)

Parameters
namethe name of the port
descriptionoptional human-readable description

◆ OutputPort() [1/2]

template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfo > BT::OutputPort ( StringView  name,
StringView  default_value,
StringView  description 
)
inline

Syntactic sugar to invoke CreatePort<T>(PortDirection::OUTPUT,...) It also sets the PortInfo::defaultValue()

Parameters
namethe name of the port
default_valuedefault blackboard entry where the output is written
descriptionoptional human-readable description

◆ OutputPort() [2/2]

template<typename T = AnyTypeAllowed>
std::pair< std::string, PortInfo > BT::OutputPort ( StringView  name,
StringView  description = {} 
)
inline

Syntactic sugar to invoke CreatePort<T>(PortDirection::OUTPUT,...)

Parameters
namethe name of the port
descriptionoptional human-readable description

◆ printTreeRecursively()

void BT::printTreeRecursively ( const TreeNode root_node,
std::ostream &  stream = std::cout 
)

Debug function to print the hierarchy of the tree. Prints to std::cout by default.

◆ SerializeTransition()

SerializedTransition BT::SerializeTransition ( uint16_t  UID,
Duration  timestamp,
NodeStatus  prev_status,
NodeStatus  status 
)
inline

Serialize manually the information about state transition No flatbuffer serialization here

◆ toStr()

template<typename T >
std::string BT::toStr ( const T &  value)

toStr is the reverse operation of convertFromString.

If T is a custom type and there is no template specialization, it will try to fall back to toJsonString()

◆ writeTreeNodesModelXML()

std::string BT::writeTreeNodesModelXML ( const BehaviorTreeFactory factory,
bool  include_builtin = false 
)

writeTreeNodesModelXML generates an XMl that contains the manifests in the <TreeNodesModel>

Parameters
factorythe factory with the registered types
include_builtinif true, include the builtin Nodes
Returns
string containing the XML.

◆ WriteTreeToXML()

std::string BT::WriteTreeToXML ( const Tree tree,
bool  add_metadata,
bool  add_builtin_models 
)

WriteTreeToXML create a string that contains the XML that corresponds to a given tree. When using this function with a logger, you should probably set both add_metadata and add_builtin_models to true.

Parameters
treethe input tree
add_metadataif true, the attributes "_uid" and "_fullPath" will be added to the nodes
add_builtin_modelsif true, include the builtin Nodes into the <TreeNodesModel>
Returns
string containing the XML.

◆ writeTreeXSD()

std::string BT::writeTreeXSD ( const BehaviorTreeFactory factory)

writeTreeXSD generates an XSD for the nodes defined in the factory

Parameters
factorythe factory with the registered types
Returns
string containing the XML.