動圖與數據同步關係研究

在昨天 將陀螺儀採集數據動態可視化 博文中,將採集到的陀螺儀動圖與採集數據合併形成GIF,觀察到圖片信息與數據採集之間的不同步的問題。

這方面不同步,經過調試,還不能夠通過簡單的對時間線性調整來達到彌補。因此,在TEASOFT採集GIF圖片的時候,時間是非線性的失真。

 

01在GIF採集過程中的時間戳存儲


1.採集命令UDP隊列

PYTHON 程序使用tsgiaa()發送GIF採集命名之後,TEASOFT是等待到UDP消息之後才執行。tsgiaa命令並沒有
▲ 採集數據過程

▲ 採集數據過程

▲ 採集到的數據

▲ 採集到的數據

▲ GIF同步記錄的時間戳

▲ GIF同步記錄的時間戳

▲ 同步後的GIF圖片

▲ 同步後的GIF圖片

▲ 採集數據過程

▲ 採集數據過程

▲ 採集五秒中的數據

▲ 採集五秒中的數據

▲ 合成的GIF結果

▲ 合成的GIF結果

▲ TEASOFT的GIF更新過程與外部的不同步

▲ TEASOFT的GIF更新過程與外部的不同步

▲ 採用同步後的時間戳的曲線

▲ 採用同步後的時間戳的曲線

▲ 同步處理之後的情況

▲ 同步處理之後的情況

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# RECORDGIF.PY                 -- by Dr. ZhuoQing 2020-06-06
#
# Note:
#============================================================
from headm import *
from tsmodule.tsstm32       import *
import ad7606
tsgifff()
tspbeep(1200, 350)
gifts = 0.06
pages = int(10 / gifts)
printf("Sample Page:%d"%pages)
#------------------------------------------------------------
stm32cmd('setus 100')
stm32cmd('ad5v')
stm32cmd("CLEAR")
stm32cmd('adbuf 10000 4 10')
#------------------------------------------------------------
begintime = time.time()
ts = []
for i in range(pages):
    tsgifaa()
    tspread()
    ts.append(time.time() - begintime)
    waittime = i * gifts - time.time() + begintime
    if waittime > 0: time.sleep(waittime)
time.sleep(1.0)
data = [d*5/0x7fff for d in ad7606.ad7606readbuffer(10000, 4)]
tspsavenew('record', data=data, ts=ts)
#------------------------------------------------------------
printf('\a')
plt.plot(data[0::4])
plt.plot(data[1::4])
plt.plot(data[2::4])
plt.plot(data[3::4])
plt.xlabel("Sample")
plt.ylabel("Voltage(V)")
plt.grid(True)
plt.show()
#------------------------------------------------------------
#        END OF FILE : RECORDGIF.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# AD7606.PY                    -- by Dr. ZhuoQing 2020-06-04
#
# Note:
#============================================================
from headm import *
from tsmodule.tsstm32       import *
#------------------------------------------------------------
stm32cmd('ad5v')
stm32cmd('setus 100')
#------------------------------------------------------------
def Base64Ascii2Bit(ascii):
    ascii = int(ascii)
    if ascii >= ord('A') and ascii <= ord('Z'): return ascii - ord('A')
    if ascii >= ord('a') and ascii <= ord('z'): return ascii - ord('a') + 26
    if ascii >= ord('0') and ascii <= ord('9'): return ascii - ord('0') + 52
    if ascii == ord('*'): return 62
    if ascii == ord('/'): return 63
    return 0
def Base64Ascii2Byte(fourb):
    data = bytearray()
    bits0 = Base64Ascii2Bit(fourb[0])
    bits1 = Base64Ascii2Bit(fourb[1])
    bits2 = Base64Ascii2Bit(fourb[2])
    bits3 = Base64Ascii2Bit(fourb[3])
    data.append(bits0 * 4 + int(bits1 / 16))
    data.append((bits1 & 0xf) * 16 + int(bits2 / 4))
    data.append((bits2 & 0x3) * 64 + bits3)
    if fourb[2] == ord('=') and fourb[3] == ord('='):
        data = data[0:1]
        return data
    if fourb[3] == ord('='):
        return data[0:2]
    return data
def Base64Ascii2Data(ascii):
    data = bytearray()
    length = len(ascii)
    for i in range(int(length / 4)):
        bytedata = Base64Ascii2Byte(ascii[i*4:i*4+4])
        if len(bytedata) > 0:
            data.extend(bytedata)
    valdim = [x*256+y for x,y in zip(data[0::2], data[1::2])]
    valdim = [(d & 0x7fff) - (d & 0x8000) for d in valdim]
    return valdim
#------------------------------------------------------------
def ad7606buffer(num, ch, period, wait=0):
    val = stm32val()[10]
    stm32cmd('adbuf %d %d %d'%(num, ch, period))
    while True:
        time.sleep(.01)
        valnew = stm32val()[10]
        if valnew != val: break
    stm32cmd('CLEAR')
    stm32cmd('bufascii %d'%(num*ch))
    val = stm32val()[10]
    if wait > 0: time.sleep(wait)
    while True and wait == 0:
        time.sleep(.1)
        valnew = stm32val()[10]
        if valnew == val: break
        val = valnew
    stm32cmd("COPY")
    time.sleep(.1)
    pastestr = bytes(clipboard.paste(), 'utf-8')
    data = Base64Ascii2Data(pastestr)
    return data
#------------------------------------------------------------
def ad7606readbuffer(num, ch, wait=0):
    stm32cmd('CLEAR')
    stm32cmd('bufascii %d'%(num*ch))
    val = stm32val()[10]
    if wait > 0: time.sleep(wait)
    while True and wait == 0:
        time.sleep(.1)
        valnew = stm32val()[10]
        if valnew == val: break
        val = valnew
    stm32cmd("COPY")
    time.sleep(.1)
    pastestr = bytes(clipboard.paste(), 'utf-8')
    data = Base64Ascii2Data(pastestr)
    return data
#------------------------------------------------------------
def ad7606sample(num, ch, period, wait=0):
    stm32cmd('CLEAR')
    stm32cmd('adascii %d %d %d'%(num, ch, period))
    val = stm32val()[10]
    if wait > 0: time.sleep(wait)
    while True and wait == 0:
        time.sleep(.1)
        valnew = stm32val()[10]
        if valnew == val: break
        val = valnew
    stm32cmd("COPY")
    time.sleep(.1)
    pastestr = bytes(clipboard.paste(), 'utf-8')
    data = Base64Ascii2Data(pastestr)
    return data
#------------------------------------------------------------
def ad7606cut():
    stm32cmd("COPY")
    time.sleep(.1)
    pastestr = bytes(clipboard.paste(), 'utf-8')
    data = Base64Ascii2Data(pastestr)
    return data
#------------------------------------------------------------
#        END OF FILE : AD7606.PY
#============================================================

 

02更多的樣例


▲ 採集數據及其顯示

▲ 採集數據及其顯示

▲ RECORD6數據顯示

▲ RECORD6數據顯示

▲ RECORD9數據顯示

▲ RECORD9數據顯示

▲ RECORD0數據

▲ RECORD0數據

▲ RECORD1數據

▲ RECORD1數據

▲ RECORD6數據

▲ RECORD6數據

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# RECORDGIF.PY                 -- by Dr. ZhuoQing 2020-06-06
#
# Note:
#============================================================
from headm import *
from tsmodule.tsstm32       import *
import ad7606
tsgifff()
tspbeep(1200, 350)
gifts = 0.06
pages = int(10 / gifts)
printf("Sample Page:%d"%pages)
#------------------------------------------------------------
stm32cmd('setus 100')
stm32cmd('ad5v')
stm32cmd("CLEAR")
stm32cmd('adbuf 10000 4 10')
#------------------------------------------------------------
begintime = time.time()
ts = []
for i in range(pages):
    tsgifaa()
    tspread()
    ts.append(time.time() - begintime)
    waittime = i * gifts - time.time() + begintime
    if waittime > 0: time.sleep(waittime)
time.sleep(1.0)
data = [d*5/0x7fff for d in ad7606.ad7606readbuffer(10000, 4)]
tspsavenew('record', data=data, ts=ts)
#------------------------------------------------------------
printf('\a')
plt.plot(data[0::4])
plt.plot(data[1::4])
plt.plot(data[2::4])
plt.plot(data[3::4])
plt.xlabel("Sample")
plt.ylabel("Voltage(V)")
plt.grid(True)
plt.show()
#------------------------------------------------------------
#        END OF FILE : RECORDGIF.PY
#============================================================

 

■ 結論


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章