机器人的描述文件Xacro解读

XACRO文件和URDF实质上是等价的,都是用来描述机器人的文件. 但是XACRO格式提供了一些更高级的方式来组织编辑机器人描述. 主要提供了三种方式来使得整个描述文件变得简单. 借用在教程中一句话来形容xacro的优势: “Fortunately, you can use the xacro package to make your life simpler”.

下面我们就来看看XACRO文件,下面是RBX2上面的一篇关于激光扫描仪的模型,我们通过注释来解读它的文法。

<?xml version="1.0" encoding="utf-8" ?>
<robot name="laser" xmlns:xacro="http://ros.org/wiki/xacro"> <!--laser:激光-->
上面两句是所有的URDF/XACRO文件开头都会使用的标签,所有在<robot>标签后的内容都是在定义我们的组件

 <!--定义激光扫描仪的宏-->
    <macro name="laser" params="parent color *origin">这个宏是定义我们宏的名称以及所需要使用的参数
    joint是关节,我们要定义它的名称和连接类型,比如fixed 

用<link> tag描述各个部件,<joint> tag描述各个关节。用<parent>和<child>描述关节连接的部件。

只要描述了Link和Joint之间的关系,我们很容易就能构建机器人的框架。

<visual>用来描述模块的视觉效果。

<geometry>用来描述模块的形状和大小。

<origin>用来描述模块的位置。

 <collision>是为机器人提供一个安全缓冲区,防止轮子和障碍物发生碰撞。
 我们可以看到collision和visual(机器人部件)是一样的
    <joint name ="${parent}_laser_bottom_joint" type ="fixed" >
<!--bottom: 底部 fixed: 固定 --> < name ="origin" /> <child link ="base_laser_bottom" /> </joint> <link name ="base_laser_bottom" > <visual> 可视部分,也就是说这个标签以内的在rviz种时可见的 <origin xyz ="0 0 0" rpy ="0 0 0" /> <geometry> 这里摄制部件形状和大小,可以设置方块、圆或者圆柱体 <box size ="0.05 0.05 0.041" /> </geometry> <material name ="${color}" /> material是设置机器人部件颜色 </visual> <collision> <origin xyz ="0 0 0" rpy ="0 0 0" /> <geometry> <box size ="0.05 0.05 0.041" /> </geometry> </collision> <inertial> 这里是设置惯性,也就是质量,转动惯量矩阵等 <mass value ="0.1" /> 设置质量 <inertia ixx ="0.001" ixy ="0.0" ixz ="0.0" 设置转动惯量矩阵 需要一些刚体力学知识 iyy ="0.001" iyz ="0.0" izz ="0.001" /> </inertial> </link> <link name ="base_laser_middle" > <visual> <origin xyz ="0 0 0" rpy ="0 0 0" /> <geometry> <cylinder length ="0.0115" radius ="0.02" /> </geometry> <material name ="dark_grey" > <color rgba ="0.2 0.2 0.2 0.1" /> </material> </visual> <collision> <origin xyz ="0 0 0" rpy ="0 0 0" /> <geometry> <cylinder length ="0.0115" radius ="0.02" /> > </geometry> </collision> <inertial> <mass value ="0.1" /> <inertia ixx ="0.001" ixy ="0.0" ixz ="0.0" iyy ="0.001" iyz ="0.0" izz ="0.001" /> </inertial> </link> <joint name ="base_laser_middle_joint" type ="fixed" > <parent link ="base_laser_bottom" /> <child link ="base_laser_middle" /> <origin xyz ="0 0 0.02625" rpy ="0 0 0" /> </joint> <link name ="base_laser" > <!--base: 底座 --> <visual> <origin xyz ="0 0 0" rpy ="0 0 0" /> <geometry> <cylinder length ="0.0175" radius ="0.0185" /> </geometry> <material name ="red" > <color rgba ="0.8 0.1 0.1 1.0" /> </material> </visual> <collision> <origin xyz ="0 0 0" rpy ="0 0 " /> <geometry> <cylinder length ="0.0175" radius ="0.0185" /> </geometry> </collision> <inertial> <mass value ="0.1" /> <inertia ixx ="0.001" ixy ="0.0" ixz ="0.0" iyy ="0.001" iyz ="0.0" izz ="0.001" /> </inertial> </link> <joint name ="base_laser_joint" type ="fixed" > <parent link ="base_laser_middle" /> <child link ="base_laser" /> <origin xyz ="0 0 0.0145" rpy ="0 0 0" /> </joint> </macro> </robot>


其实大家可以看到手写机器人描述文件是非常麻烦的,我们用的最多也是最方便的建模方法是使用SolidWorks CAD三维设计软件来制作机器人模型。

猜你喜欢

转载自blog.csdn.net/dzhongjie/article/details/80398681