Ask Your Question

Rosservice only works on shell and not on rospy

asked 2019-11-22 00:42:09 -0500

abcamiletto gravatar image

Hi, It's my first post here so i hope everything's ok.

I have my robot "snake" in gazebo simulation already spawned and if i type in the shell

rosservice call /gazebo/delete_model "model_name: 'snake'"

it actually delete the snake. But if i run a python script with the following code:

delsnake = DeleteModel()
delsnake.model_name = 'snake'
delete = rospy.ServiceProxy('delete_model', DeleteModel)

or even

delete = rospy.ServiceProxy('delete_model', DeleteModel)
delete(model_name = 'snake')

which should be equivalent the terminal tells me:

raise ServiceException("service [%s] unavailable"%self.resolved_name)
rospy.service.ServiceException: service [/delete_model] unavailable

But the service is avaible! I cannot find a solution, the only thing i could do is actually run the command line from the python script but i don't think that's the way thing should go.

Can you help me please?

Thanks in advace!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-22 04:37:31 -0500

Delb gravatar image

updated 2019-11-22 04:38:06 -0500

Your service name is missing the gazebo/ prefix and the first code isn't equivalent to the second one because you need to specify the argument as a string. Here a working code to call the service :

# you can also do this before :
# rospy.wait_for_service("/gazebo/delete_model") to ensure the service is available
delete = rospy.ServiceProxy("/gazebo/delete_model", DeleteModel)
    delete(model_name = "snake")
    # or simply delete("snake")
except rospy.ServiceException as exc:
    print("Service did not process request: " + str(exc))
edit flag offensive delete link more


Mhhh with your code now it tells me:

File "/home/andrea/Desktop/simsnake/src/killnspawn/launch/", line 12, in <module>
delete = rospy.ServiceProxy("/gazebo/delete_model", DeleteModel)
NameError: name 'DeleteModel' is not defined
abcamiletto gravatar image abcamiletto  ( 2019-11-22 10:54:01 -0500 )edit

Have you still the import at the beginning ?

from gazebo_msgs import DeleteModel
Delb gravatar image Delb  ( 2019-11-22 18:24:57 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2019-11-22 00:42:09 -0500

Seen: 239 times

Last updated: Nov 22 '19