【urdf_tutorials】Building a Visual Robot Model with URDF from Scratch 用URDF从头开始构建视觉机器人模型
Building a Visual Robot Model with URDF from Scratch 用URDF从头开始构建视觉机器人模型
原文链接:https://wiki.ros.org/urdf/Tutorials/Building a Visual Robot Model with URDF from Scratch
Description: Learn how to build a visual model of a robot that you can view in Rviz
描述:学习如何构建机器人的视觉模型,您可以在Rviz中查看
Keywords: URDF
关键词:URDF
Tutorial Level: BEGINNER
教程级别:初学者
Next Tutorial: Making the Model Move
下一篇教程:使模型移动
In this tutorial, we’re going to build a visual model of a robot that vaguely looks like R2D2. In later tutorials, you’ll learn how to articulate the model, add in some physical properties, generate neater code with xacro and make it move in Gazebo. But for now, we’re going to focus on getting the visual geometry correct.
在本教程中,我们将构建一个机器人的视觉模型,它看起来像R2D2。在以后的教程中,您将学习如何表达模型,添加一些物理属性,使用xacro生成更整洁的代码,并使其在Gazebo中移动。但现在,我们将专注于纠正视觉几何。
Before continuing, make sure you have the joint_state_publisher package installed. If you installed urdf_tutorial using apt-get, this should already be the case. If not, please update your installation to include that package (use rosdep to check).
继续之前,请确保已安装joint_state_publisher包。如果您使用apt-get安装了urdf_tutorial,情况应该已经如此。如果没有,请更新您的安装以包含该软件包(使用rosdep进行检查)。
All of the robot models mentioned in this tutorial (and the source files) can be found in the urdf_tutorial package.
本教程中提到的所有机器人模型(以及源文件)都可以在urdf_tutorial包中找到。
1 One Shape
First, we’re just going to explore one simple shape. Here’s about as simple as a urdf as you can make.
首先,我们将探索一个简单的形状。这是你能做的最简单的事情。
1 |
|
To translate the XML into English, this is a robot with the name myfirst, that contains only one link (a.k.a. part), whose visual component is just a cylinder 0.6 meters long with a 0.2 meter radius. This may seem like a lot of enclosing tags for a simple “hello world” type example, but it will get more complicated, trust me.
为了将XML翻译成英语,这是一个名为myfirst的机器人,它只包含一个链接(也称为部分),其视觉组件只是一个0.6米长、0.2米半径的圆柱体。对于一个简单的“helloworld”类型的示例,这可能看起来像是很多封闭标记,但相信我,它会变得更复杂。
To examine the model, launch the display.launch file:
要检查模型,请启动display.launch文件:
1 | $ roslaunch urdf_tutorial display.launch model:=urdf/01-myfirst.urdf |
This does three things. It
- Loads the specified model into the parameter server
- Runs nodes to publish sensor_msgs/JointState and transforms (more on these later)
- Starts Rviz with a configuration file
这做了三件事。它
- 将指定的模型加载到参数服务器
- 运行节点以发布sensor_msgs/JointState和变换(稍后将详细介绍)
- 使用配置文件启动Rviz
Note that the roslaunch line above assumes that you are executing it from the urdf_tutorial package directory (ie: the urdf directory is a direct child of the current working directory). If that is not the case, the relative path to 01-myfirst.urdf will not be valid, and you’ll receive an error as soon as roslaunch tries to load the urdf to the parameter server.
注意,上面的roslaunch行假设您正在从urdf_tutorial包目录执行它(即:urdf目录是当前工作目录的直接子目录)。如果不是这样,01-myfirst.urdf的相对路径将无效,并且当roslaunch尝试将urdf加载到参数服务器时,您将收到一个错误。
A slightly modified argument allows this to work regardless of the current working directory:
一个稍微修改的参数允许它在不考虑当前工作目录的情况下工作:
1 | $ roslaunch urdf_tutorial display.launch model:='$(find urdf_tutorial)/urdf/01-myfirst.urdf' |
note the single quotes around the argument value.
注意参数值周围的单引号。
You’ll have to change all example roslaunch lines given in these tutorials if you are not running them from the urdf_tutorial package location.
如果不是从urdf_tutorial包位置运行,则必须更改这些教程中给出的所有示例roslaunch行。
After launching display.launch, you should end up with RViz showing you the following:
启动display.launch后,您应该会看到RViz显示以下内容:
Things to note:
The fixed frame is the transform frame where the center of the grid is located. Here, it’s a frame defined by our one link, base_link.
The visual element (the cylinder) has its origin at the center of its geometry as a default. Hence, half the cylinder is below the grid.
需要注意的事项:
固定帧是网格中心所在的变换帧。这里,它是由我们的一个链接base_link定义的框架。
默认情况下,视觉元素(圆柱体)的原点位于其几何图形的中心。因此,一半圆柱体位于网格下方。
2 Multiple Shapes
Now let’s look at how to add multiple shapes/links. If we just add more link elements to the urdf, the parser won’t know where to put them. So, we have to add joints. Joint elements can refer to both flexible and inflexible joints. We’ll start with inflexible, or fixed joints.
现在让我们来看看如何添加多个形状/链接。如果我们只是向urdf添加更多的链接元素,解析器将不知道将它们放在哪里。所以,我们必须添加关节。关节元素可以指柔性关节和非柔性关节。我们将从不灵活或固定的关节开始。
1 |
|
-
Note how we defined a 0.6m x 0.1m x 0.2m box
-
The joint is defined in terms of a parent and a child. URDF is ultimately a tree structure with one root link. This means that the leg’s position is dependent on the base_link’s position.
-
注意我们如何定义0.6m x 0.1m x 0.2m的长方体
-
关节是根据父关节和子关节定义的。URDF最终是一个具有一个根链接的树结构。这意味着腿的位置取决于base_link的位置。
1 | $ roslaunch urdf_tutorial display.launch model:=urdf/02-multipleshapes.urdf |
Both of the shapes overlap with each other, because they share the same origin. If we want them not to overlap we must define more origins.
这两个形状彼此重叠,因为它们共享相同的原点。如果我们希望它们不重叠,我们必须定义更多的起源。
3 Origins
R2D2’s leg attaches to the top half of his torso, on the side. So that’s where we specify the origin of the JOINT to be. Also, it doesn’t attach to the middle of the leg, it attaches to the upper part, so we must offset the origin for the leg as well. We also rotate the leg so it is upright.
R2D2的腿附着在躯干的上半部分,在侧面。这就是我们指定关节的原点的位置。此外,它不连接到腿的中间,而是连接到上部,因此我们也必须偏移腿的原点。我们还旋转腿,使其直立。
1 |
|
-
Let’s start by examining the joint’s origin. It is defined in terms of the parent’s reference frame. So we are -0.22 meters in the y direction (to our left, but to the right relative to the axes) and 0.25 meters in the z direction (up). This means that the origin for the child link will be up and to the right, regardless of the child link’s visual origin tag. Since we didn’t specify a rpy (roll pitch yaw) attribute, the child frame will be default have the same orientation as the parent frame.
-
Now, looking at the leg’s visual origin, it has both a xyz and rpy offset. This defines where the center of the visual element should be, relative to its origin. Since we want the leg to attach at the top, we offset the origin down by setting the z offset to be -0.3 meters. And since we want the long part of the leg to be parallel to the z axis, we rotate the visual part PI/2 around the Y axis.
-
让我们从检查关节的原点开始。它是根据父对象的参考框架定义的。所以我们在y方向上是-0.22米(向左,但相对于轴向右),在z方向上是0.25米(向上)。这意味着无论子链接的视觉原点标记如何,子链接的原点都将向上并向右。由于我们没有指定rpy(滚动-俯仰-偏航)属性,因此默认情况下,子帧将与父帧具有相同的方向。
-
现在,看看腿的视觉原点,它有xyz和rpy偏移。这定义了视觉元素的中心相对于其原点的位置。因为我们希望腿附着在顶部,所以我们通过将z偏移设置为-0.3米来向下偏移原点。因为我们希望腿的长部分与z轴平行,所以我们围绕Y轴旋转视觉部分PI/2。
1 | $ roslaunch urdf_tutorial display.launch model:=urdf/03-origins.urdf |
-
The launch file runs packages that will create TF frames for each link in your model based on your URDF. Rviz uses this information to figure out where to display each shape.
-
If a TF frame does not exist for a given URDF link, then it will be placed at the origin in white (ref. related question).
-
启动文件运行的包将根据URDF为模型中的每个链接创建TF帧。Rviz使用这些信息来确定每个形状的显示位置。
-
如果给定URDF链路不存在TF帧,则它将以白色放置在原点(参考相关问题)。
4 Material Girl
“Alright,” I hear you say. “That’s very cute, but not everyone owns a B21. My robot and R2D2 are not red!” That’s a good point. Let’s take a look at the material tag.
“好吧,”我听到你说。“这很可爱,但不是每个人都拥有B21。我的机器人和R2D2不是红色的!”这是一个很好的观点。让我们看看材料标签。
1 |
|
-
The body is now blue. We’ve defined a new material called “blue”, with the red, green, blue and alpha channels defined as 0,0,0.8 and 1 respectively. All of the values can be in the range [0,1]. This material is then referenced by the base_link’s visual element. The white material is defined similarly
-
You could also define the material tag from within the visual element, and even reference it in other links. No one will even complain if you redefine it though.
-
You can also use a texture to specify an image file to be used for coloring the object
-
身体现在是蓝色的。我们定义了一种新材质,称为“蓝色”,红色、绿色、蓝色和alpha通道分别定义为0,0,0.8和1。所有值都可以在[0,1]范围内。然后,base_link的视觉元素引用该材质。白色材料的定义类似
-
您还可以从可视元素中定义材质标记,甚至在其他链接中引用它。如果你重新定义它,甚至没有人会抱怨。
-
还可以使用纹理指定用于为对象着色的图像文件
1 | roslaunch urdf_tutorial display.launch model:=urdf/04-materials.urdf |
5 Finishing the Model
Now we finish the model off with a few more shapes: feet, wheels, and head. Most notably, we add a sphere and a some meshes. We’ll also add few other pieces that we’ll use later.
现在,我们用更多的形状完成模型:脚、轮子和头。最值得注意的是,我们添加了一个球体和一些网格。我们还将添加一些稍后使用的其他片段。
1 |
|
1 | roslaunch urdf_tutorial display.launch model:=urdf/05-visual.urdf |
How to add the sphere should be fairly self explanatory:
如何添加球体应该是不言自明的:
1 | <link name="head"> |
The meshes here were borrowed from the PR2. They are separate files which you have to specify the path for. You should use the package://NAME_OF_PACKAGE/path notation. The meshes for this tutorial are located within the urdf_tutorial package, in a folder called meshes.
这里的网格是从PR2借来的。它们是单独的文件,您必须为其指定路径。您应该使用package://NAME_OF_PACKAGE/path符号本教程的网格位于urdf_tutorial包中名为mesh的文件夹中。
1 | <link name="left_gripper"> |
-
The meshes can be imported in a number of different formats. STL is fairly common, but the engine also supports DAE, which can have its own color data, meaning you don’t have to specify the color/material. Often these are in separate files. These meshes reference the .tif files also in the meshes folder.
-
Meshes can also be sized using relative scaling parameters or a bounding box size.
-
We could have also referred to meshes in a completely different package, i.e. package://pr2_description/meshes/gripper_v0/l_finger.dae which will work if the pr2_description package is installed.
-
可以以多种不同的格式导入网格。STL相当常见,但引擎也支持DAE,DAE可以有自己的颜色数据,这意味着您不必指定颜色/材质。这些文件通常在单独的文件中。这些网格也引用了网格文件夹中的.tif文件。
-
也可以使用相对缩放参数或边界框大小调整网格大小。
-
我们也可以在完全不同的包中引用网格,即。package://pr2_description/meshes/gripper_v0/l_finger.dae如果安装了pr2_description软件包,这将起作用。
There you have it. A R2D2-like URDF model. Now you can continue on to the next step, making it move.
好了,一个类似R2D2的URDF模型。现在,您可以继续下一步,使其移动。