Gazebo | Ignition | Community
Ask Your Question
0

How do you spawn an sdf in an already running simulation in gazebo garden?

asked 2023-03-03 12:55:50 -0500

ryn gravatar image

updated 2023-03-10 14:01:07 -0500

Hello,

I want to load an sdf model into a gazebo world dynamically, but I haven't figured out how. There are tutorials, but they're outdated.

I've read: https://answers.gazebosim.org/questio...

and that leads to a github page which says the ability to do so is implemented: https://github.com/robotology/gym-ign...

but it doesn't say "how" to spawn a model via its sdf.

I know there's fuel, but thats not for loading sdfs/urdfs locally

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-03-03 15:07:23 -0500

azeey gravatar image

It's not clear what dynamically means in your question, but whether you want to spawn a model from code or from the command line, the best way is to use the /world/<world name>/create service.

edit flag offensive delete link more

Comments

I'll look at that. I also clarified my title

ryn gravatar imageryn ( 2023-03-03 15:17:06 -0500 )edit

I looked at the UserCommands class and im not sure how to call it? Is there a python api or some other way to call the gazebo service?

ryn gravatar imageryn ( 2023-03-03 15:20:03 -0500 )edit

If you want to spawn a model from the command line, you can run gz service -s /world/empty/create --reqtype gz.msgs.EntityFactory --reptype gz.msgs.Boolean --timeout 1000 --req 'sdf_filename: "/path/to/model", name: "my_model"'

If you want to do it from C++, here is an example. There is no python API for that currently.

azeey gravatar imageazeey ( 2023-03-03 16:16:27 -0500 )edit

I tried the command you suggested and all I get is "service call timed out"

sudo gz service -s /world/empty/create --reqtype gz.msgs.EntityFactory --reptype gz.msgs.Boolean --timeout 1000 --req 'sdf_filename: "<full_path_to_sdf_file>", name: "diff_sdf_2"'
ryn gravatar imageryn ( 2023-03-10 14:00:27 -0500 )edit

You need to change the "empty" in /world/empty/create to the correct name of your world. Also, I wouldn't recommend using sudo with Gazebo. Do you get any messages from the terminal that's running Gazebo? It's helpful to run it using -v4.

azeey gravatar imageazeey ( 2023-03-10 23:28:05 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2023-03-03 12:55:50 -0500

Seen: 312 times

Last updated: Mar 10 '23