gazebo教程---使用roslaunch来启动gazebo,加载models

2023-05-16

1.使用roslaunch加载一个世界模型

roslaunch gazebo_ros willowgarage_world.launch

运行效果如图:
在这里插入图片描述
下面看一下willowgarage_world.launch里的内容:

<?xml version="1.0"?>
<launch>

  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="worlds/willowgarage.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
    <arg name="paused" value="false"/>
    <arg name="use_sim_time" value="true"/>
    <arg name="gui" value="true"/>
    <arg name="headless" value="false"/> <!-- Inert - see gazebo_ros_pkgs issue #491 -->
    <arg name="recording" value="false"/>
    <arg name="debug" value="false"/>
  </include>

</launch>

里面又加载一个empty_world.launch,并传入一些参数,主要是world_name,使得empty_world.launch加载willowgarage.world。empty_world.launch里的内容是:

<?xml version="1.0"?>
<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="extra_gazebo_args" default=""/>
  <arg name="gui" default="true"/>
  <arg name="recording" default="false"/>
  <!-- Note that 'headless' is currently non-functional.  See gazebo_ros_pkgs issue #491 (-r arg does not disable
       rendering, but instead enables recording). The arg definition has been left here to prevent breaking downstream
       launch files, but it does nothing. -->
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>
  <arg name="physics" default="ode"/>
  <arg name="verbose" default="false"/>
  <arg name="output" default="screen"/>
  <arg name="world_name" default="worlds/empty.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
  <arg name="respawn_gazebo" default="false"/>
  <arg name="use_clock_frequency" default="false"/>
  <arg name="pub_clock_frequency" default="100"/>
  <arg name="enable_ros_network" default="true" />
  <arg name="server_required" default="false"/>
  <arg name="gui_required" default="false"/>

  <!-- set use_sim_time flag -->
  <param name="/use_sim_time" value="$(arg use_sim_time)"/>

  <!-- set command arguments -->
  <arg unless="$(arg paused)" name="command_arg1" value=""/>
  <arg     if="$(arg paused)" name="command_arg1" value="-u"/>
  <arg unless="$(arg recording)" name="command_arg2" value=""/>
  <arg     if="$(arg recording)" name="command_arg2" value="-r"/>
  <arg unless="$(arg verbose)" name="command_arg3" value=""/>
  <arg     if="$(arg verbose)" name="command_arg3" value="--verbose"/>
  <arg unless="$(arg debug)" name="script_type" value="gzserver"/>
  <arg     if="$(arg debug)" name="script_type" value="debug"/>

  <!-- start gazebo server-->
  <group if="$(arg use_clock_frequency)">
    <param name="gazebo/pub_clock_frequency" value="$(arg pub_clock_frequency)" />
  </group>
  <group>
    <param name="gazebo/enable_ros_network" value="$(arg enable_ros_network)" />
  </group>
  <node name="gazebo" pkg="gazebo_ros" type="$(arg script_type)" respawn="$(arg respawn_gazebo)" output="$(arg output)"
	args="$(arg command_arg1) $(arg command_arg2) $(arg command_arg3) -e $(arg physics) $(arg extra_gazebo_args) $(arg world_name)"
  required="$(arg server_required)" />

  <!-- start gazebo client -->
  <group if="$(arg gui)">
    <node name="gazebo_gui" pkg="gazebo_ros" type="gzclient" respawn="false" output="$(arg output)" args="$(arg command_arg3)"
    required="$(arg gui_required)"/>
  </group>

</launch>

主要是启动两个节点,一个是gzserver,另一个是gzclient。这里的两个节点启动是利用条件判断:(1)gzserver启动的条件是debug为false(这个参数值由willowgarage_world.launch传入,debug为false);
(2)gzclient的启动条件是gui为true(这个参数值由willowgarage_world.launch传入,gui为true)。
2. 方法一:往gazebo中加载model
(1)使用一个python脚本spawn_model向gazebo_ros(在rostopic的命名空间简称gazebo)请求往gazebo中添加一个自定义的URDF,而这个脚本是放在gazebo_ros功能包。可以运行如下命令来使用这个脚本:

rosrun gazebo_ros spawn_model -file `rospack find MYROBOT_description`/urdf/MYROBOT.urdf -urdf -x 0 -y 0 -z 1 -model MYROBOT

其中上述命令对应的文件结构为:

../catkin_ws/src
    /MYROBOT_description
        package.xml
        CMakeLists.txt
        /urdf
            MYROBOT.urdf
        /meshes
            mesh1.dae
            mesh2.dae
            ...
        /materials
        /cad
    /MYROBOT_gazebo
        /launch
            MYROBOT.launch
        /worlds
            MYROBOT.world
        /models
            world_object1.dae
            world_object2.stl
            world_object3.urdf
        /materials
        /plugins

在我的工作空间中,运行如下命令加载一个汽车模型,前提是已经在gazebo中加载一个世界(如上面的使用roslaunch加载的世界):

rosrun gazebo_ros spawn_model -file `rospack find simulation`/urdf/car/prius.urdf -urdf -x 0 -y 0 -z 1 -model prius

运行结果如下图:
在这里插入图片描述
也可以将上述命令加入到launch文件中,以上述文件结构为例,在MYROBOT_gazebo/launch/YOUROBOT.launch中,添加如下内容:

<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-file $(find baxter_description)/urdf/baxter.urdf -urdf -z 1 -model baxter" />

而在我的工作文件结构中,可以往willowgarage_world.launch添加一个小车,具体内容如下:

<?xml version="1.0"?>
<launch>

  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="worlds/willowgarage.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
    <arg name="paused" value="false"/>
    <arg name="use_sim_time" value="true"/>
    <arg name="gui" value="true"/>
    <arg name="headless" value="false"/> <!-- Inert - see gazebo_ros_pkgs issue #491 -->
    <arg name="recording" value="false"/>
    <arg name="debug" value="false"/>
  </include>
  <!-- Spawn a robot into Gazebo -->
  <node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-file $(find simulation)/urdf/car/prius.urdf -urdf -z 0 -model prius" />
  <!--name:用户自定义;-urdf:加载的是urdf文件,-model prius:加载模型的名字;-->
</launch>

(2)方法二:将用户模型导入到gazebo的模型数据库中
该方法需要设置环境变量,不利于跨平台,也就是说当把你的功能包移植到其他电脑时,还需要在其他电脑配置环境变量。具体可以参考gazebo官方教程。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

gazebo教程---使用roslaunch来启动gazebo,加载models 的相关文章

随机推荐

  • 第四章 Opencv图像色彩空间与通道

    文章目录 1 色彩空间1 1 RGB BGR色彩空间1 2 GRAY色彩空间1 3 HSV色彩空间 2 通道2 1 拆分通道 xff1a 96 split 96 方法1 拆BGR色彩空间图像的通道2 拆HSV色彩空间图像的通道 2 2 合并
  • 第五章 Opencv图像的几何变换

    目录 1 缩放图像1 1 resize 方法 2 翻转图像2 1 flip 方法 3 仿射变换图像3 1 warpAffine 方法3 2 平移3 3 旋转3 4 倾斜 4 透视图像4 1 warpPerspective 方法 几何变换是指
  • pip、conda查看镜像源及更换镜像源

    1 查看已经安装过的镜像源 xff1a conda config show channels 查看配置项channels 2 删除镜像源 xff08 清华镜像源 xff09 xff1a conda config remove channel
  • 生成环境下的所有包

    pip freeze span class token operator gt span requirements span class token punctuation span txt 问题 xff1a 将虚拟环境的安装包导出 xff
  • java核心技术卷I

    第三章 xff1a java的基本程序设计结构 文章目录 第三章 xff1a java的基本程序设计结构3 2 注释3 3 数据类型3 4变量3 4 1初始化变量3 4 2常量 3 5运算符3 5 1数学函数与常量3 5 2数值类型之间的转
  • MOT学习笔记 — 行人检测及行人跟踪数据集总结

    1 行人红外数据集总结 xff08 1 xff09 OSU Thermal Pedestrian Database 下载链接 xff1a http vcipl okstate org pbvs bench Data 01 download
  • 使用k-近邻算法识别手写数字

    本文摘自 机器学习实战 案例 xff0c 对其进行了代码更新与注释 实战介绍 使用k 近邻分类器构造手写识别系统 xff0c 为了简单起见 xff0c 系统只识别0 9 xff0c 需要识别的数字已经使用图形处理软件 xff0c 处理成具有
  • ubuntu16.04下安装并使用小觅双目MYNT EYE 1.x SDK

    1 下载MYNT EYE 1 x SDK压缩包 首先 xff0c 点击进入github官网 xff0c 在右上角的搜索栏中输入mynt xff0c 进入如下界面 xff1a 点击第四个slightech MYNT EYE SDK进入 xff
  • UART通用异步收发传输器

    UART 全称Universal Asynchronous Receiver Transmitter xff0c 通用异步收发传输器 xff0c 是一种串行异步收发协议 又称为串口 xff09 功能是将并行的数据转变为串行的数据发送或者将接
  • C语言如何实现输入特定字符串(单词)作为终止符

    本文章以一个例题来进行讲解 xff08 新手第一次写 xff0c 目的仅是分享自己写代码中想到的一些方法和技巧 xff0c 仍存在很多不足 xff0c 希望能对大家有用 xff09 题目要求 xff1a 有一篇文章 xff0c 共有多行文字
  • kubernetes 教程 笔记

    K8s 安装kub ectl 下载kubectl curl LO 34 https dl k8s io release curl L s https dl k8s io release stable txt bin linux amd64
  • ros uwb2world坐标转换python示例

    ros uwb2world坐标转换python示例 span class token comment coding 61 utf 8 span span class token comment usr bin env python span
  • ARUCO marker的解释

    markers for ARUCO 一种汉明 海明 码的格子图 如图 百度百科解释汉明码规则概要 使用奇偶校验 具有一位纠错能力 校验位在2的次幂位置1 2 4 8 16 32 具体参看 https baike baidu com item
  • 使用ros_control ros_controllers 的牛刀真实驱动舵机手臂的源码

    现场 rqt graph 在一个陌生的框架下写代码 xff0c 免不了有很多疑问与槽点 不了解框架结构 xff0c 千头万续 xff0c 无从下手 xff0c 说不清 xff0c 理还乱 资料少没有文档 xff0c 要读懂程序猿的心 xff
  • 经典的pid公式,好脑子不如烂笔头。

    这个算法涉及昨天 xff0c 今天 xff0c 明天 思路就是以史为鉴 xff0c 预测明天 xff0c 改革当前
  • c++对8位灰度图进行二值化处理

    对灰度图进行位二值化 xff0c 输入图像像素部分的宽度和高度以及存储灰度像素值 得一维数组 xff0c 对灰度值进行直方图统计 xff0c 通过OSTU大律法公式 xff0c 确定自动灰度 图的阈值 xff0c 进而进行二值化处理 xff
  • vue 数组常用方法(总结)

    vue 数组常用方法 操作原数组push item pop shift unshift item n splice startIndex endIndex sort reverse 返回新数组slice startIndex endInde
  • 【亲测可用】kali linux 2020.1 设置为中文方法

    目录 0x00 提示0x01 更换更新源0x02 默认语言选择0x03 安装中文字体0x04 重启 xff0c 完成0x05 参考文章 kali 2020 1可用 进入我们的正题 xff0c 修改为中文的步骤 0x00 提示 由于kali
  • QT的TCP应用-传输图片

    1 server h span class token macro property span class token directive hash span span class token directive keyword ifnde
  • gazebo教程---使用roslaunch来启动gazebo,加载models

    1 使用roslaunch加载一个世界模型 roslaunch gazebo ros willowgarage world span class token punctuation span launch 运行效果如图 xff1a 下面看一