SHA256
DEBUG_1:Grafica
This commit is contained in:
1 parent
2a5fdabf13
commit
204b88d96f
4 files changed
+14675
-56
No files matched your search
@@ -174,3 +174,4 @@ cython_debug/
|
|||||||
# PyPI configuration file
|
# PyPI configuration file
|
||||||
.pypirc
|
.pypirc
|
||||||
|
|
||||||
|
.zed
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
import queue
|
import queue
|
||||||
|
|
||||||
from src.cliente_ws import websocket_cliente
|
from src.cliente_ws import websocket_cliente
|
||||||
from src.graficar import graficar, graficar_rt
|
from src.graficar import graficar
|
||||||
from src.gurdar import guardar_datos
|
from src.gurdar import guardar_datos
|
||||||
from src.procesor_data import data_procesor
|
from src.procesor_data import data_procesor
|
||||||
|
|
||||||
@@ -31,17 +31,17 @@ buffer_size = queue.Queue()
|
|||||||
hilo_1 = websocket_cliente(raw_data, i_paquetes, ip_server)
|
hilo_1 = websocket_cliente(raw_data, i_paquetes, ip_server)
|
||||||
hilo_2 = data_procesor(raw_data, data_clean, data_grafica, buffer_size)
|
hilo_2 = data_procesor(raw_data, data_clean, data_grafica, buffer_size)
|
||||||
# hilo_3 = threading.Thread(target=debug_print)
|
# hilo_3 = threading.Thread(target=debug_print)
|
||||||
# hilo_3 = graficar_rt(data_clean, data_grafica, buffer_size)
|
|
||||||
hilo_4 = guardar_datos(data_clean)
|
hilo_4 = guardar_datos(data_clean)
|
||||||
|
|
||||||
|
hilo_1.daemon = True
|
||||||
|
hilo_2.daemon = True
|
||||||
|
# hilo_3.daemon = True
|
||||||
|
hilo_4.daemon = True
|
||||||
|
|
||||||
hilo_1.start()
|
hilo_1.start()
|
||||||
hilo_2.start()
|
hilo_2.start()
|
||||||
# hilo_3.start()
|
# hilo_3.start()
|
||||||
hilo_4.start()
|
hilo_4.start()
|
||||||
|
|
||||||
hilo_1.join()
|
|
||||||
hilo_2.join()
|
|
||||||
# hilo_3.join()
|
|
||||||
hilo_4.join()
|
|
||||||
|
|
||||||
graficar(data_clean, data_grafica)
|
graficar(data_clean, data_grafica, buffer_size)
|
||||||
+62
-49
@@ -1,64 +1,77 @@
|
|||||||
import queue
|
|
||||||
import threading
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
from pyqtgraph.Qt import QtCore
|
from pyqtgraph.Qt import QtCore
|
||||||
|
|
||||||
|
|
||||||
def graficar(cola_clean, cola_filtrada):
|
def graficar(cola_clean, cola_filtrada, cola_buffer_size):
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
win = pg.GraphicsLayoutWidget(show=True, title="Onda senoidal")
|
win = pg.GraphicsLayoutWidget(show=True, title="Monitor de Señal")
|
||||||
p1 = win.addPlot(title="Señal cruda y filtrada")
|
p1 = win.addPlot(title="Señal Cruda y Filtrada (Historial de 1s)")
|
||||||
p1.addLegend() # leyenda automática
|
p1.addLegend()
|
||||||
curve1 = p1.plot(pen="r", name="Cruda")
|
|
||||||
curve2 = p1.plot(pen="b", name="Filtrada")
|
curve1 = p1.plot(pen=pg.mkPen("r", width=1), name="Cruda")
|
||||||
|
curve2 = p1.plot(pen=pg.mkPen("b", width=2), name="Filtrada")
|
||||||
|
|
||||||
|
# Empezamos con los buffers nulos.
|
||||||
|
# La gráfica esperará pasivamente a que el hilo de procesamiento defina el tamaño.
|
||||||
|
buffer_clean = None
|
||||||
|
buffer_filtrado = None
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
if not cola_clean.empty():
|
nonlocal buffer_clean, buffer_filtrado
|
||||||
datos = cola_clean.get()
|
|
||||||
muestras = np.arange(len(datos))
|
|
||||||
curve1.setData(muestras, datos)
|
|
||||||
|
|
||||||
if not cola_filtrada.empty():
|
# 1. VERIFICAR TAMAÑO DEL BUFFER
|
||||||
datos_f = cola_filtrada.get()
|
# Si el procesador mandó un nuevo tamaño (al inicio, o si cambia la tasa de muestreo)
|
||||||
muestras_f = np.arange(len(datos_f))
|
if not cola_buffer_size.empty():
|
||||||
curve2.setData(muestras_f, datos_f)
|
# Extraemos el valor y nos aseguramos de que sea un entero
|
||||||
|
tamano_buffer = int(cola_buffer_size.get())
|
||||||
|
|
||||||
|
# Inicializamos (o reinicializamos) los arreglos de NumPy
|
||||||
|
buffer_clean = np.zeros(tamano_buffer)
|
||||||
|
buffer_filtrado = np.zeros(tamano_buffer)
|
||||||
|
print(
|
||||||
|
f"[*] Gráfica inicializada: Buffer de {tamano_buffer} muestras configurado."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Si el buffer aún no existe (el ESP32 no ha mandado suficientes datos),
|
||||||
|
# abortamos este ciclo de dibujo y esperamos al siguiente.
|
||||||
|
if buffer_clean is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# 2. PROCESAR SEÑAL CRUDA
|
||||||
|
actualizar_cruda = False
|
||||||
|
while not cola_clean.empty():
|
||||||
|
datos_nuevos = np.array(cola_clean.get())
|
||||||
|
n = len(datos_nuevos)
|
||||||
|
|
||||||
|
# Precaución por si un paquete llega más grande que el buffer entero
|
||||||
|
if n > len(buffer_clean):
|
||||||
|
datos_nuevos = datos_nuevos[-len(buffer_clean) :]
|
||||||
|
n = len(datos_nuevos)
|
||||||
|
|
||||||
|
buffer_clean[:-n] = buffer_clean[n:]
|
||||||
|
buffer_clean[-n:] = datos_nuevos
|
||||||
|
actualizar_cruda = True
|
||||||
|
|
||||||
|
if actualizar_cruda:
|
||||||
|
curve1.setData(buffer_clean)
|
||||||
|
|
||||||
|
# 3. PROCESAR SEÑAL FILTRADA
|
||||||
|
actualizar_filtrada = False
|
||||||
|
while not cola_filtrada.empty():
|
||||||
|
nuevo_filtrado = np.array(cola_filtrada.get())
|
||||||
|
|
||||||
|
# Validación de seguridad por si el tamaño cambió en medio de una iteración
|
||||||
|
if len(nuevo_filtrado) == len(buffer_filtrado):
|
||||||
|
buffer_filtrado = nuevo_filtrado
|
||||||
|
actualizar_filtrada = True
|
||||||
|
|
||||||
|
if actualizar_filtrada:
|
||||||
|
curve2.setData(buffer_filtrado)
|
||||||
|
|
||||||
timer = QtCore.QTimer()
|
timer = QtCore.QTimer()
|
||||||
timer.timeout.connect(update)
|
timer.timeout.connect(update)
|
||||||
timer.start(100) # refresco cada 100 ms
|
timer.start(50) # 20 FPS para un barrido fluido
|
||||||
|
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
||||||
|
|
||||||
class graficar_rt(threading.Thread):
|
|
||||||
def __init__(self, cola_clean, cola_filtada, buffer_size):
|
|
||||||
super().__init__()
|
|
||||||
self.cola_clean = cola_clean
|
|
||||||
self.cola_filtrado = cola_filtada
|
|
||||||
self.buffer_size = buffer_size
|
|
||||||
self.buffer_filtrado = [0] * self.buffer_size
|
|
||||||
self.buffer_limpio = [0] * self.buffer_size
|
|
||||||
self.idx_despla = self.buffer_size / 100
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
app = QtWidgets.QApplication([])
|
|
||||||
win = pg.GraphicsLayoutWidget(show=True, title="Onda senoidal")
|
|
||||||
p1 = win.addPlot(title="Señal cruda y filtrada")
|
|
||||||
p1.addLegend()
|
|
||||||
curve1 = p1.plot(pen="r", name="Cruda")
|
|
||||||
curve2 = p1.plot(pen="b", name="Filtrada")
|
|
||||||
|
|
||||||
def update():
|
|
||||||
|
|
||||||
if not self.cola_clean.empty():
|
|
||||||
datos = self.cola_clean.get()
|
|
||||||
muestras = np.arange(len(datos))
|
|
||||||
curve1.setData(muestras, datos)
|
|
||||||
|
|
||||||
if not self.cola_filtrado.empty():
|
|
||||||
datos_f = self.cola_filtrado.get()
|
|
||||||
muestras_f = np.arange(len(datos_f))
|
|
||||||
curve2.setData(muestras_f, datos_f)
|
|
||||||
Reference in new issue
Block a user