预计完成时间:6 分钟
Gazebo GUI 专用插件需要写在
在 SDF 文件中手动添加 GUI 插件是一件比较繁琐的事情。因此,为了简化流程,它们没有直接写进你的演示 SDF 文件中。不过,请不要跳过这一节,因为这里会介绍最重要的 GUI 插件。
<gui fullscreen="0">
</gui>
把 fullscreen 设置为 0 来启动 GUI,这表示不使用全屏模式。
gz-gui 提供了大量可选插件。请添加必要的那些插件,让你的世界具备最基础的运行功能。
**注意:** 一旦你自己定义了 GUI 标签,空世界中默认可见的那些插件就都会消失!因此,只要你显式写了 GUI 标签,就必须把最少需要的插件也一并加进去。
MinimalScene 和 GzSceneManager 负责显示世界的 3D 场景。
<!-- 3D scene -->
<plugin filename="MinimalScene" name="3D View">
<gz-gui>
<title>3D View</title>
<property type="bool" key="showTitleBar">false</property>
<property type="string" key="state">docked</property>
</gz-gui>
<engine>ogre2</engine>
<scene>scene</scene>
<ambient_light>0.4 0.4 0.4</ambient_light>
<background_color>0.8 0.8 0.8</background_color>
<camera_pose>-6 0 6 0 0.5 0</camera_pose>
<camera_clip>
<near>0.25</near>
<far>25000</far>
</camera_clip>
</plugin>
<plugin filename="GzSceneManager" name="Scene Manager">
<gz-gui>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</gz-gui>
</plugin>
它具有以下属性,这些属性也是大多数 GUI 插件都会使用到的:
<title> 标签指定。在渲染引擎方面,你可以在 ogre 和 ogre2 之间进行选择。<ambient_light> 和 <background_color> 分别用于定义场景的环境光和背景颜色。此外,<camera_pose> 用于指定相机的位置(X、Y、Z)以及它的 Roll、Pitch、Yaw 旋转角。
World Control 插件负责管理世界:
<!-- World control -->
<plugin filename="WorldControl" name="World control">
<gz-gui>
<title>World control</title>
<property type="bool" key="showTitleBar">false</property>
<property type="bool" key="resizable">false</property>
<property type="double" key="height">72</property>
<property type="double" key="width">121</property>
<property type="double" key="z">1</property>
<property type="string" key="state">floating</property>
<anchors target="3D View">
<line own="left" target="left"/>
<line own="bottom" target="bottom"/>
</anchors>
</gz-gui>
<play_pause>true</play_pause>
<step>true</step>
<start_paused>true</start_paused>
<service>/world/world_demo/control</service>
<stats_topic>/world/world_demo/stats</stats_topic>
</plugin>
它包含以下属性:
<play_pause>:设为 true 时,会启用左下角的播放/暂停按钮。<stats_topic> 标签用于指定发布世界统计信息的话题,例如仿真时间和真实时间。<start_paused> 设置为 true,那么 Gazebo 启动时仿真会从暂停状态开始。World Stats 插件用于显示各种世界统计信息,包括 <sim_time>、<real_time>、<real_time_factor> 和 <iterations>。
<!-- World Statistics -->
<plugin filename="WorldStats" name="World stats">
<gz-gui>
<title>World Stats</title>
<property type="bool" key="showTitleBar">false</property>
<property type="bool" key="resizable">false</property>
<property type="double" key="height">110</property>
<property type="double" key="width">290</property>
<property type="double" key="z">1</property>
<property type="string" key="state">floating</property>
<anchors target="3D View">
<line own="right" target="right"/>
<line own="bottom" target="bottom"/>
</anchors>
</gz-gui>
<sim_time>true</sim_time>
<real_time>true</real_time>
<real_time_factor>true</real_time_factor>
<iterations>true</iterations>
<topic>/world/demo_world/stats</topic>
</plugin>
通过这些标签,你可以决定显示哪些数值(展开右下角即可查看这些统计信息),也可以指定这些数值发布到哪个 <topic> 上。
借助这些标签,你可以灵活决定要显示哪些统计值(展开右下角即可查看),同时也可以选择这些值发布到哪个 <topic> 上。
世界加载完成后,你还可以使用下面的命令监听该话题:gz topic -e -t /world/demo_world/stats
你还记得它们在第一单元中是什么作用吗?
Component Inspector 会显示当前选中实体的所有属性。
Entity Tree 会显示当前仿真场景中所有可用的模型/实体。
<!-- Component Inspector -->
<plugin filename="ComponentInspector" name="Component Inspector">
</plugin>
<!-- Entity Tree -->
<plugin filename="EntityTree" name="Entity Tree">
</plugin>
别忘了补上结束标签 </gui>。
这些插件也可以通过 Gazebo Sim 右上角的插件下拉菜单,直接在 GUI 中添加。
现在你已经完成了 Physics、World Plugins 和 GUI Plugins 的部分,接下来就可以开始向世界中添加各种元素了。
