diff --git a/emulator/obd2_emulator.py b/emulator/obd2_emulator.py index c090054..66f6c88 100755 --- a/emulator/obd2_emulator.py +++ b/emulator/obd2_emulator.py @@ -36,37 +36,55 @@ class VehicleState: t = time.time() with self.lock: if self.auto_simulate: - # 24-second cycle: - # 0 - 8s: Ramp up to maximums - # 8 - 12s: Hold at absolute MAXIMUM on all instruments for 4s - # 12 - 20s: Ramp down to idle - # 20 - 24s: Hold at IDLE for 4s - cycle_period = 24.0 + # 32-second demonstration cycle: + # 0 - 5s: FASE 1 - Batería Baja Crítica (<12V) -> ROJO con alarma destellante (10.8V, 3 bloques) + # 5 - 9s: FASE 2 - Batería en reposo / baja carga (12.0 - 13.2V) -> AMARILLO (12.4V, 8 bloques) + # 9 - 16s: FASE 3 - Marcha normal / óptima -> Todo en VERDE (RPM 2200, Vel 60, Temp 92°C, Volt 14.2V) + # 16 - 21s: FASE 4 - Precaución / carga alta -> Todo en AMARILLO (RPM 4200, Vel 120, Temp 102°C, Volt 15.0V) + # 21 - 27s: FASE 5 - MÁXIMO ABSOLUTO (100% de escala) -> Todo en ROJO con alarma destellante (RPM 6000, Vel 160, Temp 120°C, Volt 16.0V) + # 27 - 32s: FASE 6 - Descenso suave de vuelta al inicio + cycle_period = 32.0 phase = t % cycle_period - if phase < 8.0: - p = phase / 8.0 - self.rpm = 800.0 + p * (6000.0 - 800.0) - self.speed = p * 160.0 - self.coolant_temp = 85.0 + p * (120.0 - 85.0) - self.pcm_volt = 11.5 + p * (16.0 - 11.5) - elif phase < 12.0: - # MAX SCALE ON ALL INSTRUMENTS - self.rpm = 6000.0 - self.speed = 160.0 - self.coolant_temp = 120.0 - self.pcm_volt = 16.0 - elif phase < 20.0: - p = (phase - 12.0) / 8.0 - self.rpm = 6000.0 - p * (6000.0 - 800.0) - self.speed = 160.0 - p * 160.0 - self.coolant_temp = 120.0 - p * (120.0 - 85.0) - self.pcm_volt = 16.0 - p * (16.0 - 11.5) - else: + if phase < 5.0: + # Batería baja crítica (<12V) -> ROJO destellante + self.pcm_volt = 10.8 + self.rpm = 800.0 + self.speed = 0.0 + self.coolant_temp = 86.0 + elif phase < 9.0: + # Batería en reposo / baja carga (12.0 - 13.2V) -> AMARILLO + self.pcm_volt = 12.4 self.rpm = 800.0 self.speed = 0.0 self.coolant_temp = 88.0 + elif phase < 16.0: + # Marcha normal -> VERDE + p = (phase - 9.0) / 7.0 self.pcm_volt = 14.2 + self.rpm = 1500.0 + p * (2600.0 - 1500.0) + self.speed = 30.0 + p * (75.0 - 30.0) + self.coolant_temp = 90.0 + p * (94.0 - 90.0) + elif phase < 21.0: + # Exigido / autopista -> AMARILLO + p = (phase - 16.0) / 5.0 + self.pcm_volt = 14.9 + p * 0.2 # 14.9 a 15.1V (Amarillo) + self.rpm = 3800.0 + p * (4800.0 - 3800.0) # 3800 a 4800 (Amarillo) + self.speed = 112.0 + p * (128.0 - 112.0) # 112 a 128 (Amarillo) + self.coolant_temp = 99.0 + p * (104.0 - 99.0) # 99 a 104 (Amarillo) + elif phase < 27.0: + # MÁXIMO ABSOLUTO (100% de escala) -> ROJO con alarma destellante + self.pcm_volt = 16.0 + self.rpm = 6000.0 + self.speed = 160.0 + self.coolant_temp = 120.0 + else: + # Retorno progresivo + p = (phase - 27.0) / 5.0 + self.pcm_volt = 16.0 - p * (16.0 - 10.8) + self.rpm = 6000.0 - p * (6000.0 - 800.0) + self.speed = 160.0 - p * 160.0 + self.coolant_temp = 120.0 - p * (120.0 - 86.0) # Correlated auxiliary telemetry self.map_psi = 10.0 + 16.0 * ((self.rpm - 800.0) / 5200.0)