URDF文件转Xacro文件、在rviz和gazebo中同时启动

文章目录

  • URDF文件、Xacro文件介绍及参考教程
  • 文件目录:
    • urdf文件
      • urdf文件结构
    • 修改后的.xacro文件
      • car_body.urdf.xacro
      • gazebo.urdf.xacro
    • launch文件
    • 结果展示
    • 其他参考:husky
    • 遇到的问题及其解决方法

URDF文件、Xacro文件介绍及参考教程

URDF、Xacro编写及介绍及其在RVIZ中显示与控制:
https://blog.csdn.net/answerMack/article/details/89523746
urdf教程:http://wiki.ros.org/urdf/Tutorials
solidworks转urdf教程:
1.http://wiki.ros.org/sw_urdf_exporter
2.https://blog.csdn.net/gpeng832/article/details/73917487
moveit setup assistant教程:
1.http://docs.ros.org/indigo/api/moveit_tutorials/html/doc/setup_assistant/setup_assistant_tutorial.html
2.http://docs.ros.org/hydro/api/moveit_setup_assistant/html/doc/tutorial.html
urdf转xacro参考教程:
1.http://wiki.ros.org/urdf/Tutorials/Using Xacro to Clean Up a URDF File

文件目录:

urdf文件

<robot
  name="car-3">
  <link
    name="base_link">
    <inertial>
      <origin
        xyz="0.000454836605433948 1.27332861349781E-18 0.000181934642173575"
        rpy="0 0 0" />
      <mass
        value="0.497309733552923" />
      <inertia
        ixx="0.000379491084127215"
        ixy="-2.59493525107028E-19"
        ixz="-3.57796209039485E-06"
        iyy="0.00138864533975945"
        iyz="-4.48378120593819E-21"
        izz="0.00169173411179082" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/base_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/base_link.STL" />
      </geometry>
    </collision>
  </link>
  <link
    name="wheel_1">
    <inertial>
      <origin
        xyz="2.08756043780373E-05 5.32859680283521E-06 -6.93889390390723E-18"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801096E-06"
        ixy="-3.54146284907832E-09"
        ixz="-4.2351647362715E-22"
        iyy="1.27373747424717E-05"
        iyz="7.11375326795604E-23"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_1.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_1.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_1_to_base_link"
    type="continuous">
    <origin
      xyz="0.07 0.052 0"
      rpy="0 -0.75239 0" />
    <parent
      link="base_link" />
    <child
      link="wheel_1" />
    <axis
      xyz="0 1 0" />
  </joint>
  <link
    name="wheel_2">
    <inertial>
      <origin
        xyz="2.08756043780373E-05 5.32859680283521E-06 -1.44387083394547E-35"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801097E-06"
        ixy="-3.54146284907845E-09"
        ixz="4.94314925543529E-39"
        iyy="1.27373747424718E-05"
        iyz="-8.12167230901508E-39"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_2.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_2.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_2_to_base_link"
    type="continuous">
    <origin
      xyz="-0.07 0.052 0"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="wheel_2" />
    <axis
      xyz="0 1 0" />
  </joint>
  <link
    name="wheel_3">
    <inertial>
      <origin
        xyz="2.08756043780373E-05 5.32859680283521E-06 -1.44387083394547E-35"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801097E-06"
        ixy="-3.54146284907845E-09"
        ixz="4.94314925543529E-39"
        iyy="1.27373747424718E-05"
        iyz="-8.12167230901508E-39"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_3.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_3.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_3_to_base_link"
    type="continuous">
    <origin
      xyz="0.07 -0.052 0"
      rpy="0 0 3.1416" />
    <parent
      link="base_link" />
    <child
      link="wheel_3" />
    <axis
      xyz="0 -1 0" />
  </joint>
  <link
    name="wheel_4">
    <inertial>
      <origin
        xyz="2.08756043780511E-05 5.32859680283521E-06 -1.44387083394547E-35"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801097E-06"
        ixy="-3.54146284907845E-09"
        ixz="4.94314925543529E-39"
        iyy="1.27373747424718E-05"
        iyz="-8.12167230901508E-39"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_4.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_4.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_4_to_base_link"
    type="continuous">
    <origin
      xyz="-0.07 -0.052 0"
      rpy="0 0 3.14159265358979" />
    <parent
      link="base_link" />
    <child
      link="wheel_4" />
    <axis
      xyz="0 -1 0" />
  </joint>
</robot>

urdf文件结构

URDF文件转Xacro文件、在rviz和gazebo中同时启动_第1张图片

修改后的.xacro文件

将urdf文件分为了car_body.urdf.xacro和gazebo.urdf.xacro文件

car_body.urdf.xacro

<?xml version="1.0"?>  
<robot name="car_body" xmlns:xacro="http://ros.org/wiki/xacro">  
  <xacro:property name="M_PI" value="3.14159"/>    
 <xacro:include filename="$(find car-3)/robot_description/urdf/gazebo.urdf.xacro"/> 
  <xacro:property name="base_x" value="0.33" />  
  <xacro:property name="base_y" value="0.33" /> 
<link name="base_link">
    <inertial>
      <origin
        xyz="0.000454836605433948 1.27332861349781E-18 0.000181934642173575"
        rpy="0 0 0" />
      <mass
        value="0.497309733552923" />
      <inertia
        ixx="0.000379491084127215"
        ixy="-2.59493525107028E-19"
        ixz="-3.57796209039485E-06"
        iyy="0.00138864533975945"
        iyz="-4.48378120593819E-21"
        izz="0.00169173411179082" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/base_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/base_link.STL" />
      </geometry>
    </collision>
  </link>
  <link
    name="wheel_1">
    <inertial>
      <origin
        xyz="2.08756043780373E-05 5.32859680283521E-06 -6.93889390390723E-18"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801096E-06"
        ixy="-3.54146284907832E-09"
        ixz="-4.2351647362715E-22"
        iyy="1.27373747424717E-05"
        iyz="7.11375326795604E-23"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_1.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_1.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_1_to_base_link"
    type="continuous">
    <origin
      xyz="0.07 0.052 0"
      rpy="0 -0.75239 0" />
    <parent
      link="base_link" />
    <child
      link="wheel_1" />
    <axis
      xyz="0 1 0" />
  </joint>
  <link
    name="wheel_2">
    <inertial>
      <origin
        xyz="2.08756043780373E-05 5.32859680283521E-06 -1.44387083394547E-35"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801097E-06"
        ixy="-3.54146284907845E-09"
        ixz="4.94314925543529E-39"
        iyy="1.27373747424718E-05"
        iyz="-8.12167230901508E-39"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_2.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_2.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_2_to_base_link"
    type="continuous">
    <origin
      xyz="-0.07 0.052 0"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="wheel_2" />
    <axis
      xyz="0 1 0" />
  </joint>
  <link
    name="wheel_3">
    <inertial>
      <origin
        xyz="2.08756043780373E-05 5.32859680283521E-06 -1.44387083394547E-35"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801097E-06"
        ixy="-3.54146284907845E-09"
        ixz="4.94314925543529E-39"
        iyy="1.27373747424718E-05"
        iyz="-8.12167230901508E-39"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_3.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_3.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_3_to_base_link"
    type="continuous">
    <origin
      xyz="0.07 -0.052 0"
      rpy="0 0 3.1416" />
    <parent
      link="base_link" />
    <child
      link="wheel_3" />
    <axis
      xyz="0 -1 0" />
  </joint>
  <link
    name="wheel_4">
    <inertial>
      <origin
        xyz="2.08756043780511E-05 5.32859680283521E-06 -1.44387083394547E-35"
        rpy="0 0 0" />
      <mass
        value="0.0282994666235368" />
      <inertia
        ixx="6.59828205801097E-06"
        ixy="-3.54146284907845E-09"
        ixz="4.94314925543529E-39"
        iyy="1.27373747424718E-05"
        iyz="-8.12167230901508E-39"
        izz="6.61215628796161E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_4.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://car-3/meshes/wheel_4.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="wheel_4_to_base_link"
    type="continuous">
    <origin
      xyz="-0.07 -0.052 0"
      rpy="0 0 3.14159265358979" />
    <parent
      link="base_link" />
    <child
      link="wheel_4" />
    <axis
      xyz="0 -1 0" />
  </joint>
 <xacro:car_gazebo />
</robot>

gazebo.urdf.xacro

<?xml version="1.0"?>  
 <robot xmlns:xacro="http://ros.org/wiki/xacro" name="car_gazebo">
<xacro:macro name="car_gazebo">  
    <gazebo reference="base_link">  
        <material>Gazebo/Blue</material>  
    </gazebo>  
    <gazebo reference="wheel_1">  
        <material>Gazebo/FlatBlack</material>  
    </gazebo>  
    <gazebo reference="wheel_2">  
        <material>Gazebo/FlatBlack</material>  
    </gazebo>  
    <gazebo reference="wheel_3"> 
        <material>Gazebo/FlatBlack</material>  
    </gazebo>  
    <gazebo reference="wheel_4">  
        <material>Gazebo/FlatBlack</material>  
    </gazebo>  
</xacro:macro>  
</robot>

launch文件

<launch>  
        <arg name="world_name" default="worlds/empty.world"/>
		<include file="$(find gazebo_ros)/launch/empty_world.launch">
		<arg name="world_name" value="$(arg world_name)"/> <!-- world_name is wrt GAZEBO_RESOURCE_PATH environment variable -->
		<arg name="paused" value="false"/>
		<arg name="use_sim_time" value="true"/>
		<arg name="gui" value="true"/>
		<arg name="headless" value="false"/>
		<arg name="debug" value="false"/>
		</include>
		<arg name="model"/>
		<arg name="gui" default="True"/>
		<param name="robot_description" command="$(find xacro)/xacro --inorder '$(find car-3)/robot_description/urdf/car_body.urdf.xacro'" />
		<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 car-3)/urdf.rviz" />
		<node name="tf_footprint_base" pkg="tf" type="static_transform_publisher"  args="0 0 0 0 0 0 base_link base_footprint 40" />
		<node  name="spawn_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -model -unpause -param
		robot_description " output="screen" />
		<node  name="fake_joint_calibration" pkg="rostopic"  type="rostopic" args="pub /calibrated std_msgs/Bool true" />
</launch>

结果展示

显示结果:
URDF文件转Xacro文件、在rviz和gazebo中同时启动_第2张图片

rosrun rqt_tf_tree rqt_tf_tree 

URDF文件转Xacro文件、在rviz和gazebo中同时启动_第3张图片

rosrun rqt_graph rqt_graph

URDF文件转Xacro文件、在rviz和gazebo中同时启动_第4张图片

其他参考:husky

husky包:https://github.com/husky/husky
URDF文件转Xacro文件、在rviz和gazebo中同时启动_第5张图片
某些文件参考的husky的。

遇到的问题及其解决方法

URDF文件转Xacro文件、在rviz和gazebo中同时启动_第6张图片
解决方法:安装xacro文件
github地址:
https://github.com/ros/xacro/tree/kinetic-devel
http://wiki.ros.org/xacro
参考连接:https://blog.csdn.net/answerMack/article/details/89881213

20190503
20190506
未完待续

你可能感兴趣的:(Ubuntu学习)