BehaviorTree.CPP行为树学习:端口重映射

Remapping ports between Trees and SubTrees

[在行为树(主树)和子树之间端口重映射]

原英文链接:Tutorial 6: Ports remapping - BehaviorTree.CPP

In the CrossDoor example we saw that a SubTree looks like a single leaf Node from the point of view of its parent (MainTree in the example).

【在CrossDoor示例中,我们看到从父节点(示例中的MainTree)的角度来看,子树看起来像一个单叶节点。】

Furthermore, to avoid name clashing in very large trees, any tree and subtree use a different instance of the Blackboard.

【此外,为了避免在非常大的树中出现名称冲突,任何树和子树都使用不同的Blackboard实例。】

For this reason, we need to explicitly connect the ports of a tree to those of its subtrees.

【因此,我们需要显式地将树的端口连接到其子树的端口。】

Once again, you won't need to modify your C++ implementation since this remapping is done entirely in the XML definition.

【同样,您不需要修改C++实现,因为这种重新映射完全是在XML定义中完成的】

Example

【例子】

Let's consider this Beahavior Tree.

【我们来看一下这个行为树】

<root main_tree_to_execute = "MainTree">

    <BehaviorTree ID="MainTree">

        <Sequence name="main_sequence">
            <SetBlackboard output_key="move_goal" value="1;2;3" />
            <SubTree ID="MoveRobot" target="move_goal" output="move_result" />
            <SaySomething message="{move_result}"/>
        </Sequence>

    </BehaviorTree>

    <BehaviorTree ID="MoveRobot">
        <Fallback name="move_robot_main">
            <SequenceStar>
                <MoveBase       goal="{target}"/>
                <SetBlackboard output_key="output" value="mission accomplished" />
            </SequenceStar>
            <ForceFailure>
                <SetBlackboard output_key="output" value="mission failed" />
            </ForceFailure>
        </Fallback>
    </BehaviorTree>

</root>

 

You may notice that:

【你会发现】

We have a MainTree that includes a subtree called MoveRobot.

【我们有一个主树包含一个名叫“MoveRobot”的子树】

We want to "connect" (i.e. "remap") ports inside the MoveRobot subtree with other ports in the MainTree.

【我们希望将MoveRobot子树中的端口与MainTree中的其他端口“连接”(即“重新映射”)。】

This is done using the XMl tag , where the words internal/external refer respectively to a subtree and its parent.

【这是使用XMl标记完成的,其中单词internal/external分别指子树及其父树。】

The following image shows remapping between these two different trees.

【下图显示了这两个不同树之间的重新映射。】

Note that this diagram represents the dataflow and the entries in the respective blackboard, not the relationship in terms of Behavior Trees.

【请注意,此图表示数据流和相应黑板中的条目,而不是行为树的关系。】

In terms of C++, we don't need to do much. For debugging purpose, we may show some information about the current state of a blackboard with the method debugMessage().

【就C++而言,我们不需要做太多。出于调试目的,我们可以使用debugMessage()方法显示有关黑板当前状态的一些信息。】

int main()
{
    BT::BehaviorTreeFactory factory;

    factory.registerNodeType<SaySomething>("SaySomething");
    factory.registerNodeType<MoveBaseAction>("MoveBase");

    auto tree = factory.createTreeFromText(xml_text);

    NodeStatus status = NodeStatus::RUNNING;
    // Keep on ticking until you get either a SUCCESS or FAILURE state
    while( status == NodeStatus::RUNNING)
    {
        status = tree.tickRoot();
        // IMPORTANT: add sleep to avoid busy loops.
        // You should use Tree::sleep(). Don't be afraid to run this at 1 KHz.
        tree.sleep( std::chrono::milliseconds(1) );
    }

    // let's visualize some information about the current state of the blackboards.
    std::cout << "--------------" << std::endl;
    tree.blackboard_stack[0]->debugMessage();
    std::cout << "--------------" << std::endl;
    tree.blackboard_stack[1]->debugMessage();
    std::cout << "--------------" << std::endl;

    return 0;
}

/* Expected output:

    [ MoveBase: STARTED ]. goal: x=1 y=2.0 theta=3.00
    [ MoveBase: FINISHED ]
    Robot says: mission accomplished
    --------------
    move_result (std::string) -> full
    move_goal (Pose2D) -> full
    --------------
    output (std::string) -> remapped to parent [move_result]
    target (Pose2D) -> remapped to parent [move_goal]
    --------------
*/

 

【说明】

BehaviorTree.CPP行为树学习系列是翻译自源英文网站,由于个人知识能力水平有限,如有错误的地方,请在评论区留言,会不断修改和完善的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值