function J = costFun(x)

global gp iaeWeights manWeights iaeTuning

% controller special
P = x(1);
I = x(2);
D = x(3);

gc = P*(1-I-D)+P*I/tf('s')+P*D*tf('s');

% Feedback loops
gey = feedback(1,gc*gp);
ged = feedback(gp*-1,gc,1);

% Output response to input and output disturbance
sys = [gey;ged];
[e,t]=step(sys,200);

iaeTuning = iae(t,e);

J = manWeights*(iaeTuning./iaeWeights);
return
