成绩北京航空航天大学
自动控制原理实验报告
学院仪器科学与光电工程学院
专业方向惯性技术与导航仪器
班级
学号
学生姓名尧爸爸
指导教师
自动控制与测试教学实验中心
实验四控制系统数字仿真
目录
一、实验目的 (3)
二、实验内容 (3)
三、理论计算 (3)
1.求解ζ和主导极点所对应角度β (3)
2.用matlab绘制系统的根轨迹并找到主导极点 (3)
3.求解K值 (4)
四、计算机仿真 (5)
1. 实验程序 (5)
①四阶龙格库塔计算函数:RgKta.m (5)
②stepspecs.m (5)
③主程序test.m (7)
2. 超调量和ts (8)
3.阶跃响应曲线 (8)
五.实验总结 (9)
一、 实验目的
通过本实验掌握利用四阶龙格——库塔法进行控制系统数字仿真的方法,并分析系统参数改变对系统性能的影响。
二、 实验内容
已知系统结构如图4-1 :
图4-1
若输入为单位阶跃函数,计算当超调量分别为5%,25%,50%时K 的取值(用主导极点方法估算),并根据确定的K 值在计算机上进行数字仿真。
三、 理论计算
1.求解ζ和主导极点所对应角度β
①根据公式:%100%e
πξσ-=⨯,可以解得相应的ξ
2.用matlab 绘制系统的根轨迹并找到主导极点
由cos β=ξ,过原点做倾角为180-β的直线,与系统根轨迹的交点即为系统主导极点。
代码如下:
%%绘制跟轨迹和主导极点所在位置
%
hold on;
num=[1];
dun=[1,10,25,0];
rlocus(num,dun)
t=-4:0.001:0;
y1=-t*tan(46.37/57.3);
y2=-t*tan(66.19/57.3);
y3=-t*tan(77.555/57.3);
plot(t,y1,t,y2,t,y3);
3.求解K值
由模值方程K∗=s−p1|s−p2||s−p3|可解K
四、计算机仿真
1. 实验程序
①四阶龙格库塔计算函数:RgKta.m
%RgKta.m
%功能:进行龙格库塔计算。
(A,B,C,D)为系统的系数矩阵,x0为输入,h为仿真步长,
%r为输入信号幅值,t0为仿真的起始时间,tf为终止时间;t为仿真时间,y为系统输出
function [t,y]=RgKta(A,B,C,D,x0,h,r,v,t0,tf);
x=x0;
y=0;
t=t0;
for i=1:tf/h
K1=A*x+B*r;
K2=A*(x+h*K1/2)+B*r;
K3=A*(x+h*K2/2)+B*r;
K4=A*(x+h*K3)+B*r;
x=x+h*(K1+2*K2+2*K3+K4)/6;
y=[y;C*x];
t=[t;t(i)+h];
end
②stepspecs.m
function [os,ts,tr]=stepspecs(t,y,yss,sp)
%STEPSPECS System Step Response Specifications.
% [OS,Ts,Tr]=STEPSPECS(T,Y,Yss,Sp) returns the percent overshoot OS, % settling time Ts, and rise time Tr from the step response data contained
% in T and Y.
% Y is a vector containing the system response at the associated time % points in the vector T. Yss is the steady state or final value of the % response.
% If Yss is not given, Yss=Y(end) is assumed. Sp is the settling time % percentage.
% If Sp is not given, Sp = 5% is assumed. The settling time is the time it
% takes the response to converge within +-Sp percent of Yss.
% The rise time is assumed to be the time for the response to initially % travel from 10% to 90% of the final value Yss.
% D.C. Hanselman, University of Maine, Orono, ME 04469
% Mastering MATLAB 7
% 2005-03-20
%--------------------------------------------------------------------------
N=length(y);
if y(1)>0
y1=mean(y(1:floor(0.01*N)));
y=y-y1;
end
if nargin<2
error('At Least Two Input Arguments are Required.')
end
if numel(t)~=length(t) || numel(y)~=length(y)
error('T and Y Must be Vectors.')
end
if nargin==2
yss=y(end);
yss=mean(y(floor(0.9*N):N));
sp=5;
elseif nargin==3
sp=5;
end
if isempty(yss)
yss=mean(y(floor(0.9*N):N));
end
if yss==0
error('Yss Must be Nonzero.')
end
if yss<0 % handle case where step response may be negative
y=-y;
yss=-yss;
end
t=t(:);
y=y(:);
% find rise time using linear interpolation
idx1=find(y>=0.1*yss,1);
idx2=find(y>=0.9*yss,1);
if isempty(idx1) || idx1==1 || isempty(idx2)
error('Not Enough Data to Find Rise Time.')
end
alpha=(yss/10-y(idx1-1))/(y(idx1)-y(idx1-1));
t1=t(idx1-1)+alpha*(t(idx1)-t(idx1-1));
alpha=(9*yss/10-y(idx2-1))/(y(idx2)-y(idx2-1));
t2=t(idx2-1)+alpha*(t(idx2)-t(idx2-1));
tr=t2-t1;
③主程序test.m
%test.m
%功能:仿真计算当超调量为5%,25%,50%的K值,求解调节时间,并画出阶跃响应曲线
y=[0 0];
k=1;
while max(y)<=1.5%%1.05(5%超调),1.25(25%超调),1.5(50%超调)
num1=[k];
den1=[1 10 25 0];
[num,den]=feedback(num1,den1,1,1);
[A,B,C,D]=tf2ss(num,den);
x0=[0;0;0];
v=1;
tf=10;
t0=0;
h=0.1;
r=1;
[t,y]=RgKta(A,B,C,D,x0,h,r,v,t0,tf);
k=k+1;
end
[os,ts,tr]=stepspecs(t,y,y (end),5)
2. 超调量和ts
由stepspecs函数得出下图中仿真部分数据,并和理论值比较。
3.阶跃响应曲线
图4-2 超调量为5%时的系统阶跃响应曲线
图4-3 超调量为25%时的系统阶跃响应曲线
图4-4 超调量为50%时的系统阶跃响应曲线
五.实验总结
本次实验中,先通过对Runge-Kutta法推导过程的学习,了解了其原理,通过实验指导中给出的教程,运用四阶Runge-Kutta法,通过matlab编程,实现了给定系统对阶跃信号的仿真,通过与理论值的对比,得出了其算法的优越性。
而对理论值的计算也让我掌握了根轨迹法的matlab实现,对其的感性认识进一步加深。