📄 sb2slhys.m
字号:
function sb2slhys(blkname,in,fl,cod,timer)
%SB2SLHYS converts hysteresis blocks to SIMULINK.
% SB2SLHYS(BLKNAME,IN,FL,COD,TIMER) converts a SystemBuild block
% to a SIMULINK block. BLKNAME is a string containing the name of
% the block. The parameters are set up for this block based on the
% SystemBuild file coding integer IN and real number FL.
%
% COD is a three dimensional vector. The first element indicates
% whether it is a continuous (0) or discrete (1) time system.
% The second element indicates whether it does not need (0) or
% does need (1) a mask. The third element indicates the
% orientation of the block.
%
% TIMER is designed for discrete time only. The first element of
% TIMER is the sampling time. The second element is the initial time.
% Wes Wang 11/16/92
% Copyright (c) 1990-93 by The MathWorks, Inc.
% $Revision: 1.10 $ $Date: 1993/06/09 22:09:40 $
% in = [8, code1 code2, input, output, state,....
% state / output --> order of integer for each one
% if input > output --> resetable
% (input - 1)/output - 1 = highest order resetable
% This one works the same for continuous or discrete time systems.
%
% 4:6
if in(2) == 4 & in(3) == 6
temp = 0;
if in(in(17)-2) == 0
ini = zeros(1,in(5));
else
ini = fl(temp+1:temp+in(5))';
temp = in(5);
end;
if cod(1) == 0
temp = temp+2;
frq = ones(1:in(5))*fl(temp);
else
smp = ones(1:in(5))*timer(1);
end;
wid = fl(temp+1:in(5)+temp) * 2';
slp = fl(in(5)+temp+1:2*in(5)+temp)';
end;
if in(4) <= 1 & in(5) <=1
delete_block(blkname);
new_system(blkname);
add_block('built-in/Inport',[blkname,'/input1']);
add_block('built-in/Outport',[blkname,'/output1']);
end;
set_param(blkname,'Location',[582,63,1100,150+60*in(4)])
if cod(1) == 0
%continuous time
for i=1:in(4)
temp = (i-1)*120;
add_block('built-in/Sum',[blkname '/Sum' num2str(i)])
set_param([blkname '/Sum' num2str(i)],...
'position',[135,70+temp,155,90+temp])
add_block('built-in/Gain',[blkname '/Gain1' num2str(i)])
set_param([blkname '/Gain1' num2str(i)],...
'Gain',['frq(' num2str(i) ')'],...
'position',[275,70+temp,295,90+temp])
add_block('built-in/Integrator',[blkname '/Integrator' num2str(i)])
set_param([blkname '/Integrator' num2str(i)],...
'Initial',['ini(' num2str(i) ')'],...
'position',[330,70+temp,350,90+temp])
set_param([blkname '/output' num2str(i)],...
'position',[420,70+temp,440,90+temp])
set_param([blkname '/input' num2str(i)],...
'position',[45,65+temp,65,85+temp])
add_block('built-in/Gain',[blkname '/Gain2' num2str(i)])
set_param([blkname '/Gain2' num2str(i)],...
'orientation',2,...
'Gain',['1/slp(' num2str(i) ')'],...
'position',[250,120+temp,270,140+temp])
add_block('built-in/Dead Zone',[blkname '/Dead Zone' num2str(i)])
set_param([blkname '/Dead Zone' num2str(i)],...
'Lower_value',['-wid(' num2str(i) ')/2'],...
'Upper_value',['wid(' num2str(i) ')/2'],...
'position',[195,70+temp,220,90+temp])
add_line(blkname,[300,80+temp;320,80+temp])
add_line(blkname,[225,80+temp;265,80+temp])
add_line(blkname,[160,80+temp;185,80+temp])
add_line(blkname,[70,75+temp;125,75+temp])
add_line(blkname,[355,80+temp;410,80+temp])
add_line(blkname,[355,80+temp;385,80+temp;385,130+temp;280,130+temp])
add_line(blkname,[245,130+temp;110,130+temp;110,85+temp;125,85+temp])
end;
set_param(blkname,'Mask Display','Continuous\nHysteresis',...
'Mask Type','Hysteresis -- continuous time version','Mask Dialogue',...
'Hysteresis with low-pass filter.|Backlash width:|Backlash slope:|Initial condition:|Cutoff frequency (rad/s):')
set_param(blkname,...
'Mask Translate','wid=@1; slp=@2; ini=@3; frq=@4;','Mask Help',...
'HYSTERESIS A dead band is encounted when the input changes direction, causing the output of the block to remain unchanged until the opposite end of the dead band is reached. A low pass filter is placed on the input.')
set_param(blkname,'Mask Entries',...
[mat2str(wid) '\/' mat2str(slp) '\/' mat2str(ini) '\/' mat2str(frq) '\/'])
else
%discrete-time
for i=1:in(4)
temp = (i-1)*120;
add_block('built-in/Dead Zone',[blkname '/Dead Zone' num2str(i)])
set_param([blkname '/Dead Zone' num2str(i)],...
'Lower_value',['-wid(' num2str(i) ')/2'],...
'Upper_value',['wid(' num2str(i) ')/2'],...
'position',[195,70+temp,220,90+temp])
set_param([blkname '/input' num2str(i)],...
'position',[45,65+temp,65,85+temp])
add_block('built-in/Sum',[blkname '/Sum' num2str(i)])
set_param([blkname '/Sum' num2str(i)],...
'position',[135,70+temp,155,90+temp])
add_block('built-in/Gain',[blkname '/Gain' num2str(i)])
set_param([blkname '/Gain' num2str(i)],...
'orientation',2,...
'Gain',['1/slp(' num2str(i) ')'],...
'position',[175,120+temp,195,140+temp])
add_block('built-in/Unit Delay',[blkname '/Unit Delay' num2str(i)])
set_param([blkname '/Unit Delay' num2str(i)],...
'orientation',2,...
'x0',['ini(' num2str(i) ')'],...
'Sample time',['smp(' num2str(i) ')'],...
'position',[300,120+temp,350,140+temp])
add_block('built-in/Sum',[blkname '/Sum1' num2str(i)])
set_param([blkname '/Sum1' num2str(i)],...
'position',[330,75+temp,350,95+temp])
set_param([blkname '/output' num2str(i)],...
'position',[420,75+temp,440,95+temp])
add_line(blkname,[170,130+temp;110,130+temp;110,85+temp;125,85+temp])
add_line(blkname,[355,85+temp;410,85+temp])
add_line(blkname,[70,75+temp;125,75+temp])
add_line(blkname,[160,80+temp;185,80+temp])
add_line(blkname,[225,80+temp;320,80+temp])
add_line(blkname,[355,85+temp;375,85+temp;375,130+temp;360,130+temp])
add_line(blkname,[295,130+temp;205,130+temp])
add_line(blkname,[295,130+temp;260,130+temp;260,90+temp;320,90+temp])
end
set_param(blkname,'Mask Display','Discrete\nHysteresis',...
'Mask Type','Hysteresis - Discrete version','Mask Dialogue',...
'Discrete-time hysteresis.|Backlash width:|Backlash slope:|Initial condition:|Sample time:')
set_param(blkname,...
'Mask Translate','wid=@1; slp=@2; ini=@3; smp=@4;','Mask Help',...
'HYSTERESIS A dead band is encounted when the input changes direction, causing the output of the block to remain unchanged until the opposite end of the dead band is reached.')
set_param(blkname,'Mask Entries',...
[mat2str(wid) '\/' mat2str(slp) '\/' mat2str(ini) '\/' mat2str(smp) '\/'])
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -