How to subscribe to multiple topic that has no header or how to add header into topics?
ROS Kinetic Ubuntu 16.04 Python 3.5.2
I am trying to use following script to subscribe to 2 topics and combining their data into a json file.
import rospy
from std_msgs.msg import Float32
import message_filters
import json
def callback(rwheel, lwheel):
# merging rwheel.data and lwheel.data into a json file
def listener():
rospy.init_node('node_name')
rwheel = message_filters.Subscriber("rwheel_angular_vel_motor", Float32)
lwheel = message_filters.Subscriber("lwheel_angular_vel_motor", Float32)
ts = message_filters.TimeSynchronizer([rwheel,lwheel], 10)
ts.registerCallback(callback)
rospy.spin()
if __name__ == '__main__':
listener();
When I run the script, I am gettin the folowing error:
[ERROR] [1573630972.895704, 1242.480000]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7fd23d298278>>
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
self.signalMessage(msg)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/__init__.py", line 216, in add
my_queue[msg.header.stamp] = msg
AttributeError: 'Float32' object has no attribute 'header"
Acually, error seems pretty straight forward. 'Float32' object has no attribute 'header' so we have to add header to Float32 but I couldn't figure out how to do. So, is there a way to subscribe mutiple topics wihout header or how can we add a header?
Are you publishing these messages yourself or you have an existing bag that you are using?
Taking a step back: do you actually need to use
message_filters
here?I am publishing them myself, yet I am relatively new in ROS. So, I am not sure about what to do.
json
file, I thought I should use only one callback function. I searched for a way to subscribe multiple topics and it seems to memessage_filter
is the only way. I will gladly try any other method.