⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cp2_1.m

📁 离散控制系统设计的MATLAB 代码
💻 M
字号:
%%%%%%%%%%% Comprehensive Problem 2.1 %%%%%%%%%%%%   Discrete-Time Control Problems using        %%       MATLAB and the Control System Toolbox   %%   by J.H. Chow, D.K. Frederick, & N.W. Chbat  %%         Brooks/Cole Publishing Company        %%                September 2002                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ball and Beam System              % System has 4 states, 1 input, and 2 outputs% 4 states : ball's position and velocity, and%            wheel's angular position and velocity% 1 input  : motor voltage (u)% 2 outputs: ball's position (xi), and %            wheel's angular position (theta)disp('CP2.1:Ball and Beam')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part A : Load model%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear; close all% Load continuous and discrete-time systemsif ~exist('bbeam.mat'),     dbbeamelseif exist('bbeam.mat') == 2,    load bbeamendTs = 0.02;  % in dbbeam alreadydisp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part B : System Orders%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% display G2 first, because it is a lower order transfer functiondisp('Transfer Function Gm(z) from u to theta')Gm = tf(dnumm,ddenm,Ts)disp('Order of Gm(z)')oGzm = length(ddenm)-1disp('*******>'); pausedisp('Transfer Function Gb(z) from u to ball''s position')Gb = tf(dnumb,ddenb,Ts)disp('Order of Gb(z)')oGbz = length(ddenb)-1disp('*******>'); pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part C : Poles%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Poles of Gm(z) are')pole(Gm)  disp('*******>'); pausedisp('Poles of Gb(z) are')pole(Gb)disp('Gb(z) and Gm(z) differ by a pole at z = 1.0 and a pole at z = 0.9970')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part D : Zeros%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Zeros of Gm(z) are')tzero(Gm) disp('Zeros of Gb(z) are')tzero(Gb)disp('Gb(z) and Gm(z) have no common zeros')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part E : Residues%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Residues at the poles of Gm(z) are')[resm,ppm,otherm] = residue(dnumm,ddenm)disp('*******>');pausedisp('Residues at the poles of Gb(z) are')[resb,ppb,otherb] = residue(dnumb,ddenb)disp('*******>'); pausedisp('ppm are the poles of Gm(z)')disp('ppb are the poles of Gb(z)')disp('Residues resm & resb are the weights of ppm & ppb.')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part F :  pulse response%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%u       =  zeros(1000,1);     % create a pulse inputu(1:5)  =  1;u(6:10) = -1;[y,k] = lsim(Gztf,u);y = y*[100 0; 0 180/pi];figure, plot(k,y,'-o')xlabel('Time (s)'); ylabel('Amplitude (deg and cm)'); grid; title('Pulse Response')legend('ball position','beam angle')disp('A pulse voltage input to the motor rotates the wheel')disp('and brings it back to the level position (green curve).')disp('The ball (blue curve) starts to roll and eventually ')disp('comes to rest because of the friction on the beam.')disp('The nonzero displacement of the ball shows the effect of the')disp('pole at z = 1, and the friction is represented by the')disp('pole z = 0.9974.')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part G :  pulse response with a gap%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%u       =  zeros(1000,1);     % create a pulse inputu(1:5)  =  1;u(11:15) = -1;[y,k] = lsim(Gztf,u);y = y*[100 0; 0 180/pi];figure, plot(k,y,'-o')xlabel('Time (s)'); ylabel('Amplitude (deg and cm)'); grid; title('Pulse Response with a gap')legend('ball position','beam angle')disp('A pulse voltage input to the motor rotates the wheel')disp('and brings it back to the level position (green curve),')disp('after a delay of 0.1 second.')disp('The ball (blue curve) starts to roll and eventually ')disp('comes to rest because of the friction on the beam.')disp('The wheel and the ball now move substantially more,')disp('because the negative pulse to reduce the beam angle is delayed.')disp('*******>'); pause; disp(' ');disp('End of Comprehensive Problem CP2.1')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -