Classes | Namespaces | Defines | Typedefs | Functions
BT.h File Reference
#include <boost/thread.hpp>
#include <deque>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/preprocessor/slot/counter.hpp>
#include "EventSystem.h"
#include "TaskResult.h"
Include dependency graph for BT.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  decision_making::BTCaller
struct  decision_making::BTContext
struct  decision_making::BTNode

Namespaces

namespace  decision_making

Defines

#define ___BTLABEL_(p, a)   ___BTMERGE_(p, a)
#define ___BTMERGE_(a, b)   a##b
#define ___BTUNIQUE_NAME(p)   ___BTLABEL_(p,__COUNTER__)
#define __BT_CALL_BT_CALLER(NAME)
#define __BT_CALL_BT_NONAME(NAME)
#define __BT_CREATE_BT_CALL_FUNCTION(BTNAME, P_call_ctx, P_events_queu)
#define __BT_END_NODE(NAME)
#define __BT_END_NODE_NONAME
#define __BT_END_TASK(NAME)   __BT_END_NODE(NAME); BT_CALL_BT(NAME)
#define __BT_END_TASK_NONAME   __BT_END_NODE_NONAME; __BT_CALL_BT_NONAME(__COUNTER__)
#define __BT_NODE_BGN(TYPE, NAME, STR)
#define __BT_POSTDEF   ;}
#define __BT_PREDEF(NAME)
#define __BTDEFSUBCTEXT(NAME)   decision_making::CallContext& call_ctx_##NAME(call_ctx);
#define __BTDEFSUBEVENTQUEUE(NAME)   decision_making::EventQueue events_##NAME(&events);
#define __CALL_BT_FUNCTION(NAME, CALLS, EVENTS)   _bt_function_struct_instance##BT1.getThread()
#define __MAX(x, y)   ((x)>(y)?(x):(y))
#define __MIN(x, y)   ((x)<(y)?(x):(y))
#define BT_BGN(NAME)   __BT_NODE_BGN(BT_SEQ, NAME, "=>")
#define BT_CALL_BT(NAME)
#define BT_CALL_FSM(NAME)
#define BT_CALL_TASK(NAME)
#define BT_CONTEXT   calls
#define BT_DEC_FAIL_BGN(ERROR_CODE)   BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_FAIL_)){ int _error_code = ERROR_CODE;
#define BT_DEC_FAIL_END
#define BT_DEC_NOT_BGN   BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_NOT_)){
#define BT_DEC_NOT_END
#define BT_DEC_SUCCESS_BGN   BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_SUCCESS_)){
#define BT_DEC_SUCCESS_END
#define BT_DEC_WHILE_BGN(CONDITION)
#define BT_DEC_WHILE_END
#define BT_END(NAME)   __BT_END_NODE(NAME)
#define BT_HEADER(NAME)   struct BT_NODE_TYPE(NAME);
#define BT_INNER_CONTEXT   context
#define BT_LAST_NODE   __ALL_NODES.back()
#define BT_NEW_INNER_CONTEXT(...)   struct BTContext{__VA_ARGS__} context
#define BT_NODE(NAME)   __BT_NODE_##NAME##_INSTANCE
#define BT_NODE_NEW_PTR(NAME)   BT_NODE_PTR(NAME)((BTNode*)new BT_NODE_TYPE(NAME)(this))
#define BT_NODE_PTR(NAME)   boost::shared_ptr<BTNode>
#define BT_NODE_TYPE(NAME)   __BT_NODE_##NAME##_STRUCT
#define BT_PAR_BGN(NAME)   __BT_PREDEF(NAME) __BT_NODE_BGN(BT_PAR, NAME, "||")
#define BT_PAR_END(NAME)   __BT_END_TASK(NAME) __BT_POSTDEF
#define BT_RAISE(EVENT)
#define BT_RENAME_INNER_CONTEXT(NEW_NAME)   typedef BTContext NEW_NAME##Type; NEW_NAME##Type& NEW_NAME=context;
#define BT_RISE(EVENT)   BT_RAISE(EVENT)
#define BT_ROOT_BGN(NAME, EVENTS)
#define BT_RUN_LAST_NODE   BT_LAST_NODE->run()
#define BT_RUN_NODE(NAME)   BT_NODE(NODE)->run()
#define BT_SEL_BGN(NAME)   __BT_PREDEF(NAME) __BT_NODE_BGN(BT_SEL, NAME, "??")
#define BT_SEL_END(NAME)   __BT_END_TASK(NAME) __BT_POSTDEF
#define BT_SEQ_BGN(NAME)   __BT_PREDEF(NAME) __BT_NODE_BGN(BT_SEQ, NAME, "->")
#define BT_SEQ_END(NAME)   __BT_END_TASK(NAME) __BT_POSTDEF
#define BT_SET_TASK_RESULT(RESULT)
#define BT_SET_TASK_RESULT_AFTER(RESULT, time)
#define BT_SLEEP(time)   for(int i=0;i<__MAX(1,(float(time)/0.5F)) and not isTerminated();i++){ boost::this_thread::sleep(boost::posix_time::milliseconds(1000*__MIN(0.5F,time-0.5F*i))); }
#define BT_TASK_BGN(NAME)   __BT_PREDEF(NAME) __BT_NODE_BGN(BT_TASK, NAME, "") decision_making::TaskResult bt_node_return_value = decision_making::TaskResult::UNDEF();
#define BT_TASK_END(NAME)   __BT_END_TASK(NAME) __BT_POSTDEF
#define BT_TASK_END_NONAME   __BT_END_TASK_NONAME __BT_POSTDEF
#define BT_TASK_RESULT(X)   bt_node_return_value = X
#define BTNodeContructorParams_DEF   BTNodeTYPE t, string node_name, const CallContext& parent_call_ctx, EventQueue& events
#define BTNodeContructorParams_USE   parent_call_ctx, events
#define DMDEBUG(...)

Typedefs

typedef BTNode decision_making::CurrentNodeType

Functions

static EventQueue & decision_making::__tmp_event_queue ()

Define Documentation

#define ___BTLABEL_ (   p,
 
)    ___BTMERGE_(p, a)

Definition at line 300 of file BT.h.

#define ___BTMERGE_ (   a,
 
)    a##b

Definition at line 299 of file BT.h.

#define ___BTUNIQUE_NAME (   p)    ___BTLABEL_(p,__COUNTER__)

Definition at line 301 of file BT.h.

#define __BT_CALL_BT_CALLER (   NAME)
Value:
call_ctx.pop(); \
                BT_NODE_PTR(NAME) BT_NODE(NAME)((BTNode*)new BT_NODE_TYPE(NAME)(this, context, call_ctx, events));\
                __ALL_NODES.push_back(BT_NODE(NAME))

Definition at line 182 of file BT.h.

#define __BT_CALL_BT_NONAME (   NAME)
Value:
__LAST_BT_NODE_PTR BT_NODE(NAME)((BTNode*)new __LAST_BT_NODE_TYPE(this, context, call_ctx, events));\
                __ALL_NODES.push_back(BT_NODE(NAME));\
                CUR_NODE = BT_NODE(NAME);

Definition at line 177 of file BT.h.

#define __BT_CREATE_BT_CALL_FUNCTION (   BTNAME,
  P_call_ctx,
  P_events_queu 
)
Value:
struct _bt_function_struct##BTNAME: public decision_making::BTCaller{\
                                        _bt_function_structBT1(std::string task_address, decision_making::CallContext& call_ctx, decision_making::EventQueue& queue):decision_making::BTCaller(task_address,call_ctx,queue){}\
                                        decision_making::TaskResult _bt_function(){\
                                                BTContext _tmp_context;\
                                                BT_ROOT_BGN(bt_from_fsm, __tmp_event_queue()){\
                                                        call_ctx.pop();\
                                                        BT_PAR_BGN(TMP){\
                                                                call_ctx.pop();\
                                                                BT_TASK_BGN(STOP_CONDITION){\
                                                                        while(not isTerminated())\
                                                                        {\
                                                                                decision_making::Event e = events.waitEvent();\
                                                                                if(not e){\
                                                                                        DMDEBUG( cout<<" (STOP_CONDITION:TERMINATED) "; )\
                                                                                        BT_TASK_RESULT( decision_making::TaskResult::TERMINATED() );\
                                                                                        break;\
                                                                                }\
                                                                        }\
                                                                }\
                                                                BT_TASK_END(STOP_CONDITION);\
                                                                __BT_CALL_BT_CALLER(BTNAME);\
                                                        }\
                                                        BT_PAR_END(TMP);\
                                                }\
                                                BT_END(bt_from_fsm) bt_from_fsm(_tmp_context, call_ctx, queue);\
                                                decision_making::TaskResult res = bt_from_fsm.run();\
                                                DMDEBUG( cout<<"(fsm from function finished)"; )\
                                                return res;\
                                        }\
                                }  _bt_function_struct_instanceBT1(#BTNAME, P_call_ctx, P_events_queu);

Definition at line 427 of file BT.h.

#define __BT_END_NODE (   NAME)
Value:
this->run_all();\
                        DMDEBUG( cout<<" }[BT:" #NAME "] "; )\
                        ON_BT_NODE_END(#NAME, call_ctx, events, bt_node_return_value);\
                        return bt_node_return_value;\
                }\
        }

Definition at line 221 of file BT.h.

Value:
this->run_all();\
                        DMDEBUG( cout<<" }[BT:" <<MY_NODE_NAME<< "] "; )\
                        ON_BT_NODE_END(MY_NODE_NAME, call_ctx, events, bt_node_return_value);\
                        return bt_node_return_value;\
                }\
        }

Definition at line 228 of file BT.h.

Definition at line 260 of file BT.h.

Definition at line 261 of file BT.h.

#define __BT_NODE_BGN (   TYPE,
  NAME,
  STR 
)
Value:
struct BT_NODE_TYPE(NAME):public BTNode\
        { \
                typedef BT_NODE_TYPE(NAME) MY_NODE_TYPE;\
                BTContext& context;\
                std::string MY_NODE_NAME;\
                BT_NODE_TYPE(NAME)(BTNode* p, BTContext& ctx, const decision_making::CallContext& calls, decision_making::EventQueue& events):BTNode(TYPE, #NAME, calls, events),context(ctx),MY_NODE_NAME(#NAME){\
                        p->tasks.push_back(this);\
                }\
                TaskResult run()\
                {\
                        DMDEBUG( cout<<" [BT:" #NAME STR "]{ "; ) \
                        ON_BT_NODE_START(#NAME, #TYPE, call_ctx, events);\
                        BTNode* const& selfPtrForRosTaskCaller=this;\
                        std::vector<BT_NODE_PTR()> __ALL_NODES;

Definition at line 205 of file BT.h.

#define __BT_POSTDEF   ;}

Definition at line 244 of file BT.h.

#define __BT_PREDEF (   NAME)
Value:
BT_NODE_PTR(NAME) BT_NODE(NAME); \
                {\
                        BT_NODE_PTR(NAME)& CUR_NODE=BT_NODE(NAME);\
                        struct BT_NODE_TYPE(NAME);\
                        typedef BT_NODE_TYPE(NAME) __LAST_BT_NODE_TYPE;\
                        typedef BT_NODE_PTR(NAME) __LAST_BT_NODE_PTR;

Definition at line 236 of file BT.h.

#define __BTDEFSUBCTEXT (   NAME)    decision_making::CallContext& call_ctx_##NAME(call_ctx);

Definition at line 279 of file BT.h.

#define __BTDEFSUBEVENTQUEUE (   NAME)    decision_making::EventQueue events_##NAME(&events);

Definition at line 276 of file BT.h.

#define __CALL_BT_FUNCTION (   NAME,
  CALLS,
  EVENTS 
)    _bt_function_struct_instance##BT1.getThread()

Definition at line 459 of file BT.h.

#define __MAX (   x,
 
)    ((x)>(y)?(x):(y))

Definition at line 356 of file BT.h.

#define __MIN (   x,
 
)    ((x)<(y)?(x):(y))

Definition at line 357 of file BT.h.

#define BT_BGN (   NAME)    __BT_NODE_BGN(BT_SEQ, NAME, "=>")

Definition at line 247 of file BT.h.

#define BT_CALL_BT (   NAME)
Value:
BT_NODE_PTR(NAME) BT_NODE(NAME)((BTNode*)new BT_NODE_TYPE(NAME)(this, context, call_ctx, events));\
                __ALL_NODES.push_back(BT_NODE(NAME));\
                CUR_NODE = BT_NODE(NAME);

Definition at line 172 of file BT.h.

#define BT_CALL_FSM (   NAME)
Value:
__BT_NODE_BGN(BT_TASK, NAME, "")\
                                                call_ctx.pop();\
                                                bt_node_return_value = Fsm##NAME(&call_ctx, &events);\
                                        __BT_END_TASK(NAME)

Definition at line 286 of file BT.h.

#define BT_CALL_TASK (   NAME)
Value:
__BT_NODE_BGN(BT_TASK, NAME, "")\
                                                __BTDEFSUBEVENTQUEUE(NAME) __BTDEFSUBCTEXT(NAME)\
                                                bt_node_return_value = CALL_REMOTE(NAME,boost::ref(call_ctx_##NAME), boost::ref(events_##NAME))(); \
                                        __BT_END_TASK(NAME)

Definition at line 281 of file BT.h.

#define BT_CONTEXT   calls

Definition at line 169 of file BT.h.

#define BT_DEC_FAIL_BGN (   ERROR_CODE)    BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_FAIL_)){ int _error_code = ERROR_CODE;

Definition at line 328 of file BT.h.

#define BT_DEC_FAIL_END
Value:

Definition at line 331 of file BT.h.

#define BT_DEC_NOT_BGN   BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_NOT_)){

Definition at line 307 of file BT.h.

#define BT_DEC_NOT_END
#define BT_DEC_SUCCESS_BGN   BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_SUCCESS_)){

Definition at line 318 of file BT.h.

Value:

Definition at line 321 of file BT.h.

#define BT_DEC_WHILE_BGN (   CONDITION)
Value:
BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_DEC_WHILE_)){ \
                        struct CHECK_RESULT{\
                                decision_making::TaskResult task_result;\
                                bool check(){ return task_result.CONDITION ;}\
                        } _CHECK_RESULT;\
                        do{

Definition at line 339 of file BT.h.

Value:
if(not isTerminated())\
                        _CHECK_RESULT.task_result = BT_LAST_NODE->run(); }while( _CHECK_RESULT.check() and not isTerminated() );\
                BT_TASK_RESULT( _CHECK_RESULT.task_result );\
        }BT_TASK_END_NONAME;

Definition at line 347 of file BT.h.

#define BT_END (   NAME)    __BT_END_NODE(NAME)

Definition at line 258 of file BT.h.

#define BT_HEADER (   NAME)    struct BT_NODE_TYPE(NAME);

Definition at line 189 of file BT.h.

#define BT_INNER_CONTEXT   context

Definition at line 170 of file BT.h.

#define BT_LAST_NODE   __ALL_NODES.back()

Definition at line 161 of file BT.h.

#define BT_NEW_INNER_CONTEXT (   ...)    struct BTContext{__VA_ARGS__} context

Definition at line 167 of file BT.h.

#define BT_NODE (   NAME)    __BT_NODE_##NAME##_INSTANCE

Definition at line 157 of file BT.h.

#define BT_NODE_NEW_PTR (   NAME)    BT_NODE_PTR(NAME)((BTNode*)new BT_NODE_TYPE(NAME)(this))

Definition at line 160 of file BT.h.

#define BT_NODE_PTR (   NAME)    boost::shared_ptr<BTNode>

Definition at line 159 of file BT.h.

#define BT_NODE_TYPE (   NAME)    __BT_NODE_##NAME##_STRUCT

Definition at line 158 of file BT.h.

#define BT_PAR_BGN (   NAME)    __BT_PREDEF(NAME) __BT_NODE_BGN(BT_PAR, NAME, "||")

Definition at line 253 of file BT.h.

Definition at line 268 of file BT.h.

#define BT_RAISE (   EVENT)
Value:
DMDEBUG( cout<<" RAISE("<<node_name<<":"<<decision_making::Event(EVENT, call_ctx)<<") "; ) \
                        events.raiseEvent(decision_making::Event(EVENT, call_ctx));

Definition at line 292 of file BT.h.

#define BT_RENAME_INNER_CONTEXT (   NEW_NAME)    typedef BTContext NEW_NAME##Type; NEW_NAME##Type& NEW_NAME=context;

Definition at line 166 of file BT.h.

#define BT_RISE (   EVENT)    BT_RAISE(EVENT)

Definition at line 297 of file BT.h.

#define BT_ROOT_BGN (   NAME,
  EVENTS 
)
Value:
struct BT_NODE_TYPE(NAME):public BTNode\
        { \
                BTContext _tmp_context; BTContext& context;\
                BT_NODE_TYPE(NAME)():BTNode(BT_SEQ, #NAME, decision_making::CallContext(), EVENTS),_tmp_context(),context(_tmp_context){}\
                BT_NODE_TYPE(NAME)(BTContext& ctx, const decision_making::CallContext& calls, decision_making::EventQueue& events):BTNode(BT_SEQ, #NAME, calls, events),context(ctx){}\
                TaskResult run(){\
                        DMDEBUG( cout<<" [BT:" #NAME " MAIN" "]{ "; ) \
                        ON_BT_NODE_START(#NAME, "ROOT", call_ctx, events);\
                        BTNode* const& selfPtrForRosTaskCaller=this;\
                        std::vector< BT_NODE_PTR() > __ALL_NODES;

Definition at line 193 of file BT.h.

#define BT_RUN_LAST_NODE   BT_LAST_NODE->run()

Definition at line 163 of file BT.h.

#define BT_RUN_NODE (   NAME)    BT_NODE(NODE)->run()

Definition at line 164 of file BT.h.

#define BT_SEL_BGN (   NAME)    __BT_PREDEF(NAME) __BT_NODE_BGN(BT_SEL, NAME, "??")

Definition at line 254 of file BT.h.

Definition at line 269 of file BT.h.

#define BT_SEQ_BGN (   NAME)    __BT_PREDEF(NAME) __BT_NODE_BGN(BT_SEQ, NAME, "->")

Definition at line 255 of file BT.h.

Definition at line 270 of file BT.h.

#define BT_SET_TASK_RESULT (   RESULT)
Value:
BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_SET_TASK_RESULT_)){ \
                    BT_TASK_RESULT( RESULT );\
            }BT_TASK_END_NONAME;

Definition at line 362 of file BT.h.

#define BT_SET_TASK_RESULT_AFTER (   RESULT,
  time 
)
Value:
BT_TASK_BGN(___BTUNIQUE_NAME(_lbl_BT_SET_TASK_RESULT_)){ \
                        BT_SLEEP(time)\
                    BT_TASK_RESULT( RESULT );\
            }BT_TASK_END_NONAME;

Definition at line 367 of file BT.h.

#define BT_SLEEP (   time)    for(int i=0;i<__MAX(1,(float(time)/0.5F)) and not isTerminated();i++){ boost::this_thread::sleep(boost::posix_time::milliseconds(1000*__MIN(0.5F,time-0.5F*i))); }

Definition at line 359 of file BT.h.

Definition at line 256 of file BT.h.

Definition at line 271 of file BT.h.

Definition at line 272 of file BT.h.

#define BT_TASK_RESULT (   X)    bt_node_return_value = X

Definition at line 156 of file BT.h.

#define BTNodeContructorParams_DEF   BTNodeTYPE t, string node_name, const CallContext& parent_call_ctx, EventQueue& events

Definition at line 42 of file BT.h.

#define BTNodeContructorParams_USE   parent_call_ctx, events

Definition at line 43 of file BT.h.

#define DMDEBUG (   ...)

Definition at line 23 of file BT.h.



decision_making
Author(s):
autogenerated on Wed Aug 26 2015 11:16:53