state contains what the car is doing right now — RPM, gear, wheel slip, boost, temperatures and knock.if statements. Example: if wheel slip gets high, reduce throttle.throttle, boost_target, afr_target, timing, cooling and shift commands.if means “only do this when the condition is true.” The line underneath must be indented:
if slip > 0.10:
throttle = 0.65
Press Tab in the editor to insert four spaces. Shift+Tab removes indentation.
Do not immediately add more tire or more power. First look at 60 ft and peak slip. Try less first-gear boost, lower launch RPM, or a smoother throttle rule. The goal is controlled slip, not zero slip.
Compare your post-shift RPM with the turbo's full-boost RPM in the Garage. If every shift drops the engine below the useful boost range, try a higher shift point, shorter next gear, or a smaller turbo.
More boost makes more cylinder pressure and power, and more timing makes torque until the engine approaches MBT. Past the safe window, excess timing/boost, lean AFR, hot IAT, weak fuel support and cylinder pressure drive knock and engine damage. The fastest tune is aggressive without crossing that limit.
controller(state) many times during a pass.
state is what the sensors tell your code. Your returned dictionary is what your ECU commands back to the car.
Top-level constants such as GEAR_RATIOS configure the drivetrain before the pass starts.
| NAME | UNIT / RANGE | WHAT IT DOES | WHAT TO WATCH |
|---|---|---|---|
| GEAR_RATIOS | ratio • 0.3–6.0 each | Mechanical ratio for each forward gear. Larger number = more wheel torque but less road speed at the same RPM. | Post-shift RPM, number of shifts, trap speed. |
| FINAL_DRIVE | ratio • 1.5–6.0 | Multiplies every transmission gear. Higher final drive makes all gears shorter. | Launch traction, shift points, whether you run out of gear. |
| TIRE_PRESSURE | PSI • 10–45 | Changes modeled tire grip around the tire type's preferred pressure. | 60-foot and wheel slip. Too high or too low costs grip. |
| LAUNCH_RPM | RPM • 1200–7200 | Minimum engine RPM held during the first part of launch. | Wheel slip, turbo response, 60-foot. |
| SHIFT_TIME | seconds • 0.03–0.50 | How long torque is interrupted during a gear change. | ET and post-shift boost/RPM. Shorter is quicker but bounded by the game. |
| KEY | UNIT | WHAT IT MEANS | COMMON USE |
|---|---|---|---|
| time | seconds | Physical simulation time since the car launched. | Time-based boost ramps or launch strategies. |
| distance | meters | Distance traveled from the starting line. | Track-position based control. |
| speed | MPH | Current road speed. | Speed-based boost or safety logic. |
| rpm | RPM | Current engine speed. | Shift logic, turbo operating range. |
| gear | integer • 1+ | Current transmission gear. | Boost-by-gear and gear-specific shifts. |
| boost | PSI | Actual manifold boost currently achieved, not merely what you requested. | Spool monitoring and protection logic. |
| slip | ratio • 0 = none | Modeled excess wheel force beyond available tire grip. 0.10 is shown as roughly 10% slip. | Traction control / throttle reduction. |
| iat | °F | Intake-air temperature after charge heating/cooling. | Heat protection, boost/timing reduction. |
| coolant | °F | Engine coolant temperature. | Thermal protection. |
| oil_temp | °F | Engine oil temperature. | Thermal protection and durability. |
| egt | °F | Modeled exhaust-gas temperature. | Watching fuel/timing/boost heat load. |
| knock | 0–8 model scale | Modeled detonation risk/activity. Higher is worse and can damage the engine. | Pull timing/boost or enrich AFR. |
| tire_temp | °F | Current driven-tire temperature. Burnout quality sets the starting point. | Understanding launch grip. |
| track_temp | °F | Current track-surface temperature. | Conditions-aware tuning. |
| air_temp | °F | Ambient air temperature. | Heat / density-aware tuning. |
| humidity | % RH | Ambient relative humidity from the current race conditions. | Conditions-aware gas tuning and logging. |
| baro_kpa | kPa abs | Ambient barometric pressure converted from the current track conditions. | Altitude/weather compensation and manifold-pressure comparisons. |
| air_density | kg/m³ model | The same modeled ambient air density used by the vehicle simulation. | Weather-aware power and aero strategies. |
| engine_health | 0.0–1.0 | Remaining powertrain health. 1.0 = 100%. | Backing the tune down before more damage occurs. |
| afr_actual | AFR • GAS | Modeled measured AFR after fuel-system response and high-duty lean-out. | Fuel-system headroom and closed-loop protection. |
| lambda_actual | λ • GAS | Actual AFR normalized to gasoline stoichiometric AFR (14.7). 1.00 = stoich. | Fueling logic that is easier to reason about across rich/lean mixtures. |
| fuel_pressure | PSI • GAS | Modeled fuel-rail pressure. It rises with boost but can droop when the fuel system is overworked. | Detecting pump/injector supply problems before knock rises. |
| injector_duty | 0–1+ • GAS | Modeled injector/fuel-system utilization. Above 1.0 means commanded fuel exceeds supported flow. | Knowing when richer targets or more boost are no longer supportable. |
| map_kpa | kPa abs • GAS | Absolute intake-manifold pressure including atmospheric pressure. | Pressure-based load strategies. |
| engine_load | ratio • GAS | MAP divided by ambient barometric pressure. Roughly 1.0 at atmospheric pressure and higher under boost. | Load-indexed timing/fueling/boost logic. |
| cylinder_pressure | model index • GAS | Modeled peak cylinder-pressure index relative to the installed short-block limit. | Protecting rods/pistons/block even before knock becomes severe. |
| mbt_timing | degrees • GAS | Current modeled minimum-best-timing estimate for torque. | Advancing toward MBT without blindly adding timing. |
| turbo_speed | % model • GAS | Modeled compressor/turbo utilization based on boost and RPM. | Seeing when a turbo is being pushed near its flow region. |
| oil_pressure | PSI • GAS | Modeled oil pressure based on RPM and oil temperature. | Engine-protection logic. |
| pack_voltage | V • E-X | Live battery-pack terminal voltage after load sag. | Watching voltage sag at high current. |
| pack_current | A • E-X | Total DC pack current being delivered. | Launch/current-limit and thermal strategy. |
| front_current | A • E-X | Actual front-inverter DC current after the requested split and inverter ceiling. | Detecting front-inverter saturation and balancing axle power. |
| rear_current | A • E-X | Actual rear-inverter DC current after the requested split and inverter ceiling. | Detecting rear-inverter saturation and balancing axle power. |
| pack_power_kw | kW DC • E-X | Electrical power leaving the battery pack: pack voltage × pack current. | Comparing battery input power with delivered motor power. |
| battery_soc | % • E-X | Battery state of charge. | Power consistency and voltage management. |
| battery_temp | °F • E-X | Battery temperature. | Pack thermal derating. |
| front_motor_temp | °F • E-X | Front motor temperature. | Front power/thermal protection. |
| rear_motor_temp | °F • E-X | Rear motor temperature. | Rear power/thermal protection. |
| front_inverter_temp | °F • E-X | Front inverter temperature. | Front current derating. |
| rear_inverter_temp | °F • E-X | Rear inverter temperature. | Rear current derating. |
| front_slip | ratio • E-X | Front-axle traction slip. | Moving torque toward the rear when the front tires unload. |
| rear_slip | ratio • E-X | Rear-axle traction slip. | Moving torque toward the front when the rear axle saturates. |
| front_power_kw | kW • E-X | Mechanical power from the front motor. | Front/rear power-bias tuning. |
| rear_power_kw | kW • E-X | Mechanical power from the rear motor. | Front/rear power-bias tuning. |
| power_kw | kW • E-X | Total mechanical motor power. | Monitoring real delivered EV power. |
rpm or boost does not directly change the car. You must return an output command.| OUTPUT | ALLOWED RANGE | WHAT IT COMMANDS | NOTES |
|---|---|---|---|
| throttle | 0.0–1.0 | Requested throttle fraction. 1.0 = 100%. | Primary traction-control tool. During a shift the simulator temporarily reduces effective throttle. |
| boost_target | 0–40 PSI | Requested boost pressure. | Actual boost is still limited by turbo size, spool RPM and turbo boost cap. |
| afr_target | 9.0–16.0 AFR | Requested air/fuel ratio. | Very lean high-boost commands increase modeled knock/EGT risk. |
| timing | -5–30 degrees | Requested ignition timing value used by the power/knock model. | Advance toward MBT adds power; going beyond the safe window raises knock and can reduce power/damage the engine. |
| cooling | 0.0–1.0 | Requested cooling effort. | Helps manage IAT/coolant/oil but is still affected by installed intercooler hardware. |
| shift_up | True / False | Requests the next higher gear. | Only shifts if not already shifting and another gear exists. |
| shift_down | True / False | Requests the next lower gear. | Useful for experiments; usually False during a quarter-mile pass. |
| rev_limit | 3000–16500 RPM | Software rev-limit request. | Gas cars can use this for safety/shift experiments. Platform redline remains a hard ceiling. |
| power_request | 0.0–1.0 • E-X | Requested EV drive power/torque fraction. | Primary E-X launch and traction command; throttle remains a backwards-compatible alias. |
| front_torque_bias | 0.20–0.80 • E-X | Requested fraction of motor power sent to the front axle. | Balance front/rear slip as weight transfers rearward. |
| pack_current_limit | 200–1500 A • E-X | Maximum requested battery current. | More current gives more power but more voltage sag and heat. |
| front_current_limit | 100–650 A • E-X | Front inverter current ceiling. | Controls front motor contribution and inverter heat. |
| rear_current_limit | 100–750 A • E-X | Rear inverter current ceiling. | Controls rear motor contribution and inverter heat. |
| field_weakening | 0.0–1.0 • E-X | High-RPM field-weakening request. | Supports top-end motor speed/power but creates extra motor/inverter heat. |
| regen_strength | 0.0–1.0 • E-X | Regenerative-braking request. | Primarily useful after the finish line / future shutdown simulation; bounded now for ECU completeness. |
def controller(state):
rpm = state["rpm"] # INPUT: sensor
gear = state["gear"] # INPUT: sensor
slip = state["slip"] # INPUT: sensor
throttle = 1.0 # OUTPUT command
boost_target = 18.0 # OUTPUT command
# Reduce power only while the tire is slipping badly.
if slip > 0.10:
throttle = 0.65
# Less boost in first gear.
if gear == 1:
boost_target = 10.0
return {
"throttle": throttle,
"boost_target": boost_target,
"afr_target": 12.2,
"timing": 14.0,
"cooling": 0.4,
"shift_up": rpm >= 6750,
"shift_down": False
}
| RPM | Boost | HP | Torque | AFR | Timing | Knock | Cyl P | Fuel Duty | Fuel PSI |
|---|