Wiki

(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Behavior Trees C++ Reference

Description: Behavior Trees C++ Reference

Keywords: decision_making

Tutorial Level: BEGINNER

Next Tutorial: decision_making/Tutorials/CogniTAO

BT Machine and Nodes definition

BT_HEADER

BT_HEADER(BT_NAME)

BT_ROOT

BT_ROOT_BGN(BT_NAME,EVENTS){ ... }BT_END(NAME)

BT

BT_BGN(NAME){ ... }BT_END(NAME)

BT_PAR

BT_PAR_BGN(NAME){ ... }BT_PAR_END(NAME)

BT_SEQ

BT_SEQ_BGN(NAME){ ... }BT_SEQ_END(NAME)

BT_SEL

BT_SEL_BGN(NAME){ ... }BT_SEL_END(NAME)

BT Task definition

BT_TASK

BT_TASK_BGN(NAME){ TASK_ACTIONS }BT_TASK_END(NAME)

BT_CALL_TASK

BT_CALL_TASK(TASK_NAME)

BT_CALL_FSM

BT_CALL_FSM(FSM_NAME)

BT_CALL_BT

BT_CALL_BT(BT_NAME)

Call BT

Example:

 BT_ROOT_BGN(NAME,EVENTS){
 ....
 }
 BT_END(NAME) instance;
 instance.run();

BT Task Actions

The next macros you can use inside of BT_TASK block.

BT_TASK_RESULT

BT_TASK_RESULT(RESULT)

Node name, type, pointer utilities for custom BT_TASK

BT_NODE(NODE_NAME)

BT_NODE_TYPE(NODE_NAME)

BT_NODE_PTR(NODE_NAME)

BT_NODE_NEW_PTR(NODE_NAME)

BT_LAST_NODE

BT_LAST_NODE

BT_RUN_LAST_NODE

BT_RUN_LAST_NODE

BT_RUN_NODE(NODE_NAME)

Example:

 BT_TASK_BGN(T1)
 {
     BT_TASK_BGN(T1T1) // define custom bt_task
     {
        ...
     }
     BT_TASK_END(T1T1)
     BT_LAST_NODE->run(); // run last defined in current block task : run T1T1
     for(int i=0;i<3;i++){
          BT_CALL_TASK(T1RT1); // define call to remote/local task T1RT1
          TaskResult res = BT_NODE(T1RT1)->run(); // run T1RT1
          BT_TASK_RESULT(res); // set result of T1RT1 as result of T1
     }
 }
 TASK_END(T1)

BT Context

BT_RENAME_CONTEXT(NEW_NAME)

BT_NEW_CONTEXT(...)

Example:

BT_NEW_CONTEXT(
        int x;
        int y;
        double bearing;
)
BT_ROOT_BGN(B1){
        BT_TASK_BGN(T1){
                ...
                cout<<" x,y = "<<context.x<<","<<context.y<<endl;
                ...
                context.bearing = M_PI;
                ...
        }
        BT_TASK_END(T1)
}
BT_END(B1)

FSM Events

EventQueue is a events distribution system. It's used for sharing events inside of FSM/HSM/BT machines. It's possible to insert external events to system (from ROS or other custom source). It's thread safe.

Each Event is a path contains all context names when this event was created and event short name on the end. Example: /Con/tex/Na/me/EventName. When you compare two events you can use Regular Expressions in name of one event by writing @ on the begging of the name. Example: @/Con/.*/Event[NT]...e

Events usage : (STOP event for example)

Interface:

Common extensions :

BT_RAISE

BT_RAISE(EVENT)

Example

  MapResultEvent::map(''TASK_NAME'', ''ERROR_CODE'', ''EVENT_NAME'');

CallContext

This is a class for shearing parameters and call context information through calls of FSM/HSM/BT machines. You can get access to CallContext inside of BT by special local variable call_ctx.

Interface:

Tasks

Task is a atomic preemtable action. decision making support two types of Tasks

  1. ROS remote task
  2. Local task

ROS remote task

Special Activelib client. For create this kind of task, you need extend RobotTask class from robot_task package.

Local task

It's a callback function:

TaskResult FUNCTION_NAME( string task_name, const CallContext& context, EventQueue& events)

You need to registrate local task before usage (otherwise, the system assumes that the task is remote).

LocalTasks::registrate(''TASK_NAME'', ''CALLBACK'')

Wiki: decision_making/Tutorials/BehaviorTree(C++) (last edited 2013-12-29 13:42:50 by Ari Yakir)