北醒激光雷达TFmini测试

北醒激光雷达TFmini

  1. TFmini串口设置
    使用自带串口转换板,COM6,波特率115200;
    2、串口通信协议
    在这里插入图片描述
    两组串口数据
    59 59 B8 00 67 23 D8 09 D5 59 59 B8 00 62 23 D8 09 D0

3.Python解码
以下为Python3的代码,读取串口数据并显示

# !/usr/bin/env python
# encoding: utf-8
import time
import math
import threading
import serial
from tkinter import *

ser = serial.Serial('COM6')
ser.baudrate = 115200
count = 0
totalnum = 0
havePeopleNum = 0
noPeopleNum = 0
data = ser.read()
hexold = 0
hexnew= 0

def update():
    #print("test3")
    global count
    global totalnum
    global havePeopleNum,noPeopleNum
    global hexold,hexnew
    data=ser.read()
    hexnew = ord(data)
    if hexnew == 0x59 and hexold == 0x59:
        hexnew = 0
        hexold= 0
        ladar_data = ser.read(7)
        distance = ladar_data[0] + ladar_data[1]*256

        count += 1
        if count >= 10:
            count = 0
            totalnum +=1
            timeText.configure(text=distance)
            if distance <= 150:
                havePeopleNum +=1
                Text4.configure(text="有人",fg="red")
            else:
                noPeopleNum +=1
                Text4.configure(text="无人",fg="blue")
    hexold = hexnew
    root.after(2,update)


root = Tk()
root.title("北醒雷达测试")
root.geometry('500x400')
theta = StringVar()

timeText = Label(root,text="",width=3,font=("Helvetica", 100),bg="white",justify=LEFT,anchor="e")
#txt1 = Label(root,text="距离",width=3,font=("Helvetica", 30),).grid(row=0,column=0,padx=20, pady=5,sticky=W,columnspan=2)
Text2 = Label(root, text="距离", font=("Helvetica", 20))
Text3 = Label(root, text="cm", font=("Helvetica", 20))
Text4 = Label(root, text="无人", font=("Helvetica", 80),fg="red")


#timeText.grid(row=0, column=0, padx=5, pady=5)
timeText.grid(row=0,column=0,padx=20, pady=5,sticky=W,columnspan=2)
Text2.grid(row=1, column=0, padx=5, pady=5)
Text3.grid(row=1, column=1, padx=5, pady=5)
Text4.grid(row=2, column=0, padx=20, pady=5,sticky=W,columnspan=2)

def Subfun():
    update()

t = threading.Thread(target=Subfun)
t.start()
mainloop()

4、界面显示效果
界面效果
了解更多北醒激光雷达及其他传感器信息,请咨询欣佰特科技(北京)。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值