Ask Your Question
0

What is the correct way to spawn a model to Gazebo using a Python script?

asked 2019-11-07 05:00:02 -0600

vitsensei gravatar image

Hi, I'm kinda fuzzy on this part. Here's my attempt:

rospy.wait_for_service("/gazebo/spawn_urdf_model")

try:
    spawner = rospy.ServiceProxy("/gazebo/spawn_urdf_model", SpawnModel)
    spawner(rover_name, str(open("/home/anh/catkin_ws/src/rover_project/rover_description/urdf/rover.urdf",'r')), "/rover", Pose(position= Point(0,0,2),orientation=Quaternion(0,0,0,0)),"world")

except rospy.ServiceException as e:
    print("Service call failed: ",e)

However, it leads to this result:

('Service call failed: ', ServiceException('service [/gazebo/spawn_urdf_model] responded with an error: ',))

Now, I'm pretty sure I didn't pass the urdf file the correct way. So if you guys can give me a full example on how to do it in Python, that would be awesome!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-11-07 17:18:56 -0600

vitsensei gravatar image

Alright guys, I figured it out.

spawner(rover_name, str(open("/home/anh/catkin_ws/src/rover_project/rover_description/urdf/rover.urdf",'r')), "/rover", Pose(position= Point(0,0,2),orientation=Quaternion(0,0,0,0)),"world")

should be

spawner(rover_name, open("/home/anh/catkin_ws/src/rover_project/rover_description/urdf/rover.urdf",'r').read(), "/rover", Pose(position= Point(0,0,2),orientation=Quaternion(0,0,0,0)),"world")

instead!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-11-07 05:00:02 -0600

Seen: 12 times

Last updated: Nov 07