一.前言
本人所用如下配置执行此实验
硬件:IWR1642
toolbox版本:mmwave_industrial_toolbox_3_2_0
实验名称:lab0011-pplcount 实验文件下载
可在TI官网下载对于版本的toolbox找到此实验。
本文从采集数据开始。
二.数据采集
毫米波模块有两个串口通道,user port和data port。
要想获取毫米波从传回的数据需要先通过user port 向毫米波写入cfg配置信息,及后data port就会传回数据。
1.串口助手配置
首先需要打开两个串口软件,我使用VOFA+,并双开。user port的端口依照自己电脑的设备管理器查看,波特率为15200;data port的波特率则不同设置为921600
2.写入配置信息
通过连接user port的串口软件窗口写入配置信息,按顺序输入如下信息
dfeDataOutputMode 1
channelCfg 15 3 0
adcCfg 2 1
adcbufCfg 0 1 1 1
profileCfg 0 77 30 7 62 0 0 60 1 128 2500 0 0 30
chirpCfg 0 0 0 0 0 0 0 1
chirpCfg 1 1 0 0 0 0 0 2
frameCfg 0 1 128 0 50 1 0
lowPower 0 1
guiMonitor 1 1 0 0
cfarCfg 6 4 4 4 4 16 16 4 4 50 62 0
doaCfg 600 1875 30 1
SceneryParam -6 6 0.05 6
GatingParam 4 3 2 0
StateParam 10 5 10 100 5
AllocationParam 450 0.01 25 1 2
VariationParam 0.289 0.289 1.0
PointCloudEn 1
trackingCfg 1 2 250 20 200 50 90
sensorStart
输入正确毫米波会回传“done”
3.接收数据
执行完上述步骤 data port就会回传数据。
三.数据分析
可以参照官方文档对数据的解释
传回数据包含frame header(帧头)和TLV;TLV下包含TLV Header+point cloud TLV、TLV Header+Target object TLV、TLV Header+Target Index TLV。
如果全部数据都要讲解篇幅会很长,我以获取目标坐标为例。
1.寻找目标坐标数据
由于毫米波的数据是不断更新数据庞大,对单个数据包将进行提取,首先需要找到单个数据包的头部,对单个数据包的整体位置进行定位,根据官方文档帧头为“ 02 0104 03 06 05 08 07”
那么单个数据包就是两个橙色颜色块中间的数据。
坐标数据在TLVs数据段内的TLV Header+Target object TLV下,标志为“07 00 00 00“
一直到”08 00 00 00“之前都是TLV Header+Target object TLV的数据。
那么下面就要解构TLV Header+Target object TLV的数据。
posX和posY就是我所寻找的数据。
posX和posY就在TLV Header+Target object TLV字段下的13至20字节。
”07 00 00 00”是--------‘type’, {‘uint32’, 4}, … % TLV object Type
“4C 00 00 00”是--------‘length’, {‘uint32’, 4}); % TLV object Length, in bytes, including TLV header
“00 00 00 00"是--------‘tid’, {‘uint32’, 4}, … % Track ID
”4E A8 01 3E“是-------‘posX’, {‘float’, 4}, … % Target position in X dimension, m
”87 1E 5E 3F“是--------‘posY’, {‘float’, 4}, … % Target position in Y dimension, m
posX为“4E A8 01 3E”
posY为“87 1E 5E 3F”
这是32 位浮点类型。数据是小端的。可以使用python,或者matlab转换为float。
此代码完成从串口获取数据到坐标数据的提取一系列操作。
import serial
from time import sleep
import binascii
from ctypes import *
list = []## 空列表
#将byte类型转为用str表示的hex(串口传回的byte类型)
def byte_to_hexStr(byte):
return binascii.hexlify(byte).decode('utf-8')
def get_serial(): #串口数据处理+接收
return byte_to_hexStr(ser.read())
def big_to_small_convert(data): #大小端转换
return bytes.decode(binascii.hexlify(binascii.unhexlify(data)[::-1]))
def convert(data):
s=big_to_small_convert(data) #大端转小端
i = int(s, 16) # convert from hex to a Python int
cp = pointer(c_int(i)) # make this into a c integer
fp = cast(cp, POINTER(c_float)) # cast the int pointer to a float pointer
return fp.contents.value # dereference the pointer, get the float
ser = serial.Serial ("COM11", 921600) #Open port with baud rate
print("running")
while True:
if get_serial()=="07":
for i in range(19):
list.insert(i,get_serial())
if list[0]=="00" and list[1]=="00" and list[2]=="00":
#直接在串口传回的数据中寻找“07 00 00 00”这个标志位
print("origin",list[0:19])
print("list:", list[11:19])
posX = "".join(list[11:15])
posY = "".join(list[15:19])
print("posX",posX,"posY",posY)
print("posX%.2f"%convert(posX),"posY%.2f"%convert(posY))
print("----------------------------------------")