osrf / rosbook

Example code to accompany the book Programming Robots with ROS
Apache License 2.0
476 stars 237 forks source link

Please help me understand the origin tag in URDF #45

Closed lizixroy closed 6 years ago

lizixroy commented 6 years ago

Hi folks,

I have been struggling with how the origin tag means in URDF files.

In the chapter 18, there is a snippet of URDF as the following:

      <link name="base_link">
        <visual>
          <geometry>
            <cylinder length="0.05" radius="0.1"/>
          </geometry>
          <material name="silver">
            <color rgba="0.75 0.75 0.75 1"/>
          </material>
          <origin rpy="0 0 0" xyz="0 0 0.025"/>
        </visual>
      </link>

The origin tag xyz = 0 0 0.025 puzzles me. The books says the 0.025 is meant to "... offset in z the point of reference for the base link from its default in the cylinder's center to its bottom." What I don't understand is that if we need to push the origin to the bottom, shouldn't we use -0.25? Why would increase the z value make the origin go down instead of going up?

What's more perplexing is that, later in the joint, it seems using a positive z value in origin actually makes the origin go up:

      <joint name="hip" type="continuous">
        <axis xyz="0 0 1"/>
        <parent link="base_link"/>
        <child link="torso"/>
        <origin rpy="0 0 0" xyz="0.0 0.0 0.05"/>
      </joint>

Here my understanding is that the z value 0.05 is meant to push the origin of the joint to be top of the base link so the next link can start there.

Why does positive value in link's origin push origin downward but push origin upward in joints?

gbiggs commented 6 years ago

The origins in URDF files can take a little work to get your head around. It's inevitably been the biggest hurdle for people to overcome when I've taught people how to create URDF files.

The following URDF tutorial pages have a diagram and some explanation of the various origins in a single link.

http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20with%20URDF%20from%20Scratch#Origins

http://wiki.ros.org/urdf/Tutorials/Create%20your%20own%20urdf%20file

The key thing to remember is that the origin specified in the visual tag is for that visual element only. It places the visual element in relation to the link's origin. If you do not specify one, then the origin of the visual data will be the same as the link's origin, and because a cylinder by default has its origin at its own centre of mass, this would make the cylinder of base_link appear in the wrong place for where we want the link to appear. So by raising the cylinder by 0.025 m we effectively lower the origin of the link by the opposite amount. This way of thinking works because this link only has a single visual element. If you start creating links with multiple visual elements or start adding collision elements, you need to get your head around where the link's origin is (at the joint with the previous link) and how the origins of visual, collision and inertial elements relate to it.

If you can read Japanese, or at least make a guess as to the meaning, there are some different diagrams in my URDF tutorial text that might help you understand the relationships between the origins.

https://gbiggs.github.io/rosjp_urdf_tutorial_text/mobile_robot_urdf.html#%E5%8F%AF%E8%A6%96%E5%8C%96%E3%82%88%E3%81%86%E3%81%AE%E3%82%B8%E3%82%AA%E3%83%A1%E3%83%88%E3%83%AA

https://gbiggs.github.io/rosjp_urdf_tutorial_text/mobile_robot_urdf.html#%E3%82%B8%E3%83%A7%E3%82%A4%E3%83%B3%E3%83%88%E3%81%AE%E5%AE%9A%E7%BE%A9

In the future, I recommend asking questions like this at answers.ros.org. You will get better answers sooner because more people are watching.

lizixroy commented 6 years ago

@gbiggs thank you very much! This made a lot of sense.

Closing the issue now.