Rospy has no attribute ServiceProxy

asked 2021-11-15 17:35:00 -0600

jdastoor3 gravatar image

updated 2022-03-03 09:39:25 -0600

lucasw gravatar image

I have been trying to create a script that will delete and spawn objects in gazebo. When I try to run rospy.ServiceProxy, it keeps telling me that module rospy has no attribute 'ServiceProxy' although I have seen in various tutorials online that it does. This is my entire script:

import rospy, tf
from gazebo_msgs.srv import DeleteModel, SpawnModel
from geometry_msgs.msg import *

if __name__ == '__main__':
    print("Waiting for gazebo services...")
    rospy.init_node("spawn_products_in_bins")
    rospy.wait_for_service("gazebo/delete_model")
    rospy.wait_for_service("gazebo/spawn_sdf_model")
    print("Got it.")
    delete_model = rospy.ServicePoxy("gazebo/delete_model", DeleteModel)
    spawn_model = rospy.ServiceProxy("gazebo/spawn_sdf_model", SpawnModel)

    with open("$GAZEBO_MODEL_PATH/crocodile_buoy/model.sdf", "r") as f:
        product_xml = f.read()

    orient = Quaternion(tf.transformations.quaternion_from_euler(0,0,0))

    for num in xrange(0,12):
        item_name = "croc_{0}".format(num)
        print("Deleting model:%s", item_name)
        delete_model(item_name)

    for num in xrange(0,12):
        bin_y   =   2.8 *   (num    /   6)  -   1.4
        bin_x   =   0.5 *   (num    %   6)  -   1.5
        item_name   =   "croc_{0}".format(num)
        print("Spawning model:%s", item_name)
        item_pose   =   Pose(Point(x=bin_x, y=bin_y,    z=2),   orient)
        spawn_model(item_name, product_xml, "", item_pose, "world")`

The output I get is:

Waiting for gazebo services...
Got it.
Traceback (most recent call last):
  File "/home/jehan/PycharmProjects/spawner/main.py", line 11, in <module>
    delete_model = rospy.ServicePoxy("gazebo/delete_model", DeleteModel)
AttributeError: module 'rospy' has no attribute 'ServicePoxy'

Any help would be greatly appreciated as I am relatively new to ROS and gazebo! I am using ROS noetic on Ubuntu 20.04.

edit retag flag offensive close merge delete

Comments

Hi @jdastoor3 this is a syntax error. It should be ServiceProxy vs ServicePoxy

osilva gravatar image osilva  ( 2021-11-16 10:01:05 -0600 )edit