📄 cp3_1.m
字号:
%%%%%%%%%%% Comprehensive Problem 3.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 output : ball's position (xi), and % wheel's angular position (theta)disp('CP3.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 : Km(z) Proportional Control% Kb(z) Proportional Control%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Km(z) prop. control - Kb(z) prop. control'); disp(' ')for Kp1 = 0.5:0.5:5, t = [0:1:100]*Ts; Km = Kp1; disp(['Closed-loop system with Km = ',num2str(Kp1),' is : ']); G_Kmcl = feedback(Gztf*Km,1,1,2,-1) % servo CL y = step(G_Kmcl,t); figure, plot(t,0.2*y(:,2)*180/pi,'o'),grid title(['Step Response - Km = ',num2str(Kp1)]); ylabel('Wheel angle (deg)') xlabel('Time (s)') disp('*******>');pauseenddisp('Select Km = 3, giving a fast response')Km = 3;disp(['G_Kmcl with Km = ',num2str(Km),' is : ']);G_Kmcl = feedback(Gztf*Km,1,1,2,-1) % servo CLdisp('*******>');pausefigurefor Kp2 = 0.5:0.5:5, t = [0:1:1000]*Ts; Kb = Kp2; disp(['G_Kbcl with Kb = ',num2str(Kp2),' is : ']); G_Kbcl = feedback(G_Kmcl(1,1)*Kb,1,1,1) % b&b CL y_Kbcl = step(G_Kbcl,t); plot(t,0.1*y_Kbcl,'.','markersize',5),grid title(['Step Response - Kb = ',num2str(Kp2)]); ylabel('Ball position (m)') xlabel('Time (s)') disp('*******>');pauseenddisp('Note that with small proportional control gain, the')disp('response of the ball is damped but slow. At higher gain,')disp('the oscillation becomes unstable.')disp('*******>');pause; disp(' ')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part C : Km(z) proportional control % Kb(z) proportional-and-derivative control%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%disp('Km(z) prop. control - Kb(z) prop-deriv. control'); disp(' ')Km = 3;disp(['G_Kmcl with Km = ',num2str(Km),' is : ']);G_Kmcl = feedback(Gztf*Km,1,1,2,-1) % servo CLdisp('*******>');pauseKp2 = 1;Kd = 1;disp('PD controller')KbPD = tf(Kp2*[(1+Kd/Ts) -Kd/Ts],[1 0],Ts) % PD controllert = [0:1:1000]*Ts;G_PDcl = feedback(G_Kmcl(1,1)*KbPD,1,1,1) % b&b CLy_PDcl = step(G_PDcl,t);figure, plot(t,0.1*y_PDcl,'.','markersize',5), gridtitle(['Step Response using PD controller']);ylabel('Ball position (m)')xlabel('Time (s)')disp('The PD controller improves the response time and damping.')disp('*******>');pausedisp('End of Comprehensive Problem CP3.1')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -