Go to the documentation of this file.00001 __author__ = 'tom1231'
00002 import struct
00003 from BAL.Header.RiCHeader import RiCHeader
00004 from geometry_msgs.msg import Vector3, Quaternion
00005
00006 V_X_LEN = 10
00007 V_Y_LEN = 14
00008 V_Z_LEN = 18
00009
00010 A_X_LEN = 22
00011 A_Y_LEN = 26
00012 A_Z_LEN = 30
00013
00014 M_X_LEN = 34
00015 M_Y_LEN = 38
00016 M_Z_LEN = 42
00017
00018 O_X_LEN = 46
00019 O_Y_LEN = 50
00020 O_Z_LEN = 54
00021 O_W_LEN = 58
00022
00023
00024
00025
00026
00027
00028
00029 class IMUPublishResponse(RiCHeader):
00030 def __init__(self):
00031 RiCHeader.__init__(self)
00032 self._velocityX = 0.0
00033 self._velocityY = 0.0
00034 self._velocityZ = 0.0
00035
00036 self._accelerationX = 0.0
00037 self._accelerationY = 0.0
00038 self._accelerationZ = 0.0
00039
00040 self._magnetometerX = 0.0
00041 self._magnetometerY = 0.0
00042 self._magnetometerZ = 0.0
00043
00044 self._orientationX = 0.0
00045 self._orientationY = 0.0
00046 self._orientationZ = 0.0
00047 self._orientationW = 0.0
00048
00049 self._roll = 0.0
00050 self._pitch = 0.0
00051 self._yaw = 0.0
00052 self._temperature = 0.0
00053
00054 def getImuMsgId(self):
00055 return 2
00056
00057 def getVelocity(self):
00058 vec = Vector3()
00059 vec.y = -1 * (self._velocityX * 0.0174532925)
00060 vec.x = -1 * (self._velocityY * 0.0174532925)
00061 vec.z = -1 * (self._velocityZ * 0.0174532925)
00062 return vec
00063
00064 def getAcceleration(self):
00065 acc = Vector3()
00066 acc.y = self._accelerationX * 9.80665
00067 acc.x = self._accelerationY * 9.80665
00068 acc.z = self._accelerationZ * 9.80665
00069 return acc
00070
00071 def getMagnetometer(self):
00072 mag = Vector3()
00073 mag.x = self._magnetometerX * 1.0e-7
00074 mag.y = self._magnetometerY * 1.0e-7
00075 mag.z = self._magnetometerZ * 1.0e-7
00076 return mag
00077
00078 def getOrientation(self):
00079 ort = Quaternion()
00080 ort.x = self._orientationX
00081 ort.y = self._orientationY
00082 ort.z = self._orientationZ
00083 ort.w = self._orientationW
00084 return ort
00085
00086 def getRoll(self):
00087 return self._roll
00088
00089 def getPitch(self):
00090 return self._pitch
00091
00092 def getYaw(self):
00093 return self._yaw
00094
00095 def getTemperature(self):
00096 return self._temperature
00097
00098 def buildRequest(self, data):
00099 RiCHeader.buildRequest(self, data)
00100 bytes = bytearray()
00101 while self.index < V_X_LEN:
00102 bytes.append(data[self.index])
00103 self.index += 1
00104 self._velocityX = struct.unpack('<f', bytes)[0]
00105 bytes = bytearray()
00106 while self.index < V_Y_LEN:
00107 bytes.append(data[self.index])
00108 self.index += 1
00109 self._velocityY = struct.unpack('<f', bytes)[0]
00110 bytes = bytearray()
00111 while self.index < V_Z_LEN:
00112 bytes.append(data[self.index])
00113 self.index += 1
00114 self._velocityZ = struct.unpack('<f', bytes)[0]
00115 bytes = bytearray()
00116 while self.index < A_X_LEN:
00117 bytes.append(data[self.index])
00118 self.index += 1
00119 self._accelerationX = struct.unpack('<f', bytes)[0]
00120 bytes = bytearray()
00121 while self.index < A_Y_LEN:
00122 bytes.append(data[self.index])
00123 self.index += 1
00124 self._accelerationY = struct.unpack('<f', bytes)[0]
00125 bytes = bytearray()
00126 while self.index < A_Z_LEN:
00127 bytes.append(data[self.index])
00128 self.index += 1
00129 self._accelerationZ = struct.unpack('<f', bytes)[0]
00130 bytes = bytearray()
00131 while self.index < M_X_LEN:
00132 bytes.append(data[self.index])
00133 self.index += 1
00134 self._magnetometerX = struct.unpack('<f', bytes)[0]
00135 bytes = bytearray()
00136 while self.index < M_Y_LEN:
00137 bytes.append(data[self.index])
00138 self.index += 1
00139 self._magnetometerY = struct.unpack('<f', bytes)[0]
00140 bytes = bytearray()
00141 while self.index < M_Z_LEN:
00142 bytes.append(data[self.index])
00143 self.index += 1
00144 self._magnetometerZ = struct.unpack('<f', bytes)[0]
00145 bytes = bytearray()
00146 while self.index < O_X_LEN:
00147 bytes.append(data[self.index])
00148 self.index += 1
00149 self._orientationX = struct.unpack('<f', bytes)[0]
00150 bytes = bytearray()
00151 while self.index < O_Y_LEN:
00152 bytes.append(data[self.index])
00153 self.index += 1
00154 self._orientationY = struct.unpack('<f', bytes)[0]
00155 bytes = bytearray()
00156 while self.index < O_Z_LEN:
00157 bytes.append(data[self.index])
00158 self.index += 1
00159 self._orientationZ = struct.unpack('<f', bytes)[0]
00160 bytes = bytearray()
00161 while self.index < O_W_LEN:
00162 bytes.append(data[self.index])
00163 self.index += 1
00164 self._orientationW = struct.unpack('<f', bytes)[0]
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184