How to use response of service
Since, i have written my own service which takes float values [x, y, z, a, b, c, d] and respond Pose. When i run the server node, i can see the service and call it. But i create the client, i am unable to use the service values.
I want to call my service from terminal and sending it pose for commanding robot through moveit.
My code for server #
import sys
import copy
import rospy
import geometry_msgs.msg
import tf
from move_to_pose_iit.srv import getPoseArray, getPoseArrayResponse
from geometry_msgs.msg import Pose
def handle_get_pose_array(req):
my_array = Pose()
my_array.position.x = req.x
my_array.position.y = req.y
my_array.position.z = req.z
my_array.orientation.x = req.a
my_array.orientation.y = req.b
my_array.orientation.z = req.c
my_array.orientation.w = req.d
return getPoseArrayResponse(my_array)
def get_pose_array_server():
rospy.init_node('get_pose_array_server')
s =rospy.Service('get_pose_array', getPoseArray, handle_get_pose_array)
rospy.spin()
if __name__ == "__main__":
get_pose_array_server()
For client
import rospy
from move_to_pose_iit.srv import *
from geometry_msgs.msg import Pose
import sys
import copy
import rospy
import moveit_commander
import moveit_msgs.msg
import geometry_msgs.msg
import tf
def get_pose_array_client(pose):
rospy.wait_for_service('get_pose_array')
try:
# bind our local service proxy
svc_set_joint_states = rospy.ServiceProxy('get_pose_array', getPoseArray)
# create the service request
req = getPoseArrayRequest()
# populate the fields of the request
req.x = pose[0]
req.y = pose[1]
req.z = pose[2]
req.a = pose[3]
req.b = pose[4]
req.c = pose[5]
req.d = pose[6]
# invoke the service, passing it the request
resp = scv_set_joint_states(req)
# 'resp' is here of type 'SetJointStatesReponse'
# perhaps do something with the response
except rospy.ServiceException, e:
print "Service call failed: %s"%e
if __name__ == "__main__":
if len(sys.argv) == 6:
pose[0] = float(sys.argv[1])
pose[1] = float(sys.argv[2])
pose[2] = float(sys.argv[3])
pose[3] = float(sys.argv[4])
pose[4] = float(sys.argv[5])
pose[5] = float(sys.argv[6])
pose[6] = float(sys.argv[7])
get_pose_array_client(pose)
robot=moveit_commander.RobotCommander()
scene=moveit_commander.PlanningSceneInterface()
group=moveit_commander.MoveGroupCommander("panda_arm")
display=rospy.Publisher('/move_group/display_planned_path', moveit_msgs.msg.DisplayTrajectory, queue_size=10)
pose_target = Pose()
pose_target.position.x = pose[0]
pose_target.position.y = pose[1]
pose_target.position.z = pose[2]
pose_target.orientation.x = pose[3]
pose_target.orientation.y = pose[4]
pose_target.orientation.z = pose[5]
pose_target.orientation.w = pose[6]
group.set_pose_target(pose_target)
plan1 = group.plan()
group.go(wait=True)
rospy.sleep(20)
moveit_commander.roscpp_shutdown()
Please post the contents of your custom service
getPoseArray