필터 지우기
필터 지우기

PID Matlab scripts is not running

조회 수: 1 (최근 30일)
germanbrain common
germanbrain common 2020년 12월 31일
댓글: Walter Roberson 2020년 12월 31일
%Closed loop Algorthim
%Error=Setpoint -Feedback
%Setpoint:5
%Feedback:0,1,2,3,4,5(my assumption)
previous_error=0;
integral=0;
kp=1;
ki=1;
kd=1;
sp=[5,5,5,5,5,5];
fb=[0,1,2,3,4,5];
error=[5,4,3,2,1,0];
dt=[0,1,2,3,4,5]
error=sp-fb
integral=(integral + error) * dt
derivative= (error - previous_error) / dt
output=(er*kp)+(ki*integral)+(kd*derivative)
previous_error= error
plot(output,dt)

답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 31일
Change all * to .* and all / to ./
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 12월 31일
format long g
%Closed loop Algorthim
%Error=Setpoint -Feedback
%Setpoint:5
%Feedback:0,1,2,3,4,5(my assumption)
previous_error=0;
integral=0;
kp=1;
ki=1;
kd=1;
sp=[5,5,5,5,5,5];
fb=[0,1,2,3,4,5];
error=[5,4,3,2,1,0];
dt=[0,1,2,3,4,5]
dt = 1×6
0 1 2 3 4 5
error=sp-fb
error = 1×6
5 4 3 2 1 0
integral=(integral + error) .* dt
integral = 1×6
0 4 6 6 4 0
derivative= (error - previous_error) ./ (dt+(dt==0)/5)
derivative = 1×6
25 4 1.5 0.666666666666667 0.25 0
output=(error.*kp)+(ki.*integral)+(kd.*derivative)
output = 1×6
30 12 10.5 8.66666666666667 5.25 0
previous_error= error
previous_error = 1×6
5 4 3 2 1 0
plot(dt,output)
The (dt+(dt==0)/5) clause is effectively: dt if dt is non-zero, 1/5 if dt is zero. It is there to prevent division by 0, which would give infinity. The 1/5 was chosen arbitrarily to not skew the plot too high but stil emphasize that the value is much higher than the others.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by