使用launch文件启动gazebo加载world模型,或者说是将world模型加入gazebo仿真器中作为环境。

first,我们应该告诉gazebo 要加载的world文件放在哪里。并通过arg标签,设置此world文件加载时的参数。

  <!-- 设置launch文件的参数 --> <arg name="world_name" value="$(find mbot_gazebo)/worlds/playground.world"/><arg name="paused" default="false"/><arg name="use_sim_time" default="true"/><arg name="gui" default="true"/><arg name="headless" default="false"/><arg name="debug" default="false"/>

roslaunch Arguments(参数说明)

You can append the following arguments to the launch files to change the behavior of Gazebo:
paused
Start Gazebo in a paused state (default false)
use_sim_time
Tells ROS nodes asking for time to get the Gazebo-published simulation time, published over the ROS topic /clock (default true)
gui
Launch the user interface window of Gazebo (default true)
headless (deprecated) recording (previously called headless)
Enable gazebo state log recording
debug
Start gzserver (Gazebo Server) in debug mode using gdb (default false)
verbose
Run gzserver and gzclient with --verbose, printing errors and warnings to the terminal (default false)

除了上述几个,还有一个最重要的就是world_name参数,此参数用于加载其他的world模型。

第二步,我们应该通过include empty_world.launch文件,加载上述world文件,并将上面所设置的参数传递给empty_world文件中。

  <!-- 运行gazebo仿真环境 --><include file="$(find gazebo_ros)/launch/empty_world.launch"><arg name="world_name" value="$(arg world_name)" /><arg name="debug" value="$(arg debug)" /><arg name="gui" value="$(arg gui)" /><arg name="paused" value="$(arg paused)"/><arg name="use_sim_time" value="$(arg use_sim_time)"/><arg name="headless" value="$(arg headless)"/></include>

下面就要加载机器人的模型了,官网(http://gazebosim.org/tutorials?tut=ros_roslaunch)中给出来两种方法,本文中使用ROS Service Call Spawn Method,可以参考官网教程,描述如下:

The first method keeps your robot's ROS packages more portable between computers and repository check outs. It allows you to keep your robot's location relative to a ROS package path, but also requires you to make a ROS service call using a small (python) script.
This method uses a small python script called spawn_model to make a service call request to the gazebo_ros ROS node (named simply "gazebo" in the rostopic namespace) to add a custom URDF into Gazebo. The spawn_model script is located within the gazebo_ros package. You can use this script in the following way:
rosrun gazebo_ros spawn_model -file `rospack find MYROBOT_description`/urdf/MYROBOT.urdf -urdf -x 0 -y 0 -z 1 -model MYROBOT
XACRO Example with PR2
If your URDF is not in XML format but rather in XACRO format, you can make a similar modification to your launch file. You can run this PR2 example by installing this package:
ROS Jade:
sudo apt-get install ros-jade-pr2-common
Then adding this to your launch file created previously in this tutorial:
<!-- Convert an xacro and put on parameter server -->
<param name="robot_description" command="$(find xacro)/xacro.py $(find pr2_description)/robots/pr2.urdf.xacro" />

<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model pr2" />

简单来说,就是使用官方提供出的spawn_urdf节点,此节点可以将机器人导入Gazebo中。我们要做的,只是将我们需要的机器人模型传递给这个节点即可。具体做法请看下面几步:

第三步,应该加载机器人模型

 <!-- 加载机器人模型描述参数 --><param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_with_camera_gazebo.xacro'" />

第四步设置

  <!-- 运行joint_state_publisher节点,发布机器人的关节状态  --><node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node> <!-- 运行robot_state_publisher节点,发布tf  --><node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"  output="screen" ><param name="publish_frequency" type="double" value="50.0" /></node>

第五步,通过节点将机器人加载到gezebo中。

 <!-- 在gazebo中加载机器人模型--><node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"args="-urdf -model mbot -param robot_description"/> 

此节点的参数有:

Commands:-[urdf|gazebo] - specify incoming xml is urdf or gazebo format-[file|param] [<file_name>|<param_name>] - source of the model xml-model <model_name> - name of the model to be spawned.-reference_frame <entity_name> - optinal: name of the model/body where initial pose is defined.If left empty or specified as "world", gazebo world frame is used.-namespace <ros_namespace> - optional: all subsequent ROS interface plugins will be inside of this namespace.-x <x in meters> - optional: initial pose, use 0 if left out-y <y in meters> - optional: initial pose, use 0 if left out-z <z in meters> - optional: initial pose, use 0 if left out-R <roll in radians> - optional: initial pose, use 0 if left out-P <pitch in radians> - optional: initial pose, use 0 if left out-Y <yaw in radians> - optional: initial pose, use 0 if left out

gazebo加载world模型相关推荐

  1. Gazebo加载模型时黑屏

    Gazebo加载模型时黑屏 1. 黑屏状态 2. 解决办法1 3. 解决办法2 1. 黑屏状态 Gazebo加载模型的时候会发现一直处于这种状态 这可能是因为model库加载不正确导致的 2. 解决办 ...

  2. Gazebo仿真--加载世界模型

    加载世界模型 例子: <launch><include file="$(find gazebo_ros)/launch/empty_world.launch"&g ...

  3. ros学习记录:Gazebo加载速度慢,长时间停在“Preparing your world”

    前言 ros学习记录笔记,一个小白的自留地,欢迎大佬批评指正~ 一.问题描述 Gazebo加载速度慢,长时间停在"Preparing your world" 二.解决办法 1.下载 ...

  4. 在C++中加载TorchScript模型

    在C++中加载TorchScript模型 本教程已更新为可与PyTorch 1.2一起使用 顾名思义,PyTorch的主要接口是Python编程语言.尽管Python是合适于许多需要动态性和易于迭代的 ...

  5. xBIM 实战01 在浏览器中加载IFC模型文件

    系列目录    [已更新最新开发文章,点击查看详细]  一.创建Web项目 打开VS,新建Web项目,选择 .NET Framework 4.5  选择一个空的项目 新建完成后,项目结构如下: 二.添 ...

  6. Python时间序列模型推理预测实战:时序推理数据预处理(特征生成、lstm输入结构组织)、模型加载、模型预测结果保存、条件判断模型循环运行

    Python时间序列模型推理预测实战:时序推理数据预处理(特征生成.lstm输入结构组织).模型加载.模型预测结果保存.条件判断模型循环运行 目录

  7. threejs加载obj模型_Vulkan编程指南(章节31-载入模型)

    章节31 载入模型 介绍 本章节我们将会渲染一个带有纹理的三维模型. 库 我们使用tinyobjloader库来从OBJ文件加载顶点数据.tinyobjloader库是一个简单易用的单文件OBJ加载器 ...

  8. PaddleOCR加载chinese_ocr_db_crnn_modile模型进行中英文混合预测(Http服务)实践

    1. 环境搭建 参考:<PaddleOCR加载chinese_ocr_db_crnn_server模型进行中英文混合预测(命令行)实践> 2. 服务端部署 hub serving star ...

  9. threejs加载3D模型例子

    加载3D模型 首先要引入ColladaLoader加载器,Collada是一个3D模型交换方案,即不同的3D模型可以通过Collada进行相互转换,言外之意,threejs可以使用Collada将3D ...

最新文章

  1. java pdfreader去除水印_(最新)JAVA使用Icepdf 5.0.6 pro的PDF转图片去掉水印的方法...
  2. HBase 0.98 分布式集群安装详解
  3. 03.full_text interval查询
  4. 产品经理必读:用户场景分析的四要素
  5. Mybatis入门(一)
  6. php学习总结,PHP学习的技巧和学习的要素总结
  7. (76)译码器与编码器(三八译码器)
  8. phpstorm 不能选择 php language level
  9. innodb数据备份语句
  10. Axis2联接WCF(比较完整的版本)
  11. 寒江独钓——win内核编程读书笔记-1
  12. Cisco2811配置Qos实现带宽分流
  13. 无法读源文件或磁盘_磁盘阵列RAID1+0和RAID0+1的区别
  14. Zotero文献管理软件使用指南——入门篇
  15. 问道服务器etc修改教程,常用的修改etc对照表-详细版
  16. java在哪里报错_BirthDate.java程序错误在哪里运行不出来写着 c :myjavajavac Test.java Test.java:46 找不到符号 符号...
  17. 计算机美术教学应用,浅谈计算机在美术教学中的应用
  18. 【计算情与思】大学生学习和发展的思考和建议
  19. OpenCVSharp 4.5 去离焦模糊
  20. RGB转换成CMYK

热门文章

  1. python读取网页表格数据库_python 提取网页表格数据库数据库
  2. Hive利用增量表更新全量表
  3. 四国军棋界面开发(2) 让棋子动起来
  4. Unsupervised Learning-Auto Encoder
  5. USB串口转换器进入网络时代
  6. 快播团队悄然崛起:连获2大奖,业内充分肯定,抢先布局千亿市场
  7. PowerShell 管道和对象成员
  8. Python构造代理IP池提高访问量
  9. php和python做数据采集,PHP或者python进行数据采集和分析成熟的框架
  10. 一千个“鉴毒师”用八年炼了一炉丹 吃了后成了钢铁侠