urdf 学习笔记一

学习写urdf有几个地方需要注意

1. 一定要记住它使用的是右手坐标系。

x正方向朝左, y 正方向向内, z轴正方向朝上

2. 构建树结构, 即写link和joint

3. 每个link的参考坐标系都在它的底部,并与关节的参考坐标系正交,为了添加尺寸,需要指定偏移从一个link到它的关节的子link, 这通过添加origin到每个节点解决。

这么说origin表示的是关节相对于父关节的距离和旋转, xyzrpy

用ros wiki上的r2d2实例学习

1.初始版本

<?xml version="1.0"?>
<robot name="origins">
  <link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
    </visual>
  </link>

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
     </visual>
  </link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
  </joint>

</robot>

 

 

2. 加入关节origin

因为basekink没有改变,所以这里省略baselink...

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
    </visual>
  </link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0.22 0 .25"/>(左移和上移, x轴左为正, z为上, y 垂直平面, 右手坐标系)
  </joint>

 

  

 

3. 加入link origin y轴 旋转

因为basekink没有改变,所以这里省略baselink...

 

<link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
      <origin rpy="0 1.57075 0"/> (y轴旋转90度)
  </visual>
</link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0.22 0 .25"/>
  </joint> 

  

4. 加入link origin xyz偏移

 因为basekink没有改变,所以这里省略baselink...

<link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
      <origin rpy="0 1.57075 0" xyz = “0 0 -0.3 ”/> (y轴旋转90度, 往下0.3)
    </visual>
</link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0.22 0 .25"/>
  </joint>

 

5. 给模型加入材质(穿上一件衣服)

 

<?xml version="1.0"?>
<robot name="origins">
  <link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
      <material name = "blue">
          <color rgba = "0 0 .8 1"/>
     </material>
    </visual>
  </link>

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
      <material name = "white">
          <color rgba = "1 1 1 1"/>
     </material>
      <origin rpy = "0 1.57 0" xyz = "0 0 -0.3"/>
    </visual>
  </link>

  

加上左臂

<?xml version="1.0"?>
<robot name="origins">
  <link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
      <material name = "blue">
          <color rgba = "0 0 .8 1"/>
     </material>
    </visual>
  </link>

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
      <material name = "white">
          <color rgba = "1 1 1 1"/>
     </material>
      <origin rpy = "0 1.57 0" xyz = "0 0 -0.3"/>
    </visual>
  </link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0.22 0 .25"/>
  </joint>

  <link name="left_leg">
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
      <material name = "white">
          <color rgba = "1 1 1 1"/>
     </material>
      <origin rpy = "0 1.57 0" xyz = "0 0 -0.3"/>
    </visual>
  </link>

  <joint name="base_to_left_leg" type="fixed">
    <parent link="base_link"/>
    <child link="left_leg"/>
    <origin xyz="-0.22 0 .25"/> 仅仅这里不同, 关节右移所以是负
  </joint>

</robot>


6. 添加头,sphere几何体

注意每定义个link都要为它添加一个关节,否则check_urdf时报错

Error:   Failed to find root link: Two root links found: [base_link] and [head]

没有给头link添加关节导致的错误。

<link name = "head">
      <visual>
          <geometry>
              <sphere radius = "0.2"/>
          </geometry>
          <material name = "white">
              <color rgba = "1 1 1 1"/>
          </material>
      </visual>
</link>
  <joint name = "head_swivel" type = "fixed">
      <parent link = "base_link"/>
      <child link = "head"/>
      <origin xyz = "0 0 0.3"/>
  </joint>

 

 

 8. 添加车轮和车轮底座

  

<link name = "right_wheel_base"> //右车轮底座
      <visual>
          <geometry>
              <box size = "0.1 .4 .1"/>
          </geometry>
          <material name = "yellow">
              <color rgba = "1 1 0 1"/>
          </material>
      </visual>
  </link>

  <joint name = "right_wheel_base_joint" type = "fixed">
      <parent link = "right_leg"/>
      <child link = "right_wheel_base"/>
      <origin xyz = "0 0 -0.65"/>
  </joint>

  <link name = "right_front_wheel"> // 右前轮
      <visual>
          <geometry>
              <cylinder length = "0.08" radius = "0.04"/>
          </geometry>
          <material name = "black">
              <color rgba = " 0 0 0 1"/>
          </material>
      </visual>
  </link>

  <joint name = "right_front_wheel_joint" type = "fixed">
      <parent link = "right_wheel_base"/>
      <child link = "right_front_wheel"/>
      <origin xyz = "0 .14 -.05" rpy = "1.5 0 1.5"/> // 旋转了车轮
  </joint>

  <link name = "right_back_wheel"> // 右后轮
      <visual>
          <geometry>
              <cylinder length = "0.08" radius = "0.04"/>
          </geometry>
          <material name = "black">
              <color rgba = " 0 0 0 1"/>
          </material>
      </visual>
  </link>

  <joint name = "right_back_wheel_joint" type = "fixed">
      <parent link = "right_wheel_base"/>
      <child link = "right_back_wheel"/>
      <origin xyz = "0 -.14 -.05" rpy = "1.5 0 1.5"/> // y轴为负,往后移
  </joint>

 

 

左轮也是一样设置,只需把right 改成left即可, 最后效果如下

 

 

 

posted @ 2015-12-15 03:47  嫣儿  阅读(7384)  评论(0编辑  收藏  举报