44 if (status != prev_status)
62 throw LogicError(
"SyncActionNode MUST never return RUNNING");
69 #ifndef BT_NO_COROUTINES 71 #ifdef BT_BOOST_COROUTINE2 72 #include <boost/coroutine2/all.hpp> 73 using namespace boost::coroutines2;
76 #ifdef BT_BOOST_COROUTINE 77 #include <boost/coroutine/all.hpp> 78 using namespace boost::coroutines;
83 std::unique_ptr<coroutine<void>::pull_type>
coro;
84 std::function<void(coroutine<void>::push_type & yield)> func;
92 _p->func = [
this](coroutine<void>::push_type & yield) {
93 _p->yield_ptr = &yield;
110 if( !(
_p->coro) || !(*
_p->coro) )
112 _p->coro.reset(
new coroutine<void>::pull_type(
_p->func) );
141 throw std::logic_error(
"AsyncActionNode2::onStart() must not return IDLE");
151 throw std::logic_error(
"AsyncActionNode2::onRunning() must not return IDLE");
156 return initial_status;
175 halt_requested_ =
false;
176 thread_handle_ = std::async(std::launch::async, [
this]() {
181 catch (std::exception&)
183 std::cerr <<
"\nUncaught exception from the method tick(): [" 185 exptr_ = std::current_exception();
186 thread_handle_.wait();
194 std::rethrow_exception(exptr_);
201 halt_requested_.store(
true);
203 if( thread_handle_.valid() ){
204 thread_handle_.wait();
The ActionNodeBase is the base class to use to create any kind of action. A particular derived class ...
const std::string & name() const
Name of the instance, not the type.
virtual void halt() override
const NodeConfiguration & config() const
virtual NodeStatus executeTick() override
throws if the derived class return RUNNING.
SyncActionNode(const std::string &name, const NodeConfiguration &config)
void halt() overridefinal
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
std::unique_ptr< Pimpl > _p
virtual ~CoroActionNode() override
ActionNodeBase(const std::string &name, const NodeConfiguration &config)
std::unique_ptr< coroutine< void >::pull_type > coro
virtual NodeStatus executeTick() overridefinal
The method that should be used to invoke tick() and setStatus();.
virtual NodeStatus executeTick() overridefinal
The method that should be used to invoke tick() and setStatus();.
std::function< NodeStatus(TreeNode &)> TickFunctor
SimpleActionNode(const std::string &name, TickFunctor tick_functor, const NodeConfiguration &config)
void setStatusRunningAndYield()
Use this method to return RUNNING and temporary "pause" the Action.
NodeStatus status() const
NodeStatus tick() overridefinal
Method to be implemented by the user.
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)
coroutine< void >::push_type * yield_ptr
const std::string & registrationName() const
registrationName is the ID used by BehaviorTreeFactory to create an instance.
virtual NodeStatus tick() overridefinal
Method to be implemented by the user.
virtual BT::NodeStatus tick()=0
Method to be implemented by the user.
void setStatus(NodeStatus new_status)