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.
Doubts:
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?
If callback needs two inputs: callback(input1, input2), how do I know if the proper message is associate to the proper input?
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 = '192.168.1.105' #Relay board IP Adress
TCP_PORT = 2101 #Relay board LAN PORT number
BUFFER_SIZE = 1024
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)
s.send(MESSAGE)
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)
ts.registerCallback(controlling)
rospy.spin()
if __name__ == '__main__':
listener()
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,
Mercedes.
Originally posted by mmodetb on ROS Answers with karma: 21 on 2015-04-05
Post score: 0