Gazebo之MyRobot建立
1. 源由
在本章中,将学习如何在 SDFormat 中构建一个简单的两轮机器人。
注:SDFormat(Simulation Description Format),有时简称为 SDF,是一种 XML 格式,用于描述机器人模拟器、可视化和控制的对象和环境。
2. 示例
Step 1: 新建一个简单世界
从构建一个简单的世界开始,然后在其中构建我们的机器人。打开一个名为 empty_world.sdf
的新文件,并将以下代码复制到其中。
<?xml version="1.0" ?>
<sdf version="1.10">
<world name="car_world">
<physics name="1ms" type="ignored">
<max_step_size>0.001</max_step_size>
<real_time_factor>1.0</real_time_factor>
</physics>
<plugin
filename="gz-sim-physics-system"
name="gz::sim::systems::Physics">
</plugin>
<plugin
filename="gz-sim-user-commands-system"
name="gz::sim::systems::UserCommands">
</plugin>
<plugin
filename="gz-sim-scene-broadcaster-system"
name="gz::sim::systems::SceneBroadcaster">
</plugin>
<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
<pose>0 0 10 0 0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
<attenuation>
<range>1000</range>
<constant>0.9</constant>
<linear>0.01</linear>
<quadratic>0.001</quadratic>
</attenuation>
<direction>-0.5 0.1 -0.9</direction>
</light>
<model name="ground_plane">
<static>true</static>
<link name="link">
<collision name="collision">
<geometry>
<plane>
<normal>0 0 1</normal>
</plane>
</geometry>
</collision>
<visual name="visual">
<geometry>
<plane>
<normal>0 0 1</normal>
<size>100 100</size>
</plane>
</geometry>
<material>
<ambient>0.8 0.8 0.8 1</ambient>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.8 0.8 0.8 1</specular>
</material>
</visual>
</link>
</model>
</world>
</sdf>
保存文件,导航到保存文件的目录并启动模拟器:
$ gz sim empty_world.sdf
注:一个只有地面和阳光的空世界。
Step 2: 新建一个模型(model)
- 定义了模型的名称 vehicle_blue,它应该在其同级(其他标签或同级模型)中是唯一的。
- 每个模型可以有一个链接被指定为 canonical_link,模型的隐式框架附加到这个链接上。
- 如果未定义,则第一个
<link>
将被选择为 canonical_link。 <pose>
标签用于定义模型的位置和方向,relative_to
属性用于定义模型相对于任何其他框架的姿态。- 如果未定义
relative_to
,则模型的<pose>
将相对于世界。 <pose>
标签内的值如下:<pose>X Y Z R P Y</pose>
,其中 X Y Z 表示框架的位置,R P Y 表示横滚、俯仰、偏航的方向。我们将它们设置为零,使两个框架(模型和世界)相同。
<model name='vehicle_blue' canonical_link='chassis'>
<pose relative_to='world'>0 0 0 0 0 0</pose>
Step 3: 机器人组成链接(Links)
Step 3.1: 新增底盘(Links/Chassis)
定义第一个链接,即我们汽车的底盘,以及它相对于模型的姿态。
<link name='chassis'>
<pose relative_to='__model__'>0.5 0 0.4 0 0 0</pose>
Step 3.1.1: 惯性属性(Inertial properties)
在这里,定义了底盘的惯性属性,如 <mass>
和 <inertia>
矩阵。使用此工具可以计算基本形状的惯性矩阵的值。
<inertial> <!--inertial properties of the link mass, inertia matix-->
<mass>1.14395</mass>
<inertia>
&l