코어 라이브러리의 구조 (Structure of the Core Library)

코어 라이브러리의 구조 (Structure of the Core Library)

1. 개요

BehaviorTree.CPP의 코어 라이브러리는 행동 트리의 기본 메커니즘을 구현하는 핵심 모듈이다. 노드 기반 클래스, 상태 정의, tick 메커니즘, 트리 구조 관리 등이 코어 라이브러리에 포함된다.

2. 코어 클래스 계층

BT::TreeNode
├── type(): NodeType
├── status(): NodeStatus
├── executeTick(): NodeStatus
├── halt(): void
├── config(): NodeConfiguration
├── getInput<T>() / setOutput<T>()
│
├── BT::ControlNode
│   ├── children(): vector<TreeNode*>
│   ├── addChild(TreeNode*)
│   └── haltChildren()
│
├── BT::DecoratorNode
│   ├── child(): TreeNode*
│   ├── setChild(TreeNode*)
│   └── haltChild()
│
├── BT::ActionNodeBase
│   ├── BT::SyncActionNode (동기)
│   ├── BT::StatefulActionNode (상태 기반)
│   └── BT::CoroActionNode (코루틴)
│
└── BT::ConditionNode (조건)

3. 핵심 열거형

3.1 NodeStatus

enum class NodeStatus
{
    IDLE = 0,
    RUNNING = 1,
    SUCCESS = 2,
    FAILURE = 3,
    SKIPPED = 4  // 4.x에서 추가
};

3.2 NodeType

enum class NodeType
{
    UNDEFINED = 0,
    ACTION,
    CONDITION,
    CONTROL,
    DECORATOR,
    SUBTREE
};

4. TreeNode 기반 클래스의 핵심 인터페이스

메서드역할
executeTick()상태 관리 후 tick() 호출
tick()순수 가상: 노드의 핵심 로직
halt()노드 중단 및 상태 초기화
status()현재 노드 상태 반환
name()노드 이름 반환
getInput<T>()입력 포트에서 값 읽기
setOutput<T>()출력 포트에 값 쓰기
config()노드 설정(포트, 블랙보드) 접근

5. NodeConfiguration

struct NodeConfiguration
{
    std::shared_ptr<Blackboard> blackboard;
    std::unordered_map<std::string, std::string> input_ports;
    std::unordered_map<std::string, std::string> output_ports;
    std::string path;  // 트리 내 노드 경로
};

6. Tree 객체

class Tree
{
public:
    NodeStatus tickOnce();
    NodeStatus tickWhileRunning();
    void haltTree();

    std::shared_ptr<Blackboard> rootBlackboard();
    std::vector<TreeNode*> nodes;
    std::vector<std::shared_ptr<Blackboard>> blackboard_stack;
};

7. 코어 라이브러리의 외부 의존성

의존성용도필수 여부
tinyxml2XML 파싱필수 (내장)
ZeroMQGroot2 실시간 통신선택
minitraceChrome Tracing 로그선택

코어 라이브러리의 필수 의존성은 tinyxml2뿐이며, 이는 라이브러리에 내장되어 있다. 외부 의존성을 최소화하여 경량성을 유지한다.

8. 참고 문헌

  • BehaviorTree.CPP 공식 문서. https://www.behaviortree.dev/
  • BehaviorTree.CPP GitHub. https://github.com/BehaviorTree/BehaviorTree.CPP

버전날짜변경 사항
v0.12026-04-05초안 작성