How to subcribe both Image topic and Text topic in the same time ?
Hi buddy, I am newbie in ROS. And this is the first time i'm trying to subcribe 2 topics type, 1 for Image topic and 1 for Array of ints topic. And i have a problem on it. This is my source code:
#!/usr/bin/env python
import sys
import rospy
import cv2
import math
import message_filters
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
from std_msgs.msg import String,Int32,Int32MultiArray,MultiArrayLayout,MultiArrayDimension
class image_converter:
def __init__(self):
self.bridge = CvBridge()
self.image_sub = message_filters.Subscriber("/laptop/camera",Image)
self.array_sub = message_filters.Subscriber("Arduino_Publish", Int32MultiArray)
def callback(image,data):
cv_image = bridge.imgmsg_to_cv2(image, "bgr8")
def draw(img):
cv2.circle(cv_image,(100,100),50,(0,0,255),2)
return img
data_receive = value.data
rospy.logwarn(value.data)
frame = draw(cv_image)
cv2.imshow("Frame", frame)
cv2.waitKey(3)
def main():
img_cvt = image_converter()
rospy.init_node('Sub_2_Topic', anonymous=True)
try:
ts = message_filters.ApproximateTimeSynchronizer([img_cvt.image_sub,img_cvt.array_sub],10,0.1)
ts.registerCallback(img_cvt.callback)
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
if __name__ == '__main__':
main()
And i sent Image message and Text message successfully and receive them individual. Then i try using message filter to receive both of them, and i got error:
[ERROR] [WallTime: 1548902849.013077] bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7fd39b1628d0>>
Traceback (most recent call last):
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 720, in _invoke_callback
cb(msg)
File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 74, in callback
self.signalMessage(msg)
File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 56, in signalMessage
cb(*(msg + args))
File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 221, in add
my_queue[msg.header.stamp] = msg
AttributeError: 'Int32MultiArray' object has no attribute 'header'
So, what should i do to fix this, now ? Thank you !