# Simulate the Time Domain for the Cruise Control Case Study with Pylab

In this cruise control case study, you can use Pylab and the SciPy function lsim() to evaluate the cruise control performance with a 4 percent grade. Note that a grade of 4 percent means rise over run of 4/100, which is equivalent to

Set *T* = 10* *s, *v*_{max} = 120 mph and *v*_{0} = 75 mph. Units conversion is handled inside cruise_control(). The loop damping factor is

(critically damped, meaning the closed-loop poles are repeated on the negative real axis, and ω* _{n}* takes on values of 0.5, 0.1, and 0.2 rad/s).

In [241]: t = arange(0,100,.01) In [242]: b,a = ssd.cruise_control(0.05,1.0,10.,75.,120.,'HED') In [243]: tv,v,xs = signal.lsim((b,a),0.04*ones(len(t)),t) In [245]: plot(tv,v) In [247]: # similarly for wn = 0.1 and 0.2

Velocity error results can be found in the following figure.

You see that at hill onset the vehicle velocity error begins to rise, meaning the actual vehicle velocity is falling below the set point value. Over time, the cruise control responds increasing the throttle setting to correct for the hill disturbance, and the velocity error drops to zero. If you increase ω* _{n}* the control loop response time decreases, thereby lowering the velocity error when the 4 percent grade onset occurs.