Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import roslib
00026 roslib.load_manifest('std_msgs')
00027 import rospy
00028
00029 import std_msgs.msg
00030
00031 import numpy
00032
00033
00034 class MultiArrayConverter():
00035
00036
00037 def multiArrayToMatrixList(self, ma_msg):
00038 dim = len(ma_msg.layout.dim)
00039 offset = ma_msg.layout.data_offset
00040
00041 if dim != 3:
00042 print "Error: Must be 3 dimensions"
00043
00044 if (ma_msg.layout.dim[0].label != "matrix"):
00045 print "Error: dim[0] should be the matrices"
00046 num_matrices = ma_msg.layout.dim[0].size
00047
00048 if (ma_msg.layout.dim[1].label != "row"):
00049 print "Error: dim[1] should be the rows"
00050 rows = ma_msg.layout.dim[1].size
00051
00052 if (ma_msg.layout.dim[2].label != "column"):
00053 print "Error: dim[2] should be the columns"
00054 columns = ma_msg.layout.dim[2].size
00055
00056
00057
00058
00059 mat = numpy.matrix(numpy.empty([rows,columns]))
00060 mat.fill(numpy.nan)
00061
00062 matrix_list = [mat]*num_matrices
00063
00064 for i in range(0, num_matrices):
00065 for j in range(0, rows):
00066 for k in range(0, columns):
00067 matrix = matrix_list[i]
00068 data_index = ma_msg.layout.data_offset + (rows*columns) * i + (columns) * j + k
00069 matrix[j,k] = ma_msg.data[data_index]
00070
00071 return matrix_list
00072
00073
00074
00075
00076
00077 def matrixListToMultiarray(self, matrix_list):
00078 num_matrices = len(matrix_list)
00079 if num_matrices > 0:
00080 rows, columns = matrix_list[0].shape
00081 else:
00082 rows = 0
00083 columns = 0
00084
00085 msg = std_msgs.msg.Float64MultiArray()
00086
00087
00088 msg.layout.data_offset = 0
00089
00090
00091 matrix_dim = std_msgs.msg.MultiArrayDimension()
00092 matrix_dim.label = "matrix"
00093 matrix_dim.size = num_matrices
00094 matrix_dim.stride = columns * rows * num_matrices
00095
00096 row_dim = std_msgs.msg.MultiArrayDimension()
00097 row_dim.label = "row"
00098 row_dim.size = rows
00099 row_dim.stride = columns * rows
00100
00101 col_dim = std_msgs.msg.MultiArrayDimension()
00102 col_dim.label = "column"
00103 col_dim.size = columns
00104 col_dim.stride = columns
00105
00106 msg.layout.dim = [matrix_dim, row_dim, col_dim]
00107
00108
00109 msg_data = [float('NaN')] * (msg.layout.data_offset + num_matrices * rows * columns)
00110
00111 for i in range(0, num_matrices):
00112 for j in range(0, rows):
00113 for k in range(0, columns):
00114 matrix = matrix_list[i]
00115 data_index = msg.layout.data_offset + (rows*columns) * i + (columns) * j + k
00116 msg_data[data_index] = matrix[j,k]
00117
00118 msg.data = msg_data
00119
00120 return msg
00121
00122
00123
hrl_haptic_mpc
Author(s): Jeff Hawke, Phillip Grice, Marc Killpack, Advait Jain. Advisor and Co-author: Prof. Charlie Kemp.
Healthcare Robotics Lab, Georgia Tech
autogenerated on Wed Nov 27 2013 12:27:09