用MATLAB编写下图液压控制系统的仿真程序。用MATLAB编写仿真程序,采用四阶Runge-Kutta法。 50
求仿真程序以便出仿真图,我用的是matlab7.5.0.342英文版。谢谢大家。仿真程序不知处了什么问题,大家帮忙看看。%MATLABPROGRAM%******Inpu...
求仿真程序以便出仿真图,我用的是matlab7.5.0.342英文版。谢谢大家。仿真程序不知处了什么问题,大家帮忙看看。
% MATLAB PROGRAM
% ****** Input system data ***** %调入数据文件
hynat;
% Input system function; %调入系统模型
ypfun1 = ' valve ';
ypfun = ' hysys ';
% Initialization %初始化
yref = 5000; % Referent value of system output
x0 = [0 0]; % Initial value of servo valve
y0 = [0 0 0]; % Initial value of hydraulic cylinder
u0 = 0;
t0 = 0; % Start time of simulation
tfinal = 1; % End time of simulation
tsamp = 0.01; % Sample period
h = 0.001; % Simulation step size
Y1imit = 512;
Ilimit = 40;
max_epoch = fix ( tfinal / h )-1;
t = t0;
u1 = u0;
x = x0';
y = y0;
tout = zeros ( max_epoch, 1 );
uout = zeros ( max_epoch, 1);
yd = zeros ( max_epoch, 1 );
yout = zeros ( max_epoch, legth ( y ) );
i = 1;
tout ( i ) = t;
uout ( i ) = 1;
yd ( i ) = Kf * y ( l );
yout ( i, : ) = y';
% The main loop
for i = 1 : max_epoch
% Compute output of valve
svl = feval ( ypfun1, t, u, x, av, bv );
sv2 = fcval (ypfun1, t+h/2, u, x+h*sv1/2, av, hv ); %模块valve仿真
sv3 = feval (ypfun1, t+h/2, u, x+h*sv2/2, av, hv );
sv4 = feval (ypfun1, t+h, u, x+h*sv3, av, hv);
x = x+h*(svl+2*sv2+2*sv3+sv4)/6;
vo = cv*x;
% Compute output of cylinder
xl = feval (ypfun, t, vo, y, a, b);
s2 = feval (ypfun, t+h/2, vo, y+h*s1/2, a, h); %模块hysya 仿真
s3 = feval (ypfun, t+h/2, vo, y+h*s2/2, a, b);
s4 = feval (ypfun, t+h u, vo, y+h*s3, a, b);
y = y+h* (sl+2*s2+2*s3+s4)/6;
i=i+l
t=t+h;
tout(i) =t;
uout(i) =u;
yd(i)=Kf*y(l);
yout(i, :) = y';
% Discrete control process %离散控制量计算
if abs (round (t/tsamp)-t/tsamp)<le-9
ye = yref-y(l)*Kf;
ul=Kd*ye;
% Saturation block
if ul>Ylimit
xl=ylimit ;
else if ul<-ylimit
xl =-Ylimit;
else xl = ul;
end
end
% D/A conversion
x2 = Kda*xl;
% Amplifier gain
x3=Ka*x2;
% V/I conversion
u4=Kvi*x3;
% limit of current
if u4>Ilimit
x4=Ilimit;
else if u4<-Ilimit
x4=-Ilimit;
else x4 =u4;
end
end
u = Kq*x4;
end % for discrete section
end % for main loop
% save data to file %存储仿真数据
hout = [tout uout yout];
save hout.dat hout -ascii;
plot (tout, yd, ' y');
gird;
m 函数文件
valve .m
function xd = valve (t, u, x, av, bv)
xd = av*x+hv*u;
m 函数文件
hysys. M
function yd=hysys(t, u, y, a, b)
yd = a* y+h*u 展开
% MATLAB PROGRAM
% ****** Input system data ***** %调入数据文件
hynat;
% Input system function; %调入系统模型
ypfun1 = ' valve ';
ypfun = ' hysys ';
% Initialization %初始化
yref = 5000; % Referent value of system output
x0 = [0 0]; % Initial value of servo valve
y0 = [0 0 0]; % Initial value of hydraulic cylinder
u0 = 0;
t0 = 0; % Start time of simulation
tfinal = 1; % End time of simulation
tsamp = 0.01; % Sample period
h = 0.001; % Simulation step size
Y1imit = 512;
Ilimit = 40;
max_epoch = fix ( tfinal / h )-1;
t = t0;
u1 = u0;
x = x0';
y = y0;
tout = zeros ( max_epoch, 1 );
uout = zeros ( max_epoch, 1);
yd = zeros ( max_epoch, 1 );
yout = zeros ( max_epoch, legth ( y ) );
i = 1;
tout ( i ) = t;
uout ( i ) = 1;
yd ( i ) = Kf * y ( l );
yout ( i, : ) = y';
% The main loop
for i = 1 : max_epoch
% Compute output of valve
svl = feval ( ypfun1, t, u, x, av, bv );
sv2 = fcval (ypfun1, t+h/2, u, x+h*sv1/2, av, hv ); %模块valve仿真
sv3 = feval (ypfun1, t+h/2, u, x+h*sv2/2, av, hv );
sv4 = feval (ypfun1, t+h, u, x+h*sv3, av, hv);
x = x+h*(svl+2*sv2+2*sv3+sv4)/6;
vo = cv*x;
% Compute output of cylinder
xl = feval (ypfun, t, vo, y, a, b);
s2 = feval (ypfun, t+h/2, vo, y+h*s1/2, a, h); %模块hysya 仿真
s3 = feval (ypfun, t+h/2, vo, y+h*s2/2, a, b);
s4 = feval (ypfun, t+h u, vo, y+h*s3, a, b);
y = y+h* (sl+2*s2+2*s3+s4)/6;
i=i+l
t=t+h;
tout(i) =t;
uout(i) =u;
yd(i)=Kf*y(l);
yout(i, :) = y';
% Discrete control process %离散控制量计算
if abs (round (t/tsamp)-t/tsamp)<le-9
ye = yref-y(l)*Kf;
ul=Kd*ye;
% Saturation block
if ul>Ylimit
xl=ylimit ;
else if ul<-ylimit
xl =-Ylimit;
else xl = ul;
end
end
% D/A conversion
x2 = Kda*xl;
% Amplifier gain
x3=Ka*x2;
% V/I conversion
u4=Kvi*x3;
% limit of current
if u4>Ilimit
x4=Ilimit;
else if u4<-Ilimit
x4=-Ilimit;
else x4 =u4;
end
end
u = Kq*x4;
end % for discrete section
end % for main loop
% save data to file %存储仿真数据
hout = [tout uout yout];
save hout.dat hout -ascii;
plot (tout, yd, ' y');
gird;
m 函数文件
valve .m
function xd = valve (t, u, x, av, bv)
xd = av*x+hv*u;
m 函数文件
hysys. M
function yd=hysys(t, u, y, a, b)
yd = a* y+h*u 展开
1个回答
展开全部
顶起,不大懂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询