% Simple second-order system
s = tf('s');

% Can we speed this up?
% Values from FPE section 4.3.1
plant = 1 / (s^2 + 1.4*s + 1);

% Can we eliminate the overshoot?
% num = [300];
% den = [1, 4, 813];

kp = 200; % Proportional constant
kd = 120;
ki = 10;

pid = s*kd + kp + ki/s;

% Combined PID controller and plant
combined = series(pid, plant);

% Complete feedback system
% MATLAB assumes negative feedback by default
full = feedback(combined, 1);

% Plot step response
tfinal = 0.2;
t = linspace(0, tfinal, 100);
orig = step(plant, t);
compensated = step(full, t);

close all;
plot(t, orig, t, compensated);
hold on;
plot([0, tfinal], [1, 1], ':k');