最新消息:

Turtlebot仿真-编辑仿真的世界

Turtlebot2/二代机器人 少儿编程 1469浏览 0评论
Turtlebot与仿真

编辑仿真的世界

  • 在以前的经验教训中,我们遇到了模拟世界。
  • 我们知道如何在它里面移动,改变相机视图。
  • 在这一课中,我们将学习如何选择一个模拟世界,创造一个新的世界,编辑现有的世界。

指定模拟世界

  • 我们使用下面的命令来运行世界的Gazebo :
roslaunch turtlebot_gazebo turtlebot_world.launch
  • roslaunch是一个重要的管理工具,启动和停止的ROS的过程。
  • 许多的ROS程序用来启动文件,你可以运行:
roslaunch <package-name> <launch-filename> [args]
  • 用这个命令:
roslaunch turtlebot_gazebo turtlebot_world.launch
  • turtlebot_gazebo是包的名称和turtle_world.launch是启动文件。
  • 我们可以指定要使用的世界world_file
 roslaunch turtlebot_gazebo turtlebot_world.launch world_file:=<full path to the world file>
  • 你可以在这个文件夹中找到存在的世界文件选择/opt/ros/indigo/share/turtlebot_gazebo/worlds
  • 尝试运行corridor.world
roslaunch turtlebot_gazebo turtlebot_world.launch world_file:=/opt/ros/indigo/share/turtlebot_gazebo/worlds/corridor.world
  • 你会看到这个世界:

Turtlebot仿真-编辑仿真的世界

  • 默认的世界是在环境变量turtlebot_gazebo_world_file
  • 你可以看到它运行这个命令:
echo $TURTLEBOT_GAZEBO_WORLD_FILE
# Output:
/opt/ros/indigo/share/turtlebot_gazebo/worlds/playground.world
  • 你可以更新它:
  1. 对于当前的终端运行这个命令:
TURTLEBOT_GAZEBO_WORLD_FILE=<full path to the world file>
  1. 对于所有运行此命令的新终端:
echo "export TURTLEBOT_GAZEBO_WORLD_FILE=<full path to the world file>" >> .bashrc
  • 它将在重新启动的终端工作。

发射一个空的世界:

  1. 为新的世界创建一个文件夹:
mkdir ~/turtlebot_custom_gazebo_worlds
  1. 发布一个空的世界:
roslaunch turtlebot_gazebo turtlebot_world.launch world_file:=/opt/ros/indigo/share/turtlebot_gazebo/worlds/empty.world
  1. 你会看到:

Turtlebot仿真-编辑仿真的世界

编辑一个世界:

  • 可以从模型数据库中添加简单的形状对象和对象。
  1. 选择“Insert 插入”选项卡。

Turtlebot仿真-编辑仿真的世界

  • 注意:您可以看到Connecting to model database连接到模型数据库。
  • 这可能需要很长的时间连接到gazebo的模型数据库。
  • 连接后,你会看到这张照片:

Turtlebot仿真-编辑仿真的世界

  1. 添加一个盒子。
  • 选择框图标,然后将鼠标移到渲染窗口上。
  • 当您选择框的适当位置时,请单击“左”键。
  1. 添加一个球体和一个圆柱体。

  2. 添加一个书架。

  • 选择要访问模型数据库的“插入”选项卡。
  • 选择书架。将它添加到渲染窗口。
  • 注:这可能需要一些时间来从Gazebo的模型数据库下载模型。
  1. 添加一个咖啡桌和一个垃圾站。
  • 你应该有类似于这张照片的东西:

Turtlebot仿真-编辑仿真的世界

  • 你可以在图片上看到如何修改每个模型的姿势。
  1. 模型可以通过右键点击删除模型并选择删除。删除垃圾箱。

Turtlebot仿真-编辑仿真的世界

保存一个新世界

  • 选择“文件”菜单并选择“保存”

Turtlebot仿真-编辑仿真的世界

  • 将出现一个弹出窗口,要求您选择一个文件夹,并输入一个新的文件名。
  • 选择turtlebot_custom_gazebo_worlds文件夹类型tutorial.world,然后点击保存
  • 在终端按Ctrl + C,现在你可以启动你的世界:
roslaunch turtlebot_gazebo turtlebot_world.launch world_file:=/home/<user_name>/turtlebot_custom_gazebo_worlds/tutorial.world
  • 在下一节课中,我们将使用这个命令:
roslaunch turtlebot_gazebo turtlebot_world.launch
  • 用默认的世界
/opt/ros/indigo/share/turtlebot_gazebo/worlds/playground.world
  • 或者我们将指定命令中的世界文件:
roslaunch turtlebot_gazebo turtlebot_world.launch world_file:=<full path to the world file>

读什么

  • 你可以在这里阅读更多关于roslaunch。

您必须 登录 才能发表评论!