Bad message_filters.Subscriber callback: 'zip' object is not subscriptable
Hi there,
I am having trouble with the message_filters.ApproximateTimeSynchronizer. I am working on a project where I need to process camera data and BoundingBoxes as seperate topics, but keep getting this weird error when I use the ApproximateTimeSynchronizer. Therefore I tried to set up a really simple code to test the time synchronisation, but it still fails. I don't know what's going on nor can I find useful information on the internet.
This is my code:
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
import rospy
from std_msgs.msg import String, Int8
import message_filters
from message_filters import ApproximateTimeSynchronizer, Subscriber
class Example():
def __init__(self):
self.sub = message_filters.Subscriber('/chatter', Int8)
self.sub2 = message_filters.Subscriber('/chatter2', Int8)
self.ts = message_filters.ApproximateTimeSynchronizer([self.sub, self.sub2], 10, 0.3, allow_headerless=True)
self.ts.registerCallback(self.synchron_fkt)
self.pub = rospy.Publisher('/result_list', String, queue_size=10)
rospy.loginfo("Launched node heading classification")
rospy.spin()
def synchron_fkt(self, chatter, chatter2):
result = f"the numbers are {chatter} and {chatter2}"
rospy.loginfo(result)
if __name__ == '__main__':
rospy.init_node('example', anonymous=True)
hc = Example()
There are only random integers being published on the topics "/chatter" and "/chatter2". I can process the individual topics, when I call a individual callback function like
self.sub.registerCallback(self.callback_fkt)
So the topics are live, I can subscribe to them individually, but not with message_filters.ApproximateTimeSynchronizer. Here is the error I get:
[ERROR] [1643113118.568710]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f2ae3f93f10>>
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
self.signalMessage(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 282, in add
for vv in itertools.product(*[zip(*s)[0] for s in stamps]):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 282, in <listcomp>
for vv in itertools.product(*[zip(*s)[0] for s in stamps]):
TypeError: 'zip' object is not subscriptable
I am using Ubuntu 16.04 LTS and ROS Kinetic with rosversion 1.12.17 . What does this TypeError mean? Is there any other way to process two seperate topics without using this message_filters?
When I use #!/usr/bin/env python2 at the start of the script, it works fine, but I need python3 to use pytorch and other packages in my bigger project. In my bigger project I am also using the python3 path, but I get the same error like above, only with the python3 path. Does anyone have an idea?
Thank you
You can not mix Python 2 and Python 3 like this.
@honeybunny, as @gvdhoorn points out you will have issues mixing Python 2 & 3. Consider upgrading to ROS Noetic to use Python3 specially if you plan to use
pytorch