function [ret,x0,str,ts,xts]=s6_13(t,x,u,flag);
%S6_13	is the M-file description of the SIMULINK system named S6_13.
%	The block-diagram can be displayed by typing: S6_13.
%
%	SYS=S6_13(T,X,U,FLAG) returns depending on FLAG certain
%	system values given time point, T, current state vector, X,
%	and input vector, U.
%	FLAG is used to indicate the type of output to be returned in SYS.
%
%	Setting FLAG=1 causes S6_13 to return state derivatives, FLAG=2
%	discrete states, FLAG=3 system outputs and FLAG=4 next sample
%	time. For more information and other options see SFUNC.
%
%	Calling S6_13 with a FLAG of zero:
%	[SIZES]=S6_13([],[],[],0),  returns a vector, SIZES, which
%	contains the sizes of the state vector and other parameters.
%		SIZES(1) number of states
%		SIZES(2) number of discrete states
%		SIZES(3) number of outputs
%		SIZES(4) number of inputs
%		SIZES(5) number of roots (currently unsupported)
%		SIZES(6) direct feedthrough flag
%		SIZES(7) number of sample times
%
%	For the definition of other parameters in SIZES, see SFUNC.
%	See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.

% Note: This M-file is only used for saving graphical information;
%       after the model is loaded into memory an internal model
%       representation is used.

% the system will take on the name of this mfile:
sys = mfilename;
new_system(sys)
simver(1.3)
if (0 == (nargin + nargout))
     set_param(sys,'Location',[36,52,574,382])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-23')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     't_d')
set_param(sys,'Min step size', 'Tc/10')
set_param(sys,'Max step size', 'Tc')
set_param(sys,'Relative error','1e-8')
set_param(sys,'Return vars',   '')

add_block('built-in/To Workspace',[sys,'/','To Workspace7'])
set_param([sys,'/','To Workspace7'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','tau',...
		'buffer','[5001,1,Ts]',...
		'position',[470,105,520,125])

add_block('built-in/To Workspace',[sys,'/','To Workspace6'])
set_param([sys,'/','To Workspace6'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','q',...
		'buffer','[5001,1,Ts]',...
		'position',[470,155,520,175])

add_block('built-in/Discrete State-Space',[sys,'/',['constant',13,'inertia']])
set_param([sys,'/',['constant',13,'inertia']],...
		'move name',0,...
		'Font Name','Arial',...
		'A','0',...
		'B','0',...
		'C','zeros(2,1)',...
		'D','B_h',...
		'X0','0',...
		'Sample time','Tc',...
		'Mask Display','B_h')
set_param([sys,'/',['constant',13,'inertia']],...
		'position',[235,129,265,161])

add_block('built-in/To Workspace',[sys,'/','To Workspace3'])
set_param([sys,'/','To Workspace3'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','e',...
		'buffer','[5001,1,Ts]',...
		'position',[140,245,190,265])

add_block('built-in/Discrete State-Space',[sys,'/','Discrete State-Space'])
set_param([sys,'/','Discrete State-Space'],...
		'hide name',0,...
		'Font Name','Arial',...
		'A','0',...
		'B','0',...
		'C','zeros(2,1)',...
		'D','K_d',...
		'X0','0',...
		'Sample time','Tc',...
		'Mask Display','K_d')
set_param([sys,'/','Discrete State-Space'],...
		'position',[140,139,170,171])

add_block('built-in/Discrete State-Space',[sys,'/','Discrete State-Space5'])
set_param([sys,'/','Discrete State-Space5'],...
		'hide name',0,...
		'Font Name','Arial',...
		'A','0',...
		'B','0',...
		'C','zeros(2,1)',...
		'D','K_p',...
		'X0','0',...
		'Sample time','Tc',...
		'Mask Display','K_p')
set_param([sys,'/','Discrete State-Space5'],...
		'position',[140,194,170,226])


%     Subsystem  'robustness'.

new_system([sys,'/','robustness'])
set_param([sys,'/','robustness'],'Location',[6,203,604,380])

add_block('built-in/Outport',[sys,'/','robustness/w'])
set_param([sys,'/','robustness/w'],...
		'position',[575,100,595,120])

add_block('built-in/Inport',[sys,'/','robustness/de'])
set_param([sys,'/','robustness/de'],...
		'position',[5,5,25,25])

add_block('built-in/Mux',[sys,'/','robustness/Mux'])
set_param([sys,'/','robustness/Mux'],...
		'hide name',0,...
		'inputs','[2,2]',...
		'position',[45,4,75,51])

add_block('built-in/Discrete State-Space',[sys,'/','robustness/Discrete State-Space3'])
set_param([sys,'/','robustness/Discrete State-Space3'],...
		'hide name',0,...
		'A','0',...
		'B','0',...
		'C','zeros(2,1)',...
		'D','DQ',...
		'X0','0',...
		'Sample time','Tc',...
		'Mask Display','DQ',...
		'position',[95,14,135,46])

add_block('built-in/Demux',[sys,'/','robustness/Demux'])
set_param([sys,'/','robustness/Demux'],...
		'hide name',0,...
		'outputs','2',...
		'position',[305,76,345,154])

add_block('built-in/Fcn',[sys,'/','robustness/Fcn1'])
set_param([sys,'/','robustness/Fcn1'],...
		'hide name',0,...
		'Expr','1/u',...
		'position',[360,35,400,55])

add_block('built-in/Switch',[sys,'/','robustness/Switch'])
set_param([sys,'/','robustness/Switch'],...
		'hide name',0,...
		'position',[320,23,345,67])

add_block('built-in/Constant',[sys,'/','robustness/Constant'])
set_param([sys,'/','robustness/Constant'],...
		'hide name',0,...
		'Value','ep',...
		'position',[235,49,260,71])

add_block('built-in/Sum',[sys,'/','robustness/Sum1'])
set_param([sys,'/','robustness/Sum1'],...
		'hide name',0,...
		'inputs','+-',...
		'position',[285,35,300,55])

add_block('built-in/Fcn',[sys,'/','robustness/Fcn'])
set_param([sys,'/','robustness/Fcn'],...
		'hide name',0,...
		'Expr','sqrt(u)',...
		'position',[220,20,260,40])


%     Subsystem  ['robustness/Inner',13,'Product'].

new_system([sys,'/',['robustness/Inner',13,'Product']])
set_param([sys,'/',['robustness/Inner',13,'Product']],'Location',[33,479,253,634])

add_block('built-in/Inport',[sys,'/',['robustness/Inner',13,'Product/in_1']])
set_param([sys,'/',['robustness/Inner',13,'Product/in_1']],...
		'position',[15,25,35,45])

add_block('built-in/Inport',[sys,'/',['robustness/Inner',13,'Product/in_2']])
set_param([sys,'/',['robustness/Inner',13,'Product/in_2']],...
		'Port','2',...
		'position',[15,90,35,110])

add_block('built-in/Outport',[sys,'/',['robustness/Inner',13,'Product/out_1']])
set_param([sys,'/',['robustness/Inner',13,'Product/out_1']],...
		'position',[185,55,205,75])

add_block('built-in/Sum',[sys,'/',['robustness/Inner',13,'Product/Sum']])
set_param([sys,'/',['robustness/Inner',13,'Product/Sum']],...
		'inputs','+',...
		'position',[125,55,145,75])

add_block('built-in/Product',[sys,'/',['robustness/Inner',13,'Product/Product']])
set_param([sys,'/',['robustness/Inner',13,'Product/Product']],...
		'position',[65,55,90,75])
add_line([sys,'/',['robustness/Inner',13,'Product']],[150,65;180,65])
add_line([sys,'/',['robustness/Inner',13,'Product']],[95,65;120,65])
add_line([sys,'/',['robustness/Inner',13,'Product']],[40,35;60,60])
add_line([sys,'/',['robustness/Inner',13,'Product']],[40,100;60,70])
set_param([sys,'/',['robustness/Inner',13,'Product']],...
		'Mask Display','.\n',...
		'Mask Type','Dot Product',...
		'Mask Dialogue','Inner (dot) product.\ny=sum(u1.*u2)')
set_param([sys,'/',['robustness/Inner',13,'Product']],...
		'Mask Help','Computes the inner (dot) product of the inputs: sum(u1.*u2).  The inputs are vectors of the same length. Output is a scalar.')


%     Finished composite block ['robustness/Inner',13,'Product'].

set_param([sys,'/',['robustness/Inner',13,'Product']],...
		'hide name',0,...
		'position',[180,10,200,50])

add_block('built-in/Product',[sys,'/','robustness/Product1'])
set_param([sys,'/','robustness/Product1'],...
		'position',[425,118,455,142])

add_block('built-in/Product',[sys,'/','robustness/Product'])
set_param([sys,'/','robustness/Product'],...
		'position',[425,78,455,102])

add_block('built-in/Mux',[sys,'/','robustness/Mux1'])
set_param([sys,'/','robustness/Mux1'],...
		'hide name',0,...
		'inputs','2',...
		'position',[485,91,515,124])

add_block('built-in/State-Space',[sys,'/',['robustness/Matrix',13,'Gain']])
set_param([sys,'/',['robustness/Matrix',13,'Gain']],...
		'hide name',0,...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','rho',...
		'Mask Type','Matrix Gain',...
		'Mask Dialogue','Matrix Gain.|Gain matrix:')
set_param([sys,'/',['robustness/Matrix',13,'Gain']],...
		'Mask Translate','K = @1;',...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','rho*eye(2,2)\/')
set_param([sys,'/',['robustness/Matrix',13,'Gain']],...
		'position',[530,95,560,125])

add_block('built-in/Inport',[sys,'/','robustness/e'])
set_param([sys,'/','robustness/e'],...
		'Port','2',...
		'position',[5,50,25,70])
add_line([sys,'/','robustness'],[350,135;420,135])
add_line([sys,'/','robustness'],[350,95;420,95])
add_line([sys,'/','robustness'],[460,130;470,130;480,115])
add_line([sys,'/','robustness'],[460,90;470,90;480,100])
add_line([sys,'/','robustness'],[350,45;355,45])
add_line([sys,'/','robustness'],[265,60;315,60])
add_line([sys,'/','robustness'],[265,30;315,30])
add_line([sys,'/','robustness'],[305,45;315,45])
add_line([sys,'/','robustness'],[265,60;265,50;280,50])
add_line([sys,'/','robustness'],[265,30;265,40;280,40])
add_line([sys,'/','robustness'],[140,30;160,30;160,40;175,40])
add_line([sys,'/','robustness'],[205,30;215,30])
add_line([sys,'/','robustness'],[30,15;40,15])
add_line([sys,'/','robustness'],[30,60;40,40])
add_line([sys,'/','robustness'],[80,30;90,30])
add_line([sys,'/','robustness'],[160,30;160,20;175,20])
add_line([sys,'/','robustness'],[160,40;160,115;300,115])
add_line([sys,'/','robustness'],[405,45;405,125;420,125])
add_line([sys,'/','robustness'],[405,45;410,45;420,85])
add_line([sys,'/','robustness'],[520,110;525,110])
add_line([sys,'/','robustness'],[565,110;570,110])
set_param([sys,'/','robustness'],...
		'Mask Display','UV')


%     Finished composite block 'robustness'.

set_param([sys,'/','robustness'],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[140,55,175,90])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[290,136,305,169])


%     Subsystem  'arm'.

new_system([sys,'/','arm'])
set_param([sys,'/','arm'],'Location',[183,134,572,391])

add_block('built-in/Inport',[sys,'/','arm/tau'])
set_param([sys,'/','arm/tau'],...
		'position',[10,140,30,160])

add_block('built-in/Sum',[sys,'/','arm/Sum'])
set_param([sys,'/','arm/Sum'],...
		'hide name',0,...
		'inputs','--+-',...
		'position',[85,109,105,176])

add_block('built-in/Outport',[sys,'/','arm/dq'])
set_param([sys,'/','arm/dq'],...
		'position',[355,105,375,125])


%     Subsystem  'arm/resolved acc'.

new_system([sys,'/','arm/resolved acc'])
set_param([sys,'/','arm/resolved acc'],'Location',[88,137,376,234])

add_block('built-in/Inport',[sys,'/',['arm/resolved acc/tau-tau''']])
set_param([sys,'/',['arm/resolved acc/tau-tau''']],...
		'position',[10,20,30,40])

add_block('built-in/Inport',[sys,'/','arm/resolved acc/q'])
set_param([sys,'/','arm/resolved acc/q'],...
		'Port','2',...
		'position',[10,60,30,80])

add_block('built-in/Outport',[sys,'/','arm/resolved acc/ddq'])
set_param([sys,'/','arm/resolved acc/ddq'],...
		'position',[260,40,280,60])

add_block('built-in/Mux',[sys,'/','arm/resolved acc/Mux'])
set_param([sys,'/','arm/resolved acc/Mux'],...
		'hide name',0,...
		'inputs','[2,1]',...
		'position',[140,12,165,88])

add_block('built-in/Fcn',[sys,'/','arm/resolved acc/Fcn'])
set_param([sys,'/','arm/resolved acc/Fcn'],...
		'hide name',0,...
		'Expr','cos(u(2))',...
		'position',[50,59,105,81])

add_block('built-in/MATLAB Fcn',[sys,'/',['arm/resolved acc/invB',13,'']])
set_param([sys,'/',['arm/resolved acc/invB',13,'']],...
		'hide name',0,...
		'MATLAB Fcn','inv(iner_l(u(3)))*u(1:2)',...
		'Output Width','2',...
		'Mask Display','inv(B(q))',...
		'position',[185,33,235,67])
add_line([sys,'/','arm/resolved acc'],[170,50;180,50])
add_line([sys,'/','arm/resolved acc'],[35,30;135,30])
add_line([sys,'/','arm/resolved acc'],[240,50;255,50])
add_line([sys,'/','arm/resolved acc'],[35,70;45,70])
add_line([sys,'/','arm/resolved acc'],[110,70;135,70])
set_param([sys,'/','arm/resolved acc'],...
		'Mask Display','inv(B(q))')


%     Finished composite block 'arm/resolved acc'.

set_param([sys,'/','arm/resolved acc'],...
		'move name',0,...
		'position',[130,135,185,175])

add_block('built-in/Outport',[sys,'/',['arm/q',13,'']])
set_param([sys,'/',['arm/q',13,'']],...
		'Port','2',...
		'position',[355,145,375,165])

add_block('built-in/Integrator',[sys,'/','arm/Integrator1'])
set_param([sys,'/','arm/Integrator1'],...
		'hide name',0,...
		'Initial','q_i',...
		'position',[265,140,290,170])

add_block('built-in/Integrator',[sys,'/','arm/Integrator'])
set_param([sys,'/','arm/Integrator'],...
		'hide name',0,...
		'Initial','[0 0]',...
		'position',[205,140,230,170])

add_block('built-in/State-Space',[sys,'/','arm/friction'])
set_param([sys,'/','arm/friction'],...
		'orientation',2,...
		'move name',0,...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','F_v',...
		'Mask Type','Matrix Gain',...
		'Mask Dialogue','Matrix Gain.|Gain matrix:')
set_param([sys,'/','arm/friction'],...
		'Mask Translate','K = @1;',...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','F_v\/',...
		'position',[140,79,175,111])


%     Subsystem  'arm/gravity'.

new_system([sys,'/','arm/gravity'])
set_param([sys,'/','arm/gravity'],'Location',[117,196,554,309])

add_block('built-in/Outport',[sys,'/','arm/gravity/g'])
set_param([sys,'/','arm/gravity/g'],...
		'orientation',2,...
		'position',[5,50,25,70])

add_block('built-in/Sum',[sys,'/','arm/gravity/Sum5'])
set_param([sys,'/','arm/gravity/Sum5'],...
		'orientation',2,...
		'hide name',0,...
		'position',[105,29,120,51])

add_block('built-in/Gain',[sys,'/','arm/gravity/Gain1'])
set_param([sys,'/','arm/gravity/Gain1'],...
		'orientation',2,...
		'hide name',0,...
		'Gain','g*pi_l(1)',...
		'Mask Display','k_1',...
		'position',[160,18,185,52])

add_block('built-in/Fcn',[sys,'/','arm/gravity/Fcn2'])
set_param([sys,'/','arm/gravity/Fcn2'],...
		'orientation',2,...
		'hide name',0,...
		'Expr','cos(u)',...
		'position',[210,25,250,45])

add_block('built-in/Gain',[sys,'/','arm/gravity/Gain'])
set_param([sys,'/','arm/gravity/Gain'],...
		'orientation',2,...
		'hide name',0,...
		'Gain','g*pi_l(3)',...
		'Mask Display','k_2',...
		'position',[160,63,185,97])

add_block('built-in/Demux',[sys,'/','arm/gravity/Demux'])
set_param([sys,'/','arm/gravity/Demux'],...
		'orientation',2,...
		'hide name',0,...
		'outputs','2',...
		'position',[340,12,380,108])

add_block('built-in/Sum',[sys,'/','arm/gravity/Sum2'])
set_param([sys,'/','arm/gravity/Sum2'],...
		'orientation',2,...
		'hide name',0,...
		'position',[270,70,290,90])

add_block('built-in/Fcn',[sys,'/','arm/gravity/Fcn1'])
set_param([sys,'/','arm/gravity/Fcn1'],...
		'orientation',2,...
		'hide name',0,...
		'Expr','cos(u)',...
		'position',[210,70,250,90])

add_block('built-in/Mux',[sys,'/','arm/gravity/Mux'])
set_param([sys,'/','arm/gravity/Mux'],...
		'orientation',2,...
		'hide name',0,...
		'inputs','2',...
		'position',[50,21,80,99])

add_block('built-in/Inport',[sys,'/','arm/gravity/q'])
set_param([sys,'/','arm/gravity/q'],...
		'orientation',2,...
		'position',[415,50,435,70])
add_line([sys,'/','arm/gravity'],[45,60;30,60])
add_line([sys,'/','arm/gravity'],[155,80;85,80])
add_line([sys,'/','arm/gravity'],[155,80;150,80;150,45;125,45])
add_line([sys,'/','arm/gravity'],[100,40;85,40])
add_line([sys,'/','arm/gravity'],[155,35;125,35])
add_line([sys,'/','arm/gravity'],[335,35;255,35])
add_line([sys,'/','arm/gravity'],[315,35;315,75;295,75])
add_line([sys,'/','arm/gravity'],[205,35;190,35])
add_line([sys,'/','arm/gravity'],[205,80;190,80])
add_line([sys,'/','arm/gravity'],[265,80;255,80])
add_line([sys,'/','arm/gravity'],[335,85;295,85])
add_line([sys,'/','arm/gravity'],[410,60;385,60])
set_param([sys,'/','arm/gravity'],...
		'Mask Display','g(q)')


%     Finished composite block 'arm/gravity'.

set_param([sys,'/','arm/gravity'],...
		'orientation',2,...
		'move name',0,...
		'position',[140,218,175,252])


%     Subsystem  'arm/Coriolis + centrifugal'.

new_system([sys,'/','arm/Coriolis + centrifugal'])
set_param([sys,'/','arm/Coriolis + centrifugal'],'Location',[46,235,597,393])

add_block('built-in/Inport',[sys,'/','arm/Coriolis + centrifugal/dq'])
set_param([sys,'/','arm/Coriolis + centrifugal/dq'],...
		'orientation',2,...
		'Port','2',...
		'position',[525,90,545,110])

add_block('built-in/Inport',[sys,'/','arm/Coriolis + centrifugal/q'])
set_param([sys,'/','arm/Coriolis + centrifugal/q'],...
		'orientation',2,...
		'position',[525,35,545,55])

add_block('built-in/Mux',[sys,'/','arm/Coriolis + centrifugal/Mux'])
set_param([sys,'/','arm/Coriolis + centrifugal/Mux'],...
		'orientation',2,...
		'hide name',0,...
		'inputs','2',...
		'position',[40,87,70,118])

add_block('built-in/Sum',[sys,'/','arm/Coriolis + centrifugal/Sum'])
set_param([sys,'/','arm/Coriolis + centrifugal/Sum'],...
		'orientation',2,...
		'hide name',0,...
		'position',[105,85,125,105])

add_block('built-in/Product',[sys,'/','arm/Coriolis + centrifugal/Product7'])
set_param([sys,'/','arm/Coriolis + centrifugal/Product7'],...
		'orientation',2,...
		'hide name',0,...
		'position',[195,80,230,100])

add_block('built-in/Product',[sys,'/','arm/Coriolis + centrifugal/Product5'])
set_param([sys,'/','arm/Coriolis + centrifugal/Product5'],...
		'orientation',2,...
		'hide name',0,...
		'position',[195,125,230,145])

add_block('built-in/Product',[sys,'/','arm/Coriolis + centrifugal/prdiuct 1'])
set_param([sys,'/','arm/Coriolis + centrifugal/prdiuct 1'],...
		'orientation',2,...
		'hide name',0,...
		'move name',0,...
		'position',[285,15,320,35])

add_block('built-in/Product',[sys,'/','arm/Coriolis + centrifugal/Product6'])
set_param([sys,'/','arm/Coriolis + centrifugal/Product6'],...
		'orientation',2,...
		'hide name',0,...
		'position',[195,20,230,40])

add_block('built-in/Gain',[sys,'/','arm/Coriolis + centrifugal/Gain1'])
set_param([sys,'/','arm/Coriolis + centrifugal/Gain1'],...
		'orientation',2,...
		'hide name',0,...
		'Gain','2',...
		'position',[150,78,175,102])

add_block('built-in/Gain',[sys,'/','arm/Coriolis + centrifugal/Gain2'])
set_param([sys,'/','arm/Coriolis + centrifugal/Gain2'],...
		'orientation',2,...
		'hide name',0,...
		'Gain','-1',...
		'position',[150,18,175,42])

add_block('built-in/Outport',[sys,'/','arm/Coriolis + centrifugal/Cdq'])
set_param([sys,'/','arm/Coriolis + centrifugal/Cdq'],...
		'orientation',2,...
		'position',[5,95,25,115])

add_block('built-in/Gain',[sys,'/','arm/Coriolis + centrifugal/Gain'])
set_param([sys,'/','arm/Coriolis + centrifugal/Gain'],...
		'orientation',2,...
		'hide name',0,...
		'Gain','-a(1)*pi_l(3)',...
		'Mask Display','k_3',...
		'position',[380,33,405,57])

add_block('built-in/Fcn',[sys,'/','arm/Coriolis + centrifugal/Fcn1'])
set_param([sys,'/','arm/Coriolis + centrifugal/Fcn1'],...
		'orientation',2,...
		'hide name',0,...
		'Expr','sin(u(2))',...
		'position',[430,34,480,56])

add_block('built-in/Product',[sys,'/','arm/Coriolis + centrifugal/Product4'])
set_param([sys,'/','arm/Coriolis + centrifugal/Product4'],...
		'orientation',2,...
		'hide name',0,...
		'position',[285,100,320,120])

add_block('built-in/Demux',[sys,'/','arm/Coriolis + centrifugal/Demux2'])
set_param([sys,'/','arm/Coriolis + centrifugal/Demux2'],...
		'orientation',2,...
		'hide name',0,...
		'outputs','2',...
		'position',[440,69,480,131])
add_line([sys,'/','arm/Coriolis + centrifugal'],[280,110;270,110;270,130;235,130])
add_line([sys,'/','arm/Coriolis + centrifugal'],[270,110;270,95;235,95])
add_line([sys,'/','arm/Coriolis + centrifugal'],[435,85;335,85;325,30])
add_line([sys,'/','arm/Coriolis + centrifugal'],[335,85;270,85;270,35;235,35])
add_line([sys,'/','arm/Coriolis + centrifugal'],[270,85;235,85])
add_line([sys,'/','arm/Coriolis + centrifugal'],[520,45;485,45])
add_line([sys,'/','arm/Coriolis + centrifugal'],[425,45;410,45])
add_line([sys,'/','arm/Coriolis + centrifugal'],[375,45;355,45;355,20;325,20])
add_line([sys,'/','arm/Coriolis + centrifugal'],[355,45;355,105;325,105])
add_line([sys,'/','arm/Coriolis + centrifugal'],[280,25;235,25])
add_line([sys,'/','arm/Coriolis + centrifugal'],[435,115;325,115])
add_line([sys,'/','arm/Coriolis + centrifugal'],[355,115;355,140;235,140])
add_line([sys,'/','arm/Coriolis + centrifugal'],[190,90;180,90])
add_line([sys,'/','arm/Coriolis + centrifugal'],[145,90;130,90])
add_line([sys,'/','arm/Coriolis + centrifugal'],[190,135;150,135;150,100;130,100])
add_line([sys,'/','arm/Coriolis + centrifugal'],[100,95;75,95])
add_line([sys,'/','arm/Coriolis + centrifugal'],[35,105;30,105])
add_line([sys,'/','arm/Coriolis + centrifugal'],[190,30;180,30])
add_line([sys,'/','arm/Coriolis + centrifugal'],[145,30;95,30;95,110;75,110])
add_line([sys,'/','arm/Coriolis + centrifugal'],[520,100;485,100])
set_param([sys,'/','arm/Coriolis + centrifugal'],...
		'Mask Display','C(q,dq)dq')


%     Finished composite block 'arm/Coriolis + centrifugal'.

set_param([sys,'/','arm/Coriolis + centrifugal'],...
		'orientation',2,...
		'move name',0,...
		'position',[130,20,185,55])
add_line([sys,'/','arm'],[295,155;310,155;310,200;115,200;125,165])
add_line([sys,'/','arm'],[310,155;350,155])
add_line([sys,'/','arm'],[235,155;243,155;243,95;180,95])
add_line([sys,'/','arm'],[243,95;243,45;190,45])
add_line([sys,'/','arm'],[243,115;350,115])
add_line([sys,'/','arm'],[135,235;65,235;65,165;80,165])
add_line([sys,'/','arm'],[135,95;65,95;65,120;80,120])
add_line([sys,'/','arm'],[310,200;310,235;180,235])
add_line([sys,'/','arm'],[110,145;125,145])
add_line([sys,'/','arm'],[235,155;260,155])
add_line([sys,'/','arm'],[190,155;200,155])
add_line([sys,'/','arm'],[35,150;80,150])
add_line([sys,'/','arm'],[310,155;310,30;190,30])
add_line([sys,'/','arm'],[125,40;55,40;55,135;80,135])
set_param([sys,'/','arm'],...
		'Mask Display','inv(B(q))(tau-tau'')')


%     Finished composite block 'arm'.

set_param([sys,'/','arm'],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[325,136,420,174])


%     Subsystem  'Subsystem6'.

new_system([sys,'/','Subsystem6'])
set_param([sys,'/','Subsystem6'],'Location',[355,393414,500,393509])

add_block('built-in/Note',[sys,'/','Subsystem6/start'])
set_param([sys,'/','Subsystem6/start'],...
		'position',[55,45,60,50])
set_param([sys,'/','Subsystem6'],...
		'Mask Display','variables\ninitialization',...
		'Mask Dialogue','eval(''clear all;i6_13;'')')


%     Finished composite block 'Subsystem6'.

set_param([sys,'/','Subsystem6'],...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[5,5,90,41])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[420,5,440,25])

add_block('built-in/To Workspace',[sys,'/','To Workspace4'])
set_param([sys,'/','To Workspace4'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','time',...
		'buffer','[5001,1,Ts]',...
		'position',[470,5,520,25])


%     Subsystem  'Subsystem8'.

new_system([sys,'/','Subsystem8'])
set_param([sys,'/','Subsystem8'],'Location',[355,393414,500,393509])

add_block('built-in/Note',[sys,'/','Subsystem8/start'])
set_param([sys,'/','Subsystem8/start'],...
		'position',[55,45,60,50])
set_param([sys,'/','Subsystem8'],...
		'Mask Display','plot',...
		'Mask Dialogue','eval(''p6_13;'')')


%     Finished composite block 'Subsystem8'.

set_param([sys,'/','Subsystem8'],...
		'orientation',2,...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[450,290,520,321])

add_block('built-in/Sum',[sys,'/','Sum3'])
set_param([sys,'/','Sum3'],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','++++',...
		'position',[200,108,215,182])

add_block('built-in/From Workspace',[sys,'/',['From',13,'Workspace2']])
set_param([sys,'/',['From',13,'Workspace2']],...
		'hide name',0,...
		'Font Name','Arial',...
		'matl_expr','[T,ddq_d]',...
		'position',[5,112,55,138])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','-+',...
		'position',[85,137,100,173])

add_block('built-in/From Workspace',[sys,'/',['From',13,'Workspace3']])
set_param([sys,'/',['From',13,'Workspace3']],...
		'hide name',0,...
		'Font Name','Arial',...
		'matl_expr','[T,dq_d]',...
		'position',[5,153,55,177])

add_block('built-in/From Workspace',[sys,'/',['From',13,'Workspace']])
set_param([sys,'/',['From',13,'Workspace']],...
		'hide name',0,...
		'Font Name','Arial',...
		'matl_expr','[T,q_d]',...
		'position',[5,188,55,212])

add_block('built-in/Sum',[sys,'/','Sum4'])
set_param([sys,'/','Sum4'],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','+-',...
		'position',[85,190,100,225])


%     Subsystem  ['friction and gravity',13,'compensation'].

new_system([sys,'/',['friction and gravity',13,'compensation']])
set_param([sys,'/',['friction and gravity',13,'compensation']],'Location',[207,85,550,203])

add_block('built-in/Sum',[sys,'/',['friction and gravity',13,'compensation/Sum4']])
set_param([sys,'/',['friction and gravity',13,'compensation/Sum4']],...
		'orientation',2,...
		'hide name',0,...
		'position',[65,65,80,100])

add_block('built-in/Outport',[sys,'/',['friction and gravity',13,'compensation/tau_c']])
set_param([sys,'/',['friction and gravity',13,'compensation/tau_c']],...
		'orientation',2,...
		'position',[15,75,35,95])

add_block('built-in/Discrete State-Space',[sys,'/',['friction and gravity',13,'compensation/Discrete State-Space2']])
set_param([sys,'/',['friction and gravity',13,'compensation/Discrete State-Space2']],...
		'orientation',2,...
		'hide name',0,...
		'A','0',...
		'B','0',...
		'C','zeros(2,1)',...
		'D','eye(2,2)',...
		'X0','0',...
		'Sample time','Tc')
set_param([sys,'/',['friction and gravity',13,'compensation/Discrete State-Space2']],...
		'Mask Display','Sampler',...
		'position',[225,19,275,51])

add_block('built-in/Inport',[sys,'/',['friction and gravity',13,'compensation/q']])
set_param([sys,'/',['friction and gravity',13,'compensation/q']],...
		'orientation',2,...
		'Port','2',...
		'position',[305,25,325,45])

add_block('built-in/Inport',[sys,'/',['friction and gravity',13,'compensation/dq']])
set_param([sys,'/',['friction and gravity',13,'compensation/dq']],...
		'orientation',2,...
		'position',[305,80,325,100])

add_block('built-in/Discrete State-Space',[sys,'/',['friction and gravity',13,'compensation/Discrete State-Space3']])
set_param([sys,'/',['friction and gravity',13,'compensation/Discrete State-Space3']],...
		'orientation',2,...
		'hide name',0,...
		'A','0',...
		'B','0',...
		'C','zeros(2,1)',...
		'D','eye(2,2)',...
		'X0','0',...
		'Sample time','Tc')
set_param([sys,'/',['friction and gravity',13,'compensation/Discrete State-Space3']],...
		'Mask Display','Sampler',...
		'position',[225,74,275,106])

add_block('built-in/State-Space',[sys,'/',['friction and gravity',13,'compensation/friction']])
set_param([sys,'/',['friction and gravity',13,'compensation/friction']],...
		'orientation',2,...
		'move name',0,...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','F_v',...
		'Mask Type','Matrix Gain')
set_param([sys,'/',['friction and gravity',13,'compensation/friction']],...
		'Mask Dialogue','Matrix Gain.|Gain matrix:',...
		'Mask Translate','K = @1;')
set_param([sys,'/',['friction and gravity',13,'compensation/friction']],...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','F_v\/',...
		'position',[150,74,185,106])


%     Subsystem  ['friction and gravity',13,'compensation/gravity'].

new_system([sys,'/',['friction and gravity',13,'compensation/gravity']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity']],'Location',[72,102,550,215])

add_block('built-in/Mux',[sys,'/',['friction and gravity',13,'compensation/gravity/Mux']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Mux']],...
		'orientation',2,...
		'hide name',0,...
		'inputs','2',...
		'position',[50,21,80,99])

add_block('built-in/Fcn',[sys,'/',['friction and gravity',13,'compensation/gravity/Fcn1']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Fcn1']],...
		'orientation',2,...
		'hide name',0,...
		'Expr','cos(u)',...
		'position',[210,70,250,90])

add_block('built-in/Sum',[sys,'/',['friction and gravity',13,'compensation/gravity/Sum2']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Sum2']],...
		'orientation',2,...
		'hide name',0,...
		'position',[275,69,290,91])

add_block('built-in/Demux',[sys,'/',['friction and gravity',13,'compensation/gravity/Demux']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Demux']],...
		'orientation',2,...
		'hide name',0,...
		'outputs','2',...
		'position',[340,12,380,108])

add_block('built-in/Gain',[sys,'/',['friction and gravity',13,'compensation/gravity/Gain']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Gain']],...
		'orientation',2,...
		'hide name',0,...
		'Gain','g*pi_m(3)',...
		'Mask Display','k_2',...
		'position',[160,63,185,97])

add_block('built-in/Fcn',[sys,'/',['friction and gravity',13,'compensation/gravity/Fcn2']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Fcn2']],...
		'orientation',2,...
		'hide name',0,...
		'Expr','cos(u)',...
		'position',[210,25,250,45])

add_block('built-in/Gain',[sys,'/',['friction and gravity',13,'compensation/gravity/Gain1']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Gain1']],...
		'orientation',2,...
		'hide name',0,...
		'Gain','g*pi_m(1)',...
		'Mask Display','k_1',...
		'position',[160,18,185,52])

add_block('built-in/Sum',[sys,'/',['friction and gravity',13,'compensation/gravity/Sum5']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/Sum5']],...
		'orientation',2,...
		'hide name',0,...
		'position',[105,29,120,51])

add_block('built-in/Outport',[sys,'/',['friction and gravity',13,'compensation/gravity/g']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/g']],...
		'orientation',2,...
		'position',[5,50,25,70])

add_block('built-in/Inport',[sys,'/',['friction and gravity',13,'compensation/gravity/q']])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity/q']],...
		'orientation',2,...
		'position',[415,50,435,70])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[410,60;385,60])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[335,85;295,85])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[270,80;255,80])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[205,80;190,80])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[205,35;190,35])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[335,35;255,35])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[315,35;315,75;295,75])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[155,35;125,35])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[100,40;85,40])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[155,80;85,80])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[155,80;150,80;150,45;125,45])
add_line([sys,'/',['friction and gravity',13,'compensation/gravity']],[45,60;30,60])
set_param([sys,'/',['friction and gravity',13,'compensation/gravity']],...
		'Mask Display','g(q)')


%     Finished composite block ['friction and gravity',13,'compensation/gravity'].

set_param([sys,'/',['friction and gravity',13,'compensation/gravity']],...
		'orientation',2,...
		'move name',0,...
		'position',[150,18,185,52])
add_line([sys,'/',['friction and gravity',13,'compensation']],[220,35;190,35])
add_line([sys,'/',['friction and gravity',13,'compensation']],[220,90;190,90])
add_line([sys,'/',['friction and gravity',13,'compensation']],[145,35;115,35;115,75;85,75])
add_line([sys,'/',['friction and gravity',13,'compensation']],[60,85;40,85])
add_line([sys,'/',['friction and gravity',13,'compensation']],[300,35;280,35])
add_line([sys,'/',['friction and gravity',13,'compensation']],[300,90;280,90])
add_line([sys,'/',['friction and gravity',13,'compensation']],[145,90;85,90])
set_param([sys,'/',['friction and gravity',13,'compensation']],...
		'Mask Display','F_vdq+g(q)')


%     Finished composite block ['friction and gravity',13,'compensation'].

set_param([sys,'/',['friction and gravity',13,'compensation']],...
		'orientation',2,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[335,210,410,245])

add_block('built-in/Note',[sys,'/','dq'])
set_param([sys,'/','dq'],...
		'Font Name','Arial',...
		'position',[425,124,430,131])
add_line(sys,[445,15;465,15])
add_line(sys,[310,155;320,155])
add_line(sys,[220,145;230,145])
add_line(sys,[105,155;135,155])
add_line(sys,[105,210;135,210])
add_line(sys,[425,165;465,165])
add_line(sys,[425,145;435,145;435,100;70,100;80,145])
add_line(sys,[330,230;275,230;285,160])
add_line(sys,[435,145;435,220;415,220])
add_line(sys,[450,165;450,235;415,235])
add_line(sys,[60,165;80,165])
add_line(sys,[60,200;80,200])
add_line(sys,[450,235;450,275;70,275;80,215])
add_line(sys,[270,145;285,145])
add_line(sys,[120,210;120,80;135,80])
add_line(sys,[105,155;105,65;135,65])
add_line(sys,[120,210;120,255;135,255])
add_line(sys,[175,210;180,210;180,175;195,175])
add_line(sys,[175,155;195,155])
add_line(sys,[310,155;310,115;465,115])
add_line(sys,[180,75;185,75;195,115])
add_line(sys,[60,125;185,125;195,135])

drawnow

% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str,ts,xts] = feval(sys);
	end
else
	drawnow % Flash up the model and execute load callback
end
