function J = costFun_pid(gp,gc,iaeWeights,manWeights)

%global gp iaeWeights manWeights iaeTuning
global iaeTuning

% controller special
% k = x(1);
% i = x(2);
% d = x(3);
% 
% gc = k*((1-i-d)+i/tf('s')+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
