小猫

版主
  • 主题:39
  • 回复:39
  • 金钱:132
  • 积分:181
本帖最后由 Crazy_GF 于 2014-8-7 10:39 编辑


前面我们使用的是已有的机器人模型进行仿真,这一节我们将建立一个简单的智能车机器人smartcar,为后面建立复杂机器人打下基础。

一、创建硬件描述包[plain] view plaincopyroscreat-pkg  smartcar_description  urdf  


二、智能车尺寸数据

        因为建立的是一个非常简单的机器人,所以我们尽量使用简单的元素:使用长方体代替车模,使用圆柱代替车轮,具体尺寸如下:



三、建立urdf文件

        smartcar_description文件夹下建立urdf文件夹,创建智能车的描述文件smartcar.urdf,描述代码如下:
  1. <?xml version="1.0"?>  
  2. <robot name="smartcar">  
  3.   <link name="base_link">  
  4.     <visual>  
  5.       <geometry>  
  6.         <box size="0.25 .16 .05"/>  
  7.     </geometry>  
  8.     <origin rpy="0 0 1.57075" xyz="0 0 0"/>  
  9.     <material name="blue">  
  10.         <color rgba="0 0 .8 1"/>  
  11.     </material>  
  12.     </visual>  
  13. </link>  
  14.   
  15. <link name="right_front_wheel">  
  16.     <visual>  
  17.       <geometry>  
  18.         <cylinder length=".02" radius="0.025"/>  
  19.       </geometry>  
  20.       <material name="black">  
  21.         <color rgba="0 0 0 1"/>  
  22.       </material>  
  23.     </visual>  
  24.   </link>  
  25.   
  26.   <joint name="right_front_wheel_joint" type="continuous">  
  27.     <axis xyz="0 0 1"/>  
  28.     <parent link="base_link"/>  
  29.     <child link="right_front_wheel"/>  
  30.     <origin rpy="0 1.57075 0" xyz="0.08 0.1 -0.03"/>  
  31.     <limit effort="100" velocity="100"/>  
  32.     <joint_properties damping="0.0" friction="0.0"/>  
  33.   </joint>  
  34.   
  35.   <link name="right_back_wheel">  
  36.     <visual>  
  37.       <geometry>  
  38.         <cylinder length=".02" radius="0.025"/>  
  39.       </geometry>  
  40.       <material name="black">  
  41.         <color rgba="0 0 0 1"/>  
  42.       </material>  
  43.     </visual>  
  44.   </link>  
  45.   
  46.   <joint name="right_back_wheel_joint" type="continuous">  
  47.     <axis xyz="0 0 1"/>  
  48.     <parent link="base_link"/>  
  49.     <child link="right_back_wheel"/>  
  50.     <origin rpy="0 1.57075 0" xyz="0.08 -0.1 -0.03"/>  
  51.     <limit effort="100" velocity="100"/>  
  52.     <joint_properties damping="0.0" friction="0.0"/>  
  53. </joint>  
  54.   
  55. <link name="left_front_wheel">  
  56.     <visual>  
  57.       <geometry>  
  58.         <cylinder length=".02" radius="0.025"/>  
  59.       </geometry>  
  60.       <material name="black">  
  61.         <color rgba="0 0 0 1"/>  
  62.       </material>  
  63.     </visual>  
  64.   </link>  
  65.   
  66.   <joint name="left_front_wheel_joint" type="continuous">  
  67.     <axis xyz="0 0 1"/>  
  68.     <parent link="base_link"/>  
  69.     <child link="left_front_wheel"/>  
  70.     <origin rpy="0 1.57075 0" xyz="-0.08 0.1 -0.03"/>  
  71.     <limit effort="100" velocity="100"/>  
  72.     <joint_properties damping="0.0" friction="0.0"/>  
  73.   </joint>  
  74.   
  75.   <link name="left_back_wheel">  
  76.     <visual>  
  77.       <geometry>  
  78.         <cylinder length=".02" radius="0.025"/>  
  79.       </geometry>  
  80.       <material name="black">  
  81.         <color rgba="0 0 0 1"/>  
  82.       </material>  
  83.     </visual>  
  84.   </link>  
  85.   
  86.   <joint name="left_back_wheel_joint" type="continuous">  
  87.     <axis xyz="0 0 1"/>  
  88.     <parent link="base_link"/>  
  89.     <child link="left_back_wheel"/>  
  90.     <origin rpy="0 1.57075 0" xyz="-0.08 -0.1 -0.03"/>  
  91.     <limit effort="100" velocity="100"/>  
  92.     <joint_properties damping="0.0" friction="0.0"/>  
  93.   </joint>  
  94.   
  95.   <link name="head">  
  96.     <visual>  
  97.       <geometry>  
  98.         <box size=".02 .03 .03"/>  
  99.       </geometry>  
  100.       <material name="white">  
  101.           <color rgba="1 1 1 1"/>  
  102.       </material>  
  103.     </visual>  
  104.   </link>  
  105.   
  106.   <joint name="tobox" type="fixed">  
  107.     <parent link="base_link"/>  
  108.     <child link="head"/>  
  109.     <origin xyz="0 0.08 0.025"/>  
  110.   </joint>  
  111. </robot>  
复制代码


四、建立launch命令文件
        smartcar_description文件夹下建立launch文件夹,创建智能车的描述文件 base.urdf.rviz.launch,描述代码如下:
  1. <launch>  
  2.     <arg name="model" />  
  3.     <arg name="gui" default="False" />  
  4.     <param name="robot_description" textfile="$(find smartcar_description)/urdf/smartcar.urdf" />  
  5.     <param name="use_gui" value="$(arg gui)"/>  
  6.     <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>  
  7.     <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />  
  8.     <node name="rviz" pkg="rviz" type="rviz" args="-d $(find urdf_tutorial)/urdf.vcg" />  
  9. </launch>
复制代码


五、效果演示
        在终端中输入显示命令:
  1. [plain] view plaincopy
  2. roslaunch  smartcar_description  base.urdf.rviz.launch  gui:=true  
复制代码
   显示效果如下图所示,使用gui中的控制bar可以控制四个轮子单独旋转。