gazebo加载world模型

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

 

 

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

   
  
  
  
  
  
  

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文件中。

  
    
        
        
        
        
        
        
    

 

下面就要加载机器人的模型了,官网(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:




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

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

 
     

第四步设置

  
     

    
    
        
    

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

 
  

此节点的参数有:

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

你可能感兴趣的:(gazebo加载world模型)