How to use service set_pose

Hello,
Im currently running the zed_node by the command: roslaunch zed_wrapper zed2.launch

There i see the service zed_interfaces/set_pose and I believe I can set the zed camera pose. This is my code so far looking from ROS wiki examples on using srv.

from zed_interfaces.srv import set_pose
def set_zedPose(x, y, z, R, P, Y):
rospy.wait_for_service(“zed_interfaces/set_pose”)
try:
set_pose = rospy.ServiceProxy(“zed_interfaces/set_pose”, zed_interfaces.srv.set_pose)
resp = set_pose(x, y, z, R, P, Y)
return resp
except rospy.ServiceException as e:
print(“unable to set pose”)

apologize if I do stupid mistake. Im still new to ROS and services. If someone has an example code for it, it would be very much appreciated.
Thank you.

Best,
Krisna

Hi Krisna,
please format your Python code, otherwise it is not possible to read it.

image

Oh sorry, I did not know that…

from zed_interfaces.srv import set_pose

def set_zedPose(x, y, z, R, P, Y):
    rospy.wait_for_service(“zed_interfaces/set_pose”)
    try:
        set_pose = rospy.ServiceProxy(“zed_interfaces/set_pose”, zed_interfaces.srv.set_pose)
        resp = set_pose(x, y, z, R, P, Y)
        return resp
    except rospy.ServiceException as e:
        print(“unable to set pose”)

What kind of error are you getting from your code?
Do you see errors in the ZED node log?

Actually no error, but it stuck in rospy.wait_for_service(). Even though when I look on the list of services using rossrv list, there exist the service zed_interfaces/set_pose.

If I commented the line rospy.wait_for_service(), the line

set_pose = rospy.ServiceProxy("zed_interfaces/set_pose", zed_interfaces.srv.set_pose)

It gives an error saying that NameError: name ‘zed_interfaces’ is not defined

You must use the name of the service, not the type, e.g. /zed2i/zed_node/set_pose

Hi again. yes sorry for the stupid mistake. I thought “rossrv list” would give all the available ros services, but it just gives you the type. for anyone that is still newbie for me, use “rosservice list” instead.

I also attached my code if anyone is interested.

Set_Pose = set_pose()
def set_zedPose(x, y, z, R, P, Y):
    print("waiting for set pose service")
    rospy.wait_for_service("/zed2/zed_node/set_pose")
    print("found the set_pose service!")
    try:
        setpose = rospy.ServiceProxy("/zed2/zed_node/set_pose", Set_Pose)
        resp = setpose(x, y, z, R, P, Y)
        print("response of the service is: ", resp)
        return resp
    except rospy.ServiceException as e:
        print("service not working yet")

if everything goes well, the service would return:

response of the service is:  done: True

thank you @Myzhar for your help!

1 Like