0

我一直在尝试建立一个ROS服务来帮助程序之间传输图像,但无济于事。无论使用与该程序的旧版本相同的程序 - 完全有效 - 我在这里得到的只是同样令人沮丧的模糊错误消息:

Traceback (most recent call last):
File "/catkin_ws/src/package/scripts/rc.py", line 110, in <module>
main_function()
File "/catkin_ws/src/package/scripts/rc.py",    line 105, in main_function
incoming = sessionstart(f, t, x1i, y1i, x2i, y2i)
File "/catkin_ws/src/package/scripts/rc.py", line 40, in sessionstart
requestimage = rospy.ServiceProxy('StartSession', sessionstart)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 404, in __init__
super(ServiceProxy, self).__init__(name, service_class)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/service.py", line 59, in __init__
self.request_class = service_class._request_class
AttributeError: 'function' object has no attribute '_request_class'

这个错误是什么意思??我如何解决它??我没有尝试过任何工作,包括更改服务、重试 catkin_make、重写代码以确保没有多余的空格 - 没有。

服务请求如下:

global sid, f, x1i, y1i, x2i, y2i
rospy.init_node('name', log_level = rospy.INFO, anonymous = True)
bridge = CvBridge()
refPt = []
sid = 0; t = 0; x1i = 0; y1i = 0; x2i = 0; y2i = 0

def sessionstart(t, x1i, y1i, x2i, y2i):
    rospy.wait_for_service('StartSession')
    print '------------------------ service found'
    try:
        requestimage = rospy.ServiceProxy('StartSession', sessionstart)
        print "------------------------ service proxy set"
        response = requestimage(t, x1i, y1i, x2i, y2i)
        print "------------------------ service accessed"
        return response
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

def imagecallback(data):
    global sid, f, x1i, y1i, x2i, y2i
    b, t, sid = data.split()
    print '------------------------ imagecallback started'
    t = float(t); sid = int(sid)
    timestr = time.strftime("%H:%M:%S", time.getgmtime(t))
    print "Loaded image from %s."%timestr
    imagedata = bridge.imgmsg_to_cv2(b, "bgr8")
    npimg = cv2.imencode('.jpg', imagedata)
    cv2.imwrite('tempimage.jpg', imagedata)
    img = cv2.imread('tempimage.jpg')
    clone = img.copy()
    cv2.namedWindow('image', cv2.WINDOW_NORMAL)
    cv2.imshow("image", img)
    cv2.waitKey(1)

def main_function():
    global sid, f, x1i, y1i, x2i, y2i
    f = 0
    t = time.time()
    print '------------------------ time set, frame set'
    sid = 0; x1i = 0; y1i = 0; x2i = 0; y2i = 0
    print "sid %s, x1i %s, y1i %s, x2i %s, y2i %s"%(sid, x1i, y1i, x2i, y2i)
    print '------------------------ everything else set'
    incoming = sessionstart(t, x1i, y1i, x2i, y2i)
    print "------------------------ service assigned"
    imagecallback(incoming)
    print "------------------------ service called"

if __name__ == '__main__':
    main_function() 

此服务由以下代码处理(在单独的 rospy 脚本中):

def handle_sessionstart(req):
    global assignsid
    sid = assignsid
    print "Assigning SID %s to this client."%sid
    assignsid = assignsid + 1 
    t = req.t
    x1i = req.x1i
    y1i = req.y1i
    x2i = req.x2i
    y2i = req.y2i
    requestinfo = "%s %s %s %s %s %s"%(sid, t, x1i, y1i, x2i, y2i)
    print "Requesting: " + requestinfo
    client.publish('/imagerequest', requestinfo, 0)
    rosimg = imgq.get()
    imgq.join() 
    return sessionstartResponse(sid, rosimg, t, error)

def handle_sessionend(req):
    sid = req.sid
    requestinfo = "%s"%(sid)
    client.publish('/endsession', requestinfo, 0)
    closed = endq.get()
    return sessionendResponse(closed)

def handle_imgreq(req):
    # global x1v, y1v, x2v, y2v
    sid = req.sid; df = req.f; t = req.t # session id, frame increment, abs time
    xli = req.xli; y1i = req.yli; x2i = req.x2i; y2i = req.y2i
    requestinfo = "%s %s %s %s %s %s %s"%(sid, f, t, x1i, y1i, x2i, y2i)
    client.publish('/imagerequest', requestinfo, 0)
    rosimg = imgq.get()
    return imgreqResponse(rosimg, t, error)

def RDtoLDDServiceHandler():
    s = rospy.Service('StartSession', sessionstart, handle_sessionstart)
    print "Services ready..."
    rospy.spin()

if __name__ == '__main__':
    imgq = Queue.Queue(maxsize=1)
    endq = Queue.Queue(maxsize = 1)
    imgpub = rospy.Publisher('/ros_image', Image, queue_size = 10) 
    datapub = rospy.Publisher('/ros_data', String, queue_size = 10) 
    client = mqtt.Client()
    rospy.init_node('RD')
    client.connect('192.168.1.7', 1883, 60)
    RDtoLDDServiceHandler() 

任何帮助将不胜感激。谢谢!

4

1 回答 1

2

好吧,我是个白痴。在发布此消息后不久,我在整个早上试图弄清楚之后找到了解决方案。

我处理图像请求的函数与我试图调用的服务同名。所以我想我混淆了rospy/python。第二次我将功能更改为“sessionstart2”,它起作用了。

但是......我想它现在已经解决了。哈。

于 2015-12-15T17:59:15.173 回答