Matlab function in Simulink
Mostrar comentarios más antiguos
Hello,
I have problem with MATLAB function in Simulink - after Run values are always zero, while other parts of code (built in PID controller) are working quite good.
function PWMout = myPID(valTarget,valPres, kp, ki, kd, Td, Ts,errorPrev,...
PIDoutMax, PIDoutMin, errorTolerance)
upperBound = PIDoutMax - (PIDoutMax*(1-errorTolerance));
lowerBound = PIDoutMin - (PIDoutMin*(1-errorTolerance));
errPres = valTarget - valPres;
Pout = kp*(errPres - errorPrev);
Iout = ki*errPres;
Dout = kd*(Td/Ts)*(errPres - (2*errorPrev) + ...
+ errorPrev);
PIDoutTemp = Pout + Iout + Dout;
PWMout = PIDoutTemp;
errorPrev = errPres;
end


7 comentarios
Ameer Hamza
el 3 de Oct. de 2020
Try adding a breakpoint inside the function to see whether what is causing the output to remain zero. https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html
Ameer Hamza
el 3 de Oct. de 2020
Can you attach the model?
Ameer Hamza
el 4 de Oct. de 2020
I tried running the model. The brakpoint is working and it does give non zero value in PWMout.
ps19
el 5 de Oct. de 2020
Ameer Hamza
el 6 de Oct. de 2020
Btw, look at persistent variables. You will need that to properly save PID values from the last step inside the function block.
Respuestas (0)
Categorías
Más información sobre Programmatic Model Editing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!