Gazebo | Ignition | Community
Ask Your Question

Equivalent of simulator_gazebo's spawn_model for drcsim

asked 2013-04-03 17:06:25 -0500

Elizabeth C gravatar image

updated 2013-04-16 02:57:14 -0500

The versions of Gazebo that ship with the simulator_gazebo stack include a spawn_model script that calls the service /gazebo/spawn_gazebo_model or /gazebo/spawn_urdf_model to spawn a new model into an already-running world. However, drcsim doesn't provide either of these services. Is there some other way to programmatically spawn a model into an already running instance of the drcsim version of Gazebo? (I found some tutorials on modifying world contents, but they involve creating a new .world file, which is not what I want to do.) Or could I change something somewhere to make drcsim advertise the /gazebo/spawn_*_model topics?

(The reason I'm asking is because I'd like to use the drcsim version of Gazebo for something non-DRC-related that I'm doing, because it's newest and (presumably) most stable version of Gazebo that's integrated with ROS.)

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2013-04-04 00:31:50 -0500

scpeters gravatar image

I would recommend the command-line tool gzfactory. For some reason, we don't have a tutorial for it yet. To use it, you need a an sdf file. I used one of the model sdf files in the ~/.gazebo/models folder. For example to spawn a hokuyo sensor (make sure it's in your .gazebo/models folder first):

gzfactory spawn -f ~/.gazebo/models/hokuyo/model-1_3.sdf

To spawn another, you'll need to specify a different name, and you'll probably want to put it somewhere else:

gzfactory spawn -f ~/.gazebo/models/hokuyo/model-1_3.sdf -m hokuyo_1 -x 1

Here's the help output that I see when typing gzfactory:

This tool for spawning or deleting models into or from a running Gazebo simulation.

  gzfactory <spawn|delete> [options]
    spawn   : Spawn new model. Must specify a SDF model file.
    delete  : Delete existing model. Must specify model name.

Allowed options:
  -h [ --help ]           produce this help message
  -f [ --sdf ] arg        SDF model file.
  -w [ --world-name ] arg Name of Gazebo world.
  -m [ --model-name ] arg Model name.
  -x [ --pose-x ] arg     set model x position.
  -y [ --pose-y ] arg     set model y position.
  -z [ --pose-z ] arg     set model z positione.
  -R [ --pose-R ] arg     set model roll orientation in radians.
  -P [ --pose-P ] arg     set model pitch orientation in radians.
  -Y [ --pose-Y ] arg     set model yaw orientation in radians.
edit flag offensive delete link more


Thank you! Problem is, this doesn't work for URDF files, which is what all the models I'm using are. I guess I didn't specify that in my original question, though, so I'll go ahead and accept this answer (because it is correct that gzfactory does what I asked for).

Elizabeth C gravatar imageElizabeth C ( 2013-04-21 01:58:40 -0500 )edit

answered 2013-04-21 04:55:29 -0500

Elizabeth C gravatar image

updated 2013-04-21 04:58:11 -0500

I went ahead and marked @scpeters' answer as correct, because it does answer my original question. The thing I left out of the original question was that I need to spawn URDF models (and would prefer not to convert them to SDF). @AndreiHaidu's answer inspired the solution I actually used, which was to modify drcsim's gazebo_ros_api_plugin to provide the spawning services. It turns out that the lines to provide the services were present, but not being compiled due to dependency issues that would arise when compiling drcsim. (I discovered later that I should have used the simulator_gazebo version of gazebo_ros_api_plugin, because it has some bug fixes that the drcsim version doesn't.) Then I was able to use the modified version of the plugin with the system version of Gazebo to spawn URDF models via ROS, though Gazebo is displaying one of the models 100 times smaller than it should be... (But that's another issue.)

If anyone wants details on what I did, leave a comment and I'll expand the answer.

edit flag offensive delete link more

answered 2013-04-04 05:42:08 -0500

AndreiHaidu gravatar image

Also, if you want to use Gazebo with ROS without using DRCSIM, you can easily create your own ROS enabled plugin. Here is a tutorial on how to do it.

Cheers, Andrei

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2013-04-03 17:06:25 -0500

Seen: 3,725 times

Last updated: Apr 21 '13