This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IWR1642BOOST: False values while reading object data over UART

Part Number: IWR1642BOOST
Other Parts Discussed in Thread: IWR1642

Hi all

I have written a python script to read the data stream over USB, convert the object data into (x,y) coordinates and to display it on the console, using the IWR1642 EVM. I tested it in an empty room and got some bizarre results (Ex. range of 355m, etc). I have attached my python script and sample output. Please tell me where I went wrong.

output.txt
Read Data:
 [2, 1, 4, 3, 6, 5, 8, 7, 5, 0, 0, 1, 192, 2, 0, 0, 66, 22, 10, 0, 215, 151, 0, 0, 190, 102, 4, 161, 8, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 100, 0, 0, 0, 8, 0, 7, 0, 1, 0, 0, 0, 37, 0, 228, 255, 13, 0, 0, 0, 27, 0, 0, 0, 15, 0, 185, 0, 57, 3, 0, 0, 51, 0, 0, 0, 21, 0, 187, 2, 156, 5, 0, 0, 59, 0, 0, 0, 24, 0, 181, 2, 177, 6, 0, 0, 95, 0, 0, 0, 2, 0, 162, 3, 10, 11, 0, 0, 255, 0, 0, 0, 15, 0, 186, 227, 48, 13, 0, 0, 27, 0, 0, 0, 11, 0, 246, 1, 168, 2, 0, 0, 51, 0, 0, 0, 15, 0, 100, 0, 58, 6, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 216, 123, 160, 122, 62, 108, 58, 80, 98, 89, 101, 94, 250, 101, 104, 100, 196, 93, 73, 100, 88, 102, 244, 101, 182, 102, 99, 100, 49, 96, 111, 92, 126, 95, 56, 90, 164, 90, 170, 91, 80, 93, 242, 88, 36, 96, 235, 100, 11, 107, 59, 109, 107, 108, 62, 113, 37, 113, 13, 107, 24, 94, 80, 91, 73, 97, 205, 94, 175, 86, 166, 84, 87, 81, 59, 82, 191, 80, 115, 85, 65, 84, 70, 80, 70, 80, 57, 82, 246, 83, 116, 75, 185, 66, 104, 73, 44, 76, 150, 95, 246, 112, 42, 117, 224, 108, 143, 84, 159, 76, 164, 71, 134, 74, 251, 86, 29, 108, 81, 117, 1, 115, 85, 100, 165, 93, 150, 92, 220, 83, 0, 78, 52, 74, 229, 74, 163, 77, 32, 80, 126, 77, 123, 69, 181, 74, 154, 72, 43, 69, 87, 68, 28, 71, 113, 72, 3, 71, 250, 73, 9, 70, 15, 69, 144, 67, 191, 70, 7, 75, 51, 74, 112, 70, 148, 71, 232, 69, 218, 74, 227, 72, 234, 67, 99, 73, 232, 73, 73, 87, 109, 91, 143, 86, 246, 76, 117, 73, 72, 69, 166, 71, 175, 69, 159, 66, 126, 67, 176, 67, 176, 68, 22, 70, 219, 66, 186, 66, 90, 65, 163, 64, 23, 64, 131, 70, 146, 66, 219, 66, 119, 70, 83, 70, 39, 72, 150, 70, 244, 70, 66, 67, 39, 66, 182, 67, 202, 62, 22, 70, 183, 65, 52, 66, 115, 69, 250, 67, 45, 67, 32, 69, 194, 71, 141, 69, 11, 65, 133, 64, 218, 65, 141, 59, 232, 66, 147, 69, 180, 69, 78, 63, 35, 68, 194, 65, 205, 60, 250, 65, 248, 67, 99, 66, 53, 71, 210, 70, 106, 63, 190, 64, 223, 67, 182, 67, 246, 65, 111, 68, 23, 70, 147, 66, 181, 64, 48, 65, 146, 66, 42, 65, 109, 68, 39, 68, 225, 64, 70, 63, 226, 63, 105, 65, 84, 59, 139, 69, 78, 66, 161, 68, 236, 64, 201, 61, 112, 67, 246, 67, 251, 65, 239, 64, 119, 67, 164, 67, 20, 67, 62, 66, 93, 63, 163, 67, 125, 69] 

Detected Object data: 
 [1, 0, 0, 0, 37, 0, 228, 255, 13, 0, 0, 0, 27, 0, 0, 0, 15, 0, 185, 0, 57, 3, 0, 0, 51, 0, 0, 0, 21, 0, 187, 2, 156, 5, 0, 0, 59, 0, 0, 0, 24, 0, 181, 2, 177, 6, 0, 0, 95, 0, 0, 0, 2, 0, 162, 3, 10, 11, 0, 0, 255, 0, 0, 0, 15, 0, 186, 227, 48, 13, 0, 0, 27, 0, 0, 0, 11, 0, 246, 1, 168, 2, 0, 0, 51, 0, 0, 0, 15, 0, 100, 0, 58, 6, 0, 0] 

Range 		 Velocity		 X_coor 		 Y_coor

[[  7.81250000e+00   0.00000000e+00  -1.08527132e-01   5.03875969e-02]
 [  2.10937500e+02   0.00000000e+00   7.17054264e-01   3.19767442e+00]
 [  3.98437500e+02   0.00000000e+00   2.70930233e+00   5.56589147e+00]
 [  4.60937500e+02   0.00000000e+00   2.68604651e+00   6.63953488e+00]
 [  7.42187500e+02   0.00000000e+00   3.60465116e+00   1.09534884e+01]
 [  1.99218750e+03   0.00000000e+00  -2.80542636e+01   1.30852713e+01]
 [  2.10937500e+02   0.00000000e+00   1.94573643e+00   2.63565891e+00]
 [  3.98437500e+02   0.00000000e+00   3.87596899e-01   6.17829457e+00]] 

import serial
import sys
import string
import struct
import time
import numpy as np
import math
from decimal import *
# # # # # # # # # # # # # # # # # # # # # #
# GLOBAL VARIABLES
OBJ_STRUCT_SIZE_BYTES = 12;
magicWord = [2,1,4,3,6,5,8,7]
word = [1,256,65536,16777216]
#word = [1, 16, 256, 65536]
word1 = [1,256]
# # # # # # # # # # # # # # # # # # # # # #
#####CONFIGURATION PARAMETERS FROM GUI DEMO #########
txChannelEn 		= 3 #channelCfg #2
numTxAnt 			= 2
digOutSampleRate 	= 5209 # profileCfg #11
freqSlopeConst 		= 70 #profileCfg #8
numAdcSamples 		= 256 #profileCfg #10
numRangeBins 		= 8	#pow2roundup(numAdcSamples) 
startFreq 			= 77 #profileCfg #2
idleTime 			= 429 #profileCfg #3
rampEndTime 		= 57.14 #profileCfg #5
chirpEndIdx 		= 1 #frameCfg #2
chirpStartIdx 		= 0 #frameCfg #1
numLoops 			= 16 #frameCfg #3
numChirpsPerFrame 	= (chirpEndIdx -chirpStartIdx + 1) *numLoops
numDopplerBins 		=  numChirpsPerFrame/numTxAnt
########################################################

rangeIdxToMeters =  3e8 * digOutSampleRate * 1e3 /(2 * freqSlopeConst * 1e12 * numRangeBins)
dopplerResolutionMps = 3e8 / (2*startFreq*1e9 *(idleTime + rampEndTime) * 1e-6 * numDopplerBins * numTxAnt)

ser = serial.Serial(port ='COM3', baudrate = 921600, timeout = 0.2)

while True:
#if 1>0:
	#byteVec = ser.read(ser.inWaiting())
	byteVec = ser.read(520)
	x = list(byteVec)
	startIdx = []
	#print('Read Data:\n',x, '\n')
	
	for ind in (i for i,e in enumerate(x) if e==magicWord[0]):	#To obtain the start indices of all magic words
		if x[ind:ind+8]==magicWord:
			startIdx.append(ind)
	
	for j in startIdx: 			#For each packet, do the needful
		j = j + 8 				#Skip magic word
		j = j + 20 				#get to number of detected objects. Only TLV selected is Detected Points
		numDetObj = 0
		k = 1
		for k in range(4):
			if j+k >= len(x):
				break
			numDetObj = numDetObj+ x[j+k]*word[k] #Refer line 1220 of mmw_demo.m
		#print('NumDetObj= '+str(numDetObj)+'\n')
		j = j + 8 				#Exit the header part
		
		j = j+8					 # SKIP TLV INFORMATION
		if j +4>= len(x):		 # Account for exceeding the length of list
			break
		
		#detObj part Refer line 1245 of mmw_demo.m
		
		numObj = 0
		detObj = np.zeros([numDetObj, 5])
		
		numObj = x[j+1] + x[j+2]*256
		j = j+2
		xyzQFormat = 2^(x[j+1] + x[j+2]*256)
		j = j+2
		bytes = x[j: j+numDetObj*OBJ_STRUCT_SIZE_BYTES]
		#print('Detected Object data: \n', bytes, '\n')
		if len(bytes) >= numDetObj*OBJ_STRUCT_SIZE_BYTES: 
			j = j+numDetObj*OBJ_STRUCT_SIZE_BYTES
			#print(len(bytes)/numDetObj)
			bytes = np.array(bytes).reshape(numDetObj, OBJ_STRUCT_SIZE_BYTES)
			#print(bytes, '\n')
			#print('rangeIdxToMeters = ', rangeIdxToMeters, '\n')
			#print('xyzQFormat = ', xyzQFormat, '\n')
			detObj[:, 0] = (bytes[:, 0] + bytes[:, 1] * 256)* rangeIdxToMeters
			detObj[:, 1] = bytes[:, 2] + bytes[:, 3]*256
			for r in range(numDetObj):
				if detObj[r,1] > numDopplerBins/2-1:
					detObj[r,1] -= numDopplerBins
			#detObj[:,1,detObj[:,1] > numDopplerBins/2-1] =detObj[:,1,detObj[:,1] > numDopplerBins/2-1] - numDopplerBins; # Refer mmw_demo.m line 1265
			detObj[:, 1] *= dopplerResolutionMps   		
			detObj[:, 2] = (bytes[:, 6] + bytes[:, 7]*256)
			detObj[:, 3] = (bytes[:, 8] + bytes[:, 9]*256)
			for r in range(numDetObj):
				if detObj[r,2] > 32767:
					detObj[r,2] -= 65536
			#for r in range(numDetObj):
			#	if detObj[r,3] > 32767:
			#		detObj[r,3] -= 65536
			#detObj[:,2,detObj[:,2] > 32767] =  detObj[:,2, detObj[:,2] > 32767] - 65536
			detObj[:,3][detObj[:,3] > 32767] =  detObj[:,3][ detObj[:,3] > 32767] - 65536
			detObj[:,2] = detObj[:, 2] / xyzQFormat
			detObj[:,3] = detObj[:, 3] / xyzQFormat 
			
			for r in range(numDetObj):
				if detObj[r,1] == 0:
					detObj[r, 4] = -1
					continue
				detObj[r,4] = np.sqrt(detObj[r,2]**2 + detObj[r,3]**2)/abs(detObj[r,1])
			
			print("Range \t\t Velocity  \t\t X_coor \t\t  Y_coor  \tETA\n", np.around(detObj, decimals = 2), '\n')
		
		#break
	#break
ser.close()