ROS学习笔记之——gazebo模型(URDF)

最近在学习gazebo仿真。在之前博文里面《学习笔记之——gazebo仿真》,在介绍深度相机的ROS插件的时候,涉及到了gazebo里面的一些模型文件架构的定义。本博文主要是对模型文件的定义做学习记录

目录

Model

URDF

参考资料


Model

首先介绍一下怎么在gazebo的模型库里面添加模型(之前博客已经试过修改已有模型了《学习笔记之——gazebo仿真》)

Create a directory for your model under the gazebo_models directory. For this tutorial, we will assume that this directory is called mymodel, but you should give the directory an informative name about the model.

That directory must include the file model.config and at least one .sdf file. It may include other files as well (meshes, textures, templates, etc.)如下图所示

Also make sure you add the model directory to the CMakeLists.txt file.

The model.config file provides information necessary to pick the proper SDF file, information on authorship of the model, and a textual description of the model.

A sample model.config looks like this:

<?xml version="1.0"?>
<model>
  <name>Wedge juggler</name>
  <version>1.0</version>
  <sdf version="1.5">model.sdf</sdf>

  <author>
    <name>Evan Drumwright</name>
    <email>[email protected]</email>
  </author>

  <description>
    A ball-in-wedge juggler.
  </description>
</model>

如下图所示。基本就是模型的名称、作者信息,包括的.sdf文件

若有其他.sdf文件,则如下图所示

This model.config file indicates that the simulator's definition of the model (i.e., visual, inertial, kinematic, and geometric properties, among others), is located in model.sdf, and follows SDF standard 1.5. It is possible to define multiple versions of your model, which may be useful if you intend for your model to be used with different versions of Gazebo. For example, we now change the contents of the file above, to support three different versions of SDF:

<?xml version="1.0"?>
<model>
  <name>Wedge juggler</name>
  <version>1.0</version>
  <sdf version="1.5">model.sdf</sdf>
  <sdf version="1.4">model-1.4.sdf</sdf>

  <author>
    <name>Evan Drumwright</name>
    <email>[email protected]</email>
  </author>

  <description>
    A ball-in-wedge juggler.
  </description>
</model>

URDF

URDF的全称是Universal Robotic Description Format ,通用机器人描述格式。是一个XML文件,用于描述ROS中机器人的各个单元

This tutorial explains the necessary steps to successfully use your URDF-based robot in Gazebo, saving you from having to create a separate SDF file from scratch and duplicating description formats. Under the hood, Gazebo will then convert the URDF to SDF automatically.

URDF只能单独指定单个机器人的运动学和动力学特性。URDF无法指定机器人在一个世界中的姿势。它也不是一种通用的描述格式,因为它不能指定关节回路(并联机构),而且它缺乏摩擦力和其他特性。此外,它不能指定非机器人的东西,如灯光、高度图等。而且可扩展性也比较差。

因此,在gazebo中采用SDF(Simulation Description Format)格式来解决URDF的缺点。SDF是从世界级到机器人级的所有内容的完整描述。它是可伸缩的,并且可以方便地添加和修改元素。SDF格式本身是使用XML描述的,这有助于使用简单的升级工具将旧版本迁移到新版本。它也是自我描述的。

There are several steps to get a URDF robot properly working in Gazebo. 

Required

  • An <inertia> element within each <link> element must be properly specified and configured.

Optional

  • Add a <gazebo> element for every <link>
    • Convert visual colors to Gazebo format
    • Convert stl files to dae files for better textures
    • Add sensor plugins
  • Add a <gazebo> element for every <joint>
    • Set proper damping dynamics
    • Add actuator control plugins
  • Add a <gazebo> element for the <robot> element
  • Add a <link name="world"/> link if the robot should be rigidly attached to the world/base_link

The <gazebo> element is an extension (延伸) to the URDF used for specifying additional properties (指定其他属性) needed for simulation purposes in Gazebo. It allows you to specify the properties found in the SDF format that are not included in the URDF format. None of the elements within a <gazebo> element are required because default values will be automatically included. There are three different types of <gazebo> elements - one for the <robot> tag, one for <link> tags, and one for <joint> tags. 

这个连接详细的讲述了构建URDF(https://wiki.ros.org/urdf/Tutorials)

这里采用RRBot(''Revolute-Revolute Manipulator Robot'', is a simple 3-linkage, 2-joint arm)

首先,配置相关软件包(https://github.com/ros-simulation/gazebo_ros_demos

cd ~/catkin_ws/src/
git clone https://github.com/ros-simulation/gazebo_ros_demos.git
cd ..
catkin_make

然后通过运行下面命令在rviz中打开

roslaunch rrbot_description rrbot_rviz.launch

控制滑动条可以控制机械臂

It is important that while converting your robot to work in Gazebo, you don't break Rviz or other ROS-application functionality, so its nice to occasionally test your robot in Rviz to make sure everything still works.

use Rviz to monitor the state of your simulated robot by publishing /joint_states directly from Gazebo. In the previous example, the RRBot in Rviz is getting its /joint_states from a fake joint_states_publisher node (the window with the slider bars).

关于rviz监控gazebo中的机器人,可以参考博文《 学习笔记之——使用rviz来监控gazebo中的机器人

接下来看看RRBot的URDF文件

通过gazebo打开RRBot机器人

roslaunch rrbot_gazebo rrbot_world.launch

如下图所示

In the launched Gazebo window you should see the robot standing straight up. Despite there being no intentional disturbances in the physics simulator by default, numerical errors should start to build up and cause the double inverted pendulum to fall after a few seconds.

整个机器人文档如下所示(在rrbot_description/ rrbot.xacro)在上面加了些注释,由于本人不会设计机器人,所以对于其大概的结构,了解即可

<?xml version="1.0"?>
<!-- Revolute-Revolute Manipulator -->
<robot name="rrbot" xmlns:xacro="http://www.ros.org/wiki/xacro">

  <!-- Constants for robot dimensions -->
  <xacro:property name="PI" value="3.1415926535897931"/>
  <xacro:property name="mass" value="1" /> <!-- arbitrary value for mass -->
  <xacro:property name="width" value="0.1" /> <!-- Square dimensions (widthxwidth) of beams -->
  <xacro:property name="height1" value="2" /> <!-- Link 1 -->
  <xacro:property name="height2" value="1" /> <!-- Link 2 -->
  <xacro:property name="height3" value="1" /> <!-- Link 3 -->
  <xacro:property name="camera_link" value="0.05" /> <!-- Size of square 'camera' box -->
  <xacro:property name="axel_offset" value="0.05" /> <!-- Space btw top of beam and the each joint -->

  <!-- Import all Gazebo-customization elements, including Gazebo colors -->
  <xacro:include filename="$(find rrbot_description)/urdf/rrbot.gazebo" />
  <!-- Import Rviz colors -->
  <xacro:include filename="$(find rrbot_description)/urdf/materials.xacro" />

######################################################################
如果希望将URDF模型永久附着到世界框架(地平面),则必须创建“世界”链接和将其固定到模型基础的关节。RRBot通过以下操作完成此任务:
  <!-- Used for fixing robot to Gazebo 'base_link' -->
  <link name="world"/>

  <joint name="fixed" type="fixed">
    <parent link="world"/>
    <child link="link1"/>
  </joint>
但是,如果是一个移动基地或其他移动机器人,您不需要这个链接或关节。
######################################################################


  <!-- Base Link -->
  <link name="link1">
    <collision>#########碰撞
      <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>
      <geometry>
	<box size="${width} ${width} ${height1}"/>
      </geometry>
    </collision>

    <visual>##########可视化
      <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>
      <geometry>
	<box size="${width} ${width} ${height1}"/>
      </geometry>
      <material name="orange"/>####颜色
    </visual>

    <inertial>############惯性
      <origin xyz="0 0 ${height1/2}" rpy="0 0 0"/>##代表质心的位置
      <mass value="${mass}"/>
      <inertia
	  ixx="${mass / 12.0 * (width*width + height1*height1)}" ixy="0.0" ixz="0.0"
	  iyy="${mass / 12.0 * (height1*height1 + width*width)}" iyz="0.0"
	  izz="${mass / 12.0 * (width*width + width*width)}"/>
    </inertial>
  </link>
#########################################


  <joint name="joint1" type="continuous">
    <parent link="link1"/>###连接的父link和子link
    <child link="link2"/>
    <origin xyz="0 ${width} ${height1 - axel_offset}" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <dynamics damping="0.7"/>
  </joint>

#########################################

  <!-- Middle Link -->
  <link name="link2">
    <collision>
      <origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/>
      <geometry>
	<box size="${width} ${width} ${height2}"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/>
      <geometry>
	<box size="${width} ${width} ${height2}"/>
      </geometry>
      <material name="black"/>
    </visual>

    <inertial>
      <origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/>
      <mass value="${mass}"/>
      <inertia
	  ixx="${mass / 12.0 * (width*width + height2*height2)}" ixy="0.0" ixz="0.0"
	  iyy="${mass / 12.0 * (height2*height2 + width*width)}" iyz="0.0"
	  izz="${mass / 12.0 * (width*width + width*width)}"/>
    </inertial>
  </link>
#########################################



  <joint name="joint2" type="continuous">
    <parent link="link2"/>
    <child link="link3"/>
    <origin xyz="0 ${width} ${height2 - axel_offset*2}" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <dynamics damping="0.7"/>
  </joint>
#########################################


  <!-- Top Link -->
  <link name="link3">
    <collision>
      <origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/>
      <geometry>
	<box size="${width} ${width} ${height3}"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/>
      <geometry>
	<box size="${width} ${width} ${height3}"/>
      </geometry>
      <material name="orange"/>
    </visual>

    <inertial>
      <origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/>
      <mass value="${mass}"/>
      <inertia
	  ixx="${mass / 12.0 * (width*width + height3*height3)}" ixy="0.0" ixz="0.0"
	  iyy="${mass / 12.0 * (height3*height3 + width*width)}" iyz="0.0"
	  izz="${mass / 12.0 * (width*width + width*width)}"/>
    </inertial>
  </link>


#########################################
  <joint name="hokuyo_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="0 0 ${height3 - axel_offset/2}" rpy="0 0 0"/>
    <parent link="link3"/>
    <child link="hokuyo_link"/>
  </joint>

#########################################


  <!-- Hokuyo Laser -->
  <link name="hokuyo_link">
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
	<box size="0.1 0.1 0.1"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <mesh filename="package://rrbot_description/meshes/hokuyo.dae"/>
      </geometry>
    </visual>

    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

#########################################


  <joint name="camera_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="${camera_link} 0 ${height3 - axel_offset*2}" rpy="0 0 0"/>
    <parent link="link3"/>
    <child link="camera_link"/>
  </joint>

  <!-- Camera -->
  <link name="camera_link">
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
	<box size="${camera_link} ${camera_link} ${camera_link}"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
	<box size="${camera_link} ${camera_link} ${camera_link}"/>
      </geometry>
      <material name="red"/>
    </visual>

    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

  <!-- generate an optical frame http://www.ros.org/reps/rep-0103.html#suffix-frames
      so that ros and opencv can operate on the camera frame correctly -->
  <joint name="camera_optical_joint" type="fixed">
    <!-- these values have to be these values otherwise the gazebo camera image
        won't be aligned properly with the frame it is supposedly originating from -->
    <origin xyz="0 0 0" rpy="${-pi/2} 0 ${-pi/2}"/>
    <parent link="camera_link"/>
    <child link="camera_link_optical"/>
  </joint>

  <link name="camera_link_optical">
  </link>

  <transmission name="tran1">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint1">
      <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor1">
      <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

  <transmission name="tran2">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint2">
      <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor2">
      <hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

</robot>

参考资料

http://gazebosim.org/tutorials?cat=connect_ros

http://gazebosim.org/tutorials?tut=model_contrib&cat=build_robot

http://gazebosim.org/tutorials?tut=ros_urdf&cat=connect_ros

发布了237 篇原创文章 · 获赞 254 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/gwplovekimi/article/details/104304084