message filiter doesn't call callback() function

asked 2019-12-18 10:58:13 -0500

rosfreshman gravatar image

updated 2019-12-18 13:40:57 -0500

jayess gravatar image

I tried to use both ApproximateTimeSynchronizer or exact time policy. But it never calls the callback. The frequency of Position is about 50hz and that of imu/data is about 100hz. Since the timestamps in these two topics are zero, I adopt allow_headerless=True in ApproximateTime Policy.

def callback(position, imu):

        print("done")

rospy.init_node('pytopics', anonymous=True)

position_sub = message_filters.Subscriber('position', PoseStamped)

Imu_sub = message_filters.Subscriber('imu/data', Imu)

ts = message_filters.ApproximateTimeSynchronizer([position_sub, Imu_sub], 50, 0.1, allow_headerless=True)

ts.registerCallback(callback)

rospy.spin()
edit retag flag offensive close merge delete

Comments

Have you checked that if you set up just normal subscrbers, that they are called? Have you played with the slop parameter to make sure that you're able to get them?

An answer here: https://answers.ros.org/question/8112... as an example working, try modifying that to see if you had an issue, but it looks fine to me assuming the topics are correct and your parameters aren't blocking the message pairs. Did you try with debug logging? That will give you a great deal of information

stevemacenski gravatar image stevemacenski  ( 2019-12-18 15:10:43 -0500 )edit

I can subscribe to these two topics separately. After I add the time stamp, it still doesn't work. I don't change the slop parameter. I'll try it later. I have used print to see which step it runs. It turns out that it stops at rospy.spin() and never enters callback. And I saw results of print after closing the code by pressing ctrl+c.

rosfreshman gravatar image rosfreshman  ( 2019-12-18 17:07:21 -0500 )edit

I tried to change the slop and modify the example you gave. They all fail to work. But when I change the position_sub in message_filters.ApproximateTimeSynchronizer into Imu_sub or change Imu_sub into position_sub, callback function is called, which means it can only call one topic. I'm wondering whether ApproximateTimeSynchronizer doesn't work when the difference of hz is too large. Do you have any idea how to receive a topic,imu/data, with 100hz and publish the message in imu/data with 50hz using another topic? Thanks.

rosfreshman gravatar image rosfreshman  ( 2019-12-20 22:03:24 -0500 )edit