ROS-URDF-建立模型

前言:建立一个简单的urdf模型

详解请参看教程http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20with%20URDF%20from%20Scratch

教程写的非常好,这里只做最终版解析部分。

查看是否安装了joint_state_publisher功能包:

 rospack find joint_state_publisher

一、基本模型

1.1 新建urdf_tutorial功能包

1.2 新建urdf文件

新建01-myfirst.urdf文件

xml version="1.0"?>
<robot name="materials">

  <material name="blue">
    <color rgba="0 0 0.8 1"/>
  material>

  <material name="white">
    <color rgba="1 1 1 1"/>
  material>


  <link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      geometry>
      <material name="blue"/>
    visual>
  link>

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>
      geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>
      <material name="white"/>
    visual>
  link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0 -0.22 0.25"/>
  joint>

  <link name="left_leg">
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>
      geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>
      <material name="white"/>
    visual>
  link>

  <joint name="base_to_left_leg" type="fixed">
    <parent link="base_link"/>
    <child link="left_leg"/>
    <origin xyz="0 0.22 0.25"/>
  joint>

robot>
View Code

----------------------------------------------------------------------------------------------------------------------------

代码解释:

<robot name="materials">此文件的机器人名称

<material name="blue">定义材料属性名称为蓝色
     <color rgba="0 0 0.8 1"/>材料属性为rgba值
material>

<link name="base_link">定义基本连杆
    <visual>可视化属性
      <geometry>几何形状
        <cylinder length="0.6" radius="0.2"/>圆柱,半径0.2米,高0.6米
      geometry>
      <material name="blue"/>材料属性引用为蓝色
    visual>
 link>

<link name="right_leg">定义右腿连杆
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>盒状,长宽高为0.6米,0.1米,0.2米
      geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>位置,位于关节点base_to_right_legz轴负方向0.3米,绕y轴旋转90°=π/2=1.57075
      <material name="white"/>
    visual>

<joint name="base_to_right_leg" type="fixed">定义基本连杆和右腿之间的关节,属性为固定。其实就是新建了一个相对坐标系。
    <parent link="base_link"/>父连杆为base_link
    <child link="right_leg"/>子连杆为right_leg
    <origin xyz="0 -0.22 0.25"/>关节位置,位于父连杆关节y轴负方向0.22米,z轴正方向0.25米
joint>

----------------------------------------------------------------------------------------------------------------------------

1.3 新建launch文件

<launch>

  <arg name="model" default="$(find urdf_tutorial)/urdf/01-myfirst.urdf"/>
  <arg name="gui" default="true" />
  <arg name="rvizconfig" default="$(find urdf_tutorial)/rviz/urdf.rviz" />

  <param name="robot_description" command="$(find xacro)/xacro --inorder $(arg model)" />
  <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 $(arg rvizconfig)" required="true" />

launch>
View Code

1.4 查看模型

roslaunch urdf_tutorial display.launch 

ROS-URDF-建立模型_第1张图片

二、进阶模型

2.1 修改urdf文件

xml version="1.0"?>
<robot name="visual">

<material name="blue">
    <color rgba="0 0 0.8 1"/>
  material>
  <material name="black">
    <color rgba="0 0 0 1"/>
  material>
  <material name="white">
    <color rgba="1 1 1 1"/>
  material>

  <link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      geometry>
      <material name="blue"/>
    visual>
  link>

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>
      geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>
      <material name="white"/>
    visual>
  link>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0 -0.22 0.25"/>
  joint>

  <link name="right_base">
    <visual>
      <geometry>
        <box size="0.4 0.1 0.1"/>
      geometry>
      <material name="white"/>
    visual>
  link>

  <joint name="right_base_joint" type="fixed">
    <parent link="right_leg"/>
    <child link="right_base"/>
    <origin xyz="0 0 -0.6"/>
  joint>

  <link name="right_front_wheel">
    <visual>
      <origin rpy="1.57075 0 0" xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.1" radius="0.035"/>
      geometry>
      <material name="black"/>
      <origin rpy="0 0 0" xyz="0 0 0"/>
    visual>
  link>
  <joint name="right_front_wheel_joint" type="fixed">
    <parent link="right_base"/>
    <child link="right_front_wheel"/>
    <origin rpy="0 0 0" xyz="0.133333333333 0 -0.085"/>
  joint>

  <link name="right_back_wheel">
    <visual>
      <origin rpy="1.57075 0 0" xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.1" radius="0.035"/>
      geometry>
      <material name="black"/>
    visual>
  link>
  <joint name="right_back_wheel_joint" type="fixed">
    <parent link="right_base"/>
    <child link="right_back_wheel"/>
    <origin rpy="0 0 0" xyz="-0.133333333333 0 -0.085"/>
  joint>

  <link name="left_leg">
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>
      geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>
      <material name="white"/>
    visual>
  link>

  <joint name="base_to_left_leg" type="fixed">
    <parent link="base_link"/>
    <child link="left_leg"/>
    <origin xyz="0 0.22 0.25"/>
  joint>

  <link name="left_base">
    <visual>
      <geometry>
        <box size="0.4 0.1 0.1"/>
      geometry>
      <material name="white"/>
    visual>
  link>

  <joint name="left_base_joint" type="fixed">
    <parent link="left_leg"/>
    <child link="left_base"/>
    <origin xyz="0 0 -0.6"/>
  joint>

  <link name="left_front_wheel">
    <visual>
      <origin rpy="1.57075 0 0" xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.1" radius="0.035"/>
      geometry>
      <material name="black"/>
    visual>
  link>
  <joint name="left_front_wheel_joint" type="fixed">
    <parent link="left_base"/>
    <child link="left_front_wheel"/>
    <origin rpy="0 0 0" xyz="0.133333333333 0 -0.085"/>
  joint>

  <link name="left_back_wheel">
    <visual>
      <origin rpy="1.57075 0 0" xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.1" radius="0.035"/>
      geometry>
      <material name="black"/>
    visual>
  link>
  <joint name="left_back_wheel_joint" type="fixed">
    <parent link="left_base"/>
    <child link="left_back_wheel"/>
    <origin rpy="0 0 0" xyz="-0.133333333333 0 -0.085"/>
  joint>

  <joint name="gripper_extension" type="fixed">
    <parent link="base_link"/>
    <child link="gripper_pole"/>
    <origin rpy="0 0 0" xyz="0.19 0 0.2"/>
  joint>

  <link name="gripper_pole">
    <visual>
      <geometry>
        <cylinder length="0.2" radius="0.01"/>
      geometry>
      <origin rpy="0 1.57075 0 " xyz="0.1 0 0"/>
    visual>
  link>

  <joint name="left_gripper_joint" type="fixed">
    <origin rpy="0 0 0" xyz="0.2 0.01 0"/>
    <parent link="gripper_pole"/>
    <child link="left_gripper"/>
  joint>

  <link name="left_gripper">
    <visual>
      <origin rpy="0.0 0 0" xyz="0 0 0"/>
      <geometry>
        <mesh filename="package://urdf_tutorial/meshes/l_finger.dae"/>
      geometry>
    visual>
  link>

  <joint name="left_tip_joint" type="fixed">
    <parent link="left_gripper"/>
    <child link="left_tip"/>
  joint>

  <link name="left_tip">
    <visual>
      <origin rpy="0.0 0 0" xyz="0.09137 0.00495 0"/>
      <geometry>
        <mesh filename="package://urdf_tutorial/meshes/l_finger_tip.dae"/>
      geometry>
    visual>
  link>
  <joint name="right_gripper_joint" type="fixed">
    <origin rpy="0 0 0" xyz="0.2 -0.01 0"/>
    <parent link="gripper_pole"/>
    <child link="right_gripper"/>
  joint>

  <link name="right_gripper">
    <visual>
      <origin rpy="-3.1415 0 0" xyz="0 0 0"/>
      <geometry>
        <mesh filename="package://urdf_tutorial/meshes/l_finger.dae"/>
      geometry>
    visual>
  link>

  <joint name="right_tip_joint" type="fixed">
    <parent link="right_gripper"/>
    <child link="right_tip"/>
  joint>

  <link name="right_tip">
    <visual>
      <origin rpy="-3.1415 0 0" xyz="0.09137 0.00495 0"/>
      <geometry>
        <mesh filename="package://urdf_tutorial/meshes/l_finger_tip.dae"/>
      geometry>
    visual>
  link>

  <link name="head">
    <visual>
      <geometry>
        <sphere radius="0.2"/>
      geometry>
      <material name="white"/>
    visual>
  link>
  <joint name="head_swivel" type="fixed">
    <parent link="base_link"/>
    <child link="head"/>
    <origin xyz="0 0 0.3"/>
  joint>

  <link name="box">
    <visual>
      <geometry>
        <box size="0.08 0.08 0.08"/>
      geometry>
      <material name="blue"/>
    visual>
  link>

  <joint name="tobox" type="fixed">
    <parent link="head"/>
    <child link="box"/>
    <origin xyz="0.1814 0 0.1414"/>
  joint>
robot>
View Code

--------------------------------------------------------------------------

部分代码解释:

 <geometry >
        <mesh  filename = “package://urdf_tutorial/meshes/l_finger.dae” />  几何形状可以引用外部dae文件
geometry> 

2.2 运行launch文件  

 ROS-URDF-建立模型_第2张图片

 

-END-

转载于:https://www.cnblogs.com/chendeqiang/p/10335632.html

你可能感兴趣的:(ROS-URDF-建立模型)