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

📄 cp8_2.m

📁 离散控制系统设计的MATLAB 代码
💻 M
字号:
%%%%%%%%%%% Comprehensive Problem 8.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('CP8.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 : design 1st-order unstable pendulum %          controller%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% locate the unstable pole at z = 1.0619disp('The poles of the system are')pole(Gz)disp('*******>'); pause% set up Kp(z)disp('Controller Kp(z)')Kp_zero = 0.96Kp_pole = 1.01Kpz = tf([1 -Kp_zero],[1 -Kp_pole],Ts)disp('*******>'); pausedisp('Root-locus plot')disp('Select Kpz to achieve a damping ratio of 0.8.')figure, ucircle, hold onrlocus(-Gz(1,1)*Kpz)dzline(0.8), hold offaxis([0.8 1.1 -0.15 0.15])[Kp_gain,ppp] = rlocfind(-Gz(1,1)*Kpz)disp('The designed pendulum controller is')% Kp_gain = 22.8; % recommended valueKpz = -Kp_gain*Kpz;disp('*******>'); pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Part C : design cart position controller%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Close the pendulum controller disp('System with pendulum loop closed')Gz_pen_CL = feedback(Gz,Kpz,1,1)disp('*******>'); pausedisp('Poles of system should include one at z = 1')pole(Gz_pen_CL)disp('Design the cart controller to move this z = 1 pole inside the unit circle')disp('*******>'); pause% use a proportional controllerdisp('Root-locus plot')disp('Select Kcz to achieve critical damping.')figure, ucircle, hold onrlocus(Gz_pen_CL(2,1)), hold offaxis([0.9 1.1 -0.05 0.05])[Kcz,ppc] = rlocfind(Gz_pen_CL(2,1))disp('*******>'); pausedisp('The closed-loop system is')% Kcz = 0.6; % recommended valueGz_CL = feedback(Gz_pen_CL*Kcz,1,1,2)disp('*******>'); pausedisp('Step response to 0.1 m step command of cart position')[y,dtime] = step(Gz_CL);figureplot(dtime,0.1*y*[180/pi 0; 0 1]); grid  xlabel('Time (sec)')ylabel('Pendulum angle (deg), cart position (m)')title('Step response of closed-loop system: pendulum (blue), cart (green)')% Donedisp('End of Comprehensive Problem CP8.2')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

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