41 if (status != prev_status)
59 throw LogicError(
"SyncActionNode MUST never return RUNNING");
65 #ifndef BT_NO_COROUTINES 67 #ifdef BT_BOOST_COROUTINE2 68 #include <boost/coroutine2/all.hpp> 69 using namespace boost::coroutines2;
72 #ifdef BT_BOOST_COROUTINE 73 #include <boost/coroutine/all.hpp> 74 using namespace boost::coroutines;
79 std::unique_ptr<coroutine<void>::pull_type>
coro;
80 std::function<void(coroutine<void>::push_type& yield)> func;
87 _p->func = [
this](coroutine<void>::push_type& yield) {
88 _p->yield_ptr = &yield;
104 if (!(
_p->coro) || !(*
_p->coro))
106 _p->coro.reset(
new coroutine<void>::pull_type(
_p->func));
133 throw std::logic_error(
"StatefulActionNode::onStart() must not return IDLE");
143 throw std::logic_error(
"StatefulActionNode::onRunning() must not return " 149 return initial_status;
162 using lock_type = std::unique_lock<std::mutex>;
168 halt_requested_ =
false;
169 thread_handle_ = std::async(std::launch::async, [
this]() {
173 if (!isHaltRequested())
178 catch (std::exception&)
180 std::cerr <<
"\nUncaught exception from the method tick(): [" 185 exptr_ = std::current_exception();
197 const auto exptr_copy = exptr_;
199 std::rethrow_exception(exptr_copy);
206 halt_requested_.store(
true);
208 if (thread_handle_.valid())
210 thread_handle_.wait();
The ActionNodeBase is the base class to use to create any kind of action. A particular derived class ...
virtual void halt() override
const NodeConfiguration & config() const
NodeStatus tick() override final
Method to be implemented by the user.
void halt() override final
NodeStatus status() const
virtual NodeStatus executeTick() override
throws if the derived class return RUNNING.
SyncActionNode(const std::string &name, const NodeConfiguration &config)
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
const std::string & name() const
Name of the instance, not the type.
std::unique_ptr< Pimpl > _p
const std::string & registrationName() const
registrationName is the ID used by BehaviorTreeFactory to create an instance.
virtual ~CoroActionNode() override
virtual NodeStatus executeTick() override final
The method that should be used to invoke tick() and setStatus();.
ActionNodeBase(const std::string &name, const NodeConfiguration &config)
std::unique_ptr< coroutine< void >::pull_type > coro
std::function< NodeStatus(TreeNode &)> TickFunctor
SimpleActionNode(const std::string &name, TickFunctor tick_functor, const NodeConfiguration &config)
virtual NodeStatus tick() override final
Method to be implemented by the user.
void setStatusRunningAndYield()
Use this method to return RUNNING and temporary "pause" the Action.
TickFunctor tick_functor_
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
CoroActionNode(const std::string &name, const NodeConfiguration &config)
virtual NodeStatus executeTick() override final
The method that should be used to invoke tick() and setStatus();.
coroutine< void >::push_type * yield_ptr
virtual BT::NodeStatus tick()=0
Method to be implemented by the user.
void setStatus(NodeStatus new_status)