我是新來的ros + python,我試圖從python ros節點發布一維數組。我用Int32MultiArray,但我不能理解多陣列布局的概念。任何人都可以解釋給我嗎?還是有任何其他方式發佈數組?ROS發佈數組從python節點
謝謝。
#!/usr/bin/env python
import roslib
roslib.load_manifest('test_drone')
import numpy
import rospy
import sys
import serial
from std_msgs.msg import String,Int32,Int32MultiArray,MultiArrayLayout,MultiArrayDimension
from rospy.numpy_msg import numpy_msg
from rospy_tutorials.msg import Floats
#port = "dev/ttyS0"
#baud = 115200
#ser = serial.Serial()
#ser.port = port
#ser.baudrate = baud
################################################################################################
def main(args):
pub=rospy.Publisher('sonar_vals',Int32MultiArray,queue_size = 10)
rospy.init_node('ca_serial')
r = rospy.Rate(0.2)
while not rospy.is_shutdown():
print "LOOP running"
a = [3250,2682,6832,2296,8865,7796,6955,8236]
pub.publish(a)
r.sleep();
# try:
#data_raw = ser.readline()
# except e:
# print e
#sd = data_raw.split(',')
#a = numpy.array([sd[0],sd[1],sd[2],sd[3],sd[4],sd[5],sd[6],sd[7],sd[8],sd[9]],dtype=numpy.float32)
#if sd[0] == 777:
# pub.publish(a)
# else:
# print 'Invalid Data'
if __name__ == '__main__':
import sys, getopt
main(sys.argv)
感謝luator你的答案的工作! –