机械臂建模与仿真(一):创建机械臂的urdf模型描述文件

要做机械臂的控制,就会用到机器人的urdf描述文件,moveit需要根据urdf中的数据进行机械臂的路径规划.

准备工作: 创建工作空间,在src下创建six_arm功能包(见相关ROS基础入门)
1.创建ros package命名为six_arm

catkin_create_pkg smartcar std_msgs rospy roscpp urdf

2.建立文件夹launch和urdf分别用来存放.launch文件和.urdf文件
3 在six_arm文件夹下建立urdf文件夹,创建机械臂的描述文件six_arm.urdf

首先要注意的是在ros中使用的右手坐标系,所以描述文件中的数据都是以此坐标系为原则
这里写图片描述
描述代码如下:

<?xml version="1.0"?>
<robot name="six_arm"> 
<!--建立baseline-->
  <link name="base_link">
    <visual>
      <geometry>
        <box size="0.20 .15 .003"/>
      </geometry>
    </visual>
  </link>
<!--增加身体-->
  <link name="body">
    <visual>
      <geometry>
       <box size="0.19 .11 .08"/>
      </geometry>
      <material name="blue">
          <color rgba="0 0 255 1"/>
      </material>  
    </visual>
  </link>  

  <joint name="base_to_body" type="fixed">
    <parent link="base_link"/>
    <child link="body"/>
    <origin xyz="0.0 0.0 0.04"/>
  </joint> 
<!--肩部XZ平面旋转舵机-->
  <!-- shoulder stevo-->
  <link name="shoulder_stevo">
    <visual>
      <geometry>
       <box size="0.054 .0403 .027"/>
      </geometry>
      <material name="black">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link> 
<joint name="body_to_left_shoulder_stevo" type="fixed">
    <parent link="body"/>
    <child link="shoulder_stevo"/>
    <origin xyz="0.04 0.035 0.026"/>
  </joint>  

  <link name="shoulder_stevo_axis">
    <visual>
      <geometry>
       <cylinder length=".04" radius="0.0029"></cylinder>
      </geometry>
      <material name="yellow">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link>

  <joint name="shoulder_stevo_to_axis" type="fixed">
    <axis xyz="0 0 1"/> 
    <parent link="shoulder_stevo"/>
    <child link="shoulder_stevo_axis"/>
    <origin rpy="1.57075 0 0" xyz="0.0 0.027 0.0"/>
    <limit effort="100" velocity="100" lower="0" upper="3.1415926"/> 
    <joint_properties damping="0.0" friction="0.0"/>
  </joint>  

<!--肩部摆动的舵机-->
 <!-- shoulder stevo lift -->
  <link name="shoulder_stevo_lift">
    <visual>
      <geometry>
       <box size="0.054 .0403 .027"/>
      </geometry>
      <material name="black">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="shoulder_stevo_axis_to_lift_stevo" type="fixed">
    <parent link="shoulder_stevo_axis"/>
    <child link="shoulder_stevo_lift"/>
    <origin xyz="0.0 -0.01015 -0.028"/>
  </joint>

  <link name="shoulder_stevo_lift_axis">
    <visual>
      <geometry>
       <cylinder length=".0704" radius="0.0029"></cylinder>
      </geometry>
      <material name="yellow">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link>

  <joint name="shoulder_stevo_lift_to_axis" type="fixed">
    <axis xyz="0 0 1"/> 
    <parent link="shoulder_stevo_lift"/>
    <child link="shoulder_stevo_lift_axis"/>
    <origin rpy="1.57075 0 0" xyz="0.0135 0.0 0.0"/>
    <limit effort="100" velocity="100"/> 
    <joint_properties damping="0.0" friction="0.0"/>
  </joint>     
<!--上臂-->
    <!-- big arm -->
  <link name="big_arm_up">
    <visual>
      <geometry>
       <box size="0.145 .027 .002"/>
      </geometry>
      <material name="sliver">
          <color rgba="223 223 223 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="shoulder_stevo_lift_axis_to_left_big_arm" type="fixed">
    <parent link="shoulder_stevo_lift_axis"/>
    <child link="big_arm_up"/>
    <origin xyz="0.059 0.0 -0.035"/>
  </joint>  

  <link name="big_arm_down">
    <visual>
      <geometry>
       <box size="0.145 .027 .002"/>
      </geometry>
      <material name="sliver">
          <color rgba="223 223 223 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="big_arm_up_to_left_big_arm_down" type="fixed">
    <parent link="big_arm_up"/>
    <child link="big_arm_down"/>
    <origin xyz="0.0 0.0 0.07"/>
  </joint>   
<!--肘部关键舵机 -->
  <!-- arm stevo-->
  <link name="arm_stevo_axis">
    <visual>
      <geometry>
       <cylinder length=".0704" radius="0.0029"></cylinder>
      </geometry>
      <material name="yellow">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link>

  <joint name="big_arm_up_to_axis" type="fixed">
    <axis xyz="0 0 1"/> 
    <parent link="big_arm_up"/>
    <child link="arm_stevo_axis"/>
    <origin rpy="0 0 0.5" xyz="0.059 0.0 0.0352"/>
    <limit effort="100" velocity="100" lower="0" upper="3.1415926"/> 
    <joint_properties damping="0.0" friction="0.0"/>
  </joint>  

  <link name="arm_stevo">
    <visual>
      <geometry>
       <box size="0.054 .027 .0403"/>
      </geometry>
      <material name="black">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="big_arm_up_to_axis_to_arm_stevo" type="fixed">
    <parent link="arm_stevo_axis"/>
    <child link="arm_stevo"/>
    <origin xyz="0.0135 0.0 0.0"/>
  </joint>  
<!--小臂 -->
    <!-- small arm -->
  <link name="small_arm_up">
    <visual>
      <geometry>
       <box size="0.0725 .027 .002"/>
      </geometry>
      <material name="sliver">
          <color rgba="223 223 223 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="arm_stevo_to_left_small_arm_up" type="fixed">
    <parent link="arm_stevo"/>
    <child link="small_arm_up"/>
    <origin xyz="0.059 0.0 -0.035"/>
  </joint>  

  <link name="small_arm_down">
    <visual>
      <geometry>
       <box size="0.0725 .027 .002"/>
      </geometry>
      <material name="sliver">
          <color rgba="223 223 223 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="small_arm_up_to_small_arm_down" type="fixed">
    <parent link="small_arm_up"/>
    <child link="small_arm_down"/>
    <origin xyz="0.0 0.0 0.07"/>
  </joint>  

  <link name="small_arm_middle">
    <visual>
      <geometry>
       <box size="0.07 .027 .002"/>
      </geometry>
      <material name="sliver">
          <color rgba="223 223 223 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="small_arm_up_to_small_arm_middle" type="fixed">
    <parent link="small_arm_up"/>
    <child link="small_arm_middle"/>
    <origin rpy="0 1.57075 0" xyz="-0.035 0.0 0.035"/>
  </joint> 
<!--手腕手臂方向关节舵机 -->
  <!--wrist stevo-->
  <link name="wrist_stevo_axis">
    <visual>
      <geometry>
       <cylinder length=".0704" radius="0.0029"></cylinder>
      </geometry>
      <material name="yellow">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link>

  <joint name="small_arm_up_to_axis" type="fixed">
    <axis xyz="0 0 1"/> 
    <parent link="small_arm_up"/>
    <child link="wrist_stevo_axis"/>
    <origin rpy="0 0 0.5" xyz="0.0295 0.0 0.0352"/>
    <limit effort="100" velocity="100" lower="0" upper="3.1415926"/> 
    <joint_properties damping="0.0" friction="0.0"/>
  </joint>  

  <link name="wrist_stevo">
    <visual>
      <geometry>
       <box size="0.054 .027 .0403"/>
      </geometry>
      <material name="black">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="small_arm_up_to_axis_to_axis_stevo" type="fixed">
    <parent link="wrist_stevo_axis"/>
    <child link="wrist_stevo"/>
    <origin xyz="0.0135 0.0 0.0"/>
  </joint> 
<!--手腕旋转关节舵机 -->
  <!--wrist run stevo-->
  <link name="wrist_run_stevo">
    <visual>
      <geometry>
       <box size="0.054 .027 .0403"/>
      </geometry>
      <material name="color1">
          <color rgba="0 255 255 1 "/>
      </material>  
    </visual>
  </link> 

 <joint name="wrist_stevo_to_wrist_run_stevo" type="fixed">
    <parent link="wrist_stevo"/>
    <child link="wrist_run_stevo"/>
    <origin rpy="0 1.57075 0" xyz="0.0135 -0.027 0.0"/>
  </joint>   

  <link name="wrist_run_stevo_axis">
    <visual>
      <geometry>
       <cylinder length=".04" radius="0.0029"></cylinder>
      </geometry>
      <material name="yellow">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link>

  <joint name="wrist_run_stevo_to_axis" type="fixed">
    <axis xyz="0 0 1"/> 
    <parent link="wrist_run_stevo"/>
    <child link="wrist_run_stevo_axis"/>
    <origin rpy="0 0 0" xyz="0.0135 0 0.020"/>
    <limit effort="100" velocity="100" lower="0" upper="3.1415926"/> 
    <joint_properties damping="0.0" friction="0.0"/>
  </joint> 
  <!--left wrist run stevo-->
  <link name="hand_run_stevo">
    <visual>
      <geometry>
       <box size="0.054 .027 .0403"/>
      </geometry>
      <material name="black">
          <color rgba="0 0 0 1 "/>
      </material>  
    </visual>
  </link> 

 <joint name="wrist_run_stevo_axis_to_hand_run_stevo" type="fixed">
    <parent link="wrist_run_stevo_axis"/>
    <child link="hand_run_stevo"/>
    <origin rpy="1.57075 0 0" xyz="0.0 0.0 0.0335"/>
  </joint>  

 <link name="hand_run_stevo_axis">
    <visual>
      <geometry>
       <cylinder length=".04" radius="0.0029"></cylinder>
      </geometry>
      <material name="yellow">
          <color rgba="1 1 0 1"/>
      </material>  
    </visual>
  </link>

  <joint name="hand_run_stevo_to_hand_run_stevo_axis" type="fixed">
    <axis xyz="0 0 1"/> 
    <parent link="hand_run_stevo"/>
    <child link="hand_run_stevo_axis"/>
    <origin rpy="0 0 0" xyz="0.0135 0 0.0135"/>
    <limit effort="100" velocity="100" lower="0" upper="3.1415916"/> 
    <joint_properties damping="0.0" friction="0.0"/>
  </joint>    

 <!--爪子-->
  <!--finger-->
  <link name="finger">
    <visual>
      <geometry>
       <box size="0.0375 .0135 .002"/>
      </geometry>
      <material name="sliver">
          <color rgba="223 223 223 1"/>
      </material>  
    </visual>
  </link> 

 <joint name="hand_run_stevo_axis_to_finger" type="fixed">
    <parent link="hand_run_stevo_axis"/>
    <child link="finger"/>
    <origin rpy="0 0 1.57075" xyz="0.0 0.0173 0.02"/>
  </joint>     

</robot>

4.创建display.launch文件

该文件可以帮助启动RViz来观察机械臂。其中有三个node,一个是rviz,另外两个joint_state_publisher robot_state_publisher是必须的node。

第一个输入参数 model 就是要启动的urdf文件路径。
第二个输入参数 gui 指定是否启用关节转动控制面板窗口。

<launch>  
    <arg name="model" />  
    <arg name="gui" default="False" />  
    <param name="robot_description" textfile="($find urdf_tutorial)/home/daniel/catkin_ws/src/six_arm/urdf/six_arm.urdf)" />  
    <param name="use_gui" value="$(arg gui)"/>  
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />  
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />  
        <node name="rviz" pkg="rviz" type="rviz" args="-d $(find urdf_tutorial)/urdf.rviz" required="true" />  
</launch>  

5.切换到six_arm文件夹下,使用下面命令启动rviz来查看我们刚刚完成的机器人模型:

roslaunch urdf_tutorial display.launch model:=urdf/six_arm.urdf

切忌:urdf文件中最好不要有汉字注释~否则仿真有错

阅读更多
换一批

没有更多推荐了,返回首页