The XML format

翻译自:https://www.behaviortree.dev

BT XML

Basics of the XML schema [基础格式]

In the first tutorial this simple tree was presented. [在第一个教程中,介绍了这个简单的树。]

 <root main_tree_to_execute = "MainTree" >
     <BehaviorTree ID="MainTree">
        <Sequence name="root_sequence">
            <SaySomething   name="action_hello" message="Hello"/>
            <OpenGripper    name="open_gripper"/>
            <ApproachObject name="approach_object"/>
            <CloseGripper   name="close_gripper"/>
        </Sequence>
     </BehaviorTree>
 </root>

You may notice that: [您可能会注意到:]

  • The first tag of the tree is <root>. It should contain 1 or more tags <BehaviorTree>. [树的第一个标签是 。它应该包含 1 个或多个标签 。]

  • The tag <BehaviorTree> should have the attribute [ID]. [标签 应该具有属性 [ID]。]

  • The tag <root> should contain the attribute [main_tree_to_execute]. [标签 应包含属性 [main_tree_to_execute]。]

  • The attribute [main_tree_to_execute] is mandatory if the file contains multiple <BehaviorTree>, optional otherwise. [如果文件包含多个 ,则属性 [main_tree_to_execute] 是必需的,否则是可选的。]

  • Each TreeNode is represented by a single tag. In particular: [每个 TreeNode 都由一个标签表示。尤其是:]

    • The name of the tag is the ID used to register the TreeNode in the factory. [标签的名称是用于在工厂中注册 TreeNode 的 ID。]
    • The attribute [name] refers to the name of the instance and is optional. [属性 [name] 是指实例的名称,并且是可选的。]
    • Ports are configured using attributes. In the previous example, the action SaySomething requires the input port message. [端口是使用属性配置的。在前面的示例中,SaySomething 操作需要输入端口消息。]
  • In terms of number of children: [从孩子数量来看:]

    • ControlNodes contain 1 to N children. [ControlNodes 包含 1 到 N 个子节点。]
    • DecoratorNodes and Subtrees contain only 1 child. [DecoratorNodes 和 Subtrees 仅包含 1 个子节点。]
    • ActionNodes and ConditionNodes have no child. [ActionNodes 和 ConditionNodes 没有子节点。]

Ports Remapping and pointers to Blackboards entries [端口映射]

As explained in the second tutorial input/output ports can be remapped using the name of an entry in the Blackboard, in other words, the key of a key/value pair of the BB. [正如第二个教程中所解释的,输入/输出端口可以使用 Blackboard 中的条目名称重新映射,换句话说,BB 的键/值对的键。]

An BB key is represented using this syntax: {key_name}. [BB 键使用以下语法表示:{key_name}。]

In the following example: [在以下示例中:]

  • the first child of the Sequence prints “Hello”, [序列的第一个孩子打印“Hello”,]
  • the second child reads and writes the value contained in the entry of the blackboard called “my_message”; [第二个孩子读取和写入黑板条目中包含的值,称为“my_message”;]
 <root main_tree_to_execute = "MainTree" >
     <BehaviorTree ID="MainTree">
        <Sequence name="root_sequence">
            <SaySomething message="Hello"/>
            <SaySomething message="{my_message}"/>
        </Sequence>
     </BehaviorTree>
 </root>

Compact vs Explicit representation [紧凑表示 vs 显示表示]

The following two syntaxes are both valid: [以下两种语法均有效:]

 <SaySomething               name="action_hello" message="Hello World"/>
 <Action ID="SaySomething"   name="action_hello" message="Hello World"/>

We will call the former syntax “compact” and the latter “explicit”. The first example represented with the explicit syntax would become: [我们将前一种语法称为“紧凑”,后一种称为“显式”。用显式语法表示的第一个示例将变为:]

 <root main_tree_to_execute = "MainTree" >
     <BehaviorTree ID="MainTree">
        <Sequence name="root_sequence">
           <Action ID="SaySomething"   name="action_hello" message="Hello"/>
           <Action ID="OpenGripper"    name="open_gripper"/>
           <Action ID="ApproachObject" name="approach_object"/>
           <Action ID="CloseGripper"   name="close_gripper"/>
        </Sequence>
     </BehaviorTree>
 </root>

Even if the compact syntax is more convenient and easier to write, it provides too little information about the model of the TreeNode. Tools like Groot require either the explicit syntax or additional information. This information can be added using the tag <TreeNodeModel>. [即使紧凑的语法更方便、更容易编写,它提供的关于 TreeNode 模型的信息也太少了。像 Groot 这样的工具需要明确的语法或附加信息。可以使用标签 添加此信息。]

To make the compact version of our tree compatible with Groot, the XML must be modified as follows: [为了使我们的树的紧凑版本与 Groot 兼容,必须按如下方式修改 XML:]

 <root main_tree_to_execute = "MainTree" >
     <BehaviorTree ID="MainTree">
        <Sequence name="root_sequence">
           <SaySomething   name="action_hello" message="Hello"/>
           <OpenGripper    name="open_gripper"/>
           <ApproachObject name="approach_object"/>
           <CloseGripper   name="close_gripper"/>
        </Sequence>
    </BehaviorTree>
	
	<!-- the BT executor don't require this, but Groot does --> 	
    <TreeNodeModel>
        <Action ID="SaySomething">
            <input_port name="message" type="std::string" />
        </Action>
        <Action ID="OpenGripper"/>
        <Action ID="ApproachObject"/>
        <Action ID="CloseGripper"/>      
    </TreeNodeModel>
 </root>

Note “XML Schema available for explicit version”
You can download the XML Schema here: behaviortree_schema.xsd. [您可以在此处下载 XML 模式:behaviortree_schema.xsd。]

Subtrees [子树]

As we saw in this tutorial, it is possible to include a Subtree inside another tree to avoid “copy and pasting” the same tree in multiple location and to reduce complexity. [正如我们在本教程中看到的,可以在另一棵树中包含一个子树,以避免在多个位置“复制和粘贴”同一棵树并降低复杂性。]

Let’s say that we want to incapsulate few action into the behaviorTree “GraspObject” (being optional, attributes [name] are omitted for simplicity). [假设我们想将一些动作封装到行为树“GraspObject”中(为可选,为简单起见省略了属性 [name])。]

 <root main_tree_to_execute = "MainTree" >
 
     <BehaviorTree ID="MainTree">
        <Sequence>
           <Action  ID="SaySomething"  message="Hello World"/>
           <SubTree ID="GraspObject"/>
        </Sequence>
     </BehaviorTree>
     
     <BehaviorTree ID="GraspObject">
        <Sequence>
           <Action ID="OpenGripper"/>
           <Action ID="ApproachObject"/>
           <Action ID="CloseGripper"/>
        </Sequence>
     </BehaviorTree>  
 </root>

We may notice as the entire tree “GraspObject” is executed after “SaySomething”. [我们可能会注意到整个树“GraspObject”是在“SaySomething”之后执行的。]

Include external files [外部文件引入]

Since version 2.4. [从 2.4 版开始。]

You can include external files in a way that is similar to #include in C++. We can do this easily using the tag: [您可以采用类似于 C++ 中的#include 的方式包含外部文件。我们可以使用标签轻松做到这一点:]

  <include path="relative_or_absolute_path_to_file">

using the previous example, we may split the two behavior trees into two files: [使用前面的示例,我们可以将两个行为树拆分为两个文件:]

 <!-- file maintree.xml -->

 <root main_tree_to_execute = "MainTree" >
	 
	 <include path="grasp.xml"/>
	 
     <BehaviorTree ID="MainTree">
        <Sequence>
           <Action  ID="SaySomething"  message="Hello World"/>
           <SubTree ID="GraspObject"/>
        </Sequence>
     </BehaviorTree>
  </root>
 <!-- file grasp.xml -->

 <root main_tree_to_execute = "GraspObject" >
     <BehaviorTree ID="GraspObject">
        <Sequence>
           <Action ID="OpenGripper"/>
           <Action ID="ApproachObject"/>
           <Action ID="CloseGripper"/>
        </Sequence>
     </BehaviorTree>  
 </root>

Note “Note for ROS users”

If you want to find a file inside a ROS package, you can use this syntax: [如果要在 ROS 包中查找文件,可以使用以下语法:]
<include ros_pkg="name_package" path="path_relative_to_pkg/grasp.xml"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值