Service server and client in python following tutorial does not work
I'm trying to make a service that I could call to change a pose of a robotic arm using MoveIt!. I follow this tutorial, but I get an error:
Traceback (most recent call last):
File "/home/linux/catkin_ws/src/robotic_arm_algorithms/scripts/set_joint_states_client.py", line 24, in <module>
set_joint_states(joint_states)
File "/home/linux/catkin_ws/src/robotic_arm_algorithms/scripts/set_joint_states_client.py", line 17, in set_joint_states
resp = set_joint_states(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 435, in __call__
return self.call(*args, **kwds)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 495, in call
service_uri = self._get_service_uri(request)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 444, in _get_service_uri
raise TypeError("request object is not a valid request message instance")
TypeError: request object is not a valid request message instance
This seems as a problem purely in the client code, so I show the client code and the service definition bellow. I have defined the servise as 4 float numbers each with a specific name. So when I pass the client four numbers (via terminal arguments), I expect to be able to simply assign those values to the service message as shown below. But something is not right. Can you point out the mistake for me?
srv/SetJointStates.srv:
std_msgs/Float32 forearm_0
std_msgs/Float32 forearm_1
std_msgs/Float32 arm_0
std_msgs/Float32 arm_1
---
script/set_joint_states_client.py:
#!/usr/bin/env python
import sys
import rospy
from robotic_arm_algorithms.srv import SetJointStates
def set_joint_states(joint_states):
rospy.wait_for_service('set_joint_states')
try:
set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates)
msg = SetJointStates()
msg.forearm_0 = joint_states[0]
msg.forearm_1 = joint_states[1]
msg.arm_0 = joint_states[2]
msg.arm_1 = joint_states[3]
resp = set_joint_states(msg)
except rospy.ServiceException, e:
print "Service call failed: %s"%e
if __name__ == "__main__":
if len(sys.argv) == 5:
joint_states = [float(sys.argv[1]), float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4])]
set_joint_states(joint_states)
else:
print("not enaugh arguments. Four arguments required: forearm 0, forearm 1, arm 0, arm 1")
sys.exit(1)
EDIT 1
When I put print (dir(SetJointStates))
into set_joint_states
method of the client source code, following strings prints on terminal:
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_md5sum', '_request_class', '_response_class', '_type']