# Revision history [back]

### Python: message_filter AttributeError when registering callback

So I've wrapped my python node in a class, and I've been trying to approximate sync two messages at once (one being Image and another custom message ofMsg that consists of two Float32s) as below:

Class Node:
def __init__(self):
self.image_sub = rospy.Subscriber("/usb_cam/image_raw", Image)
self.opticalflow_sub = rospy.Subscriber("/opticalflow", ofMsg)
ts = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.opticalflow_sub], 10, 0.1, allow_headerless=True)
self.ts.registerCallback(self.callback)

def callback(image, custom_message):
#...

def main(self):
rospy.init_node('node')
while not rospy.is_shutdown():
rospy.spin()
self.rate.sleep()


However, I get: AttributeError: 'Subscriber' object has no attribute 'registerCallback'

I've been looking at other questions regarding message_filters in python with approximate time synchronizes, and they seem to have implemented things similarly (albeit outside of a class) and I can't really see where I might have gone wrong. My package.xml seems to check out as well, catkin_make works just fine.

Any suggestions?

(I'm using Ubuntu 16.04 on kinetic using python2.7)

### Python: message_filter AttributeError when registering callback

So I've wrapped my python node in a class, and I've been trying to approximate sync two messages at once (one being Image and another custom message ofMsg that consists of two Float32s) as below:

Class Node:
def __init__(self):
self.image_sub = rospy.Subscriber("/usb_cam/image_raw", Image)
self.opticalflow_sub = rospy.Subscriber("/opticalflow", ofMsg)
ts self.ts = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.opticalflow_sub], 10, 0.1, allow_headerless=True)
self.ts.registerCallback(self.callback)

def callback(image, custom_message):
#...

def main(self):
rospy.init_node('node')
while not rospy.is_shutdown():
rospy.spin()
self.rate.sleep()


However, I get: AttributeError: 'Subscriber' object has no attribute 'registerCallback'

I've been looking at other questions regarding message_filters in python with approximate time synchronizes, and they seem to have implemented things similarly (albeit outside of a class) and I can't really see where I might have gone wrong. My package.xml seems to check out as well, catkin_make works just fine.

Any suggestions?

(I'm using Ubuntu 16.04 on kinetic using python2.7)

### Python: message_filter AttributeError when registering callback

So I've wrapped my python node in a class, and I've been trying to approximate sync two messages at once (one being Image and another custom message ofMsg that consists of two Float32s) as below:

Class Node:
def __init__(self):
self.image_sub = rospy.Subscriber("/usb_cam/image_raw", Image)
self.opticalflow_sub = rospy.Subscriber("/opticalflow", ofMsg)
self.ts = message_filters.ApproximateTimeSynchronizer([self.image_sub, self.opticalflow_sub], 10, 0.1, allow_headerless=True)
self.ts.registerCallback(self.callback)

def callback(image, callback(self, image, custom_message):
#...

def main(self):
rospy.init_node('node')
while not rospy.is_shutdown():
rospy.spin()
self.rate.sleep()


However, I get: AttributeError: 'Subscriber' object has no attribute 'registerCallback'

I've been looking at other questions regarding message_filters in python with approximate time synchronizes, and they seem to have implemented things similarly (albeit outside of a class) and I can't really see where I might have gone wrong. My package.xml seems to check out as well, catkin_make works just fine.

Any suggestions?

(I'm using Ubuntu 16.04 on kinetic using python2.7)