ROS: URDF file writing syntax

URDF file writing syntax

The urdf file is a standard xml file, and some columns of tags are predefined to describe the robot model. It is mainly divided into two types: link (link) and joint (joint).

  • Connecting rod: the visible part of the robot, that is, the rigid body part
  • Joint: Hunger connection (joint) between connecting rods, but this part of the joint is not visible intuitively
  • robot: Similar to the existence of tags
  • gazebo: The label used in gazebo simulation, which is used to configure the required parameters of the robot, such as the material properties of the robot, gazebo plug-ins, etc., but such labels are not necessary, only set when simulation is required.

(1) robot tag

  In order to ensure the grammatical integrity of the xml file, urdf uses the robot tag as the root tag. All links, joints and other tags must be included in the robot tag. In this tag, the name of the robot model can be set through the name attribute.

(2) link tag

  Describe the appearance and rigid body properties of a certain part of the robot, such as: robot base, wheels, lidar, camera... Each part corresponds to a link. In the link tag, you can design the shape, size, color, inertia matrix, and collision of the part A series of attributes such as parameters

When writing urdf files, the key is to clarify the hierarchical relationship

1. Attribute
name —> name the connecting rod
2. Sub-label
visual —> describe the appearance (the corresponding data is visible)

① geometry Set the geometry of the connecting rod

​ Label 1: box (box shape)

​ Attribute: size=length (x) width (y) height (z)
Label 2: cylinder (cylinder)

​ Attribute: radius=radius length=height
​ Label 3: sphere (sphere)

​ Attribute: radius=radius
​ Label 4: mesh (add skin to the connecting rod)

​ Attribute: filename=resource path (format: \package:/// /document)

Examples are as follows:

<!-- 设置不同形状的机器人部件 -->
<robot name="mycar">
    <link name="base_link">
        <!-- 可视化标签 -->
        <visual>
            <!-- 形状 -->
            <geometry>
                <!-- 立方体 -->
                <!-- <box size="0.3 0.2 0.1"/> -->
                <!-- 圆柱体-->
                <!-- <cylinder radius="0.2" length="1"/> -->
                <!--  球体-->
                <!-- <sphere radius="1"/> -->
                <!-- 添加皮肤 -->
                <mesh filename="package://urdf_rviz/meshes/autolabor_mini.stl"/>
            </geometry>
        </visual>
    </link>
</robot>

②origin sets the offset and tilt radian

​ Attribute 1: xyz=x offset y cheap z offset

​ Attribute 2: rpy=x roll y pitch z yaw (unit is radian)

Examples are as follows:

  <!-- 偏移量与倾斜弧度 -->
            <!-- xyz:设置分别在xyz上的偏移量
            rpy用于设置xyz三个方向的旋转角 -->
            <origin xyz='0 0 0' rpy='1.57 0 0'/>

③metric set material properties (color)

​ Attribute: name

​ Tags: color

​ Attribute: rgba=red, green, blue weight value and transparency (each weight value and transparency value [0,1])

Examples are as follows:

 <!-- 颜色 -->
            <!-- rgba:
            rgb三原色,a透明度,四个值取值都在0到1之间 -->
            <material name="car_color">
                <color rgba = "0.7 0.34 0.8 0.5"/>
            </material>

collision —> The collision property of the connecting rod

Inertial —> Inertia matrix of the connecting rod

(3) joint label

​ The joint tag in urdf is used to describe the kinematics and dynamics properties of the robot joints, and can also specify the safety limit of joint motion. The two parts of the robot (referred to as parent link and child link respectively) are in the form of "joints" Connected, different joints have different motion forms: rotation, sliding, fixation, rotation speed, rotation angle limit... For example: the wheels installed on the base can rotate 360 ​​degrees, and the camera may be completely fixed on the base. The data corresponding to the joint tag is not visible in the model.

  1. Attributes
  • name —> Name the joint
  • type —> joint motion form
    • continuous: revolving joint, which can rotate infinitely around a single axis
    • revolute: revolute joint, similar to continues, but with rotation angle limit
    • prismatic: sliding joints, joints that move along a certain axis, with position limits
    • planer: a planar joint that allows translation or rotation in a direction orthogonal to the plane
    • floating: floating joints, allowing translational and rotational movements
    • fixed: fixed joints, special joints that do not allow movement
  1. child label
  • parent (required)

    The name of the parent link is a mandatory attribute:

    • link: The name of the parent link, which is the name of this link in the robot structure tree.
  • child (required)

    The name of the child link is a mandatory attribute:

    • link: The name of the child link, which is the name of this link in the robot structure tree.
  • origin

    • Attributes: xyz=offset on each axis rpy=offset arc on each axis.
  • axis

    • Attribute: xyz is used to set which joint axis to move around.
<!-- 需求:设置机器人底盘,并添加摄像头 -->
<robot name="mycar">
    <!-- 1 底盘link -->
    <link name="base_link">
        <!-- 可视化标签 -->
        <visual>
            <!-- 形状 -->
            <geometry>
                <!-- 立方体 -->
                <box size="0.3 0.2 0.1"/>
            </geometry>
            <!-- 偏移量与倾斜弧度 -->
            <!-- xyz:设置分别在xyz上的偏移量
            rpy用于设置xyz三个方向的旋转角 -->
            <origin xyz='0 0 0' rpy='0 0 0'/>

            <!-- 颜色 -->
            <!-- rgba:
            rgb三原色,a透明度,四个值取值都在0到1之间 -->
            <material name="car_color">
                <color rgba = "0.3 0.4 0.8 0.8"/>
            </material>
        </visual>
    </link>

    <!-- 2 摄像头link -->
    <link name="camera">
        <!-- 可视化标签 -->
        <visual>
            <!-- 形状 -->
            <geometry>
                <!-- 立方体 -->
                <box size="0.03 0.05 0.05"/>
            </geometry>
            <!-- 偏移量与倾斜弧度 -->
            <!-- xyz:设置分别在xyz上的偏移量
            rpy用于设置xyz三个方向的旋转角 -->
            <origin xyz='0 0 0.025' rpy='0 0 0'/>
            <!-- 需要上移半个摄像头的高度,才不会导致摄像头内嵌在机器人车体里 -->
            <!-- 颜色 -->
            <!-- rgba:
            rgb三原色,a透明度,四个值取值都在0到1之间 -->
            <material name="car_color">
                <color rgba = "0 1 0 0.8"/>
            </material>
        </visual>
    </link>
    <!-- 3 关节 -->
    <joint name="camera_to_link" type="continuous">
        <!-- 父级link -->
        <parent link="base_link"/>
        <!-- 子级link -->
        <child link="camera"/>
        <!-- 设置偏移量 -->
        <origin xyz='0.13 0 0.05' rpy='0 0 0'/>
        <!-- 设置关节旋转参考的坐标轴 -->
        <axis xyz='0 0 1'/>
    </joint>
</robot>

Launch file writing:

<launch>
    <!-- 1、在参数服务器载入urdf文件 -->
    <param name="robot_description" textfile="$(find urdf_rviz)/urdf/urdf/joint.urdf"/>
    <!-- 2、启动rviz -->
    <node pkg="rviz" type="rviz" name="rviz" args="-d $(find urdf_rviz)/config/showmycar.rviz"/>
    <!-- 注意:只有上述两条语句时会抛出异常:显示位置与颜色异常,给出提示 no transform from camera to baselink(缺少坐标变换) -->
    <!-- 原因:rviz中显示urdf时.必须发布不同部件之间的坐标系关系 -->
    <!-- 解决:ROS中提供的关于机器人模型显示的坐标发布相关节点(joint_state_publisher 和 robot_state_publisher) -->
    <!-- 关节状态发布节点 -->
    <node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher"/>
    <!-- 机器人状态发布节点 -->
    <node pkg="robot_state_publisher" type="robot_state_publisher" 
name="robot_state_publisher"/>
    <!--添加控制机器人关节运动的节点-->
    <node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui"
name="joint_state_publisher_gui"/>
</launch>

Note: The joint control node is not necessary. Its function is to provide a UI interface to control the movement of the joint node, which is convenient for debugging whether the urdf file is normal.

Guess you like

Origin blog.csdn.net/weixin_45205599/article/details/129538780