Skip to content

Commit 954c729

Browse files
committed
Calibracion
1 parent 87d810c commit 954c729

14 files changed

+193
-19
lines changed

lib/Caudal/Caudal.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "C:\Users\user\Desktop\Taller_de_Ing\Azucarado\include\Config.h"
55
#include <Memoria_no_volatil.h>
66
#include <HX711.h>
7+
//#include <LiquidCrystal.h>
78

89
#define elementos 3
910
#define pi 3.14

server/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Monitor de control Del tanque:

server/src/Datos.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"xonxoff": false,
88
"dsrdtr": false,
99
"rtscts": false,
10-
"timeout": 5,
10+
"timeout": 2,
1111
"write_timeout": null,
1212
"inter_byte_timeout": null
1313
},
@@ -51,5 +51,17 @@
5151
0.0,
5252
0.0
5353
],
54-
"Tiempo llenado": 0
54+
"Tiempo llenado": 5000,
55+
"Regresion_x": [
56+
-2.0,
57+
1.0,
58+
4.0,
59+
3.0,
60+
0.0
61+
],
62+
"Regresion": {
63+
"a0": 1.1428571428571428,
64+
"x1": 0.3896103896103897,
65+
"x2": 0.06493506493506493
66+
}
5567
}
Binary file not shown.
Binary file not shown.
1.54 KB
Binary file not shown.

server/src/botones.py

+33-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, pantalla: Ventana, Dispostivo: Arduino, caja: tkinter.Listbox
1414
self.dispositivo: Arduino = Dispostivo
1515
self.caja = caja
1616
self.ventanas: Ventana = pantalla
17+
self.values_x : list = []
1718

1819
#Funcionalidades para realizar la regresion:
1920
def __boton_regresion(self, posx: float, posy: float, size: str) -> tkinter.Button:
@@ -79,14 +80,26 @@ def __regresion(self, size: str) -> None:
7980
Realizar = tkinter.Button(
8081
nueva, text="Realizar", command=lambda: self.__regresion_datos(
8182
etiqueta1, etiqueta2, etiqueta3, etiqueta4, etiqueta5, pantalla=nueva, estado1=opcion, estado2=opcion2
82-
), bg='lightgreen'
83+
), bg='lightgreen', state="disabled"
8384
)
8485
Realizar.place(relx=0.36, rely=0.85)
8586
# eliminar datos ingresados:
8687
reset = tkinter.Button(
8788
nueva, text="Reset", command=lambda: self.__reset(nueva), bg='indian red'
8889
)
8990
reset.place(relx=0.53, rely=0.85)
91+
# desactivar opciones por un cierto tiempo:
92+
self.dispositivo.limpiar()
93+
self.dispositivo.escribir_datos("[true/8]")
94+
self.pantalla.after(self.dispositivo.Guardar.tiempo, self.__activar_Valores, Realizar)
95+
96+
def __activar_Valores(self, boton: tkinter.Button) -> None:
97+
self.values_x = self.dispositivo.leer_valores_celdad_carga()
98+
boton.config(state="active")
99+
if len(self.values_x) == 5:
100+
self.caja.insert(tkinter.END, "Se recivieron los datos.")
101+
else:
102+
self.caja.insert(tkinter.END, "No se recivieron los datos.")
90103

91104
def __estado(self, estado: tkinter.IntVar, boton: tkinter.Checkbutton, estado2: tkinter.IntVar):
92105
if (estado.get() == 1 and estado2.get() == 1):
@@ -123,23 +136,34 @@ def __regresion_datos(self, *args: tkinter.StringVar, pantalla: tkinter.Toplevel
123136
self.caja.insert(tkinter.END, "Intente de nuevo")
124137
break
125138
else:
126-
if (indx == 4):
127-
list1: list = [-2, 1, 4, 3, 0]
139+
if indx == 4 and len(self.values_x) == 5:
140+
#list1: list = [-2, 1, 4, 3, 0]
128141
aux: str = self.__definir(estado1, estado2)
129-
regresion_final: list = realizar(aux, list1, lista)
142+
regresion_final: list = realizar(aux, self.values_x, lista)
130143
self.caja.insert(
131144
tkinter.END, "Valores de la Regresion {}:".format(aux))
132145
for element in regresion_final:
133146
self.caja.insert(
134147
tkinter.END, "{:.2f}".format(element))
135148
self.dispositivo.Regresion(element)
136-
self.pantalla.after(1400, self.confirmar)
137-
self.caja.insert(
138-
tkinter.END, "Regresion configurada")
149+
self.pantalla.after(2000, self.valorar_regresion)
139150
pantalla.destroy()
151+
elif len(self.values_x) < 5:
152+
for widget in pantalla.winfo_children():
153+
if isinstance(widget, tkinter.Button):
154+
if widget.config('text')[-1] == "Realizar":
155+
self.__activar_Valores(widget)
156+
break
157+
self.caja.insert(tkinter.END, "Valores del eje x no han sido recividos aún completos")
140158
else:
141159
pass
142160

161+
def valorar_regresion(self):
162+
if self.dispositivo.confirmar_regresion():
163+
self.caja.insert(tkinter.END, "Regresion configurada")
164+
else:
165+
self.caja.insert(tkinter.END, "Regresion No configurada")
166+
143167
def regresion(self, posx: float, posy: float, size: str) -> None:
144168
self.__boton_regresion(posx, posy, size)
145169

@@ -178,6 +202,7 @@ def conection_arduino(self) -> None:
178202
aux.config(state="disabled")
179203
var.set(self.dispositivo.Port())
180204
self.caja.insert(tkinter.END, self.dispositivo.conexion)
205+
self.dispositivo.limpiar()
181206

182207
#Boton para obtener las opciones:
183208
def menu_opciones_conexion(self, var: tkinter.StringVar, port: list) -> tkinter.OptionMenu:
@@ -209,6 +234,7 @@ def __conectar(self, var: tkinter.StringVar, etiqueta: tkinter.Label, var2: tkin
209234
elif isinstance(widget, tkinter.Entry):
210235
widget.config(state="disabled")
211236
self.caja.insert(tkinter.END, self.dispositivo.conexion)
237+
self.dispositivo.limpiar()
212238
else:
213239
self.caja.insert(tkinter.END, self.dispositivo.Errores)
214240

server/src/conectado_datos.py

+39-2
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,42 @@ def terminado(self) -> None:
288288
self.pantalla.destroy()
289289

290290
def confi_regresion(self) -> None:
291-
boton = tkinter.Button(self.pantalla, text= "Configuracion", command=lambda:print("Hola"), )
292-
boton.place(relx=0.83, rely=0.84)
291+
boton = tkinter.Button(self.pantalla, text= "Configuracion", command=self.realizar_configuracion)
292+
boton.place(relx=0.83, rely=0.84)
293+
294+
def realizar_configuracion(self) -> None:
295+
nueva : tkinter.Toplevel = tkinter.Toplevel(background="#2a8d90")
296+
nueva.geometry("380x120")
297+
nueva.resizable(False, False)
298+
nueva.title("Set the time")
299+
self.ventanas.etiqueta_titulo(nueva, "Tiempo de Llenado Tanque")
300+
variable = tkinter.StringVar(value="En segundos")
301+
etiqueta = tkinter.Entry(nueva, width=35, textvariable=variable)
302+
etiqueta.place(relx=0.1, rely=0.4)
303+
boton = tkinter.Button(nueva, text="Guardar", command=lambda:self.configuracion_tiempo(variable,etiqueta,nueva))
304+
boton.place(relx=0.7, rely=0.4)
305+
boton1 = tkinter.Button(nueva, text="Imprimir", command=self.mostrar_confi)
306+
boton1.place(relx = 0.4, rely = 0.7)
307+
308+
def configuracion_tiempo(self, var: tkinter.StringVar, eti: tkinter.Entry, pantalla: tkinter.Toplevel) -> None:
309+
guarda: float
310+
try:
311+
guarda = float(var.get())
312+
except:
313+
eti.delete(0, 'end')
314+
var.set("")
315+
self.caja.insert(tkinter.END, "Dato no valido. Ingrese otro valor.")
316+
else:
317+
aux_21 : int = int(guarda*1000)
318+
self.dispositivo.set_the_time(aux_21)
319+
self.caja.insert(tkinter.END, "Dato configurado correctamente.")
320+
pantalla.destroy()
321+
322+
def mostrar_confi(self) -> None:
323+
self.caja.insert(tkinter.END, "Configuración del dispostivio:")
324+
for key, value in self.dispositivo.Guardar.configuracion.items():
325+
self.caja.insert(tkinter.END, f"{key}: {value}")
326+
self.caja.insert(tkinter.END, f"tiempo de llenado: {self.dispositivo.Guardar.tiempo}")
327+
328+
329+

server/src/logica.py

+64-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from module.Transfer import Transfer
22
from module.Base_datos import Almacenamiento
3-
import time
43

54
class Arduino(Transfer):
65

@@ -28,6 +27,7 @@ def __Enviar_valores_regresion(self, lista : list) -> None:
2827
aux = aux + "0]"
2928
print(aux)
3029
super().escribir_datos(aux)
30+
self.guardar_valores_regresion(lista)
3131

3232
def Regresion(self, value : float):
3333
if (contador := self.__contador2 + 1) <= (3):
@@ -41,6 +41,33 @@ def Regresion(self, value : float):
4141
self.__Enviar_valores_regresion(list(self.__Regresion.values()))
4242
self.Guardar.Guardar_datos()
4343

44+
def confirmar_regresion(self) -> bool:
45+
if self.Arduino.is_open:
46+
if self.señal.isSet():
47+
count: int = 0
48+
try:
49+
if(len(self.data) == 3):
50+
for indx, element in enumerate(self.data , start=0):
51+
if(element == self.data[indx]):
52+
count += 1
53+
if count == 3:
54+
self.limpiar()
55+
return True
56+
else:
57+
self.limpiar()
58+
return False
59+
else:
60+
return False
61+
except ValueError:
62+
self.limpiar()
63+
return False
64+
else:
65+
print("Hilo fallo")
66+
self.Arduino.close()
67+
return False
68+
else:
69+
return False
70+
4471
def conection(self, value: str) -> bool:
4572
if self.Arduino.is_open:
4673
if self.señal.isSet():
@@ -103,6 +130,42 @@ def recolectar_datos(self, validacion: bool) -> dict:
103130
print("Sin datos")
104131
return self.Guardar.datos_arduino
105132

133+
def set_the_time(self, value: int) -> None:
134+
self.Guardar.tiempo = value
135+
self.Guardar.Guardar_datos()
136+
137+
def leer_valores_celdad_carga(self) -> list:
138+
aux_list_regre: list = []
139+
if(len(self.data) == 5):
140+
for element in self.data:
141+
try:
142+
variable : float = float(element)
143+
aux_list_regre.append(variable)
144+
except ValueError:
145+
self.Errores = "Error en el recivimiento del mensaje."
146+
pass
147+
else:
148+
self.__guardar_Value_x(aux_list_regre)
149+
self.limpiar()
150+
return aux_list_regre.copy()
151+
return aux_list_regre
152+
153+
def __guardar_Value_x(self, lista: list ):
154+
self.Guardar.Resion_values_x = lista
155+
self.Guardar.Guardar_datos()
156+
157+
def guardar_valores_regresion(self, lista : list) -> None:
158+
if len(lista) == 3:
159+
self.Guardar.Regresion_metodo = {
160+
"a0" : lista[0],
161+
"x1" : lista[1],
162+
"x2" : lista[2]
163+
}
164+
self.Guardar.Guardar_datos()
165+
else:
166+
pass
167+
168+
106169
if __name__ == '__main__':
107170
logic = Arduino(9600)
108171
logic.comprobar_data()

server/src/module/Base_datos.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ def __init__(self, configuracion : dict = {}) -> None:
2323
self.__datos_arduino : dict = {}
2424
self.__datos_estadisticos: list = []
2525
self.__guardar :dict = {}
26-
self.__tiempo_regr : float = 0
26+
self.__tiempo_regr : int = 0
27+
self.__values_x : list = []
28+
self.__regresion: dict = {}
2729

2830
def Guardar_datos(self) -> None:
2931
self.__guardar = {
3032
"configuracion": self.__configuracion,
3133
"Datos_Arduino": self.__datos_arduino,
3234
"Estadistica": self.__datos_estadisticos,
33-
"Tiempo llenado": self.__tiempo_regr
35+
"Tiempo llenado": self.__tiempo_regr,
36+
"Regresion_x": self.__values_x,
37+
"Regresion": self.__regresion
3438
}
3539
with open(self.ruta_archivo, 'w') as archivo:
3640
json.dump(self.__guardar, archivo, indent=4)
@@ -41,7 +45,9 @@ def Cargar_datos(self) -> dict:
4145
self.__configuracion = self.__guardar.setdefault("configuracion")
4246
self.__datos_arduino = self.__guardar.setdefault("Datos_Arduino")
4347
self.__datos_estadisticos = self.__guardar.setdefault("Estadistica")
44-
self.__tiempo = self.__guardar.setdefault("Tiempo llenado")
48+
self.__tiempo_regr = self.__guardar.setdefault("Tiempo llenado")
49+
self.__values_x = self.__guardar.setdefault("Regresion")
50+
self.__regresion = self.__guardar.setdefault("Regresion")
4551
return self.__guardar
4652

4753
@property
@@ -69,12 +75,28 @@ def datos_estadisticos(self, diccionario: list) -> None:
6975
self.__datos_estadisticos = diccionario
7076

7177
@property
72-
def tiempo_regr(self) -> float:
78+
def tiempo_regr(self) -> int:
7379
return self.__tiempo_regr
7480

7581
@tiempo_regr.setter
76-
def tiempo(self, valor_time: float) -> None:
82+
def tiempo(self, valor_time: int) -> None:
7783
self.__tiempo_regr = valor_time
84+
85+
@property
86+
def Regresion_values_x(self) -> list:
87+
return self.__values_x
88+
89+
@Regresion_values_x.setter
90+
def Resion_values_x(self, valor_list: list) -> None:
91+
self.__values_x = valor_list
92+
93+
@property
94+
def Regresion_metodo(self) -> dict:
95+
return self.__regresion
96+
97+
@Regresion_metodo.setter
98+
def Regresion_metodo(self, valor_dict: dict) -> None:
99+
self.__regresion = valor_dict
78100

79101
def __str__(self):
80102
aux : str = ""
Binary file not shown.

server/src/tempCodeRunnerFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
380x480
1+
#2a8d90

src/Correr.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ namespace Correr
153153
Manejo_datos::guarda_config_peso(Variables_datos.altura);
154154
Serial.println(Variables_datos.altura);
155155
}
156+
//Valores x de la regresion:
157+
else if(list[0] == "8")
158+
{
159+
if (list[1] == "true")
160+
{
161+
float array_regr[5] = {-2, 1, 4, 3, 0};
162+
Serial.println(array_regr[0]);
163+
Serial.println(array_regr[1]);
164+
Serial.println(array_regr[2]);
165+
Serial.println(array_regr[3]);
166+
Serial.println(array_regr[4]);
167+
}
168+
}
156169
delete[] list;
157170
}
158171
}

src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
//Elementos de ejecuión:
2121
#include "..\include\Correr.h"
2222

23-
2423
/**
2524
* @brief Función que se encarga de configurar los parametros inciales de las funciones.
2625
*/

0 commit comments

Comments
 (0)