%% PID Controller example, taken from MATLAB tutorial http://ctms.engin.umich.edu/
% m = vehicle mass 1000kg 
% b = damping coefficient 50 N.s/m
% r = reference speed 28 m/s
m = 1000;
b = 50; 
r = 28; % roughly 100 m/h or 63 mph

% s = tf('s') to specify a TF model using a rational function in the 
% Laplace variable, s. It takes a function of a positive real variable t 
% (often time) to a function of a complex variable s (frequency).
s = tf('s'); 
P_cruise = 1/(m*s + b);

Kp = 1700;
Ki = 20;
Kd = 5;
C = pid(Kp,Ki,Kd);

t = 0:0.1:20;
T = feedback(C*P_cruise,1);
step(r*T,t)
axis([0 20 0 40]);