|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
关于离散PID的大量程序中的P,I,D,参数初始值不明白怎么来的。求助大神!
8 I: l. y6 k/ n8 j) C5 ^/ l Vclear all;. I) t- `9 s3 ^8 |4 ? e
close all;
8 e) y4 f; z8 v( @- {1 }. V7 Qts=0.001;
+ `" y* W. D$ W) D M9 ]1 n% y* \sys=tf(400,[1,50,0]);" ]1 g3 U+ y s2 A3 w
dsys=c2d(sys,ts,'z');2 B: o% |6 Z' g
[num,den]=tfdata(dsys,'v');7 b6 s* S* C0 g, e6 R, |/ h6 i& v
u_1=0.0;u_2=0.0;u_3=0.0;. [! @5 V2 J1 c) `# l
y_1=0;y_2=0;y_3=0;( {' o) R0 A$ d6 f( ^4 b
x=[0,0,0]';
. z. |& M2 ^7 j- a X7 gerror_1=0;9 d7 t; d J- `( i3 O
error_2=0;
& L! P6 K/ }5 {6 |0 F3 |3 \7 }for k=1:1:1000
- G; x! @6 i \' P7 |4 A& Q; W7 e time(k)=k*ts;* D7 h2 s- }: i3 i7 t
9 O9 `" A4 B g% X6 ?3 ` yd(k)=1.0;
- v$ J8 V8 C4 r kp=8;
( ?9 Y5 U: H1 y& i, M ki=0.10;(请问这三个参数的初始值怎么确定的). {. P' s& ^# e2 b/ A- i
kd=10;/ Q/ @; F/ O% g0 [( }
: b: f6 A5 z* B) t, r5 L du(k)=kp*x(1)+kd*x(2)+ki*x(3);( Z" ?8 y4 ^1 w. f5 D, n' k" j
u(k)=u_1+du(k);
% k9 d: [1 x/ f V6 M. ~( S if u(k)>=10" T- k- n; _! @4 U8 X
u(k)=10;
2 [$ F& {" F. j& U end6 j9 M$ Z# a* L4 H1 x
if u(k)<=-10
; ?$ [6 G4 J, Q0 O( g0 ]9 d u(k)=-10; k6 ~2 J) a. x9 o; I- d
end ( \3 w2 F3 M6 B
y(k)=-den(2)*y_1-den(3)*y_2+num(2)*u_1+num(3)*u_2;
3 `- p# ?+ [3 Z$ a* h3 h
* p: k1 i1 l) X5 X2 f! F4 M1 u error=yd(k)-y(k);+ O* _( e* ]9 m c( Q
u_3=u_2;u_2=u_1;u_1=u(k);* s, g$ g: a5 e
y_3=y_2;y_2=y_1;y_1=y(k);4 C" x# P4 F3 @* u/ {# q
( s% _% h+ W9 b% z! c* @4 S& f7 T
x(1)=error-error_1; %Calculating P
3 V4 H! n* d- @, p x(2)=error-2*error_1+error_2; %Calculating D
) h7 u* s$ Q- A5 g, g! k# B x(3)=error; %Calculating I
. m& j" e6 _6 c# e
8 m9 s" @0 R M7 M. G error_2=error_1;) R1 {; @) R7 s" T+ \
error_1=error;
' O+ x. j N5 P+ }. i$ Y" ]/ Rend; j1 V6 ~1 c0 u# x D% H) F4 E3 g
figure(1);
4 o6 U) G7 m/ @; b# Q+ iplot(time,yd,'r',time,y,'k:','linewidth',2);
/ W4 o. a2 g/ W; _- z4 Rxlabel('time(s)');ylabel('yd,y');
8 F- V2 G+ b& g: B2 W, Glegend('Ideal position signal','Position tracking')( |9 [0 O6 e, {$ z$ K
|
|