【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模

2023-05-16

【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模

在这里插入图片描述

文章目录

  • 【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
    • 一、自定义模型并导入Gazebo
      • 1. 基础操作准备
      • 2. 建立模型基础部件(静态)
      • 3. 创建关节连接部件(动态)
      • 4. Gazebo基本仿真
    • 二、创建Velodyne HDL-32 LiDAR传感器
      • 1. 创建基本世界
      • 2. 创建传感器静态模型
      • 3. 添加模型惯性
      • 4. 添加关节
      • 5. 添加传感器
  • 总结

一、自定义模型并导入Gazebo

  • 内容简介:本节内容以一个两轮移动机器人为例,使用差动驱动机构运动,从无到有,使用SDF完成建模并在Gazebo中完成仿真,重点在于通过建模的细致流程掌握如何使用SDF文件和Gazebo软件完成机器人仿真。

1. 基础操作准备

  • 注意:Gazebo的模型文件有着严格的要求,具体规则可见SDF格式

\qquad ① 创建模型目录

mkdir -p ~/.gazebo/models/my_robot

\qquad ② 创建模型配置文件

gedit ~/.gazebo/models/my_robot/model.config

\qquad 元数据(config)内容如下:

	<?xml version="1.0"?>
	<model>
	  <name>My Robot</name>
	  <version>1.0</version>
	  <sdf version='1.4'>model.sdf</sdf>
	
	  <author>
	   <name>My Name</name>
	   <email>me@my.email</email>
	  </author>
	
	  <description>
	    My awesome robot.
	  </description>
	</model>

\qquad ② 创建模型配置文件

gedit ~/.gazebo/models/my_robot/model.sdf

\qquad 必要标记(sdf)内容如下:

	<?xml version='1.0'?>
	<sdf version='1.4'>
	  <model name="my_robot">
	  </model>
	</sdf>

2. 建立模型基础部件(静态)

  • 基本要求:本节内容主要是单独创建机器人的各部件,例如底座、轮子等,不涉及相关关节连杆等链接内容,重点在于对齐组件,故模型为静态,忽略物理效果。

\qquad ① 令机器人模型静态

注意:在static标签后将会在link标签下生成对应部件,通过collision的name隔开,故在后代码展示中则会忽略一部分,请自行补充

	<?xml version='1.0'?>
	<sdf version='1.4'>
	  <model name="my_robot">
	  <static>true</static>
	  </model>
	</sdf>

\qquad ② 创建长方体的底座

代码解释:

  1. box 标签,用于产生对应尺寸的长方体
  2. collision 标签,指定碰撞尺寸
  3. visual 标签,指定视觉尺寸,常见情况下与collision相同
<?xml version='1.0'?>
<sdf version='1.4'>
  <model name="my_robot">
  <static>true</static>
    <link name='chassis'>
      <pose>0 0 .1 0 0 0</pose>

      <collision name='collision'>
        <geometry>
          <box>
            <size>.4 .2 .1</size>
          </box>
        </geometry>
      </collision>

      <visual name='visual'>
        <geometry>
          <box>
            <size>.4 .2 .1</size>
          </box>
        </geometry>
      </visual>
    </link>
  </model>
</sdf>

\qquad ③ 创建脚轮(万向轮)

注意:脚轮固定在底座上,故二者同属一个link

<collision name='caster_collision'>
        <pose>-0.15 0 -0.05 0 0 0</pose>
        <geometry>
            <sphere>
            <radius>.05</radius>
          </sphere>
        </geometry>

        <surface>
          <friction>
            <ode>
              <mu>0</mu>
              <mu2>0</mu2>
              <slip1>1.0</slip1>
              <slip2>1.0</slip2>
            </ode>
          </friction>
        </surface>
      </collision>

      <visual name='caster_visual'>
        <pose>-0.15 0 -0.05 0 0 0</pose>
        <geometry>
          <sphere>
            <radius>.05</radius>
          </sphere>
        </geometry>
      </visual>
    </link>

\qquad ④ 创建前轮和后轮

注意:前轮和后轮分别创建了新的link

	  <link name="left_wheel">
      <pose>0.1 0.13 0.1 0 1.5707 1.5707</pose>

      <collision name="collision">
        <geometry>
          <cylinder>
            <radius>.1</radius>
            <length>.05</length>
          </cylinder>
        </geometry>
      </collision>

      <visual name="visual">
        <geometry>
          <cylinder>
            <radius>.1</radius>
            <length>.05</length>
          </cylinder>
        </geometry>
      </visual>
    </link>

    <link name="right_wheel">
      <pose>0.1 -0.13 0.1 0 1.5707 1.5707</pose>

      <collision name="collision">
        <geometry>
          <cylinder>
            <radius>.1</radius>
            <length>.05</length>
          </cylinder>
        </geometry>
      </collision>

      <visual name="visual">
        <geometry>
          <cylinder>
            <radius>.1</radius>
            <length>.05</length>
          </cylinder>
        </geometry>
      </visual>
    </link>

\qquad ⑤ 导入Gazebo可视化模型

  • 使用INSERT导入对应文件夹的模型,可看到模型如下:

在这里插入图片描述

注意:修改SDF文件后,只需要删除原有模型重新插入就会更新模型

3. 创建关节连接部件(动态)

  • 基本要求:将static设为false,为左右车轮添加铰链关节,关节绕Y轴旋转,将各车轮连接到底盘
	<static>false</static>
	<joint type="revolute" name="left_wheel_hinge">
      <pose>0 0 -0.03 0 0 0</pose>
      <child>left_wheel</child>
      <parent>chassis</parent>
      <axis>
        <xyz>0 1 0</xyz>
      </axis>
    </joint>

    <joint type="revolute" name="right_wheel_hinge">
      <pose>0 0 0.03 0 0 0</pose>
      <child>right_wheel</child>
      <parent>chassis</parent>
      <axis>
        <xyz>0 1 0</xyz>
      </axis>
    </joint>

4. Gazebo基本仿真

  • 基本操作:启动Gazebo,插入最新模型,打开隐藏的右面板,选择好要控制的模型,如下图给Force下的各关节力进行修改,机器人就会发生移动:

在这里插入图片描述

二、创建Velodyne HDL-32 LiDAR传感器

  • 内容简介:本节内容以一个两轮移动机器人为例,使用差动驱动机构运动,从无到有,使用SDF完成建模并在Gazebo中完成仿真,重点在于通过建模的细致流程掌握如何使用SDF文件和Gazebo软件完成机器人仿真。

1. 创建基本世界

  • 创建新的.world文件:
	gedit velodyne.world
  • 创建世界的环境:地面与光线
<?xml version="1.0" ?>
<sdf version="1.5">
  <world name="default">

    <!-- A global light source -->
    <include>
      <uri>model://sun</uri>
    </include>

    <!-- A ground plane -->
    <include>
      <uri>model://ground_plane</uri>
    </include>
  </world>
</sdf>

2. 创建传感器静态模型

  • 传感器基础部分2D绘图如下:

在这里插入图片描述

  • 对应代码如下:位于< world >的内部
<model name="velodyne_hdl-32">
  <!-- Give the base link a unique name -->
  <link name="base">

    <!-- Offset the base by half the lenght of the cylinder -->
    <pose>0 0 0.029335 0 0 0</pose>
    <collision name="base_collision">
      <geometry>
        <cylinder>
          <!-- Radius and length provided by Velodyne -->
          <radius>.04267</radius>
          <length>.05867</length>
        </cylinder>
      </geometry>
    </collision>

    <!-- The visual is mostly a copy of the collision -->
    <visual name="base_visual">
      <geometry>
        <cylinder>
          <radius>.04267</radius>
          <length>.05867</length>
        </cylinder>
      </geometry>
    </visual>
  </link>

  <!-- Give the base link a unique name -->
  <link name="top">

    <!-- Vertically offset the top cylinder by the length of the bottom
        cylinder and half the length of this cylinder. -->
    <pose>0 0 0.095455 0 0 0</pose>
    <collision name="top_collision">
      <geometry>
        <cylinder>
          <!-- Radius and length provided by Velodyne -->
          <radius>0.04267</radius>
          <length>0.07357</length>
        </cylinder>
      </geometry>
    </collision>

    <!-- The visual is mostly a copy of the collision -->
    <visual name="top_visual">
      <geometry>
        <cylinder>
          <radius>0.04267</radius>
          <length>0.07357</length>
        </cylinder>
      </geometry>
    </visual>
  </link>
</model>
  • 启动Gazebo查看模型:(先cd到文件路径下)
	cd ~/
	gazebo velodyne.world -u  

在这里插入图片描述

  • 查看碰撞属性:右键点击模型,view→Collisions

在这里插入图片描述

3. 添加模型惯性

  • 3.1 查看当前惯性值:右键单击模型,选择View->Inertia

在这里插入图片描述

注意:紫色框对应关联的链接大小,此时模型没有惯性信息,故尺寸过大

  • 3.2 添加惯性信息:质量设为1.3kg,添加对应质量和惯性矩阵

在< link name=“base” >块中添加以下内容:

  <link name="base">
    <pose>0 0 0.029335 0 0 0</pose>
    <inertial>
      <mass>1.2</mass>
      <inertia>
        <ixx>0.001087473</ixx>
        <iyy>0.001087473</iyy>
        <izz>0.001092437</izz>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyz>0</iyz>
      </inertia>
    </inertial>

在< link name=“top” >块中添加以下内容:

 <link name="top">
   <pose>0 0 0.095455 0 0 0</pose>
   <inertial>
     <mass>0.1</mass>
     <inertia>
       <ixx>0.000090623</ixx>
       <iyy>0.000090623</iyy>
       <izz>0.000091036</izz>
       <ixy>0</ixy>
       <ixz>0</ixz>
       <iyz>0</iyz>
     </inertia>
   </inertial>

最终效果如下:

在这里插入图片描述

4. 添加关节

  • 4.1 定义顶部围绕底部旋转关节,在< world >最后添加内容如下:
<!-- Each joint must have a unique name -->
<joint type="revolute" name="joint">

  <!-- Position the joint at the bottom of the top link -->
  <pose>0 0 -0.036785 0 0 0</pose>

  <!-- Use the base link as the parent of the joint -->
  <parent>base</parent>

  <!-- Use the top link as the child of the joint -->
  <child>top</child>

  <!-- The axis defines the joint's degree of freedom -->
  <axis>

    <!-- Revolve around the z-axis -->
    <xyz>0 0 1</xyz>

    <!-- Limit refers to the range of motion of the joint -->
    <limit>

      <!-- Use a very large number to indicate a continuous revolution -->
      <lower>-10000000000000000</lower>
      <upper>10000000000000000</upper>
    </limit>
  </axis>
</joint>
  • 4.2 检验效果:

1. 启动Gazebo,右键单击模型,选择View->Joints,View->Transparent

在这里插入图片描述

2. 打开右面板,选择Velodyne模型。使用Force选项卡向关节施加较小的,可看到关节旋转即可

在这里插入图片描述

5. 添加传感器

  • 传感器基本信息:

激光传感器,可以发出一个或多个光束,光束产生距离和强度数据,对应SDF文件中的< scan >和< range >,分别对应波束的布局、数量和限定束的性质,其中< scan >中包含< horizontal >和< vertical >两个块。< horizontal >组件定义在水平平面中发出的光线,该< vertical >组件定义在垂直平面中发出的光线,Velodyne传感器需要垂直射线,然后旋转。我们将其模拟为旋转的水平扇面。

  • 添加并设置传感器:(在的最后部分添加以下内容)
<!-- Add a ray sensor, and give it a name -->
<sensor type="ray" name="sensor">

  <!-- Position the ray sensor based on the specification. Also rotate
       it by 90 degrees around the X-axis so that the <horizontal> rays
       become vertical -->
  <pose>0 0 -0.004645 1.5707 0 0</pose>

  <!-- Enable visualization to see the rays in the GUI -->
  <visualize>true</visualize>

  <!-- Set the update rate of the sensor -->
  <update_rate>30</update_rate>
  <ray>

  <!-- The scan element contains the horizontal and vertical beams.
       We are leaving out the vertical beams for this tutorial. -->
  <scan>

    <!-- The horizontal beams -->
    <horizontal>
      <!-- The velodyne has 32 beams(samples) -->
      <samples>32</samples>

      <!-- Resolution is multiplied by samples to determine number of
           simulated beams vs interpolated beams. See:
           http://sdformat.org/spec?ver=1.6&elem=sensor#horizontal_resolution
           -->
      <resolution>1</resolution>

      <!-- Minimum angle in radians -->
      <min_angle>-0.53529248</min_angle>

      <!-- Maximum angle in radians -->
      <max_angle>0.18622663</max_angle>
    </horizontal>
  </scan>

  <!-- Range defines characteristics of an individual beam -->
  <range>

    <!-- Minimum distance of the beam -->
    <min>0.05</min>

    <!-- Maximum distance of the beam -->
    <max>70</max>

    <!-- Linear resolution of the beam -->
    <resolution>0.02</resolution>
  </range>
</ray>
</sensor>
  • 查看仿真效果:

在这里插入图片描述

  • 添加高斯噪声:

在< sensor >的子标签< ray >中添加如下代码:

<noise>
     <!-- Use gaussian noise -->
     <type>gaussian</type>
     <mean>0.0</mean>
     <stddev>0.1</stddev>
</noise>

效果如下:

在这里插入图片描述

  • 通过Ctrl+T打开topic visualization查看:

在这里插入图片描述



总结

  • 内容分析:本篇博客主要介绍了在Gazebo中如何使用SDF进行手动的编程建模,通过编写SDF文件,实现对于机器人从无到有的一步步建造,体会SDF文件的语法使用,并在文章整体使用两个具体实例,分别是轮式小车和Velodyne HDL-32 LiDAR传感器模型进行了深入研究。

在这里插入图片描述

  • 注意:本文参考了Gazebo官方网站以及古月居中的Gazebo有关教程,主要目的是方便自行查询知识,巩固学习经验,无任何商业用途。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模 的相关文章

  • VUE前端导出表格功能实现 前端 从后端获取(下载,导出)文件的方法

    场景 在很多时候需要从前端下载文件的情况 xff0c 最为典型就是导出指定格式的数据 一般存在两种方式 xff1a 请求接口之后 xff0c 直接打开请求该文件的地址 xff0c 下载到本地 请求接口之后 xff0c 将获取到的文件数据格式
  • Java将中国标准时间字符串转换为Date格式

    一 xff1a Java将中国标准时间字符串转换为Date格式 当前方法作用 xff0c 主要将标准时间格式如 xff1a 星期三 五月 01 22 25 49 CST 2023 输出按照指定格式内容 Data 和 String span
  • mysql中处理某个字段的json,将json中冗余内容去掉

    mysql中某个字段存在json xff0c 且json数据过大 xff0c 严重影响查询效率 处理办法 xff1a 将此字段提出来 xff0c 新建一个字段 xff0c 将此json中的字段除大文件 xff08 类似于图片和音视频的bas
  • 在xshell里面永久显示vim行数

    输入命令 xff1a vim vimrc 在里面输入 set nu wq OK xff0c 完成
  • 使用“时间机器”备份您的 Mac

    使用 时间机器 备份您的 Mac 了解如何在 Mac 上创建文件的备份 您可以使用 Mac 的内建备份功能 时间机器 对您的所有文件进行自动备份 xff0c 包括应用 音乐 照片 电子邮件 文稿和系统文件 如果您拥有备份 xff0c 当原始
  • 记录Debian11安装docker-desktop(一)

    64 TOC 一 首先系统安装Debian11 0linux系统 xff0c 并修改配置信息 1 切换安装源为alibaba debian 11 x bullseye 1 1编辑sudo vim etc apt sources list文件
  • docker环境安装运行tomcat8.5

    1 docker pull tomcat 8 5 56 2 mkdir opt tomcat 3 cd opt tomcat 4 docker run d p 8080 8080 v opt tomcat webapps usr local
  • SessionFactory中getCurrentSession地址的对比

    1 首先 xff0c 建立一个静态factory方法 xff0c 提供给CurrentSession public class CongUtil public static SessionFactory getUtil Configurat
  • springMVC中bean容器:bean.xml的配置

    lt xml version 61 34 1 0 34 encoding 61 34 UTF 8 34 gt lt beans xmlns 61 34 http www springframework org schema beans 34
  • Maven+spring +dubbo+zookeeper

    maven 43 springmvc 43 dubbo 43 zookeeper 为什么要用dubbo xff1f 还是让官方来解释吧 xff1a http dubbo io User 43 Guide zh htm http dubbo
  • window环境搭载elasticsearch学习(一)

    前言 xff1a 没太大比较 xff0c 因为工作项目需要 短时间运用elasticsearch做一个简单demo并能够实现一些简单操作 xff0c 所以选择用了windows环境 估计会比较多的坑 xff0c 让我们积极入坑吧 一 官网下
  • window环境搭载elasticsearch学习(三)--中文分词器

    前言 系统 xff1a Windows10 elasticsearch版本 xff1a 5 6 6 中文分词版本 xff1a 5 6 6 xff08 需要与elasticsearch版本匹配 xff09 maven版本 xff1a 3 5
  • 基于Windows10基于Linux的C语言笔记Ⅰ

    这玩意儿就是自己的学习笔记 xff0c 不过 xff0c 也可以用来入门学习C语言 However xff0c 你需要 xff1a 学习C语言兴致 xff0c Windows10 xff08 或者你有一台Linux系统的电脑 xff09 x
  • PDF文件中电子签名(安全性、有效性、合法性)验证指南

    电子合同是电子签名较为常见的一种应用方式 xff0c 目前大多数的的电子合同与电子文书都采用PDF的文件格式 本文以PDF格式的电子合同为例解释如何验证电子签名的安全性 有效性与合法性 xff08 下文统称 验签 xff09 xff0c 同
  • 数据结构专题——二叉树

    什么是二叉树 通俗的讲就是树上每一个节点最多有两个子节点 官方的递归定义是 xff1a 要么二叉树没有根节点 xff0c 是一颗空树要么二叉树由根结点 左子树 右子树组成 xff0c 且左右子树也都是二叉树 这里有两种特殊的二叉树 满二叉树
  • CSS filter滤镜属性使用

    前言 CSS的滤镜filter属性 xff0c 可以对网页中的图片进行类似Photoshop图片处理的效果 xff0c 通过CSS对图像进行处理 xff0c CSS的filter属性可以得到一些类似PS的滤镜效果 浏览器支持情况 xff1a
  • vtk中的剪裁

    在VTK中 xff0c 我们通常需要的并不是严格标准的几何体 xff0c 我们需要对这些几何体进行加工 xff0c 修改其内容 xff0c 得到我们想要的效果 xff0c 下面结合例子介绍如何在VTK中实现对几何体的裁剪 要对几何体进行裁剪
  • Ubuntu18.04搭建jenkins,并关联Github

    一 Ubuntu搭建jenkins 1 安装Java环境 sudo apt install openjdk 11 jre headless 创建一个Jenkins目录 xff0c 并进入 mkdir Jenkins cd Jenkins 3
  • 使用FOFA进行资产收集

    使用FOFA进行资产收集 FOFA是一款空间搜索引擎 它可以通过进行网络空间测绘快速进行网络资产匹配FOFA官方地址 https fofa so 我们使用FOFA进行搜索资产的时候他是不区分大小写的 xff1b 并且我们可以使用一些逻辑连接
  • python针对文本的操作

    Python文件的处理 1 我们可以把文件想象成一个仓库 xff1b 可以供我们操作使用 针对文件的操作流程为 xff1a 打开文件并且创建对象 xff1b 对该文件内容进行 读取 写入 删除 修改等操作 关闭并且保存 2 常用操作函数 o

随机推荐