Pass an object to Service handler callback() function
Hello
is there a way to pass objects to a callback()? I just found this post: https://answers.ros.org/question/2314...
but if I pass the object like mentioned in the post I get this error message:
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 737, in receive_once
self.stat_bytes += recv_buff(sock, b, p.buff_size)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 104, in recv_buff
d = sock.recv(buff_size)
TypeError: 'AiService' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_service.py", line 667, in handle
requests = transport.receive_once()
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 758, in receive_once
raise TransportException("receive_once[%s]: unexpected error %s"%(self.name, str(e)))
rospy.exceptions.TransportException: receive_once[/image_ack]: unexpected error 'AiService' object cannot be interpreted as an integer
My code (shortened):
def callback(request, arg):
response = ImageAckResponse()
ai_machine = arg[0]
...
return response
def main():
rospy.init_node('ai_service')
ai_machine = AiMachine()
...
rospy.Service('image_ack', ImageAck, callback, (ai_machine))
rospy.spin()
Is
service
already atuple
? If not, you must enclose it in()
. Otherwise you cannot unpack it in your callback.Changed the object name to
ai_machine
for better understanding and enclosed the object but still getting the same error