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

📄 cnf.m

📁 hard disk drive servo control tools, it is very helpful
💻 M
📖 第 1 页 / 共 5 页
字号:
function cnf

%   This is a MatLab-based Toolkit for Composite Nonlinear Feedback (CNF) control.
%   Author(s): HDD Servo Group, 
%   The Department of Electrical and Computer Engineering
%   National University of Singapore
%   Copyright 2004/3/31 22:18:28, Version: 1.0  
%   Copyright 2005/4/28 22:18:28, Revised Version: 1.1  
%   Copyright 2005/9/28 22:18:28, Version: 2.0 for nonlinear zero dynamics.
%   

%  Create a persistent variable to hold data required by the toolbox
persistent CnfFigHdl

%---Return if the figure is already open
%---(only allow 1 instance of the toolkit)
if ishandle(CnfFigHdl)
   Msgbox('An instance of CNF Toolkit is already running.','CNF Toolkit');
   return;
end

%*************************************************************************
 
Params = struct(...
   'hBorder', 0.01,...
   'vBorder', 0.01,...
   'ButtonW', 0.1,...
   'ButtonH', 0.04,...
   'EditW',   0.12,...
   'EditH',   0.028,...
   'TextH',   0.028,...
   'TextW',   0.12,...
   'TextWL',  0.2,...
   'StdUnit','normalized ',...
   'BgColor', [.7 .7 .8],...
   'StdColor',[.6 .7 .8] );   %get(0,'DefaultUIControlBackground')

% Create the main GUI
set(0,'Units','normalized');
CnfFigHdl = figure( ...
    'Name','The CNF Control Toolkit  Version 2.0 - Developed by a Research Team at National University of Singapore', ...
    'Units',Params.StdUnit, ...
    'Position',[0.0,0.0, 1, 0.9],...  %[0.0,0.03, 1, 0.92]
    'IntegerHandle','off', ...
    'NumberTitle','off', ...
    'DoubleBuffer','on', ...
    'Visible','off', ...
    'MenuBar','none', ...
    'HandleVisibility','callback',...
    'CloseRequestFcn',@Menu_Close_Callback,...
    'Color', Params.BgColor, ...  
    'DefaultAxesFontSize',7,...
    'DefaultTextFontSize',7);
%    'DeleteFcn',@localCloseButton,...
%    'BackgroundColor',[1 1 1], ...


centerfig(CnfFigHdl);

cnfdb = struct(...
    'Figure',CnfFigHdl, ...
    'sys_ok', 0, ...
    'ctrl_ok',0, ...
    'Running',0, ...
    'ErrorBound',2, ...
    'ErrorInPercent',1, ...
    'SetPoint','1', ...
    'StepSize',0.1, ...
    'StopTime',10, ...
    'Entry',struct( ...
    'x0','[0;0]', ...
    'A', '[0 1;0 0]', ...
    'B', '[0;1]', ...
    'C1','[1 0]', ...
    'C2','[1 0]', ...
    'D2','[0]', ...
    'E','', ...
    'Um','1', ...
    'RM','', ...
    'F','', ...
    'K',''), ...
    'System',struct( ...
    'Name','Sample system', ...
    'x0',[], ...
    'A',[], ...
    'B',[], ...
    'C1',[], ...
    'C2',[], ...
    'D2',[], ...
    'DT_in',0, ...
    'DT_E',[0;0], ...
    'DT_w','0', ...
    'CS_in',1, ...
    'CS_Umax',1, ...
    'RM_in',0, ...
    'RM',zpk(1), ...
    'QD_in',0, ...   
    'QD_Fcn','', ...   % dot(q)=f(q,h);
    'Q0',0, ...        % q(0)    
    'NL_in',0, ...
    'NL_Fcn',''), ...
    'Controller',struct( ...
    'ctrl_type', 0, ...
    'FB_choice', 3, ...   % pole placement
    'FB_poles',[1  0.3  1.5 -0.01], ...
    'FB_F',[0 0], ...
    'FB_G',[0], ...
    'FB_Ge',[0;0], ...
    'FB_H',[0], ...
    'OV_type', 2 , ...    % reduced order observer
    'OV_choice',3, ...    % butterworth pattern
    'OV_poles',[1 5], ...
    'OV_K',[0; 0], ...
    'OV_Ao',[0], ...
    'OV_Bo',[0], ...
    'OV_Co',[0], ...
    'OV_Do',[0], ...
    'OV_K1',[0], ...
    'OV_K2',[0], ...
    'CNF_F',[0 0], ...
    'CNF_P',diag([]), ...
    'CNF_W',[1 1], ...
    'CNF_Alpha', 1, ...
    'CNF_Beta', 3, ...
    'CNF_Rho_Fcn', 'exp(-Alpha*abs(h-r))', ...
    'CNF_Rho', 1, ...
    'FT_in',0, ...
    'FT_Fcn','', ...
    'IC_in', 0, ...
    'NC_in', 0, ...
    'NC_Fcn',''), ...
    'Simulink',struct( ...
    'Model','cnf_sim', ...
    'GetData','cnf_sim/Get Data', ...
    'CS_Block','cnf_sim/Saturation', ...
    'CS_Block1','cnf_sim/Saturation1', ...
    'Target','cnf_sim/Target Fcn', ...
    'DT_w','cnf_sim/DT Fcn', ...
    'DT_E','cnf_sim/DT Gain E', ...
    'Sys','cnf_sim/Kernel System', ...
    'Sys_B','cnf_sim/Input Gain B', ...
    'Sys_C1','cnf_sim/Measure Gain', ...
    'Sys_C2','cnf_sim/Output Gain', ...
    'Sys_D2','cnf_sim/Output Gain D2', ...
    'RM_Model','cnf_sim/RM Model', ...
    'FT_Model','cnf_sim/Filter', ...
    'NL_Fcn','cnf_sim/NL Fcn', ...
    'NC_Fcn','cnf_sim/NC Fcn', ...
    'QD_Fcn','cnf_sim/QD Fcn', ...
    'QD_Int','cnf_sim/QIntegrator', ...
    'QDK',   'cnf_sim/QGain', ...
    'Int_gain','cnf_sim/Int_gain', ...
    'Observer','cnf_sim/Observer', ...
    'OV_K1','cnf_sim/Gain K1', ...
    'OV_K2','cnf_sim/Gain K2', ...
    'FB_F','cnf_sim/Feedback Gain F', ...
    'FB_H','cnf_sim/Feedback Gain H', ...
    'FB_Ge','cnf_sim/Steady Gain Ge', ...
    'CNF_F','cnf_sim/CNF Gain Fn', ...
    'CNF_Rho_Fcn','cnf_sim/Rho Fcn', ...
    'CNF_Beta','cnf_sim/CNF_Beta', ...
    'CNF_Rho_offset','cnf_sim/Rho offset'));

% Widget database
ud = struct('Figure',CnfFigHdl,...
    'Handles',[],...
    'Handles2',[],...
    'WM_size',0,...
    'WM_slider',[],...
    'Display',struct( ...
    'xdata',[], ...
    'time_val', [],...    
    'ref_val', [],...
    'out_val', [],...
    'con_val', [],...
    'SysDiagramHandle',[],...
    'GraphHandles',[], ...
    'rLineHandles',[], ...
    'hLineHandles',[], ...
    'xLineHandles',[], ...
    'uLineHandles',[], ...    %    'LineHandles',[], ...
    'LineWidth', 2,...
    'LineStyle','-',...
    'LineColorR', 'b',...
    'LineColorY', 'm',...  % not used
    'LineColorU', 'r'),...
    'StartFcn',@button_Start_Callback,...
    'StopFcn',@button_Stop_Callback);

% setup the menu bar

menu_load_handle = uimenu(CnfFigHdl,'Label','Load data', 'Callback',{@Menu_Load_Data});
menu_save_handle = uimenu(CnfFigHdl,'Label','Save data','Callback',{@Menu_Save_Data});

% uimenu(CnfFigHdl,'Label','Export model','Callback',{@Menu_Export_Model});
menu_export_handle = uimenu(CnfFigHdl,'Label','Export controller','Callback',{@Menu_Export_Controller});

menu_locus_handle = uimenu(CnfFigHdl,'Label','Root locus','Callback',{@Menu_Rlocus_Callback});
menu_bode_handle = uimenu(CnfFigHdl,'Label','Bode plot', 'Tag','Bode', 'Callback',{@Menu_Bode_Nyquist});
menu_nyquist_handle = uimenu(CnfFigHdl,'Label','Nyquist plot', 'Tag','Nyquist', 'Callback',{@Menu_Bode_Nyquist});
menu_sensitivity_handle = uimenu(CnfFigHdl,'Label','Sensitivity functions', 'Tag','Sensitivity', 'Callback',{@Menu_Bode_Nyquist});

uimenu(CnfFigHdl,'Label','Print','Callback',{@Menu_Print_Callback});
% uimenu(CnfFigHdl,'Label','Help','Callback',{@Menu_Help_Callback});
uimenu(CnfFigHdl,'Label','Close','Callback',{@Menu_Close_Callback});

% setup the context menu for axes/plot
ctmenu=uicontextmenu('Parent',CnfFigHdl);

top=0.99;
frmBorder=0.01;

frmLft = 0.08;
frmWid = 0.5;
frmHt  = 0.3;
frmBtm = top-frmBorder-frmHt;
frmRight = frmLft + frmWid;  % to be used later for button position

frmPos   = [frmLft frmBtm frmWid frmHt];

% set up the axes for displaying simulation results
% for state variabls
ud.Display.GraphHandles(3) = axes( ...
    'Parent',CnfFigHdl, ...
    'UIContextMenu', ctmenu, ...
    'Units','normalized', ...
    'Position',frmPos, ...
    'XLim',[0 200], ...
    'YLim',[-1.1 1.5], ...
    'XTick',[0:50:200], ...
    'YTick',[-1.0 -0.5 0 0.5 1.0 1.5], ...
    'XGrid','on', ...
    'YGrid','on', ...        
    'Box','on',...
    'FontSize',8);

% for output
frmHt  = 0.28;
frmBtm = frmBtm - 2*frmBorder-frmHt;
frmPos = [frmLft frmBtm frmWid frmHt];
ud.Display.GraphHandles(1) = axes( ...
    'Parent',CnfFigHdl, ...
    'UIContextMenu', ctmenu, ...
    'Units','normalized', ...
    'Position',frmPos, ...
    'XLim',[0 200], ...
    'YLim',[-1.1 1.5], ...
    'XTick',[0:50:200], ...
    'YTick',[-1.0 -0.5 0 0.5 1.0 1.5], ...
    'XGrid','on', ...
    'YGrid','on', ...        
    'Box','on',...
    'FontSize',8);

% for control signal
frmHt=0.26;
frmBtm = frmBtm - 2*frmBorder-frmHt;
frmPos = [frmLft frmBtm frmWid frmHt];
ud.Display.GraphHandles(2) = axes( ...
    'Parent', CnfFigHdl, ...
    'UIContextMenu', ctmenu, ...
    'Units','normalized', ...
    'Position',frmPos, ...
    'XLim',[0 200], ...
    'YLim',[-1.1 1.5], ...
    'XTick',[0:50:200], ...
    'YTick',[-1.0 -0.5 0 0.5 1.0 1.5], ...
    'XGrid','on', ...
    'YGrid','on', ...        
    'Box','on',...
    'FontSize',8);


% XLabelHdl = get(cnfdb.Display.GraphHandles(1),'XLabel');
% set(XLabelHdl,'String','Time (seconds)','FontSize',7);
YLabelHdl = get(ud.Display.GraphHandles(1),'YLabel');
set(YLabelHdl,'String','System Output','FontSize',8);
% TitleHdl = get(cnfdb.Display.GraphHandles(1),'Title');
% set(TitleHdl,'String', ['The controlled output of ',cnfdb.System.Name] );

XLabelHdl = get(ud.Display.GraphHandles(2),'XLabel');
set(XLabelHdl,'String','Time (seconds)','FontSize',8,'HorizontalAlignment','Right');
YLabelHdl = get(ud.Display.GraphHandles(2),'YLabel');
set(YLabelHdl,'String','Control Signal','FontSize',8);

YLabelHdl = get(ud.Display.GraphHandles(3),'YLabel');
set(YLabelHdl,'String','State Variables','FontSize',8);   %, 'Color', 'b'


% % Create the lines that will plot the result (r,y,u) from the simulation
% ref_val  = [0];
% out_val  = [0];
% con_val  = [0];
% time_val = [0];
% x_val = [0];
% 
% ud.Display.rLineHandles(1) = line(...
%     'Parent',ud.Display.GraphHandles(1),...
%     'YData',ref_val,...
%     'XData',time_val,...
%     'LineStyle',':',...
%     'LineWidth',ud.Display.LineWidth,...
%     'Color',ud.Display.LineColorR,...
%     'EraseMode','normal');
% 
% ud.Display.hLineHandles(1) = line(...
%     'Parent',ud.Display.GraphHandles(1),...
%     'YData',out_val,...
%     'XData',time_val,...
%     'LineStyle',ud.Display.LineStyle,...
%     'LineWidth',ud.Display.LineWidth,...
%     'Color',ud.Display.LineColorY,...
%     'EraseMode','normal');    
% 
% ud.Display.uLineHandles(1) = line(...
%     'Parent',ud.Display.GraphHandles(2),...
%     'YData',con_val,...
%     'XData',time_val,...
%     'LineStyle','-',...
%     'LineWidth',ud.Display.LineWidth,...
%     'Color',ud.Display.LineColorU,...
%     'EraseMode','normal');    
% 
% ud.Display.xLineHandles(1) = line(...
%     'Parent',ud.Display.GraphHandles(3),...
%     'YData',x_val,...
%     'XData',time_val,...
%     'LineWidth',ud.Display.LineWidth,...
%     'Color','b',...
%     'EraseMode','normal');    
% 
% ud.Display.xLineHandles(2) = line(...
%     'Parent',ud.Display.GraphHandles(3),...
%     'YData',x_val,...
%     'XData',time_val,...
%     'LineWidth',ud.Display.LineWidth,...
%     'Color','g',...
%     'EraseMode','normal');    
% 
% % Create a legend and handles to the line colors
% % [Lgd,LgdL1,LgdL1C1] = 
% legend(ud.Display.GraphHandles(1),'r','h',4);
% % ud.Display.LegendHandles = LgdL1C1;
% legend(ud.Display.GraphHandles(3),'x1','x2',4);


% setup the Simulation console

TextH = Params.TextH;
TextW = Params.TextW;
TextWL = Params.TextWL;
EditH = Params.EditH *1.1;
EditW = Params.EditW;

Y = top ;   
Vgap = EditH ;  % * 1.1

frmLft = frmLft + frmWid + 0.025;
X0 = frmLft + Params.hBorder*1.5;
X = X0 + TextW;
X1 = X + EditW + Params.hBorder/2;

% uicontrol('Parent',CnfFigHdl, ...
%     'Unit',Params.StdUnit,...
%     'Position',[X0,Y0, TextWL  TextH*1.2], ...
%     'ForegroundColor',[0.6 0.6 0.3],...  % 'k'
%     'String','Simulation Panel', ...
%     'Style','text',...
%     'Fontsize',13,...
%     'FontWeight','bold',...
%     'HorizontalAlignment','left');


% frmLft =  X0-Params.hBorder*2;
frmWid = 1-Params.hBorder-frmLft;
frmHt  = 0.2;
frmBtm = Y-frmBorder-frmHt;
% frmRight = frmLft + frmWid;  % to be used later for button position

bg_panel=[.6 .7 .8];
frmPos   = [frmLft frmBtm frmWid frmHt];
ud.Display.SysDiagramHandle = axes( ...
    'Parent',CnfFigHdl, ...
    'Position',frmPos,...
    'Color', Params.StdColor, ...
    'XColor',[.5 .5 .75], ...
    'YColor',[.5 .5 .75], ...
    'XLim',[0 10], ...
    'XTick',[], ...
    'YLim',[0 5], ...
    'YTick',[], ...
    'Box','on', ...
    'Visible','on');

% draw the block diagram of the whole system
cnf_diagram(ud.Display.SysDiagramHandle,'All');


Y=Y-frmHt -frmBorder*1.2;
% draw the frame
% frmLft = X0-Params.hBorder;
frmBot = Vgap/2;
frmWid = 1-Params.hBorder-frmLft;
frmHt = Y-frmBot;
ud.Handles.axes_Panel=axes('Parent',CnfFigHdl, ...
    'Position',[frmLft frmBot frmWid frmHt],...
    'Color', Params.StdColor, ...  %  [.7 .7 .75]
    'XColor', [.5 .5 .75], ...  % 'w'
    'YColor', [.5 .5 .75], ...
    'XTick',[], ...
    'YTick',[], ...
    'Box','on', ...
    'Visible','on');


% uicontrol('Parent',CnfFigHdl, ...
%     'Unit',Params.StdUnit,...
%     'BackgroundColor',Params.StdColor, ...
%     'ForegroundColor','w',...
%     'Position',[frmLft frmBot frmWid frmHt], ...
%     'Enable','off', ...
%     'Style','frame');


⌨️ 快捷键说明

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