ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Python: message_filter AttributeError when registering callback

asked 2018-10-17 14:49:09 -0600

almond gravatar image

updated 2018-10-17 15:34:18 -0600

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)

    def callback(self, image, custom_message):

    def main(self):
        while not rospy.is_shutdown():

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)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2019-06-10 12:57:33 -0600

bmgatten gravatar image

message filters has its own subscriber method so you should change it so that you are calling message_filters.Subscriber instead of rospy.Subscriber. I made this same mistake.

edit flag offensive delete link more

answered 2018-10-18 01:05:25 -0600

Choco93 gravatar image

Change your subscription to following and it should work.

self.image_sub = message_filters.Subscriber("/usb_cam/image_raw", Image)
self.opticalflow_sub = message_filters.Subscriber("/opticalflow", ofMsg)
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-10-17 14:49:09 -0600

Seen: 2,153 times

Last updated: Oct 18 '18