diff --git a/include/behaviortree_cpp/bt_factory.h b/include/behaviortree_cpp/bt_factory.h index 242fa17fc..0ba3c86bb 100644 --- a/include/behaviortree_cpp/bt_factory.h +++ b/include/behaviortree_cpp/bt_factory.h @@ -137,6 +137,14 @@ class Tree */ void emitWakeUpSignal(); + /** + * @brief Returns the shared WakeUpSignal used by this tree. + * This can be used to check for preemption externally, e.g. when + * implementing custom sleep logic with a different clock source. + * Returns nullptr if the tree has not been initialized yet. + */ + [[nodiscard]] std::shared_ptr wakeUpSignal() const; + ~Tree(); /// Tick the root of the tree once, even if a node invoked diff --git a/src/bt_factory.cpp b/src/bt_factory.cpp index 42cf43307..acd907a31 100644 --- a/src/bt_factory.cpp +++ b/src/bt_factory.cpp @@ -664,6 +664,11 @@ void Tree::emitWakeUpSignal() wake_up_->emitSignal(); } +std::shared_ptr Tree::wakeUpSignal() const +{ + return wake_up_; +} + Tree::~Tree() { haltTree();