publish list of lists with Python
Hello,
I am currently trying for my thesis Project to create topics with ROS where I publish and subscribe a list of lists with python. I have created two messages:
int_list_1d.msg : int32[] data and another message
int_list_2d.msg : int_list_1d[] data. I use the message for the list of lists (int_list_2d) but, despite the fact that the catkin_make is completed without errors when I execute the roslaunch file for the two nodes I receive the following answer:
AttributeError: 'list' object has no attribute 'data'.
Can you please help me? I am stuck.
Thank you
The code comprises of two files:
pub.py
import rospy
from iot_humans_track.msg import int_array2d
if __name__ == "__main__":
rospy.init_node('pub', anonymous=True)
msg_list = int_array2d()
msg_list.data = [[1,2,3], [1,2]]
puber = rospy.Publisher('topic', int_array2d, queue_size=10)
while not rospy.is_shutdown():
puber.publish(msg_list)
and the sub.py
import rospy
from iot_humans_track.msg import int_array2d
def callback(msg):
print msg.data
if __name__ == "__main__":
rospy.init_node('sub', anonymous=True)
sub_node = rospy.Subscriber('topic', int_array2d, callback, queue_size=10)
rospy.spin()
Can you share your code please ? The
CMakeList.txt
might help too.Currently ROS can not publish a 2D array. One solution could be that you convert your list to 1D array before publishing and then convert it back upon reception. What is your usage? How are you publishing and receiving the message. Share the code snippet.
I have followed the instructions from ROS Wiki. The catkin_make is completed without problems.