Prueba inicial rpm y bateria añadida

This commit is contained in:
adrigongv23 2026-02-25 12:09:08 +01:00
parent aacfd2f6c3
commit b60f47cfb6
2 changed files with 142 additions and 62 deletions

View file

@ -3,27 +3,40 @@ import time
import math
import random
# --- CONFIGURACIÓN ---
UDP_IP = "127.0.0.1"
# --- CONFIGURACIÓN DE RED ---
UDP_IP = "127.0.0.1" # Enviamos a nuestro propio PC (Localhost)
UDP_PORT = 4210
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print(f"--- SIMULADOR DE COCHE G26 ---")
print(f"Enviando datos falsos a {UDP_IP}:{UDP_PORT}")
print("--- SIMULADOR G26 INICIADO ---")
print("Formato de envío: ECT | RPM | BATT")
print("Simulando batería bajando de 20V a 0V...")
t = 0
batt = 20.0 # La batería empieza al máximo
while True:
# Generar una temperatura que sube y baja mucho para probar todos los colores
# Oscilará entre 40ºC y 120ºC
ect = 80 + (40 * math.sin(t / 10.0)) + random.uniform(-0.5, 0.5)
# 1. Simular Temperatura (ECT) - Oscila entre 80 y 90
ect = 85 + (5 * math.sin(t / 5.0)) + random.uniform(-0.5, 0.5)
# Enviar solo el número
mensaje = f"{ect:.2f}"
# 2. Simular RPM - Acelerones entre 0 y 15000 RPM
# Usamos valor absoluto del seno para simular que pisa el acelerador y suelta
rpm = abs(15000 * math.sin(t / 2.0))
sock.sendto(mensaje.encode(), (UDP_IP, UDP_PORT))
# 3. Simular Batería - Baja progresivamente
batt -= 0.05 # Restamos un poco de voltaje en cada ciclo
if batt < 0:
batt = 20.0 # Si llega a 0, reiniciamos a 20V para que el test continúe
# 4. Empaquetar el mensaje (3 datos separados por '|')
mensaje = f"{ect:.1f}|{int(rpm)}|{batt:.1f}"
print(f"Simulando: {mensaje} °C")
# 5. Enviar por UDP
sock.sendto(mensaje.encode('utf-8'), (UDP_IP, UDP_PORT))
# Imprimir en consola para confirmar visualmente
print(f"Enviando -> {mensaje}")
t += 0.1
time.sleep(0.05)
time.sleep(0.05) # Espera 50 milisegundos (20 veces por segundo)