I have been trying to establish a ROS service to help transfer images between programs to no avail. Regardless of using procedures identical to an older version of this program - that works entirely - all I get here is the same frustratingly vague error message:
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'
What does this error mean?? How do I fix it?? Nothing I have tried works, including changing the service, retrying catkin_make, rewriting the code to make sure there are no extraneous spaces - nothing.
The service request follows:
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()
This service is being handled by the following code (in a separate rospy script):
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()
Any help would be greatly appreciated. Thanks!
Well, I'm an idiot. I found the solution, after trying to figure it out all morning, shortly after posting this.
My function for handling the image request has the same name as the service I was trying to call. So I guess I confused rospy/python. The second I changed the function to "sessionstart2", it worked.
But... I guess it's solved now. ha.