Init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import math
|
||||
|
||||
class Engine:
|
||||
rpm = 0
|
||||
throttle = 0
|
||||
load = 0
|
||||
instant_torque = 0
|
||||
gear = 0
|
||||
flywheel_inertia = 0
|
||||
idle_rpm = 750
|
||||
max_rpm = 6500
|
||||
|
||||
fuel_rate = 0
|
||||
afr = 0
|
||||
coolant_temp = 0
|
||||
oil_temp = 0
|
||||
|
||||
ignition_timing = 0
|
||||
|
||||
ambient_temp = 0
|
||||
altitude = 0
|
||||
intake_pressure = 0
|
||||
vehicle_mass = 0
|
||||
drivetrain_loss = 0
|
||||
|
||||
oil_pressure = 0
|
||||
turbo_boost = 0
|
||||
kr = 0
|
||||
exhaust_temp = 0
|
||||
|
||||
def start(self):
|
||||
rpm = 250
|
||||
|
||||
def update(self, throttle, load, dt):
|
||||
|
||||
if not self.running:
|
||||
return
|
||||
|
||||
self.throttle = throttle
|
||||
self.load = load
|
||||
|
||||
# Apply simplified engine RPM dynamics
|
||||
rpm_change = (throttle - load) * self.torque_curve(self.rpm) / self.flywheel_inertia
|
||||
self.rpm += rpm_change * dt
|
||||
self.rpm = max(self.idle_rpm, min(self.rpm, self.max_rpm))
|
||||
|
||||
self.torque = self.torque_curve(self.rpm) * throttle
|
||||
self.fuel_rate = self.rpm * throttle * self.fuel_efficiency
|
||||
|
||||
self._update_temps(dt)
|
||||
Reference in New Issue
Block a user