【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模
【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 ② 创建长方体的底座
代码解释:
- box 标签,用于产生对应尺寸的长方体
- collision 标签,指定碰撞尺寸
- 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 bottomcylinder 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 rotateit by 90 degrees around the X-axis so that the <horizontal> raysbecome 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 ofsimulated 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有关教程,主要目的是方便自行查询知识,巩固学习经验,无任何商业用途。
【Gazebo入门教程】第三讲 SDF文件的静/动态编程建模相关推荐
- 【Gazebo入门教程】第二讲 模型库导入与可视化机器人建模(模型编辑器)
[Gazebo入门教程]第二讲 模型库导入与可视化机器人建模(模型编辑器) 文章目录 [Gazebo入门教程]第二讲 模型库导入与可视化机器人建模(模型编辑器) 一.模型库导入 二.模型编辑器(以轮式 ...
- 【Gazebo入门教程】第一讲 Gazebo的安装、UI界面、SDF文件介绍
[Gazebo入门教程]第一讲 Gazebo的安装.UI界面.SDF文件介绍 文章目录 [Gazebo入门教程]第一讲 Gazebo的安装.UI界面.SDF文件介绍 一.Gazebo的简介与安装 1. ...
- 【Gazebo入门教程】第四讲 场景建模/建筑编辑器
[Gazebo入门教程]第四讲 场景建模/建筑编辑器 文章目录 [Gazebo入门教程]第四讲 场景建模/建筑编辑器 一.场景编辑器 1.1 打开方式: 1.2 UI界面分析: 二.导入平面图 2.1 ...
- 【Gazebo入门教程】第六讲 控制器插件的编写与配置(下)
[Gazebo入门教程]第六讲 控制器插件的编写与配置(下) \qquad 文章目录 [Gazebo入门教程]第六讲 控制器插件的编写与配置(下) 一.系统插件 二.Velodyne传感器插件 1. ...
- 【Gazebo入门教程】第五讲 控制器插件的编写与配置(上)
[Gazebo入门教程]第五讲 控制器插件的编写与配置(上) 文章目录 [Gazebo入门教程]第五讲 控制器插件的编写与配置(上) 一.控制插件的使用方法 1. 插件简介 2. 插件编写流程 二.模 ...
- gazebo入门教程(二)建立简单模型
创建模型 本节目标 一.模型编辑器用户界面 调色板(左面板) 工具列 局限性 二.车辆构造 1.创建车辆 (1).底盘 (2)前轮 (3)脚轮 2.添加传感器 3.添加插件 保存模型 本节目标 现在, ...
- c语言编程:vc++6.0入门教程及习题_百度文库,C语言编程:vc++6.0入门教程及习题.doc...
C语言编程:vc++6.0入门教程及习题.doc 下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览.不比对内容而直接下载带来的问题本站不予受理. 2.下载的文档,不会出现我们的网址 ...
- python入门教程第三讲_第三讲 使用Template
# Django Step by Step (三) ## 1 引言 本教程只想从浅到深地将大家带入到 Django 的世界,因此都是以简单的例子出发,而且这些例子都是为了说明问题,本身并没有什么实际的 ...
- Pr 入门教程:如何处理图片文件?
欢迎观看 Premiere Pro 教程,小编带大家学习 Pr 的基本编辑技巧,了解如何在 Pr 中处理照片. 在本文中,我将会使用图像文件,只需双击该项目文件即可在 Pr 中将其打开.想要在项目中加 ...
最新文章
- 七、使用栈实现综合计算器(中缀表达式)
- 算法----左叶子之和
- bottle+jquery 前后端分离
- 一文彻底理解Java单元测试
- proguard的简单配置说明
- 调用CALL TRANSACTION的三种方法
- SpringBoot应用日志通过logstash远程上传到ES
- leetcode 173. 二叉搜索树迭代器
- html框架有什么作用,使用HTML5+CSS+JS框架有那些好处
- 质量管理系统_智慧工地管理系统,进度安全质量三合一
- dll可以在linux下使用吗_Linux下使用rm删除文件,并排除指定文件
- 简记docker用法
- Win10 多出4个显示器无法删除的“通用非即插即用监视器”问题解决
- cad lisp 示坡线_AutoCAD命令-画示坡线
- 科恒khs202温控器使用说明书_WS203数字显示温控器使用说明书
- 计算机应用基础压缩文件操作题目演示,计算机应用基础操作题题目
- Urchin.exe使用说明
- 什么时候,董明珠能成功卖给记者一部格力手机?
- 电脑绘画的必备工具——绘图板
- rust 飞天指令_rust腐蚀游戏指令 游戏命令大全