Skip to main content

ForEachUntilSuccess Class

A decorator node that iterates through a vector of items, stopping on first successful child node tick. More...

Declaration

class moveit_pro::behaviors::ForEachUntilSuccess { ... }

Included Headers

#include <for_each_until_success.hpp>

Base class

classSharedResourcesNode<BehaviorTreeNodeT>

The SharedResourcesNode class provides a BehaviorContext object when constructing a BehaviorTree.Cpp node. More...

Public Constructors Index

ForEachUntilSuccess (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< moveit_pro::behaviors::BehaviorContext > &shared_resources)

Public Destructor Index

~ForEachUntilSuccess () override=default

Private Member Functions Index

BT::NodeStatustick () override

Ticks each child until one succeeds. More...

voidhalt () override

Implementation of halt() for ForEach behaviors. More...

Private Member Attributes Index

std::size_tcurrent_index_ { 0 }

Tracks the current index into the input vector. Initialized to be 0. More...

Public Static Functions Index

static BT::PortsListprovidedPorts ()

Required implementation of the static providedPorts function. More...

static BT::KeyValueVectormetadata ()

Description

A decorator node that iterates through a vector of items, stopping on first successful child node tick.

  • Given an instance of std::vector<BT::Any> which is provided on an input data port and contains N items, set the value of an output data port to the item in the vector which is at index 0 and then tick the ForEachUntilSuccess decorator's child node until the child returns SUCCESS or FAILURE.
  • If the vector is empty do not call the child, return SUCCESS.
  • If the child returns SUCCESS, stop iterating through the vector or ticking the child and return SUCCESS.
  • If the child returns FAILURE, move on to the next vector element and repeat ticking the child node.
  • Repeat until we have iterated through all elements of the input vector, and finally return FAILURE.

For each element set in the output, the index of the element in the input vector is also set in the index output data port. Therefore this Behavior outputs pairs [index, out] for each element in the input vector, containing the element index (starting at 0) and its value.

NOTE: The output values are only expected to be used by the child node or subtree of the ForEachUntilSuccess node which sets it. While it is possible to access these ports from elsewhere in the behavior tree, this may result in unexpected behavior so it is not recommended.

Data Port NamePort TypeObject Type
vector_ininputstd::vector<BT::Any>
indexoutputint
outoutputBT::Any

Definition at line 44 of file for_each_until_success.hpp.

Public Constructors

ForEachUntilSuccess()

moveit_pro::behaviors::ForEachUntilSuccess::ForEachUntilSuccess (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< moveit_pro::behaviors::BehaviorContext > & shared_resources)

Declaration at line 47 of file for_each_until_success.hpp, definition at line 41 of file for_each_until_success.cpp.

Public Destructor

~ForEachUntilSuccess()

moveit_pro::behaviors::ForEachUntilSuccess::~ForEachUntilSuccess ()
default

Definition at line 49 of file for_each_until_success.hpp.

Private Member Functions

halt()

void moveit_pro::behaviors::ForEachUntilSuccess::halt ()

Implementation of halt() for ForEach behaviors.

Sets current_index_ to 0, then calls DecoratorNode::halt().

Declaration at line 71 of file for_each_until_success.hpp, definition at line 123 of file for_each_until_success.cpp.

tick()

BT::NodeStatus moveit_pro::behaviors::ForEachUntilSuccess::tick ()

Ticks each child until one succeeds.

Returns

the current status of the decorator.

Exceptions
BT::LogicError

if the child node returns IDLE, since this is an internal BehaviorTree.CPP error condition.

Declaration at line 65 of file for_each_until_success.hpp, definition at line 58 of file for_each_until_success.cpp.

Private Member Attributes

current_index_

std::size_t moveit_pro::behaviors::ForEachUntilSuccess::current_index_ { 0 }

Tracks the current index into the input vector. Initialized to be 0.

Definition at line 74 of file for_each_until_success.hpp.

Public Static Functions

metadata()

BT::KeyValueVector moveit_pro::behaviors::ForEachUntilSuccess::metadata ()
static

Declaration at line 57 of file for_each_until_success.hpp, definition at line 52 of file for_each_until_success.cpp.

providedPorts()

BT::PortsList moveit_pro::behaviors::ForEachUntilSuccess::providedPorts ()
static

Required implementation of the static providedPorts function.

Returns

The list of input and output ports used by this behavior.

Declaration at line 55 of file for_each_until_success.hpp, definition at line 47 of file for_each_until_success.cpp.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.