diff --git a/emulator/obd2_emulator.py b/emulator/obd2_emulator.py index c224fca..8010000 100755 --- a/emulator/obd2_emulator.py +++ b/emulator/obd2_emulator.py @@ -32,25 +32,40 @@ class VehicleState: self.lock = threading.Lock() def update_simulation(self): - """Simulates driving telemetry with smooth sinusoidal variation""" + """Simulates driving telemetry with clear transitions through color zones and holds at max scale""" t = time.time() with self.lock: if self.auto_simulate: - # RPM smoothly moves between 1000 and 3600 - self.rpm = 2100.0 + 1200.0 * math.sin(t * 0.8) + 200.0 * math.cos(t * 1.7) - if self.rpm < 800: - self.rpm = 800 - # MAP pressure fluctuates with RPM - self.map_psi = 12.0 + 10.0 * ((self.rpm - 800.0) / 3000.0) + 1.5 * math.sin(t * 2.0) + # 24-second cycle: + # 0 - 8s: Ramp up 800 -> 6000 RPM (Verde -> Amarillo -> Rojo) + # 8 - 12s: Hold at MAX (6000 RPM, redline/escala máxima) for 4s + # 12 - 20s: Ramp down 6000 -> 800 RPM (Rojo -> Amarillo -> Verde) + # 20 - 24s: Hold at IDLE (800 RPM) for 4s + cycle_period = 24.0 + phase = t % cycle_period + + if phase < 8.0: + p = phase / 8.0 + self.rpm = 800.0 + p * (6000.0 - 800.0) + elif phase < 12.0: + self.rpm = 6000.0 + elif phase < 20.0: + p = (phase - 12.0) / 8.0 + self.rpm = 6000.0 - p * (6000.0 - 800.0) + else: + self.rpm = 800.0 + + # MAP pressure correlates with RPM + self.map_psi = 10.0 + 16.0 * ((self.rpm - 800.0) / 5200.0) # Engine load correlates with RPM - self.load = 20.0 + 45.0 * ((self.rpm - 800.0) / 3000.0) - # Vehicle speed correlates with RPM/gear - self.speed = 25.0 + 65.0 * ((self.rpm - 800.0) / 2600.0) + 5.0 * math.sin(t * 0.7) + self.load = 15.0 + 75.0 * ((self.rpm - 800.0) / 5200.0) + # Vehicle speed correlates with RPM (up to 175 km/h, turning RED past 130 km/h) + self.speed = 15.0 + 160.0 * ((self.rpm - 800.0) / 5200.0) if self.speed < 0: self.speed = 0.0 - # Temperatures fluctuate slightly around operating values - self.coolant_temp = 92.0 + 3.0 * math.sin(t * 0.1) - self.oil_temp = 93.0 + 1.5 * math.sin(t * 0.12) + # Coolant temp rises slightly with engine load (88°C -> 102°C, showing warn RED past 100°C) + self.coolant_temp = 88.0 + 14.0 * ((self.rpm - 800.0) / 5200.0) + self.oil_temp = 90.0 + 12.0 * ((self.rpm - 800.0) / 5200.0) self.trans_temp = 82.0 + 1.0 * math.cos(t * 0.09) self.pcm_volt = 14.2 + 0.15 * math.sin(t * 0.5)