A linear bicycle model of a car's lateral and yaw dynamics, written in Python. The same bicycle_model.py that's in the repository runs in your browser (through Pyodide). Change the vehicle below and watch how it handles a lane change.
Loading Python…
The model
The car is reduced to one front and one rear wheel at a constant forward speed u. Two states are left: lateral velocity v and yaw rate r. The tyres are linear, so each lateral force is cornering stiffness times slip angle:
αf = (v + a·r)/u − δ αr = (v − b·r)/u
Fyf = −Cf·αf Fyr = −Cr·αr
m·(v̇ + u·r) = Fyf + Fyr
Iz·ṙ = a·Fyf − b·Fyr
It's integrated with explicit Euler at 1 ms, then the body-frame velocities are integrated into a global path. The manoeuvre steers +δ from 0.5 to 3 s and −δ from 3 to 5.5 s. The front wheel is drawn with its steer angle exaggerated 5× so you can see it.
The handling balance comes from the understeer gradient K = m/L·(b/Cf − a/Cr), where L = a + b. A positive K understeers, and the steady-state yaw rate is r = u·δ/(L + K·u²). A negative K oversteers, and above the critical speed √(L/−K) the linear model goes unstable and the car spins. To try it, move the CG forward (shorter a) or soften the rear tyres.