Ask Your Question
0

Python: message_filter AttributeError when registering callback

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

almond gravatar image

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

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(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)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

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

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
0

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 205 times

Last updated: Oct 18 '18