Gazebo 加载xacro文件和URDF文件的方式

 版权声明:

<--本博客所有内容均为自己在学习工作中的总结、摘录等-- --转载请注明出处-- --如有侵权请联系删除-->  https://blog.csdn.net/xuehuafeiwu123/article/details/71108959


打开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 mud_world.launch
roslaunch gazebo_ros shapes_world.launch
roslaunch gazebo_ros rubble_world.launch

注意在mud_world.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 文件


  
  
    
    
  

创建MYROBOT.world 文件



  
    
      model://ground_plane
    
    
      model://sun
    
    
      model://gas_station
      gas_station
      -2.0 7.0 0 0 0 0
    
  

运行文件

. ~/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 中。

urdf

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

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

xacro

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文件中,可以编写为形如:

urdf


xacro





  • Model Database

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

参考
https://bitbucket.org/osrf/gazebo_models/downloads/ 
http://gazebosim.org 
http://wiki.ros.org/urdf
--------------------- 
作者:飘零过客 
来源:CSDN 
原文:https://blog.csdn.net/xuehuafeiwu123/article/details/71108959 
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(ROS,Gazebo)