Gazebo | Ignition | Community
Ask Your Question

debugging spawning sdf model in Gazebo

asked 2021-08-17 21:56:29 -0500

Anirban Sinha gravatar image


I am trying to spawn SDF model of a human in Gazebo environment. The human sdf model I have got from here. In order to spawn that model in Gazebo, I have created 3 roslaunch files. The first roslaunch file (named start_world.launch) is just to start the empty Gazebo world in ROS which is as below

<?xml version="1.0"?>
    <!-- startup simulated world -->
    <include file="$(find gazebo_ros)/launch/empty_world.launch">

The second launch file, spawn_sdf.launch, is pertaining to spawning a general sdf model in Gazebo which is as below

<?xml version="1.0"?>
  <arg name="x" default="0.0" />
  <arg name="y" default="0.0" />
  <arg name="z" default="0.0" />
  <arg name="roll" default="0.0" />
  <arg name="pitch" default="0.0" />
  <arg name="yaw" default="0.0" />
  <arg name="sdf_robot_file" default="$(find person_sim)/models/model.sdf"/>
  <arg name="robot_name" default="person_standing"/>

  <node name="$(arg robot_name)_spawn_urdf" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-file $(arg sdf_robot_file) -sdf -x $(arg x) -y $(arg y) -z $(arg z) -R $(arg roll) -P $(arg pitch) -Y $(arg yaw) -model $(arg robot_name)"/>

The third roslaunch file, spawn_person.launch, includes the second roslaunch file and presented below

<?xml version="1.0"?>
  <arg name="x" default="0.0" />
  <arg name="y" default="0.0" />
  <arg name="z" default="0.0" />
  <arg name="yaw" default="0.0" />
  <arg name="sdf_robot_file" default="$(find person_sim)/models/model.sdf"/>
  <arg name="robot_name" default="person_standing"/>

  <!-- startup simulated world -->
  <include file="$(find person_sim)/launch/spawn_sdf.launch">
      <arg name="sdf_robot_file" value="$(arg sdf_robot_file)"/>
      <arg name="robot_name" value="$(arg robot_name)" />
      <arg name="x" value="1.0" />
      <arg name="y" value="1.0" />
      <arg name="z" value="0.0" />
      <arg name="yaw" value="0.0" />

In one terminal I launch start_world.launch and in the second terminal I launch spawn_person.launch. Please note that all these launch files and the sdf model reside in a package named person_sim. After running the second launch file in the terminal, I see the following output

$ roslaunch person_sim spawn_person.launch 
... logging to /home/robot/.ros/log/d4d37442-ff59-11eb-906a-db8f4ebf8eb8/roslaunch-robot-133639.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://robot:43401/


 * /rosdistro: noetic
 * /rosversion: 1.15.11

    person_standing_spawn_urdf (gazebo_ros/spawn_model)


process[person_standing_spawn_urdf-1]: started with pid [133668]
[INFO] [1629204731.354375, 0.000000]: Loading model XML from file /home/robot/robot_ws/src/ur5-simulation-package/person_sim/models/model.sdf
[INFO] [1629204731.359082, 43.753000]: Waiting for service /gazebo/spawn_sdf_model
[INFO] [1629204731.364632, 43.759000]: Calling service /gazebo/spawn_sdf_model
[INFO] [1629204731.552085, 43.889000]: Spawn status: SpawnModel: Successfully spawned entity
[person_standing_spawn_urdf-1] process has finished cleanly
log file: /home/robot/.ros/log/d4d37442-ff59-11eb-906a-db8f4ebf8eb8/person_standing_spawn_urdf-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete

After that I do not see any sdf model was spawned ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-20 23:34:56 -0500

anishdiwan gravatar image

updated 2021-08-20 23:37:11 -0500

Hello, instead of creating three separate launch files for each of your models, you might want to create a .world file containing all your models and then use a single .launch to start the simulation Please refer to the "creating a custom world file" part of this tutorial for more information.

Basically, your .world file can be something like this:

<?xml version="1.0" ?>
<sdf version="1.4">
<world name="default">
  <pose>5 7 0 0 0 0</pose>

Then create a launch file to start the simulation as well as spawn any custom models using the spawn_model method. Something like this:


  <!-- This launch file launches a world as described in the .world file. It then spawns a custom robot model -->

 <!-- Generate the world based on the empty world and change only the below-mentioned arguments -->

 <include file="$(find gazebo_ros)/launch/empty_world.launch">

<arg name="world_name" value="$(find pkg_name)/worlds/"/>
<arg name="paused" value="true"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="true"/>
<arg name="recording" value="false"/>
<arg name="debug" value="false"/>

<!-- Spawn a custom model into Gazebo -->  
<param name="robot_description" command="cat '$(find pkg_name)/urdf/model_name.urdf'"/>
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" output="screen" args="-urdf -param robot_description -x 0 -y 0 -z 0 -model test_robot"/>

edit flag offensive delete link more


Thank you for your suggestion. I had created a minimal example which I have posted here . I am able to solve the problem based on your suggestion and the other given in the link.

Anirban Sinha gravatar imageAnirban Sinha ( 2021-08-31 08:12:38 -0500 )edit

Question Tools

1 follower


Asked: 2021-08-17 21:56:29 -0500

Seen: 787 times

Last updated: Aug 20 '21