📄 cp2_2.m
字号:
%%%%%%%%%%% Comprehensive Problem 2.2 %%%%%%%%%%%% 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Inverted Pendulum% System has 4 states, 1 input, and 2 outputs% 4 states : pendulum's angular position and velocity, and% cart's position and velocity% 1 input : motor voltage (u)% 2 outputs: pendulum's angular position (theta)% cart's position (x) disp('CP2.2: Inverted Pendulum')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part A : Load model%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear; close all% Load continuous and discrete-time systemsif ~exist('stick.mat'), dstickelseif exist('stick.mat') == 2, load stickendTs = 0.01; % in dstick alreadydisp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part B : System Orders%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% display Gp firstdisp('Transfer Function Gp(z) from u to theta')Gp = tf(dnump,ddenp,Ts)disp('Order of Gp(z)')oGp = length(ddenp)-1disp('*******>'); pause% display Gc firstdisp('Transfer Function Gc(z) from u to cart''s position')Gc = tf(dnumc,ddenc,Ts)disp('Order of Gc(z)')oGc = length(ddenc)-1disp('*******>'); pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part C : Poles%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Poles of Gp(z) are')pole(Gp) disp('*******>'); pausedisp('Poles of Gc(z) are')pole(Gc)disp('Gp(z) and Gc(z) differ by a pole at z = 1.0')disp('This is because pendulum dynamics are not affected by ')disp('the relative position of the cart. ')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part D : Zeros%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Zeros of Gp(z) are')tzero(Gp) disp('Zeros of Gc(z) are')tzero(Gc)disp('Gp(z) and Gc(z) have a common zero at -0.9453')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part E : Residues%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Residues at the poles of Gp(z) are')[resp,ppp,otherp] = residue(dnump,ddenp)disp('*******>');pausedisp('Residues at the poles of Gc(z) are')[resc,ppc,otherc] = residue(dnumc,ddenc)disp('*******>'); pausedisp('ppp are the poles of Gp(z)')disp('ppc are the poles of Gc(z)')disp('Residues resp & resc are the weights of ppp & ppc.')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part F : step response%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[y,k] = step(Gztf);y = y*[180/pi 0; 0 100];figure, stem(k,y)xlabel('Time (s)'); ylabel('Amplitude (deg and cm)'); grid; title('Step Response')legend('pendulum angle','cart position',3)disp('A step voltage input to the motor moves the cart') disp('(green curve) forward. As a result, the pendulum (blue')disp('curve) falls backward or rotates in the negative direction.')disp('*******>'); pause; disp(' ');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part G : impulse response %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[y,k] = impulse(Gztf);y = y*[180/pi 0; 0 100];figure, stem(k,y)xlabel('Time (s)'); ylabel('Amplitude (deg and cm)'); grid; title('Impulse Response')legend('pendulum angle','cart position',3)disp('An impulse voltage input to the motor moves the cart') disp('(green curve) forward. As a result, the pendulum (blue')disp('curve) falls backward or rotates in the negative direction.')disp('The motion is less than that due to the step input.')disp('*******>'); pause; disp(' ');disp('End of Comprehensive Problem CP2.2')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -