How to publish and subscribe to the dictionary?
I am trying to publish and subscribe to a dictionary similar to a list but I can't.
The list is [1.1,2,3,4,5]
My code for slave or talker is:
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float32MultiArray
def talker():
pub = rospy.Publisher('chatter', Float32MultiArray, queue_size=1)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = [1.1,2,3,4,5]
array = Float32MultiArray(data=hello_str)
print 'gggggggggggggggggggggggg', type(array)
rospy.loginfo(array)
pub.publish(array)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
The code for slave or listener is:
#!/usr/bin/env python
import rospy
from std_msgs.msg import Float32MultiArray
def callback(data):
# rospy.loginfo(data.data)
a = list (data.data)
print (a)
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("chatter", Float32MultiArray, callback)
rospy.spin()
if __name__ == '__main__':
listener()
How can do it with the dictionary?
The dictionary is {u'person': [(360, 196, 558, 460), (184, 183, 342, 477)]}