Sim12ex8.m
上传用户:eighthdate
上传日期:2014-05-24
资源大小:270k
文件大小:9k
源码类别:

其他行业

开发平台:

Matlab

  1. function [ret,x0,str,ts,xts]=chp12sm8(t,x,u,flag);
  2. %CHP12SM8   is the M-file description of the SIMULINK system named CHP12SM8.
  3. %   The block-diagram can be displayed by typing: CHP12SM8.
  4. %
  5. %   SYS=CHP12SM8(T,X,U,FLAG) returns depending on FLAG certain
  6. %   system values given time point, T, current state vector, X,
  7. %   and input vector, U.
  8. %   FLAG is used to indicate the type of output to be returned in SYS.
  9. %
  10. %   Setting FLAG=1 causes CHP12SM8 to return state derivatives, FLAG=2
  11. %   discrete states, FLAG=3 system outputs and FLAG=4 next sample
  12. %   time. For more information and other options see SFUNC.
  13. %
  14. %   Calling CHP12SM8 with a FLAG of zero:
  15. %   [SIZES]=CHP12SM8([],[],[],0),  returns a vector, SIZES, which
  16. %   contains the sizes of the state vector and other parameters.
  17. %       SIZES(1) number of states
  18. %       SIZES(2) number of discrete states
  19. %       SIZES(3) number of outputs
  20. %       SIZES(4) number of inputs
  21. %       SIZES(5) number of roots (currently unsupported)
  22. %       SIZES(6) direct feedthrough flag
  23. %       SIZES(7) number of sample times
  24. %
  25. %   For the definition of other parameters in SIZES, see SFUNC.
  26. %   See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.
  27. % Note: This M-file is only used for saving graphical information;
  28. %       after the model is loaded into memory an internal model
  29. %       representation is used.
  30. % the system will take on the name of this mfile:
  31. sys = mfilename;
  32. new_system(sys)
  33. simver(1.3)
  34. if (0 == (nargin + nargout))
  35.      set_param(sys,'Location',[21,298,921,743])
  36.      open_system(sys)
  37. end;
  38. set_param(sys,'algorithm',     'RK-45')
  39. set_param(sys,'Start time',    '0.0')
  40. set_param(sys,'Stop time',     '2')
  41. set_param(sys,'Min step size', '0.0001')
  42. set_param(sys,'Max step size', '.010')
  43. set_param(sys,'Relative error','1e-3')
  44. set_param(sys,'Return vars',   '')
  45. add_block('built-in/Transfer Fcn',[sys,'/','Sensor'])
  46. set_param([sys,'/','Sensor'],...
  47.         'orientation',2,...
  48.         'Denominator','[0.05  1]',...
  49.         'position',[410,259,505,311])
  50. add_block('built-in/Step Fcn',[sys,'/','Step Input'])
  51. set_param([sys,'/','Step Input'],...
  52.         'Time','2',...
  53.         'Before','1',...
  54.         'position',[20,92,60,128])
  55. add_block('built-in/Note',[sys,'/','Vref'])
  56. set_param([sys,'/','Vref'],...
  57.         'position',[75,55,80,75])
  58. add_block('built-in/Sum',[sys,'/','Sum'])
  59. set_param([sys,'/','Sum'],...
  60.         'inputs','+-',...
  61.         'position',[95,100,130,140])
  62. %     Subsystem  'PID Controller'.
  63. new_system([sys,'/','PID Controller'])
  64. set_param([sys,'/','PID Controller'],'Location',[0,0,362,244])
  65. add_block('built-in/Sum',[sys,'/','PID Controller/Sum'])
  66. set_param([sys,'/','PID Controller/Sum'],...
  67.         'inputs','+++',...
  68.         'position',[245,57,265,93])
  69. add_block('built-in/Gain',[sys,'/','PID Controller/D'])
  70. set_param([sys,'/','PID Controller/D'],...
  71.         'Gain','D',...
  72.         'position',[95,129,115,151])
  73. add_block('built-in/Gain',[sys,'/','PID Controller/Proportional'])
  74. set_param([sys,'/','PID Controller/Proportional'],...
  75.         'Gain','P',...
  76.         'position',[120,13,140,37])
  77. add_block('built-in/Transfer Fcn',[sys,'/','PID Controller/Integral'])
  78. set_param([sys,'/','PID Controller/Integral'],...
  79.         'Numerator','[I]',...
  80.         'Denominator','[1 0]',...
  81.         'position',[110,57,145,93])
  82. add_block('built-in/Derivative',[sys,'/','PID Controller/Derivative'])
  83. set_param([sys,'/','PID Controller/Derivative'],...
  84.         'position',[150,128,190,152])
  85. add_block('built-in/Outport',[sys,'/','PID Controller/Out_1'])
  86. set_param([sys,'/','PID Controller/Out_1'],...
  87.         'position',[290,65,310,85])
  88. add_block('built-in/Inport',[sys,'/','PID Controller/In_1'])
  89. set_param([sys,'/','PID Controller/In_1'],...
  90.         'position',[25,65,45,85])
  91. add_line([sys,'/','PID Controller'],[120,140;145,140])
  92. add_line([sys,'/','PID Controller'],[270,75;285,75])
  93. add_line([sys,'/','PID Controller'],[50,75;105,75])
  94. add_line([sys,'/','PID Controller'],[65,75;65,140;90,140])
  95. add_line([sys,'/','PID Controller'],[80,75;80,25;115,25])
  96. add_line([sys,'/','PID Controller'],[195,140;215,140;215,85;240,85])
  97. add_line([sys,'/','PID Controller'],[150,75;240,75])
  98. add_line([sys,'/','PID Controller'],[145,25;210,25;210,65;240,65])
  99. set_param([sys,'/','PID Controller'],...
  100.         'Mask Display','PID',...
  101.         'Mask Type','PID Controller',...
  102.         'Mask Dialogue','Enter expressions for proportional, integral, and derivative terms.nP+I/s+Ds|Proportional:|Integral|Derivative:')
  103. set_param([sys,'/','PID Controller'],...
  104.         'Mask Translate','P=@1; I=@2; D=@3;')
  105. set_param([sys,'/','PID Controller'],...
  106.         'Mask Help','This block implements a PID controller where parameters are entered for the Proportional, Integral and Derivative terms. Unmask this block to see how it works. The derivative term is implemented using a true derivative block.')
  107. set_param([sys,'/','PID Controller'],...
  108.         'Mask Entries','1/0.25/0.28/')
  109. %     Finished composite block 'PID Controller'.
  110. set_param([sys,'/','PID Controller'],...
  111.         'position',[175,104,215,136])
  112. add_block('built-in/Transfer Fcn',[sys,'/','Amplifier'])
  113. set_param([sys,'/','Amplifier'],...
  114.         'Numerator','10',...
  115.         'Denominator','[0.1  1]',...
  116.         'position',[260,92,345,148])
  117. add_block('built-in/Note',[sys,'/','VR'])
  118. set_param([sys,'/','VR'],...
  119.         'position',[360,95,390,101])
  120. add_block('built-in/Transfer Fcn',[sys,'/','Exciter'])
  121. set_param([sys,'/','Exciter'],...
  122.         'Numerator','1',...
  123.         'Denominator','[0.4  1]',...
  124.         'position',[410,92,495,148])
  125. add_block('built-in/Note',[sys,'/','VF'])
  126. set_param([sys,'/','VF'],...
  127.         'position',[515,85,525,101])
  128. add_block('built-in/Transfer Fcn',[sys,'/','Generator'])
  129. set_param([sys,'/','Generator'],...
  130.         'Denominator','[1  1]',...
  131.         'position',[555,94,635,146])
  132. add_block('built-in/Note',[sys,'/','Vt'])
  133. set_param([sys,'/','Vt'],...
  134.         'position',[650,94,675,99])
  135. add_block('built-in/Note',[sys,'/','Ve'])
  136. set_param([sys,'/','Ve'],...
  137.         'position',[145,84,150,91])
  138. add_block('built-in/Mux',[sys,'/','Mux'])
  139. set_param([sys,'/','Mux'],...
  140.         'orientation',2,...
  141.         'inputs','2',...
  142.         'position',[640,211,675,249])
  143. add_block('built-in/To Workspace',[sys,'/','Terminal Voltage'])
  144. set_param([sys,'/','Terminal Voltage'],...
  145.         'orientation',2,...
  146.         'mat-name','Vt',...
  147.         'position',[540,215,590,245])
  148. %     Subsystem  'Graph'.
  149. new_system([sys,'/','Graph'])
  150. set_param([sys,'/','Graph'],'Location',[0,59,274,252])
  151. add_block('built-in/Inport',[sys,'/','Graph/x'])
  152. set_param([sys,'/','Graph/x'],...
  153.         'position',[65,55,85,75])
  154. add_block('built-in/S-Function',[sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
  155. set_param([sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
  156.         'function name','sfuny',...
  157.         'parameters','ax, color,dt',...
  158.         'position',[130,55,180,75])
  159. add_line([sys,'/','Graph'],[90,65;125,65])
  160. set_param([sys,'/','Graph'],...
  161.         'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
  162.         'Mask Type','Graph scope.')
  163. set_param([sys,'/','Graph'],...
  164.         'Mask Dialogue','Graph scope using MATLAB graph window.nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
  165. set_param([sys,'/','Graph'],...
  166.         'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
  167. set_param([sys,'/','Graph'],...
  168.         'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
  169. set_param([sys,'/','Graph'],...
  170.         'Mask Entries','2/0/1.2/''y-/g--/c-./w:/m*/ro/b+''/')
  171. %     Finished composite block 'Graph'.
  172. set_param([sys,'/','Graph'],...
  173.         'Drop Shadow',4,...
  174.         'position',[670,125,710,165])
  175. add_block('built-in/Clock',[sys,'/','Clock'])
  176. set_param([sys,'/','Clock'],...
  177.         'orientation',2,...
  178.         'position',[705,190,725,210])
  179. add_line(sys,[65,110;90,110])
  180. add_line(sys,[500,120;550,120])
  181. add_line(sys,[405,285;80,285;90,130])
  182. add_line(sys,[350,120;405,120])
  183. add_line(sys,[135,120;170,120])
  184. add_line(sys,[220,120;255,120])
  185. add_line(sys,[640,120;765,120;765,285;510,285])
  186. add_line(sys,[650,120;650,145;665,145])
  187. add_line(sys,[635,230;595,230])
  188. add_line(sys,[700,200;690,200;680,220])
  189. add_line(sys,[745,120;745,240;680,240])
  190. drawnow
  191. % Return any arguments.
  192. if (nargin | nargout)
  193.     % Must use feval here to access system in memory
  194.     if (nargin > 3)
  195.         if (flag == 0)
  196.             eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
  197.         else
  198.             eval(['ret =', sys,'(t,x,u,flag);'])
  199.         end
  200.     else
  201.         [ret,x0,str,ts,xts] = feval(sys);
  202.     end
  203. else
  204.     drawnow % Flash up the model and execute load callback
  205. end