I want to send multiple requst and multiple response,but something wrong,how to debug it?[solved]
this is client
#! /usr/bin/env python
import roslib; roslib.load_manifest('beginner_tutorials')
from beginner_tutorials.srv import *
import rospy
import sys
from beginner_tutorials.srv import xin2
import beginner_tutorials.msg
def callserver2(aa,bb):
rospy.wait_for_service('girl')
try:
pse = rospy.ServiceProxy('girl',xin2)
reqMsg = beginner_tutorials.msg.xin2(aa,bb)
resp2 = pse(reqMsg)
return resp2
except rospy.ServiceException ,e:
print "failed to send "
if __name__=='__main__':
aa = "PSD has closed"
bb = "routine is ok"
res = callserver2(aa,bb)
print res
print res.out.cc
print res.out.dd
print "train number is :%s" %res.out.ee
this is server
#! /usr/bin/env python
import roslib;roslib.load_manifest('beginner_tutorials')
import sys
import rospy
from beginner_tutorials.srv import *
import beginner_tutorials.msg
def processReq2(req):
print "req :train\'speed is %s km/h, train\'local is %s"%(req.in_.aa,req.in_.bb)
print req
try:
respMsg = beginner_tutorials.msg.xin2_2(cc,dd,ee)
return xin2Response(respMsg)
except :
print "ATO failed to send back "
def Server(cc,dd,ee):
rospy.init_node('ATO')
s= rospy.Service('girl',xin2, processReq2)
print "readying "
rospy.spin()
if __name__=='__main__':
cc = "train door : closed"
dd = "operation model : AM"
ee = 801
Server(cc,dd,ee)
xin2.srv
beginner_tutorials/xin2 in
---
beginner_tutorials/xin2_2 out
xin2.msg ## :
string aa
string bb
xin2_2.msg
string cc
string dd
int16 ee
Asked by malong on 2012-06-01 17:00:35 UTC
Answers
From @malong's comment:
ok,i have solved this peoblem.thank you! in this file, msg is called in the srv; called xin2.msg in the req of xin2.srv, and called xin2_2.msg in the resp of xin2.srv.thus,i can realise two values in the req and two values in the resp.
Asked by tfoote on 2012-06-05 20:46:15 UTC
Comments
i have no idea about the typesetting,i just copy the code from my file
Asked by malong on 2012-06-01 17:10:06 UTC
You say something went wrong. What did you expect? What happened instead?
Asked by joq on 2012-06-01 18:05:26 UTC
1st: I copy the code from my file,why it is shambles? what is karma? 2nd : I have 2 requsts and 2 response ,how to realise it ? 3rd: i have run files in the terminal, but there are something wrong.all the code , msg and srv are above.
Asked by malong on 2012-06-01 19:19:41 UTC
For literal code to display correctly, this forum requires you to add four spaces in front of each line. I fixed it for you once already. I am not going to do that again.
Asked by joq on 2012-06-02 05:11:47 UTC
You still have not told us what you expect this code to do.
Asked by joq on 2012-06-02 05:12:16 UTC
ok,i have solved this peoblem.thank you! in this file, msg is called in the srv; called xin2.msg in the req of xin2.srv, and called xin2_2.msg in the resp of xin2.srv.thus,i can realise two values in the req and two values in the resp.
Asked by malong on 2012-06-03 15:51:08 UTC