Go to the documentation of this file.
16 #include <condition_variable>
28 #pragma warning(disable : 4127)
58 typedef std::shared_ptr<TreeNode>
Ptr;
79 virtual void halt() = 0;
86 const std::string&
name()
const;
136 uint16_t
UID()
const;
152 template <
typename T>
158 template <
typename T>
163 return (res) ?
Optional<T>(out) : nonstd::make_unexpected(res.error());
166 template <
typename T>
231 template <
typename T>
237 return nonstd::make_unexpected(
StrCat(
"getInput() failed because "
238 "NodeConfiguration::input_ports "
239 "does not contain the key: [",
247 destination = convertFromString<T>(remap_it->second);
250 const auto& remapped_key = remapped_res.value();
254 return nonstd::make_unexpected(
"getInput() trying to access a Blackboard(BB) "
256 "but BB is invalid");
264 return nonstd::make_unexpected(
StrCat(
"getInput() failed because it was unable to "
265 "find the port [", key,
266 "] remapped to BB [", remapped_key,
"]"));
271 return nonstd::make_unexpected(
StrCat(
"getInput() failed because the port [", key,
272 "] remapped to BB [", remapped_key,
"] was found,"
273 "but its content was not initialized correctly"));
276 if (!std::is_same<T, std::string>::value && val->
type() ==
typeid(std::string))
278 destination = convertFromString<T>(val->
cast<std::string>());
282 destination = val->
cast<T>();
286 catch (std::exception& err)
288 return nonstd::make_unexpected(err.what());
292 template <
typename T>
297 return nonstd::make_unexpected(
"setOutput() failed: trying to access a "
298 "Blackboard(BB) entry, but BB is invalid");
304 return nonstd::make_unexpected(
StrCat(
"setOutput() failed: "
305 "NodeConfiguration::output_ports "
307 "contain the key: [",
311 if (remapped_key ==
"=")
325 template <
typename T>
328 for (
const auto& it : getProvidedPorts<T>())
330 const auto& port_name = it.first;
331 const auto direction = it.second.direction();
Result getInput(const std::string &key, T &destination) const
nonstd::expected< T, std::string > Optional
std::shared_ptr< CallableFunction > Subscriber
void setPreTickOverrideFunction(PreTickOverrideCallback callback)
void setPostTickOverrideFunction(PostTickOverrideCallback callback)
StatusChangeSignal state_change_signal_
PreTickOverrideCallback pre_condition_callback_
NodeType
Enumerates the possible types of nodes.
static pthread_mutex_t mutex
StatusChangeSignal::Subscriber StatusChangeSubscriber
TreeNode(std::string name, NodeConfiguration config)
TreeNode main constructor.
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Abstract base class for Behavior Tree Nodes.
std::unordered_map< std::string, std::string > PortsRemapping
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
std::unordered_map< std::string, PortInfo > PortsList
std::shared_ptr< TreeNode > Ptr
PortsRemapping input_ports
std::function< void(CallableArgs...)> CallableFunction
const NodeConfiguration & config() const
PostTickOverrideCallback post_condition_callback_
static bool isBlackboardPointer(StringView str)
PortsRemapping output_ports
const std::string & registrationName() const
registrationName is the ID used by BehaviorTreeFactory to create an instance.
virtual ~TreeNode()=default
std::shared_ptr< WakeUpSignal > wake_up_
NodeStatus status() const
Optional< T > getInput(const std::string &key) const
BT::NodeStatus waitValidStatus()
std::string registration_ID
void setStatus(NodeStatus new_status)
bool empty() const noexcept
StringView getRawPortValue(const std::string &key) const
std::condition_variable state_condition_variable_
static Optional< StringView > getRemappedKey(StringView port_name, StringView remapping_value)
This information is used mostly by the XMLParser.
virtual NodeType type() const =0
void setRegistrationID(StringView ID)
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Result setOutput(const std::string &key, const T &value)
const std::string & name() const
Name of the instance, not the type.
virtual BT::NodeStatus tick()=0
Method to be implemented by the user.
void modifyPortsRemapping(const PortsRemapping &new_remapping)
Blackboard::Ptr blackboard
void setWakeUpInstance(std::shared_ptr< WakeUpSignal > instance)
StatusChangeSubscriber subscribeToStatusChange(StatusChangeCallback callback)
subscribeToStatusChange is used to attach a callback to a status change. When StatusChangeSubscriber ...
void assignDefaultRemapping(NodeConfiguration &config)
void resetStatus()
Equivalent to setStatus(NodeStatus::IDLE)
const std::type_info & type() const noexcept
std::shared_ptr< Blackboard > Ptr
std::function< Optional< NodeStatus >(TreeNode &, NodeStatus, NodeStatus)> PostTickOverrideCallback
NodeConfiguration config_
std::function< Optional< NodeStatus >(TreeNode &, NodeStatus)> PreTickOverrideCallback
nonstd::string_view StringView
StatusChangeSignal::CallableFunction StatusChangeCallback
std::string registration_ID_
static StringView stripBlackboardPointer(StringView str)
behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Wed Jun 26 2024 02:51:19