function [inv ctrl clipped] = PID(Ir, Ic, It) 
global elast;

clipped = 0;
Kp = 0.0;  
Kd = 0*0.008;




%ctrl = It-Ic;
FF = It-Ic;
e = It-Ir;
edot = (e-elast)/.005;
elast = e;
ctrl = FF+Kp*e-Kd*edot;

ctrl = 0.5*ctrl;  %Convert to voltage representing currrent (.5A/V)

inv = -ctrl;
if(ctrl > 0)
    clipped = ctrl;
end

end

