I am trying to spawn my robot model using rospy in my python interface to Gazebo. In the launch file, I spawn the robot using:

ns="$(arg robot_name)"
args="-urdf -model $(arg robot_model) -param robot_description -z 1.015"/>

What would be the python way of doing the same? I'd be happy to share more details if needed. Thanks in advance!


2 Answers 2


I haven't tried it myself but found something similar. Give it a try and let me know as well if it works for you. Good luck!

This is the code that they used.

import roslaunch

package = 'rqt_gui'
executable = 'rqt_gui'
node = roslaunch.core.Node(package, executable)

launch = roslaunch.scriptapi.ROSLaunch()

process = launch.launch(node)

In this, they used rqt_gui but not gazebo. I have a feeling that you need to use OS module to run gazebo using python but not sure how.

  • 1
    $\begingroup$ Thanks for the reply! I ended up launching the ROS node using a launch file only, and defined a function in Python which simply sends the command to the terminal to launch this file (providing the path and launch file name as the arguments) - hence being able to initialize the node whenever needed in my script! $\endgroup$
    – rl4haai
    Commented Aug 2, 2022 at 15:34

For resetting the robot to the initial pose - I was able to fix this by using

import rospy
from gazebo_msgs.srv import SetModelConfiguration

set_model = rospy.ServiceProxy("/gazebo/set_model_configuration", SetModelConfiguration)

joint_names = ['waist', 'shoulder', 'elbow', 'wrist_angle', 'left_finger', 'right_finger'] #example
joint_positions = [0.0, 0.0, 0.0, 0.0, 0.0195, -0.0195]


Note, it is important to pause the Gazebo physics before calling set_model and unpause once done.

When launching the robot for the first time in the Gazebo world, I use the gazebo_ros package to spawn the robot using a node of type spawn_model and pass the desired spawn coordinates.

  • $\begingroup$ Please ask a new self contained question instead of trying to get a follow up answer here. $\endgroup$
    – Tully
    Commented Aug 4, 2022 at 18:43
  • 1
    $\begingroup$ Thanks! My doubt got resolved as to why this worked without the need of sending the spawn coordinates when resetting the robot. I realized I am not restarting the simulation (which would require me to spawn the robot again), but only resetting the world and robot pose to the initial pose configuration (which is where the above-mentioned Gazebo Service came handy)! $\endgroup$
    – rl4haai
    Commented Aug 8, 2022 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.