Rosanswers logo

Hello. I want to define a subscriber that subscribes to two different topics and sends the messages on it to just one callback. I have seen that the best to do that is to use message_filters.


  1. Does it mean that unless both messages contains in the topics change their value at the same time they will not be send to the callback?

  2. If callback needs two inputs: callback(input1, input2), how do I know if the proper message is associate to the proper input?

  3. The error that I obtain with the code bellow is the following:

    [ERROR] [WallTime: 1428256539.740225] bad callback: <bound method Subscriber.callback of <message_filters.Subscriber instance at 0xb6e36ecc>> Traceback (most recent call last): File "/home/Clanton/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/rospy/topics.py", line 682, in _invoke_callback cb(msg) File "/home/Clanton/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/message_filters/init.py", line 73, in callback self.signalMessage(msg) File "/home/Clanton/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/message_filters/init.py", line 55, in signalMessage cb(*(msg + args)) File "/home/Clanton/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/message_filters/init.py", line 134, in add my_queue[msg.header.stamp] = msg AttributeError: 'Bool' object has no attribute 'header'

The code:

import rospy #based package to create Publishers and subcriber                                                                                  
from std_msgs.msg import Bool                 
import message_filters
import socket    # used for TCP/IP communication                                                                                                
import struct    # used to change the message format                                                                                            
TCP_IP = '' #Relay board IP Adress                                                                                                 
TCP_PORT = 2101 #Relay board LAN PORT number                                                                                                    
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))

def controlling(gen1, gen2):
   print gen1
   if gen1==True:
       MESSAGE = struct.pack("BBB", 254, 108, 1)

def listener():

   rospu.init_node('listener', anonymus=True)

   gen1_sub=message_filters.Subscriber('gen1topic', Bool)
   gen2_sub=message_filters.Subscriber('gen2topic', Bool)

   ts=message_filters.TimeSynchronizer([gen1_sub, gen2_sub],10,1)


if __name__ == '__main__':

If you could help me figure out if the problem is in the concept and thats why I cant use message_filter for this purpose or if there is something wrong in my code...

Thanks in advance,


Originally posted by mmodetb on ROS Answers with karma: 21 on 2015-04-05

Post score: 0


1 Answer 1


Rosanswers logo

The time synchronizer in the message filters requires that your messages have a header with a timestamp, so that it can synchronize them based on time.

Bool messages don't have a header, so you can't use them with the message filters.

Originally posted by ahendrix with karma: 47576 on 2015-04-10

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.