1zlab / 1ZLAB_PyEspCar

1ZLab在准备挑选合适的小车来研发计算机视觉的教程时候 , 发现习惯了Python语法的我们, 在市面上找不到合适小车, 后来我们选了ESP32作为小车的控制主板, 可以使用Python对其进行交互式编程, 极大的提升了开发效率.
http://www.1zlab.com
GNU General Public License v3.0
91 stars 25 forks source link

小车波形数据可视化 #9

Closed mushroom-x closed 6 years ago

mushroom-x commented 6 years ago

用于PID参数调节。

mushroom-x commented 6 years ago

借助串口示波器软件SerialTool https://github.com/gztss/SerialTool

mushroom-x commented 6 years ago

小峰写的测试程序 小峰写的测试程序


import struct

class SendWave:
    def __init__(self,Channel_cnt=16,Value_type='Int16'):
        '''
        Oscilloscope 初始化
        SendWave(UART,Channel_cnt=16,Value_type='Int16')
        Channel_cnt         ---开启通道个数,在同步传输的时候会用到
        Value_type          -- 数据类型,Int8,Int16,Int32,Float
        '''
        self.Ch_Num          = Channel_cnt
        self.Frame_Head      = 163      #帧头识别字
        self.Frame_PointMode = 168      #点模式识别字
        self.Frame_SyncMode  = 169      #同步模式识别字
        self.Frame_InfoMode  = 170      #信息帧识别字 
        self.buffer =  []               #数据缓存区 
        self.Format_type = Value_type   #数据格式信息

        self.types = {'Int8':(16,'BBBb','Bb'),
                      'Int16':(32,'BBBh','Bh'),
                      'Int32':(48,'BBBi','Bi'),
                      'Float':(0,'BBBf','Bf')}
        self.Format=self.types[self.Format_type][1]

    def ws_point(self,*values):
        data = ''
        patten = ''
        Channels = len(values)
        if Channels > 0 and Channels<17:        
            for Channel in range(Channels):
                self.buffer.append(self.Frame_Head)
                self.buffer.append(self.Frame_PointMode)
                self.buffer.append(Channel | self.types[self.Format_type][0]) # 通道及数据格式信息
                self.buffer.append(values[Channel]); # 数据                
            patten = '>'+self.Format*Channels
            data = struct.pack(patten,*self.buffer)
            self.buffer = []
        return data

    def ws_sync(self,*values):
        data = ''
        patten = ''
        Channels = len(values)

        self.buffer.append(self.Frame_Head)
        self.buffer.append(self.Frame_SyncMode)

        if Channels > 0 and Channels<17:        
            for Channel in range(Channels):
                self.buffer.append(Channel | self.types[self.Format_type][0]) # 通道及数据格式信息            
                self.buffer.append(values[Channel]); # 数据 
            patten = '>'+self.Format+self.types[self.Format_type][2]*(Channels-1)
            data = struct.pack(patten,*self.buffer)
            self.buffer = []
        return data

'''        
import sendwave
import random
import time

osc = sendwave.SendWave()
value = [random.randint(20, 2000) for x in range(16)]

data = osc.ws_sync(*value)  
print(data)
data = osc.ws_point(*value)  
print(data)

'''
mushroom-x commented 6 years ago

想用 Tkinter 写个上位机, 这样可以更加灵活方便

mushroom-x commented 6 years ago

Thinter + Matplotlib