How do ros service responses work.
hello everyone,
I have the following problem:
When I can call a service"server node" to calculate something(for simplicity float_A/float_B), how can i use the response to do something in my client node(for instance make a dissension in my state_2). The code of the server node and client node is given below. (.srv file float32[] a ------- float32[] sum)
#client node
class State_2(smach.State):
def __init__(self):
smach.State.__init__(self, outcomes=['outcome1','outcome2'])
self.check = False
self.subscriber = rospy.Subscriber("chatter",Array, self.callback)
def callback(self,data):
self.ranges_list = list(data.ranges)
def execute(self, userdata):
rospy.sleep(1.0)
rospy.wait_for_service('check_teammember_behind_turtle')
check_teammember_behind_turtle = rospy.ServiceProxy('check_teammember_behind_turtle', teammember)
check_teammember_behind_turtle(self.ranges_list[0:3])
## THINK I MISS HERE SOMETHING##
## MAYBE YOU CAN HELP ME##
rospy.loginfo('Executing state STATE_2')
if self.check:
return 'outcome1'
else:
return 'outcome2'
## CODE SERVER ##
def handle_teammember(req):
list_teammember = list(req.a)
tx = list_teammember[0]/list_teammember[1]
ty = list_teammember[1]/list_teammember[2]
if (tx>ty):
tx_list = [tx]
print ("tx")
else:
tx_list = [ty]
print ("ty")
return teammemberResponse(tx_list)
def add_two_ints_server():
rospy.init_node('add_two_ints_server')
s = rospy.Service('check_teammember_behind_turtle', teammember, handle_teammember)
print "Ready to add two ints."
rospy.spin()