필터 지우기
필터 지우기

PID implementation using code

조회 수: 4 (최근 30일)
Sanjeet Kulkarni
Sanjeet Kulkarni 2022년 11월 24일
댓글: Sanjeet Kulkarni 2022년 11월 28일
I have implemented a PID controller using simulink pid block for a system. I was trying to implement the same thing using a PID code (formula) in a matlab function block and compare the performances. However, I am getting differences in both the cases. Unable to figure out where exactly is the problem.
For simulink block I have implemented antiwindup, similarly I have done it in the code.
PID code as in the matlab function is as below:
function y = fcn(error,kp,ki)
dt = sampletime;
persistent integral newintegral
if isempty(integral)
integral = 0;
end
if isempty(newintegral)
newintegral = 0;
end
newintegral = integral + (error*dt);
output = kp*error + ki * integral;
if output>48000
output=48000;
elseif output<3000
output =3000;
else
integral = newintegral;
end
y = output;
Is there anything that I am implementing wrong in the code? Requesting some help/direction.
Thank you

답변 (1개)

Sam Chak
Sam Chak 2022년 11월 25일
Wouldn't it be simpler if you obtain the signal directly from the Integrator block, and then feed it into the MATLAB function block? Something like this
function y = fcn(err, errint, Kp, Ki)
where err is the error signal and errint is the intergral of error signal.
  댓글 수: 3
Sam Chak
Sam Chak 2022년 11월 25일
Two questions.
Does your Anti-Windup involve some sort of integration but not the Integral action of the PID controller?
Is "integral" as a special variable or the built-in MATLAB integral function?
Sanjeet Kulkarni
Sanjeet Kulkarni 2022년 11월 28일
I have used the clamp method of antiwindup, where in the integral action should be clamped to the maximum and mininum limits of the actuator.
Have declared integral as a persistent variable (not the built in function).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 PID Controller Tuning에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by