gazebo 仿真 —URDF机器人建模

  • Post author:
  • Post category:其他




URDF机器人建模



URDF机器人建模的介绍



URDF的概念

  • URDF(Unified Robot Description Format),统一机器人描述格式
  • ROS中一个非常重要的机器人模型描述格式
  • 可以解析URDF文件中使用XML格式描述的机器人模型
  • ROS同时也提供URDF文件的C++解析器(可以在C++代码中直接解析- -URDF机器人模型,好处:在基于模型的计算算法中,可以在代码中调用模型的信息,方便计算)



URDF机器人模型的内容

  • 连杆 link
  • 关节 joint
  • 运动学参数 axis
  • 动力学参数 dynamics
  • 可视化模型 visual
  • 碰撞检测模型 collision



URDF机器人模型的标签说明

  • link标签

    用于描述机器人某个刚体部分的外观和物理属性(比如尺寸(size)、颜色(color)、形状(shape)、惯性矩阵(inertial matrix)、碰撞属性(collision properties)等)

    xml的格式的描述

    <link name="<link name>">
    <!-- 描述机器人link部分的外观参数, 尺寸、颜色、形状等的外观信息 -->
    	<inertial>......</inertial>
    	<!-- 描述link的惯性参数,主要用到机器人动力学的运算部分 -->
    	<visual>......</visual>
    	<!-- 描述link的碰撞属性 -->
    	<collision>......</collision>
    </link>
    
         
         
  • joint标签

    描述机器人关节的运动学和动力学属性,包括关节运动的位置和速度限制。根据关节的运动形式,可以将其分为六种类型

    关节类型 描述
    continuous 旋转关节,可以围绕单轴无限旋转
    revolute 旋转关节,类似于continuous,但是有旋转的角度限制
    prismatic 滑动关节,沿某一轴线移动的关节,带有位置极限
    planar 平面关节,允许在平面正交方向上平移或者旋转
    floating 浮动关节,允许进行平移、旋转运动
    fixed 固定关节,不允许运动的特殊关节

    xml格式的描述

    <joint name="<name of the joint>" type="<joint type>">
    	<parent link="parent_link"/>
    	<child link="child_link"/>
    	<!--关节的参考位置,用来校准关节的绝对位置-->
    	<calibration ....../>
    	<!--描述关节的物理属性,例如物理静摩擦力-->
    	<dynamics damping ....../>
    	<!--描述运动的一些极限值,包括关节运动的上下限位置,速度限制-->
    	<limit effort ....../>
    	......
    </joint>
    
         
         
  • robot标签

    完整机器人模型的最顶层标签,< link > 和 < joint >标签必须包含在 < robot > 标签内

    xml格式描述

    <robot name="name of the robot">
    	<link>......</link>
    	<link>......</link>
    	<joint>......</joint>
    	<joint>......</joint>
    </robot>
    
         
         



URDF机器人建模的实现



创建URDF功能包

1.创建一个机器人建模的功能包

#进入工作空间
cd ./catkin_ws/src/
#创建功能包
catkin_create_pkg mbot_description urdf xacro

   
   

2.创建机器人建模的功能包的文件结构

cd ./catkin_ws/src/mbot_description
mkdir urdf
mkdir meshes
mkdir launch
mkdir config

   
   
目录名称 描述
urdf 存放机器人模型的URDF或xacro文件
meshes 放置URDF中引用的模型渲染文件,机器人外观纹理,让外观和实际更相似
launch 保存相关启动文件
config 保存rviz的配置文件、功能包的配置文件



编辑launch启动文件

cd ./catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_base_urdf.launch

   
   

display_mbot_base_urdf.launch文件内容

<launch>
   <!-- 加载的参数名字叫robot_description,具体内容是urdf相关模型的路径 -->
	<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_base.urdf" />
	<!-- 设置GUI参数,显示关节控制插件 -->
	<param name="use_gui" value="true"/>
	<!-- 运行joint_state_publisher节点,发布机器人的关节状态  -->
	<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
	<!-- 运行robot_state_publisher节点,发布tf  -->
	<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
	<!-- 运行rviz可视化界面,保存每次打开之后的相关插件,保存到config文件夹下面 -->
	<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>

   
   



创建URDF模型



创建小车底盘(圆柱体)

cd ./catkin_ws/src/mbot_description/urdf
sudo gedit mbot_base.urdf

   
   

mbot_base.urdf文件内容

<?xml version="1.0" ?>
<robot name="mbot">
    <link name="base_link">
        <visual>
            <origin xyz=" 0 0 0" rpy="0 0 0" />
            <!-- link坐标位置,放在最中央 ,xyz单位是米,rpy单位是弧度-->
            <geometry>
                <cylinder length="0.16" radius="0.20"/>
            </geometry>
            <!-- 机器人的外观效果,使用圆柱体,高0.16,半径0.20 -->
            <material name="yellow">
                <color rgba="1 0.4 0 1"/>
            </material>
             <!--  通过rgba来描述颜色,颜色命名为yellow,a为1是不透明-->
        </visual>
        <!--visual指的是一些物理属性的标签 -->
    </link>




</

robot


>

查看显示的效果

roslaunch mbot_description display_mbot_base_urdf.launch

 
 

问题描述

1.

Could not find the GUI, install the ‘joint_state_publisher_gui’ package


解决方法:

sudo apt-get install ros-melodic-joint-state-publisher-gui(melodic版本)

2.

[joint_state_publisher-1] process has died [pid 12201, exit code 1, cmd /opt/


解决方法:

urdf文件第一行前面到空格全部去掉,一般格式正确后都会有颜色的,写urdf一定要注意格式,并且将其中的注释给去掉,后面再添加相应代码的时候注意去掉注释内容

3.

RVIZ成功启动不显示模型


解决方法:

①将Fixed Frame改为base_link

②点击下方的Add按钮添加RobotModel

显示效果

在这里插入图片描述



创建左侧车轮

sudo gedit mbot_base.urdf

 
 

添加代码内容(添加到上面文件代码所留出的空白位置)

    <joint name="left_wheel_joint" type="continuous">
    <!--   joint名字为left_wheel_joint,属性为continuous,即无限旋转-->
        <origin xyz="0 0.19 -0.05" rpy="0 0 0"/>
        <!--  坐标位置,在base_link基础上,Y偏移0.19,z偏移-0.05-->
        <parent link="base_link"/>
        <child link="left_wheel_link"/>
        <!--  主关节:base_link,上面的圆柱形车体-->
        <!--  子关节:left_wheel_link,左轮-->
        <!--  主关节最后是一个,本代码是base_link-->
        <axis xyz="0 1 0"/>
        <!--left_wheel_link绕某一个轴做旋转,指定为Y轴  -->
    </joint>
     <!--joint用来连接两个link-->
    <link name="left_wheel_link">
        <visual>
            <origin xyz="0 0 0" rpy="1.5707 0 0" />
            <geometry>
                <cylinder radius="0.06" length = "0.025"/>
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.9"/>
            </material>
        </visual>
    </link>
  <!--左轮信息-->

 
 


注意:


去掉注释

查看显示效果

roslaunch mbot_description display_mbot_base_urdf.launch

 
 

在这里插入图片描述

查看小车主体和轮子之间的TF坐标位置

添加TF坐标,将左面robotmodel选项取消

在这里插入图片描述



创建右侧车轮

方法跟上面类似

添加内容

    <joint name="right_wheel_joint" type="continuous">
        <origin xyz="0 -0.19 -0.05" rpy="0 0 0"/>
        <!--  坐标位置,在base_link基础上,Y偏移-0.19,z偏移-0.05,与左轮正好相反-->
        <parent link="base_link"/>
        <child link="right_wheel_link"/>
        <axis xyz="0 1 0"/>
    </joint>
    <link name="right_wheel_link">
        <visual>
            <origin xyz="0 0 0" rpy="1.5707 0 0" />
            <geometry>
                <cylinder radius="0.06" length = "0.025"/>
            </geometry>
            <material name="white">
                <color rgba="1 1 1 0.9"/>
            </material>
        </visual>
    </link>

 
 

查看显示效果

roslaunch mbot_description display_mbot_base_urdf.launch

 
 

在这里插入图片描述



创建前后支撑轮

方法同上

添加内容

    <joint name="front_caster_joint" type="continuous">
        <origin xyz="0.18 0 -0.095" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="front_caster_link"/>
        <axis xyz="0 1 0"/>
    </joint>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>front_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>sphere</span> <span class="token attr-name">radius</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.015<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
              <span class="token comment">&lt;!--用圆形轮子代替  --&gt;</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>black<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0 0.95<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>joint</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>back_caster_joint<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>continuous<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>-0.18 0 -0.095<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>parent</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>child</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>back_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>axis</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 1 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>joint</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>back_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>sphere</span> <span class="token attr-name">radius</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.015<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>black<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0 0.95<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

查看显示效果

roslaunch mbot_description display_mbot_base_urdf.launch

 
 

在这里插入图片描述



增加传感器



加入摄像头
cd ./catkin_ws/src/mbot_description/urdf
sudo gedit mbot_with_camera.urdf 
cd ./catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_with_camera_urdf.launch  

 
 

mbot_with_camera.urdf 文件内容

<?xml version="1.0" ?>
<robot name="mbot">
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span> 0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>cylinder</span> <span class="token attr-name">length</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.16<span class="token punctuation">"</span></span> <span class="token attr-name">radius</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.20<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>yellow<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1 0.4 0 1<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>joint</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>left_wheel_joint<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>continuous<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0.19 -0.05<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>parent</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>child</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>left_wheel_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>axis</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 1 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>joint</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>left_wheel_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1.5707 0 0<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            &lt;cylinder radius="0.06" length = "0.025"/&gt;
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>white<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1 1 1 0.9<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>joint</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>right_wheel_joint<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>continuous<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 -0.19 -0.05<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>parent</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>child</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>right_wheel_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>axis</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 1 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>joint</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>right_wheel_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1.5707 0 0<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            &lt;cylinder radius="0.06" length = "0.025"/&gt;
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>white<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1 1 1 0.9<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>joint</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>front_caster_joint<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>continuous<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.18 0 -0.095<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>parent</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>child</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>front_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>axis</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 1 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>joint</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>front_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>sphere</span> <span class="token attr-name">radius</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.015<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>black<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0 0.95<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>joint</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>back_caster_joint<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>continuous<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>-0.18 0 -0.095<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>parent</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>child</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>back_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>axis</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 1 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>joint</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>back_caster_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>sphere</span> <span class="token attr-name">radius</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.015<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>black<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0 0.95<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>
<span class="token comment">&lt;!--摄像头相关内容--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>camera_link<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span> 0 0 0 <span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">&gt;</span></span>
        
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>box</span> <span class="token attr-name">size</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.03 0.04 0.04<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
               <span class="token comment">&lt;!--外观是个盒子模拟成摄像头,长宽高分别是0.03 0.04 0.04--&gt;</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>geometry</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>material</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>black<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>color</span> <span class="token attr-name">rgba</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0 0.95<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>material</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>link</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>joint</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>camera_joint<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>fixed<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0.17 0 0.10<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>parent</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>base_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>child</span> <span class="token attr-name">link</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>camera_link<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>joint</span><span class="token punctuation">&gt;</span></span>




</

robot


>

display_mbot_with_camera_urdf.launch文件内容和display_mbot_base_urdf.launch文件内容基本一致,需要修改urdf相关模型的路径

   <!-- 加载的参数名字叫robot_description,具体内容是urdf相关模型的路径 -->
	<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_with_camera.urdf "/>

 
 

查看显示效果

roslaunch mbot_description display_mbot_with_camera_urdf.launch  

 
 

在这里插入图片描述



加入激光雷达
cd ./catkin_ws/src/mbot_description/urdf
sudo gedit mbot_with_laser.urdf
cd ./catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_with_laser_urdf.launch

 
 

mbot_with_laser.urdf文件内容(其他内容跟未添加传感器内容一致)

    <!--激光雷达配置内容-->
    <link name="laser_link">
		<visual>
			<origin xyz=" 0 0 0 " rpy="0 0 0" />
			<geometry>
				<cylinder length="0.05" radius="0.05"/>
			</geometry>
			<material name="black"/>
		</visual>
    </link>
    <joint name="laser_joint" type="fixed">
        <origin xyz="0 0 0.105" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="laser_link"/>
    </joint>

 
 

display_mbot_with_laser_urdf.launch文件内容和display_mbot_urdf.launch文件内容基本一致,需要修改urdf相关模型的路径

   <!-- 加载的参数名字叫robot_description,具体内容是urdf相关模型的路径 -->
	<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_with_laser.urdf " />

 
 

查看显示效果

roslaunch mbot_description display_mbot_with_laser_urdf.launch

 
 

在这里插入图片描述



加入Kinect
cd ./catkin_ws/src/mbot_description/urdf
sudo gedit mbot_with_kinect.urdf
cd ./catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_with_kinect_urdf.launch

 
 

mbot_with_kinect.urdf文件内容(其他内容跟未添加传感器内容一致)

    <!--Kinect配置-->
    <link name="kinect_link">
        <visual>
            <origin xyz="0 0 0" rpy="0 0 1.5708"/>
            <geometry>
                <mesh filename="package://mbot_description/meshes/kinect.dae" />
                 <!--直接加载Kinect的外观纹理描述文件-->
            </geometry>
        </visual>
    </link>
    <joint name="laser_joint" type="fixed">
        <origin xyz="0.15 0 0.11" rpy="0 0 0"/>
        <parent link="base_link"/>
        <child link="kinect_link"/>
    </joint>

 
 

display_mbot_with_kinect_urdf.launch文件内容和display_mbot_urdf.launch文件内容基本一致,需要修改urdf相关模型的路径

   <!-- 加载的参数名字叫robot_description,具体内容是urdf相关模型的路径 -->
	<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_with_kinect.urdf " />

 
 

在meshes文件中创建纹理描述信息。

新建文件名称: kinect.dae

文件下载可以参考该链接(下载需要VIP):


https://download.csdn.net/download/weixin_43262513/10990016


查看显示效果

roslaunch mbot_description display_mbot_with_kinect_urdf.launch

 
 

由于无法获得kinect纹理描述信息的文件,所有就无法得到它的显示效果。



检查URDF模型整体结构

urdf文件夹下执行 urdf_to_graphiz+要检查的urdf文件

urdf_to_graphiz mbot_with_camera.urdf

 
 

打开生成的pdf文件查看

在这里插入图片描述

整个内容比较多,但是有较多部分都是重复的,只有理解到一部分内容,其他的内容可以根据理解部分的内容去理解。



参考链接

1.

URDF机器人建模 理论+实践


2.

ROS学习笔记——ROS机器人系统设计—–基础编程 day 7 2019/3/2 帅某(URDF机器人建模,urdf功能包的建立,urdf相关模型建立代码已经上传)


3.

圆柱urdf:Could not find the GUI, install the ‘joint_state_publisher_gui’ package.RVIZ成功启动不显示圆柱模型