ROS Gazebo(三):启动gazebo/URDF

2023-05-16

打开Gazebo的方式主要有两种:rosrun 和 roslaunch。

1、启动ROS节点

启动ROS节点、bring up 机器人的标准工具是roslaunch。打开一个空的Gazebo世界命令如下:

roslaunch gazebo_ros empty_world.launch

参数:

  • paused
    在暂停状态打开Gazebo (default false)
  • use_sim_time
    节点启动模拟时间,启动主题topic /clock (default true)
  • gui
    启动Gazebo用户接口 (default true)
  • headless
    禁止仿真器调用任何渲染组件。不能在gui:=true (default false)是使用
  • debug
    用gdb (default false)调试模式启动 gzserver (Gazebo Server)

例如:

roslaunch gazebo_ros empty_world.launch paused:=true use_sim_time:=false gui:=true throttled:=false headless:=false debug:=true

2、demo 环境

还有一些demo可以直接使用,它们在包含在gazebo_ros功能包中,包括:

roslaunch gazebo_ros willowgarage_world.launch
roslaunch gazebo_ros mud_world.launch
roslaunch gazebo_ros shapes_world.launch
roslaunch gazebo_ros rubble_world.launch

注意mud_world.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/mud.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"/>
    <arg name="debug" value="false"/>
  </include>
</launch>

所有的文件都继承了empty.world,只改变了一个参数:world_name

这里写图片描述

3、创建Gazebo ROS Package

1、建立工作空间

/home/user/catkin_ws/src

2、编写sdf文件

文件夹目录如下:

../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

3、创建通用的 World 文件

  • 创建ROS功能包

  • 创建launch文件夹

  • 创建 YOUROBOT.launch 文件

<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="$(find MYROBOT_gazebo)/worlds/MYROBOT.world"/>
    <!-- more default parameters can be changed here -->
  </include>
</launch>
  • 创建MYROBOT.world 文件
<?xml version="1.0" ?>
<sdf version="1.4">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>
    <include>
      <uri>model://gas_station</uri>
      <name>gas_station</name>
      <pose>-2.0 7.0 0 0 0 0</pose>
    </include>
  </world>
</sdf>
  • 运行文件
. ~/catkin_ws/devel/setup.bash
roslaunch MYROBOT_gazebo MYROBOT.launch

4、加载 URDF 模型

如何把自己建立的URDF模型添加到gazebo环境中?

利用 roslaunch,有两种方法:

  • ROS Service Call Spawn Method

这种方法保持ROS软件包在不同电脑间轻松移植。只要软件包在一个ROS包路径中即可。不过要求编写一个ROS service call脚本。

  • Model Database Method

只要放置在默认的数据库路径中,或者自己建立一个数据库,并把它包含在环境变量中


1、ROS Service Call

利用 pawn_model脚本向 gazebo_ros 节点(在主题中,空间名为”gazebo” )发出服务请求,进而添加 URDF 到 Gazebo 中。

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

如果是.xacro,可以转化为 urdf 文件:

rosrun xacro xacro.py `rospack find pr2_description`/robots/pr2.urdf.xacro -o /tmp/pr2.urdf

查看其关节图:

check_urdf pr2.urdf
urdf_to_graphiz pr2.urdf

cd ~
rosrun tf view_frames
evince frames.pdf

查看 pawn_model的所有参数,可以运行:

rosrun gazebo_ros spawn_model -h

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" />

例子:

<!-- 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" />

2、Model Database

此种方法需要编辑 sdf 文件,官方的模型都是采用的这种方法。

参考

https://bitbucket.org/osrf/gazebo_models/downloads/
http://gazebosim.org
http://wiki.ros.org/urdf

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

ROS Gazebo(三):启动gazebo/URDF 的相关文章

随机推荐