Public Member Functions | Private Attributes | List of all members
BT::ThreadedAction Class Reference

The ThreadedAction executes the tick in a different thread. More...

#include <action_node.h>

Inheritance diagram for BT::ThreadedAction:
Inheritance graph
[legend]

Public Member Functions

virtual NodeStatus executeTick () override final
 The method that should be used to invoke tick() and setStatus();. More...
 
virtual void halt () override
 
bool isHaltRequested () const
 
 ThreadedAction (const std::string &name, const NodeConfig &config)
 
- Public Member Functions inherited from BT::ActionNodeBase
 ActionNodeBase (const std::string &name, const NodeConfig &config)
 
virtual NodeType type () const override final
 
 ~ActionNodeBase () override=default
 
- Public Member Functions inherited from BT::LeafNode
 LeafNode (const std::string &name, const NodeConfig &config)
 
virtual ~LeafNode () override=default
 
- Public Member Functions inherited from BT::TreeNode
const NodeConfigconfig () const
 
void emitWakeUpSignal ()
 Notify that the tree should be ticked again() More...
 
const std::string & fullPath () const
 
template<typename T >
Expected< T > getInput (const std::string &key) const
 
template<typename T >
Result getInput (const std::string &key, T &destination) const
 
template<typename T >
Expected< StampedValue< T > > getInputStamped (const std::string &key) const
 
template<typename T >
Expected< TimestampgetInputStamped (const std::string &key, T &destination) const
 getInputStamped is similar to getInput(dey, destination), but it returne also the Timestamp object, that can be used to check if a value was updated and when. More...
 
AnyPtrLocked getLockedPortContent (const std::string &key)
 getLockedPortContent should be used when: More...
 
StringView getRawPortValue (const std::string &key) const
 
void haltNode ()
 
bool isHalted () const
 
const std::string & name () const
 Name of the instance, not the type. More...
 
TreeNodeoperator= (const TreeNode &other)=delete
 
TreeNodeoperator= (TreeNode &&other) noexcept
 
const std::string & registrationName () const
 registrationName is the ID used by BehaviorTreeFactory to create an instance. More...
 
bool requiresWakeUp () const
 
template<typename T >
Result setOutput (const std::string &key, const T &value)
 setOutput modifies the content of an Output port More...
 
void setPostTickFunction (PostTickCallback callback)
 
void setPreTickFunction (PreTickCallback callback)
 
void setTickMonitorCallback (TickMonitorCallback callback)
 
NodeStatus status () const
 
StatusChangeSubscriber subscribeToStatusChange (StatusChangeCallback callback)
 subscribeToStatusChange is used to attach a callback to a status change. When StatusChangeSubscriber goes out of scope (it is a shared_ptr) the callback is unsubscribed automatically. More...
 
 TreeNode (const TreeNode &other)=delete
 
 TreeNode (std::string name, NodeConfig config)
 TreeNode main constructor. More...
 
 TreeNode (TreeNode &&other) noexcept
 
uint16_t UID () const
 
BT::NodeStatus waitValidStatus ()
 
virtual ~TreeNode ()
 

Private Attributes

std::exception_ptr exptr_
 
std::atomic_bool halt_requested_ = false
 
std::mutex mutex_
 
std::future< void > thread_handle_
 

Additional Inherited Members

- Public Types inherited from BT::TreeNode
using PostTickCallback = std::function< NodeStatus(TreeNode &, NodeStatus)>
 
using PreTickCallback = std::function< NodeStatus(TreeNode &)>
 
typedef std::shared_ptr< TreeNodePtr
 
using StatusChangeCallback = StatusChangeSignal::CallableFunction
 
using StatusChangeSignal = Signal< TimePoint, const TreeNode &, NodeStatus, NodeStatus >
 
using StatusChangeSubscriber = StatusChangeSignal::Subscriber
 
using TickMonitorCallback = std::function< void(TreeNode &, NodeStatus, std::chrono::microseconds)>
 
- Static Public Member Functions inherited from BT::TreeNode
static Expected< StringViewgetRemappedKey (StringView port_name, StringView remapped_port)
 
template<class DerivedT , typename... ExtraArgs>
static std::unique_ptr< TreeNodeInstantiate (const std::string &name, const NodeConfig &config, ExtraArgs... args)
 
static bool isBlackboardPointer (StringView str, StringView *stripped_pointer=nullptr)
 Check a string and return true if it matches the pattern: {...}. More...
 
static StringView stripBlackboardPointer (StringView str)
 
- Protected Types inherited from BT::TreeNode
using PostScripts = std::array< ScriptFunction, size_t(PostCond::COUNT_)>
 
using PreScripts = std::array< ScriptFunction, size_t(PreCond::COUNT_)>
 
- Protected Member Functions inherited from BT::TreeNode
NodeConfigconfig ()
 
void modifyPortsRemapping (const PortsRemapping &new_remapping)
 
template<typename T >
parseString (const std::string &str) const
 
PostScriptspostConditionsScripts ()
 
PreScriptspreConditionsScripts ()
 
void resetStatus ()
 Set the status to IDLE. More...
 
void setRegistrationID (StringView ID)
 
void setStatus (NodeStatus new_status)
 setStatus changes the status of the node. it will throw if you try to change the status to IDLE, because your parent node should do that, not the user! More...
 
void setWakeUpInstance (std::shared_ptr< WakeUpSignal > instance)
 
virtual BT::NodeStatus tick ()=0
 Method to be implemented by the user. More...
 

Detailed Description

The ThreadedAction executes the tick in a different thread.

IMPORTANT: this action is quite hard to implement correctly. Please make sure that you know what you are doing.

For a complete example, look at AsyncActionTest in action_test_node.h in the folder test.

NOTE: when the thread is completed, i.e. the tick() returns its status, a TreeNode::emitWakeUpSignal() will be called.

Definition at line 116 of file action_node.h.

Constructor & Destructor Documentation

◆ ThreadedAction()

BT::ThreadedAction::ThreadedAction ( const std::string &  name,
const NodeConfig config 
)
inline

Definition at line 119 of file action_node.h.

Member Function Documentation

◆ executeTick()

NodeStatus BT::ThreadedAction::executeTick ( )
finaloverridevirtual

The method that should be used to invoke tick() and setStatus();.

Reimplemented from BT::TreeNode.

Definition at line 189 of file action_node.cpp.

◆ halt()

void ThreadedAction::halt ( )
overridevirtual

The method used to interrupt the execution of a RUNNING node. Only Async nodes that may return RUNNING should implement it.

Implements BT::TreeNode.

Reimplemented in BT::AsyncActionTest.

Definition at line 233 of file action_node.cpp.

◆ isHaltRequested()

bool BT::ThreadedAction::isHaltRequested ( ) const
inline

Definition at line 123 of file action_node.h.

Member Data Documentation

◆ exptr_

std::exception_ptr BT::ThreadedAction::exptr_
private

Definition at line 134 of file action_node.h.

◆ halt_requested_

std::atomic_bool BT::ThreadedAction::halt_requested_ = false
private

Definition at line 135 of file action_node.h.

◆ mutex_

std::mutex BT::ThreadedAction::mutex_
private

Definition at line 137 of file action_node.h.

◆ thread_handle_

std::future<void> BT::ThreadedAction::thread_handle_
private

Definition at line 136 of file action_node.h.


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


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:09