├── README.md ├── SMC_01 ├── Draw_image.m ├── SMC_20231127.slx ├── SMC_20231127.slxc ├── Setsignal_sin.m ├── ctrl.m ├── parameters.m ├── plant.m └── slprj │ └── sim │ └── varcache │ └── SMC_20231127 │ ├── checksumOfCache.mat │ ├── tmwinternal │ └── simulink_cache.xml │ └── varInfo.mat ├── SMC_02 ├── Draw_image.m ├── SMC_02.slx ├── SMC_02.slxc ├── SMC_20231127 │ ├── Draw_image.m │ ├── SMC_20231127.slx │ ├── SMC_20231127.slxc │ ├── Setsignal_sin.m │ ├── ctrl.m │ ├── parameters.m │ ├── plant.m │ └── slprj │ │ └── sim │ │ └── varcache │ │ └── SMC_20231127 │ │ ├── checksumOfCache.mat │ │ ├── tmwinternal │ │ └── simulink_cache.xml │ │ └── varInfo.mat ├── Setsignal_sin.m ├── ctrl.m ├── parameters.m ├── plant.m └── slprj │ └── sim │ └── varcache │ ├── SMC_02 │ ├── checksumOfCache.mat │ ├── tmwinternal │ │ └── simulink_cache.xml │ └── varInfo.mat │ └── SMC_20231127 │ ├── checksumOfCache.mat │ ├── tmwinternal │ └── simulink_cache.xml │ └── varInfo.mat ├── SMC_03 ├── Draw_image.m ├── SMC_03.slx ├── SMC_03.slxc ├── Setsignal_sin.m ├── ctrl.m ├── parameters.asv ├── parameters.m ├── plant.m └── slprj │ └── sim │ └── varcache │ ├── SMC_03 │ ├── checksumOfCache.mat │ ├── tmwinternal │ │ └── simulink_cache.xml │ └── varInfo.mat │ └── SMC_20231127 │ ├── checksumOfCache.mat │ ├── tmwinternal │ └── simulink_cache.xml │ └── varInfo.mat └── Sfunction_stepback ├── Sfunction_stepback.slx ├── Sfunction_stepback.slxc ├── control.m ├── paramters.m ├── plant.m └── slprj ├── _jitprj ├── jitEngineAccessInfo.mat ├── sX2Yfe1pxyu2xC8T2Eu5H7F.l ├── sX2Yfe1pxyu2xC8T2Eu5H7F.mat ├── sfXW1nIMkrZLYsvBGqRrigE.l ├── sfXW1nIMkrZLYsvBGqRrigE.mat ├── socxbc910PMJ01QGKVGzVvE.l ├── socxbc910PMJ01QGKVGzVvE.mat ├── sstI0F1QMWe9LhhL5JPDucD.l ├── sstI0F1QMWe9LhhL5JPDucD.mat ├── stA8n33fjMBWrgpgaffxmEC.l └── stA8n33fjMBWrgpgaffxmEC.mat ├── _sfprj ├── EMLReport │ ├── emlReportAccessInfo.mat │ ├── sX2Yfe1pxyu2xC8T2Eu5H7F.mat │ ├── sfXW1nIMkrZLYsvBGqRrigE.mat │ ├── socxbc910PMJ01QGKVGzVvE.mat │ ├── sstI0F1QMWe9LhhL5JPDucD.mat │ └── stA8n33fjMBWrgpgaffxmEC.mat ├── Sfunction_stepback │ ├── _self │ │ └── sfun │ │ │ └── info │ │ │ └── binfo.mat │ └── amsi_serial.mat ├── precompile │ ├── 40AINUu0jtHx6tQTp8eOfC.mat │ ├── OrXLW1YDvOiz7Xo1y3hGhB.mat │ ├── asaTyfKRNSdP8MYejGFpyD.mat │ ├── autoInferAccessInfo.mat │ ├── evRWH5OJTBskC1teQMmMbF.mat │ └── pbIqipBPuPBo5Sz5ynqMwE.mat └── sliding_mode │ ├── _self │ └── sfun │ │ └── info │ │ └── binfo.mat │ └── amsi_serial.mat └── sim └── varcache └── Sfunction_stepback ├── checksumOfCache.mat ├── tmwinternal └── simulink_cache.xml └── varInfo.mat /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Sliding_Mode_Control_simulink 3 | %matlab simulink仿真文件 ,来源参考B站UP主德狗追求独立关于滑模控制的视频 4 | 其中一共有四个文件夹: 5 | Sfunction_setpback是反步法用s函数搭建对应的仿真 6 | SMC_01是普通滑模控制对应的仿真 7 | SMC_02是鲁棒滑模控制中干扰知道最大值和最小值的情况 8 | SMC_03是鲁棒滑模控制中干扰只知道绝对值小于某个值对应的情况,这种情况有点特殊,或是我搭错了,我发现无论怎么修改D的值,仿真结果都能很好跟上输入 9 | 10 | 11 | -------------------------------------------------------------------------------- /SMC_01/Draw_image.m: -------------------------------------------------------------------------------- 1 | 2 | e=out.e; 3 | de=out.de 4 | ce=-pa.c.*e; 5 | plot(e,ce,'r',e,de,'g','LineWidth',2); 6 | title('e_de'); 7 | xlabel('e'),ylabel('de'); 8 | legend('s=0','s_chang') 9 | -------------------------------------------------------------------------------- /SMC_01/SMC_20231127.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_01/SMC_20231127.slx -------------------------------------------------------------------------------- /SMC_01/SMC_20231127.slxc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_01/SMC_20231127.slxc -------------------------------------------------------------------------------- /SMC_01/Setsignal_sin.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = Setsignal_sin(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 0; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | 234 | A = pa.A; 235 | T = pa.T; 236 | 237 | x1d= A*sin(2*pi/T*t); 238 | dx1d=2*pi/T*A*cos(2*pi/T*t); 239 | ddx1d=-2*pi/T*2*pi/T*A*sin(2*pi/T*t); 240 | 241 | sys = [x1d;dx1d;ddx1d]; 242 | 243 | % end mdlOutputs 244 | 245 | % 246 | %============================================================================= 247 | % mdlGetTimeOfNextVarHit 248 | % Return the time of the next hit for this block. Note that the result is 249 | % absolute time. Note that this function is only used when you specify a 250 | % variable discrete-time sample time [-2 0] in the sample time array in 251 | % mdlInitializeSizes. 252 | %============================================================================= 253 | % 254 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 255 | 256 | sampleTime = 1; % Example, set the next hit to be one second later. 257 | sys = t + sampleTime; 258 | 259 | % end mdlGetTimeOfNextVarHit 260 | 261 | % 262 | %============================================================================= 263 | % mdlTerminate 264 | % Perform any end of simulation tasks. 265 | %============================================================================= 266 | % 267 | function sys=mdlTerminate(t,x,u) 268 | 269 | sys = []; 270 | 271 | % end mdlTerminate 272 | -------------------------------------------------------------------------------- /SMC_01/ctrl.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = ctrl(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 5; 172 | sizes.DirFeedthrough = 1; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | x1d=u(1); 234 | dx1d=u(2); 235 | ddx1d=u(3); 236 | x1=u(4); 237 | x2=u(5); 238 | 239 | c=pa.c; 240 | cosai=pa.cosai; 241 | p=pa.p; 242 | k=pa.k; 243 | m=pa.m; 244 | 245 | e=x1d-x1; 246 | de=dx1d-x2; 247 | s=c*e+de; 248 | 249 | if pa.M==1 250 | uc=m*[cosai*sign(s)+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3] 251 | elseif pa.M==2 252 | if(abs(s)>pa.dert) 253 | sat=sign(s) 254 | else 255 | sat=s/pa.dert 256 | end 257 | uc=m*[cosai*sat+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3] 258 | end 259 | sys =[uc;e;de]; 260 | 261 | % end mdlOutputs 262 | 263 | % 264 | %============================================================================= 265 | % mdlGetTimeOfNextVarHit 266 | % Return the time of the next hit for this block. Note that the result is 267 | % absolute time. Note that this function is only used when you specify a 268 | % variable discrete-time sample time [-2 0] in the sample time array in 269 | % mdlInitializeSizes. 270 | %============================================================================= 271 | % 272 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 273 | 274 | sampleTime = 1; % Example, set the next hit to be one second later. 275 | sys = t + sampleTime; 276 | 277 | % end mdlGetTimeOfNextVarHit 278 | 279 | % 280 | %============================================================================= 281 | % mdlTerminate 282 | % Perform any end of simulation tasks. 283 | %============================================================================= 284 | % 285 | function sys=mdlTerminate(t,x,u) 286 | 287 | sys = []; 288 | 289 | % end mdlTerminate 290 | -------------------------------------------------------------------------------- /SMC_01/parameters.m: -------------------------------------------------------------------------------- 1 | clc 2 | pa=struct('k',8,'m',1,'p',5,'c',15,'A',5,'T',20,'cosai',5,'M',2,'dert',0.1) 3 | -------------------------------------------------------------------------------- /SMC_01/plant.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = plant(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u,pa); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 2; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 2; 171 | sizes.NumInputs = 1; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = [0.5;0.5]; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u,pa) 208 | k=pa.k; 209 | m=pa.m; 210 | x2=x(2); 211 | x1=x(1); 212 | 213 | dx1=x2; 214 | dx2=-k/m*x1^3+1/m*u; 215 | 216 | sys = [dx1;dx2]; 217 | 218 | % end mdlDerivatives 219 | 220 | % 221 | %============================================================================= 222 | % mdlUpdate 223 | % Handle discrete state updates, sample time hits, and major time step 224 | % requirements. 225 | %============================================================================= 226 | % 227 | function sys=mdlUpdate(t,x,u) 228 | 229 | sys = []; 230 | 231 | % end mdlUpdate 232 | 233 | % 234 | %============================================================================= 235 | % mdlOutputs 236 | % Return the block outputs. 237 | %============================================================================= 238 | % 239 | function sys=mdlOutputs(t,x,u) 240 | 241 | sys = x; 242 | 243 | % end mdlOutputs 244 | 245 | % 246 | %============================================================================= 247 | % mdlGetTimeOfNextVarHit 248 | % Return the time of the next hit for this block. Note that the result is 249 | % absolute time. Note that this function is only used when you specify a 250 | % variable discrete-time sample time [-2 0] in the sample time array in 251 | % mdlInitializeSizes. 252 | %============================================================================= 253 | % 254 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 255 | 256 | sampleTime = 1; % Example, set the next hit to be one second later. 257 | sys = t + sampleTime; 258 | 259 | % end mdlGetTimeOfNextVarHit 260 | 261 | % 262 | %============================================================================= 263 | % mdlTerminate 264 | % Perform any end of simulation tasks. 265 | %============================================================================= 266 | % 267 | function sys=mdlTerminate(t,x,u) 268 | 269 | sys = []; 270 | 271 | % end mdlTerminate 272 | -------------------------------------------------------------------------------- /SMC_01/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_01/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat -------------------------------------------------------------------------------- /SMC_01/slprj/sim/varcache/SMC_20231127/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | qSPu1UMO1EorfPVlOOOjaoggSRXg9i+d/Vuqm+ZBEtMLOdwgPt8Y/Vp4lbX92HhW8z7iMIBxqxVAGsivmD/Mxg== 5 | 6 | -------------------------------------------------------------------------------- /SMC_01/slprj/sim/varcache/SMC_20231127/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_01/slprj/sim/varcache/SMC_20231127/varInfo.mat -------------------------------------------------------------------------------- /SMC_02/Draw_image.m: -------------------------------------------------------------------------------- 1 | 2 | e=out.e; 3 | de=out.de 4 | ce=-pa.c.*e; 5 | plot(e,ce,'r',e,de,'g','LineWidth',2); 6 | title('e_de'); 7 | xlabel('e'),ylabel('de'); 8 | legend('s=0','s_chang') 9 | -------------------------------------------------------------------------------- /SMC_02/SMC_02.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/SMC_02.slx -------------------------------------------------------------------------------- /SMC_02/SMC_02.slxc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/SMC_02.slxc -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/Draw_image.m: -------------------------------------------------------------------------------- 1 | 2 | e=out.e; 3 | de=out.de 4 | ce=-pa.c.*e; 5 | plot(e,ce,'r',e,de,'g','LineWidth',2); 6 | title('e_de'); 7 | xlabel('e'),ylabel('de'); 8 | legend('s=0','s_chang') 9 | -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/SMC_20231127.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/SMC_20231127/SMC_20231127.slx -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/SMC_20231127.slxc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/SMC_20231127/SMC_20231127.slxc -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/Setsignal_sin.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = Setsignal_sin(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 0; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | 234 | A = pa.A; 235 | T = pa.T; 236 | 237 | x1d= A*sin(2*pi/T*t); 238 | dx1d=2*pi/T*A*cos(2*pi/T*t); 239 | ddx1d=-2*pi/T*2*pi/T*A*sin(2*pi/T*t); 240 | 241 | sys = [x1d;dx1d;ddx1d]; 242 | 243 | % end mdlOutputs 244 | 245 | % 246 | %============================================================================= 247 | % mdlGetTimeOfNextVarHit 248 | % Return the time of the next hit for this block. Note that the result is 249 | % absolute time. Note that this function is only used when you specify a 250 | % variable discrete-time sample time [-2 0] in the sample time array in 251 | % mdlInitializeSizes. 252 | %============================================================================= 253 | % 254 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 255 | 256 | sampleTime = 1; % Example, set the next hit to be one second later. 257 | sys = t + sampleTime; 258 | 259 | % end mdlGetTimeOfNextVarHit 260 | 261 | % 262 | %============================================================================= 263 | % mdlTerminate 264 | % Perform any end of simulation tasks. 265 | %============================================================================= 266 | % 267 | function sys=mdlTerminate(t,x,u) 268 | 269 | sys = []; 270 | 271 | % end mdlTerminate 272 | -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/ctrl.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = ctrl(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 5; 172 | sizes.DirFeedthrough = 1; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | x1d=u(1); 234 | dx1d=u(2); 235 | ddx1d=u(3); 236 | x1=u(4); 237 | x2=u(5); 238 | 239 | c=pa.c; 240 | cosai=pa.cosai; 241 | p=pa.p; 242 | k=pa.k; 243 | m=pa.m; 244 | 245 | e=x1d-x1; 246 | de=dx1d-x2; 247 | s=c*e+de; 248 | 249 | if pa.M==1 250 | uc=m*[cosai*sign(s)+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3] 251 | elseif pa.M==2 252 | if(abs(s)>pa.dert) 253 | sat=sign(s) 254 | else 255 | sat=s/pa.dert 256 | end 257 | uc=m*[cosai*sat+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3] 258 | end 259 | sys =[uc;e;de]; 260 | 261 | % end mdlOutputs 262 | 263 | % 264 | %============================================================================= 265 | % mdlGetTimeOfNextVarHit 266 | % Return the time of the next hit for this block. Note that the result is 267 | % absolute time. Note that this function is only used when you specify a 268 | % variable discrete-time sample time [-2 0] in the sample time array in 269 | % mdlInitializeSizes. 270 | %============================================================================= 271 | % 272 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 273 | 274 | sampleTime = 1; % Example, set the next hit to be one second later. 275 | sys = t + sampleTime; 276 | 277 | % end mdlGetTimeOfNextVarHit 278 | 279 | % 280 | %============================================================================= 281 | % mdlTerminate 282 | % Perform any end of simulation tasks. 283 | %============================================================================= 284 | % 285 | function sys=mdlTerminate(t,x,u) 286 | 287 | sys = []; 288 | 289 | % end mdlTerminate 290 | -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/parameters.m: -------------------------------------------------------------------------------- 1 | clc 2 | pa=struct('k',8,'m',1,'p',5,'c',15,'A',5,'T',20,'cosai',5,'M',2,'dert',0.1) 3 | -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/plant.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = plant(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u,pa); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 2; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 2; 171 | sizes.NumInputs = 1; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = [0.5;0.5]; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u,pa) 208 | k=pa.k; 209 | m=pa.m; 210 | x2=x(2); 211 | x1=x(1); 212 | 213 | dx1=x2; 214 | dx2=-k/m*x1^3+1/m*u; 215 | 216 | sys = [dx1;dx2]; 217 | 218 | % end mdlDerivatives 219 | 220 | % 221 | %============================================================================= 222 | % mdlUpdate 223 | % Handle discrete state updates, sample time hits, and major time step 224 | % requirements. 225 | %============================================================================= 226 | % 227 | function sys=mdlUpdate(t,x,u) 228 | 229 | sys = []; 230 | 231 | % end mdlUpdate 232 | 233 | % 234 | %============================================================================= 235 | % mdlOutputs 236 | % Return the block outputs. 237 | %============================================================================= 238 | % 239 | function sys=mdlOutputs(t,x,u) 240 | 241 | sys = x; 242 | 243 | % end mdlOutputs 244 | 245 | % 246 | %============================================================================= 247 | % mdlGetTimeOfNextVarHit 248 | % Return the time of the next hit for this block. Note that the result is 249 | % absolute time. Note that this function is only used when you specify a 250 | % variable discrete-time sample time [-2 0] in the sample time array in 251 | % mdlInitializeSizes. 252 | %============================================================================= 253 | % 254 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 255 | 256 | sampleTime = 1; % Example, set the next hit to be one second later. 257 | sys = t + sampleTime; 258 | 259 | % end mdlGetTimeOfNextVarHit 260 | 261 | % 262 | %============================================================================= 263 | % mdlTerminate 264 | % Perform any end of simulation tasks. 265 | %============================================================================= 266 | % 267 | function sys=mdlTerminate(t,x,u) 268 | 269 | sys = []; 270 | 271 | % end mdlTerminate 272 | -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/SMC_20231127/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/slprj/sim/varcache/SMC_20231127/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | qSPu1UMO1EorfPVlOOOjaoggSRXg9i+d/Vuqm+ZBEtMLOdwgPt8Y/Vp4lbX92HhW8z7iMIBxqxVAGsivmD/Mxg== 5 | 6 | -------------------------------------------------------------------------------- /SMC_02/SMC_20231127/slprj/sim/varcache/SMC_20231127/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/SMC_20231127/slprj/sim/varcache/SMC_20231127/varInfo.mat -------------------------------------------------------------------------------- /SMC_02/Setsignal_sin.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = Setsignal_sin(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 0; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | 234 | A = pa.A; 235 | T = pa.T; 236 | 237 | x1d= A*sin(2*pi/T*t); 238 | dx1d=2*pi/T*A*cos(2*pi/T*t); 239 | ddx1d=-2*pi/T*2*pi/T*A*sin(2*pi/T*t); 240 | 241 | sys = [x1d;dx1d;ddx1d]; 242 | 243 | % end mdlOutputs 244 | 245 | % 246 | %============================================================================= 247 | % mdlGetTimeOfNextVarHit 248 | % Return the time of the next hit for this block. Note that the result is 249 | % absolute time. Note that this function is only used when you specify a 250 | % variable discrete-time sample time [-2 0] in the sample time array in 251 | % mdlInitializeSizes. 252 | %============================================================================= 253 | % 254 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 255 | 256 | sampleTime = 1; % Example, set the next hit to be one second later. 257 | sys = t + sampleTime; 258 | 259 | % end mdlGetTimeOfNextVarHit 260 | 261 | % 262 | %============================================================================= 263 | % mdlTerminate 264 | % Perform any end of simulation tasks. 265 | %============================================================================= 266 | % 267 | function sys=mdlTerminate(t,x,u) 268 | 269 | sys = []; 270 | 271 | % end mdlTerminate 272 | -------------------------------------------------------------------------------- /SMC_02/ctrl.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = ctrl(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 5; 172 | sizes.DirFeedthrough = 1; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | x1d=u(1); 234 | dx1d=u(2); 235 | ddx1d=u(3); 236 | x1=u(4); 237 | x2=u(5); 238 | 239 | c=pa.c; 240 | cosai=pa.cosai; 241 | p=pa.p; 242 | k=pa.k; 243 | m=pa.m; 244 | dU=pa.dU; 245 | dL=pa.dL; 246 | 247 | e=x1d-x1; 248 | de=dx1d-x2; 249 | s=c*e+de; 250 | dt=5*sin(2*t); 251 | d1=(dU-dL)/2; 252 | d2=(dU+dL)/2; 253 | dc=d2-d1*sign(s); 254 | 255 | if pa.M==1 256 | uc=m*[cosai*sign(s)+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3-dc/m] 257 | elseif pa.M==2 258 | if(abs(s)>pa.dert) 259 | sat=sign(s) 260 | else 261 | sat=s/pa.dert 262 | dc=d2-d1*sat; 263 | end 264 | uc=m*[cosai*sat+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3-dc/m] 265 | end 266 | sys =[uc;e;de]; 267 | 268 | % end mdlOutputs 269 | 270 | % 271 | %============================================================================= 272 | % mdlGetTimeOfNextVarHit 273 | % Return the time of the next hit for this block. Note that the result is 274 | % absolute time. Note that this function is only used when you specify a 275 | % variable discrete-time sample time [-2 0] in the sample time array in 276 | % mdlInitializeSizes. 277 | %============================================================================= 278 | % 279 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 280 | 281 | sampleTime = 1; % Example, set the next hit to be one second later. 282 | sys = t + sampleTime; 283 | 284 | % end mdlGetTimeOfNextVarHit 285 | 286 | % 287 | %============================================================================= 288 | % mdlTerminate 289 | % Perform any end of simulation tasks. 290 | %============================================================================= 291 | % 292 | function sys=mdlTerminate(t,x,u) 293 | 294 | sys = []; 295 | 296 | % end mdlTerminate 297 | -------------------------------------------------------------------------------- /SMC_02/parameters.m: -------------------------------------------------------------------------------- 1 | clc 2 | pa=struct('k',8,'m',1,'p',5,'c',15,'A',5,'T',20,'cosai',5,'M',2,'dert',0.1,'dU',5,'dL',-5) 3 | -------------------------------------------------------------------------------- /SMC_02/plant.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = plant(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u,pa); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 2; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 2; 171 | sizes.NumInputs = 1; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = [0.5;0.5]; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u,pa) 208 | k=pa.k; 209 | m=pa.m; 210 | x2=x(2); 211 | x1=x(1); 212 | dt=5*sin(2*t); 213 | 214 | dx1=x2; 215 | dx2=-k/m*x1^3+1/m*u-dt/m; 216 | 217 | sys = [dx1;dx2]; 218 | 219 | % end mdlDerivatives 220 | 221 | % 222 | %============================================================================= 223 | % mdlUpdate 224 | % Handle discrete state updates, sample time hits, and major time step 225 | % requirements. 226 | %============================================================================= 227 | % 228 | function sys=mdlUpdate(t,x,u) 229 | 230 | sys = []; 231 | 232 | % end mdlUpdate 233 | 234 | % 235 | %============================================================================= 236 | % mdlOutputs 237 | % Return the block outputs. 238 | %============================================================================= 239 | % 240 | function sys=mdlOutputs(t,x,u) 241 | 242 | sys = x; 243 | 244 | % end mdlOutputs 245 | 246 | % 247 | %============================================================================= 248 | % mdlGetTimeOfNextVarHit 249 | % Return the time of the next hit for this block. Note that the result is 250 | % absolute time. Note that this function is only used when you specify a 251 | % variable discrete-time sample time [-2 0] in the sample time array in 252 | % mdlInitializeSizes. 253 | %============================================================================= 254 | % 255 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 256 | 257 | sampleTime = 1; % Example, set the next hit to be one second later. 258 | sys = t + sampleTime; 259 | 260 | % end mdlGetTimeOfNextVarHit 261 | 262 | % 263 | %============================================================================= 264 | % mdlTerminate 265 | % Perform any end of simulation tasks. 266 | %============================================================================= 267 | % 268 | function sys=mdlTerminate(t,x,u) 269 | 270 | sys = []; 271 | 272 | % end mdlTerminate 273 | -------------------------------------------------------------------------------- /SMC_02/slprj/sim/varcache/SMC_02/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/slprj/sim/varcache/SMC_02/checksumOfCache.mat -------------------------------------------------------------------------------- /SMC_02/slprj/sim/varcache/SMC_02/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | bqObjZ5MPL5neoRDwFpjGLsY07Yi2EQq1xsYWV4A5obTjyfCmR260b/H6Lg8RM02zUtHN3D6TcL20XNrGnY3Jw== 5 | 6 | -------------------------------------------------------------------------------- /SMC_02/slprj/sim/varcache/SMC_02/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/slprj/sim/varcache/SMC_02/varInfo.mat -------------------------------------------------------------------------------- /SMC_02/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat -------------------------------------------------------------------------------- /SMC_02/slprj/sim/varcache/SMC_20231127/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | qSPu1UMO1EorfPVlOOOjaoggSRXg9i+d/Vuqm+ZBEtMLOdwgPt8Y/Vp4lbX92HhW8z7iMIBxqxVAGsivmD/Mxg== 5 | 6 | -------------------------------------------------------------------------------- /SMC_02/slprj/sim/varcache/SMC_20231127/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_02/slprj/sim/varcache/SMC_20231127/varInfo.mat -------------------------------------------------------------------------------- /SMC_03/Draw_image.m: -------------------------------------------------------------------------------- 1 | 2 | e=out.e; 3 | de=out.de 4 | ce=-pa.c.*e; 5 | plot(e,ce,'r',e,de,'g','LineWidth',2); 6 | title('e_de'); 7 | xlabel('e'),ylabel('de'); 8 | legend('s=0','s_chang') 9 | -------------------------------------------------------------------------------- /SMC_03/SMC_03.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_03/SMC_03.slx -------------------------------------------------------------------------------- /SMC_03/SMC_03.slxc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_03/SMC_03.slxc -------------------------------------------------------------------------------- /SMC_03/Setsignal_sin.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = Setsignal_sin(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 0; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | 234 | A = pa.A; 235 | T = pa.T; 236 | 237 | x1d= A*sin(2*pi/T*t); 238 | dx1d=2*pi/T*A*cos(2*pi/T*t); 239 | ddx1d=-2*pi/T*2*pi/T*A*sin(2*pi/T*t); 240 | 241 | sys = [x1d;dx1d;ddx1d]; 242 | 243 | % end mdlOutputs 244 | 245 | % 246 | %============================================================================= 247 | % mdlGetTimeOfNextVarHit 248 | % Return the time of the next hit for this block. Note that the result is 249 | % absolute time. Note that this function is only used when you specify a 250 | % variable discrete-time sample time [-2 0] in the sample time array in 251 | % mdlInitializeSizes. 252 | %============================================================================= 253 | % 254 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 255 | 256 | sampleTime = 1; % Example, set the next hit to be one second later. 257 | sys = t + sampleTime; 258 | 259 | % end mdlGetTimeOfNextVarHit 260 | 261 | % 262 | %============================================================================= 263 | % mdlTerminate 264 | % Perform any end of simulation tasks. 265 | %============================================================================= 266 | % 267 | function sys=mdlTerminate(t,x,u) 268 | 269 | sys = []; 270 | 271 | % end mdlTerminate 272 | -------------------------------------------------------------------------------- /SMC_03/ctrl.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = ctrl(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 3; 171 | sizes.NumInputs = 5; 172 | sizes.DirFeedthrough = 1; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | x1d=u(1); 234 | dx1d=u(2); 235 | ddx1d=u(3); 236 | x1=u(4); 237 | x2=u(5); 238 | 239 | c=pa.c; 240 | cosai=pa.cosai; 241 | p=pa.p; 242 | k=pa.k; 243 | m=pa.m; 244 | 245 | e=x1d-x1; 246 | de=dx1d-x2; 247 | s=c*e+de; 248 | 249 | if pa.M==1 250 | uc=m*[cosai*sign(s)+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3] 251 | elseif pa.M==2 252 | if(abs(s)>pa.dert) 253 | sat=sign(s) 254 | else 255 | sat=s/pa.dert 256 | end 257 | uc=m*[cosai*sat+p*s+c*(dx1d-x2)+ddx1d+k/m*x1^3] 258 | end 259 | sys =[uc;e;de]; 260 | 261 | % end mdlOutputs 262 | 263 | % 264 | %============================================================================= 265 | % mdlGetTimeOfNextVarHit 266 | % Return the time of the next hit for this block. Note that the result is 267 | % absolute time. Note that this function is only used when you specify a 268 | % variable discrete-time sample time [-2 0] in the sample time array in 269 | % mdlInitializeSizes. 270 | %============================================================================= 271 | % 272 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 273 | 274 | sampleTime = 1; % Example, set the next hit to be one second later. 275 | sys = t + sampleTime; 276 | 277 | % end mdlGetTimeOfNextVarHit 278 | 279 | % 280 | %============================================================================= 281 | % mdlTerminate 282 | % Perform any end of simulation tasks. 283 | %============================================================================= 284 | % 285 | function sys=mdlTerminate(t,x,u) 286 | 287 | sys = []; 288 | 289 | % end mdlTerminate 290 | -------------------------------------------------------------------------------- /SMC_03/parameters.asv: -------------------------------------------------------------------------------- 1 | clc 2 | pa=struct('k',8,'m',1,'p',5,'c',15,'A',5,'T',20,'cosai',5,'M',2,'dert',0.1,'D',10) 3 | -------------------------------------------------------------------------------- /SMC_03/parameters.m: -------------------------------------------------------------------------------- 1 | clc 2 | pa=struct('k',8,'m',1,'p',5,'c',15,'A',5,'T',20,'cosai',5,'M',2,'dert',0.1,'D',5) 3 | -------------------------------------------------------------------------------- /SMC_03/plant.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = plant(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u,pa); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 2; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 2; 171 | sizes.NumInputs = 1; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = [0.5;0.5]; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u,pa) 208 | k=pa.k; 209 | m=pa.m; 210 | x2=x(2); 211 | x1=x(1); 212 | dt=5*sin(2*t); 213 | 214 | dx1=x2; 215 | dx2=-k/m*x1^3+1/m*u-dt/m; 216 | 217 | sys = [dx1;dx2]; 218 | 219 | % end mdlDerivatives 220 | 221 | % 222 | %============================================================================= 223 | % mdlUpdate 224 | % Handle discrete state updates, sample time hits, and major time step 225 | % requirements. 226 | %============================================================================= 227 | % 228 | function sys=mdlUpdate(t,x,u) 229 | 230 | sys = []; 231 | 232 | % end mdlUpdate 233 | 234 | % 235 | %============================================================================= 236 | % mdlOutputs 237 | % Return the block outputs. 238 | %============================================================================= 239 | % 240 | function sys=mdlOutputs(t,x,u) 241 | 242 | sys = x; 243 | 244 | % end mdlOutputs 245 | 246 | % 247 | %============================================================================= 248 | % mdlGetTimeOfNextVarHit 249 | % Return the time of the next hit for this block. Note that the result is 250 | % absolute time. Note that this function is only used when you specify a 251 | % variable discrete-time sample time [-2 0] in the sample time array in 252 | % mdlInitializeSizes. 253 | %============================================================================= 254 | % 255 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 256 | 257 | sampleTime = 1; % Example, set the next hit to be one second later. 258 | sys = t + sampleTime; 259 | 260 | % end mdlGetTimeOfNextVarHit 261 | 262 | % 263 | %============================================================================= 264 | % mdlTerminate 265 | % Perform any end of simulation tasks. 266 | %============================================================================= 267 | % 268 | function sys=mdlTerminate(t,x,u) 269 | 270 | sys = []; 271 | 272 | % end mdlTerminate 273 | -------------------------------------------------------------------------------- /SMC_03/slprj/sim/varcache/SMC_03/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_03/slprj/sim/varcache/SMC_03/checksumOfCache.mat -------------------------------------------------------------------------------- /SMC_03/slprj/sim/varcache/SMC_03/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /Y72PBqCG1Y4UpJtc5xKkzCTDRPmL0s9TZBSU2wZ1idM+C75FZ3uhI7pjyNpr/M0Lvgsfu5I7zRUHARkRsMobA== 5 | 6 | -------------------------------------------------------------------------------- /SMC_03/slprj/sim/varcache/SMC_03/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_03/slprj/sim/varcache/SMC_03/varInfo.mat -------------------------------------------------------------------------------- /SMC_03/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_03/slprj/sim/varcache/SMC_20231127/checksumOfCache.mat -------------------------------------------------------------------------------- /SMC_03/slprj/sim/varcache/SMC_20231127/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | qSPu1UMO1EorfPVlOOOjaoggSRXg9i+d/Vuqm+ZBEtMLOdwgPt8Y/Vp4lbX92HhW8z7iMIBxqxVAGsivmD/Mxg== 5 | 6 | -------------------------------------------------------------------------------- /SMC_03/slprj/sim/varcache/SMC_20231127/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/SMC_03/slprj/sim/varcache/SMC_20231127/varInfo.mat -------------------------------------------------------------------------------- /Sfunction_stepback/Sfunction_stepback.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/Sfunction_stepback.slx -------------------------------------------------------------------------------- /Sfunction_stepback/Sfunction_stepback.slxc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/Sfunction_stepback.slxc -------------------------------------------------------------------------------- /Sfunction_stepback/control.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = control(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u,pa); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 0; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 1; 171 | sizes.NumInputs = 5; 172 | sizes.DirFeedthrough = 1; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = []; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u) 208 | 209 | sys = []; 210 | 211 | % end mdlDerivatives 212 | 213 | % 214 | %============================================================================= 215 | % mdlUpdate 216 | % Handle discrete state updates, sample time hits, and major time step 217 | % requirements. 218 | %============================================================================= 219 | % 220 | function sys=mdlUpdate(t,x,u) 221 | 222 | sys = []; 223 | 224 | % end mdlUpdate 225 | 226 | % 227 | %============================================================================= 228 | % mdlOutputs 229 | % Return the block outputs. 230 | %============================================================================= 231 | % 232 | function sys=mdlOutputs(t,x,u,pa) 233 | m=pa.m; 234 | k1=pa.k1; 235 | k2=pa.k2; 236 | k=pa.k; 237 | 238 | x1d=u(1); 239 | dx1d=u(2); 240 | ddx1d=u(3); 241 | x1=u(4); 242 | x2=u(5); 243 | 244 | e1=x1d-x1; 245 | e2 = dx1d + k1*e1 -x2; 246 | 247 | uc=m*e1+m*ddx1d+m*k1*(dx1d-x2)+k*x1^3+m*k2*e2; 248 | 249 | sys = uc; 250 | 251 | % end mdlOutputs 252 | 253 | % 254 | %============================================================================= 255 | % mdlGetTimeOfNextVarHit 256 | % Return the time of the next hit for this block. Note that the result is 257 | % absolute time. Note that this function is only used when you specify a 258 | % variable discrete-time sample time [-2 0] in the sample time array in 259 | % mdlInitializeSizes. 260 | %============================================================================= 261 | % 262 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 263 | 264 | sampleTime = 1; % Example, set the next hit to be one second later. 265 | sys = t + sampleTime; 266 | 267 | % end mdlGetTimeOfNextVarHit 268 | 269 | % 270 | %============================================================================= 271 | % mdlTerminate 272 | % Perform any end of simulation tasks. 273 | %============================================================================= 274 | % 275 | function sys=mdlTerminate(t,x,u) 276 | 277 | sys = []; 278 | 279 | % end mdlTerminate 280 | -------------------------------------------------------------------------------- /Sfunction_stepback/paramters.m: -------------------------------------------------------------------------------- 1 | 2 | pa.k=8; 3 | pa.k1=1; 4 | pa.k2=1; 5 | pa.m=1 -------------------------------------------------------------------------------- /Sfunction_stepback/plant.m: -------------------------------------------------------------------------------- 1 | function [sys,x0,str,ts,simStateCompliance] = plant(t,x,u,flag,pa) 2 | %SFUNTMPL General MATLAB S-Function Template 3 | % With MATLAB S-functions, you can define you own ordinary differential 4 | % equations (ODEs), discrete system equations, and/or just about 5 | % any type of algorithm to be used within a Simulink block diagram. 6 | % 7 | % The general form of an MATLAB S-function syntax is: 8 | % [SYS,X0,STR,TS,SIMSTATECOMPLIANCE] = SFUNC(T,X,U,FLAG,P1,...,Pn) 9 | % 10 | % What is returned by SFUNC at a given point in time, T, depends on the 11 | % value of the FLAG, the current state vector, X, and the current 12 | % input vector, U. 13 | % 14 | % FLAG RESULT DESCRIPTION 15 | % ----- ------ -------------------------------------------- 16 | % 0 [SIZES,X0,STR,TS] Initialization, return system sizes in SYS, 17 | % initial state in X0, state ordering strings 18 | % in STR, and sample times in TS. 19 | % 1 DX Return continuous state derivatives in SYS. 20 | % 2 DS Update discrete states SYS = X(n+1) 21 | % 3 Y Return outputs in SYS. 22 | % 4 TNEXT Return next time hit for variable step sample 23 | % time in SYS. 24 | % 5 Reserved for future (root finding). 25 | % 9 [] Termination, perform any cleanup SYS=[]. 26 | % 27 | % 28 | % The state vectors, X and X0 consists of continuous states followed 29 | % by discrete states. 30 | % 31 | % Optional parameters, P1,...,Pn can be provided to the S-function and 32 | % used during any FLAG operation. 33 | % 34 | % When SFUNC is called with FLAG = 0, the following information 35 | % should be returned: 36 | % 37 | % SYS(1) = Number of continuous states. 38 | % SYS(2) = Number of discrete states. 39 | % SYS(3) = Number of outputs. 40 | % SYS(4) = Number of inputs. 41 | % Any of the first four elements in SYS can be specified 42 | % as -1 indicating that they are dynamically sized. The 43 | % actual length for all other flags will be equal to the 44 | % length of the input, U. 45 | % SYS(5) = Reserved for root finding. Must be zero. 46 | % SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function 47 | % has direct feedthrough if U is used during the FLAG=3 48 | % call. Setting this to 0 is akin to making a promise that 49 | % U will not be used during FLAG=3. If you break the promise 50 | % then unpredictable results will occur. 51 | % SYS(7) = Number of sample times. This is the number of rows in TS. 52 | % 53 | % 54 | % X0 = Initial state conditions or [] if no states. 55 | % 56 | % STR = State ordering strings which is generally specified as []. 57 | % 58 | % TS = An m-by-2 matrix containing the sample time 59 | % (period, offset) information. Where m = number of sample 60 | % times. The ordering of the sample times must be: 61 | % 62 | % TS = [0 0, : Continuous sample time. 63 | % 0 1, : Continuous, but fixed in minor step 64 | % sample time. 65 | % PERIOD OFFSET, : Discrete sample time where 66 | % PERIOD > 0 & OFFSET < PERIOD. 67 | % -2 0]; : Variable step discrete sample time 68 | % where FLAG=4 is used to get time of 69 | % next hit. 70 | % 71 | % There can be more than one sample time providing 72 | % they are ordered such that they are monotonically 73 | % increasing. Only the needed sample times should be 74 | % specified in TS. When specifying more than one 75 | % sample time, you must check for sample hits explicitly by 76 | % seeing if 77 | % abs(round((T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD) 78 | % is within a specified tolerance, generally 1e-8. This 79 | % tolerance is dependent upon your model's sampling times 80 | % and simulation time. 81 | % 82 | % You can also specify that the sample time of the S-function 83 | % is inherited from the driving block. For functions which 84 | % change during minor steps, this is done by 85 | % specifying SYS(7) = 1 and TS = [-1 0]. For functions which 86 | % are held during minor steps, this is done by specifying 87 | % SYS(7) = 1 and TS = [-1 1]. 88 | % 89 | % SIMSTATECOMPLIANCE = Specifices how to handle this block when saving and 90 | % restoring the complete simulation state of the 91 | % model. The allowed values are: 'DefaultSimState', 92 | % 'HasNoSimState' or 'DisallowSimState'. If this value 93 | % is not speficified, then the block's compliance with 94 | % simState feature is set to 'UknownSimState'. 95 | 96 | 97 | % Copyright 1990-2010 The MathWorks, Inc. 98 | 99 | % 100 | % The following outlines the general structure of an S-function. 101 | % 102 | switch flag, 103 | 104 | %%%%%%%%%%%%%%%%%% 105 | % Initialization % 106 | %%%%%%%%%%%%%%%%%% 107 | case 0, 108 | [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes; 109 | 110 | %%%%%%%%%%%%%%% 111 | % Derivatives % 112 | %%%%%%%%%%%%%%% 113 | case 1, 114 | sys=mdlDerivatives(t,x,u,pa); 115 | 116 | %%%%%%%%%% 117 | % Update % 118 | %%%%%%%%%% 119 | case 2, 120 | sys=mdlUpdate(t,x,u); 121 | 122 | %%%%%%%%%%% 123 | % Outputs % 124 | %%%%%%%%%%% 125 | case 3, 126 | sys=mdlOutputs(t,x,u); 127 | 128 | %%%%%%%%%%%%%%%%%%%%%%% 129 | % GetTimeOfNextVarHit % 130 | %%%%%%%%%%%%%%%%%%%%%%% 131 | case 4, 132 | sys=mdlGetTimeOfNextVarHit(t,x,u); 133 | 134 | %%%%%%%%%%%%% 135 | % Terminate % 136 | %%%%%%%%%%%%% 137 | case 9, 138 | sys=mdlTerminate(t,x,u); 139 | 140 | %%%%%%%%%%%%%%%%%%%% 141 | % Unexpected flags % 142 | %%%%%%%%%%%%%%%%%%%% 143 | otherwise 144 | DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag)); 145 | 146 | end 147 | 148 | % end sfuntmpl 149 | 150 | % 151 | %============================================================================= 152 | % mdlInitializeSizes 153 | % Return the sizes, initial conditions, and sample times for the S-function. 154 | %============================================================================= 155 | % 156 | function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes 157 | 158 | % 159 | % call simsizes for a sizes structure, fill it in and convert it to a 160 | % sizes array. 161 | % 162 | % Note that in this example, the values are hard coded. This is not a 163 | % recommended practice as the characteristics of the block are typically 164 | % defined by the S-function parameters. 165 | % 166 | sizes = simsizes; 167 | 168 | sizes.NumContStates = 2; 169 | sizes.NumDiscStates = 0; 170 | sizes.NumOutputs = 2; 171 | sizes.NumInputs = 1; 172 | sizes.DirFeedthrough = 0; 173 | sizes.NumSampleTimes = 1; % at least one sample time is needed 174 | 175 | sys = simsizes(sizes); 176 | 177 | % 178 | % initialize the initial conditions 179 | % 180 | x0 = [0,0]; 181 | 182 | % 183 | % str is always an empty matrix 184 | % 185 | str = []; 186 | 187 | % 188 | % initialize the array of sample times 189 | % 190 | ts = [0 0]; 191 | 192 | % Specify the block simStateCompliance. The allowed values are: 193 | % 'UnknownSimState', < The default setting; warn and assume DefaultSimState 194 | % 'DefaultSimState', < Same sim state as a built-in block 195 | % 'HasNoSimState', < No sim state 196 | % 'DisallowSimState' < Error out when saving or restoring the model sim state 197 | simStateCompliance = 'UnknownSimState'; 198 | 199 | % end mdlInitializeSizes 200 | 201 | % 202 | %============================================================================= 203 | % mdlDerivatives 204 | % Return the derivatives for the continuous states. 205 | %============================================================================= 206 | % 207 | function sys=mdlDerivatives(t,x,u,pa) 208 | k=pa.k; 209 | m=pa.m; 210 | 211 | x1=x(1); 212 | x2=x(2); 213 | 214 | dx1=x2; 215 | dx2=-k/m*x1^3+u/m; 216 | 217 | sys = [dx1;dx2]; 218 | 219 | % end mdlDerivatives 220 | 221 | % 222 | %============================================================================= 223 | % mdlUpdate 224 | % Handle discrete state updates, sample time hits, and major time step 225 | % requirements. 226 | %============================================================================= 227 | % 228 | function sys=mdlUpdate(t,x,u) 229 | 230 | sys = []; 231 | 232 | % end mdlUpdate 233 | 234 | % 235 | %============================================================================= 236 | % mdlOutputs 237 | % Return the block outputs. 238 | %============================================================================= 239 | % 240 | function sys=mdlOutputs(t,x,u) 241 | 242 | sys = x; 243 | 244 | % end mdlOutputs 245 | 246 | % 247 | %============================================================================= 248 | % mdlGetTimeOfNextVarHit 249 | % Return the time of the next hit for this block. Note that the result is 250 | % absolute time. Note that this function is only used when you specify a 251 | % variable discrete-time sample time [-2 0] in the sample time array in 252 | % mdlInitializeSizes. 253 | %============================================================================= 254 | % 255 | function sys=mdlGetTimeOfNextVarHit(t,x,u) 256 | 257 | sampleTime = 1; % Example, set the next hit to be one second later. 258 | sys = t + sampleTime; 259 | 260 | % end mdlGetTimeOfNextVarHit 261 | 262 | % 263 | %============================================================================= 264 | % mdlTerminate 265 | % Perform any end of simulation tasks. 266 | %============================================================================= 267 | % 268 | function sys=mdlTerminate(t,x,u) 269 | 270 | sys = []; 271 | 272 | % end mdlTerminate 273 | -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/jitEngineAccessInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/jitEngineAccessInfo.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/sX2Yfe1pxyu2xC8T2Eu5H7F.l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/sX2Yfe1pxyu2xC8T2Eu5H7F.l -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/sX2Yfe1pxyu2xC8T2Eu5H7F.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/sX2Yfe1pxyu2xC8T2Eu5H7F.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/sfXW1nIMkrZLYsvBGqRrigE.l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/sfXW1nIMkrZLYsvBGqRrigE.l -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/sfXW1nIMkrZLYsvBGqRrigE.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/sfXW1nIMkrZLYsvBGqRrigE.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/socxbc910PMJ01QGKVGzVvE.l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/socxbc910PMJ01QGKVGzVvE.l -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/socxbc910PMJ01QGKVGzVvE.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/socxbc910PMJ01QGKVGzVvE.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/sstI0F1QMWe9LhhL5JPDucD.l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/sstI0F1QMWe9LhhL5JPDucD.l -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/sstI0F1QMWe9LhhL5JPDucD.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/sstI0F1QMWe9LhhL5JPDucD.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/stA8n33fjMBWrgpgaffxmEC.l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/stA8n33fjMBWrgpgaffxmEC.l -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_jitprj/stA8n33fjMBWrgpgaffxmEC.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_jitprj/stA8n33fjMBWrgpgaffxmEC.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/EMLReport/emlReportAccessInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/EMLReport/emlReportAccessInfo.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/EMLReport/sX2Yfe1pxyu2xC8T2Eu5H7F.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/EMLReport/sX2Yfe1pxyu2xC8T2Eu5H7F.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/EMLReport/sfXW1nIMkrZLYsvBGqRrigE.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/EMLReport/sfXW1nIMkrZLYsvBGqRrigE.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/EMLReport/socxbc910PMJ01QGKVGzVvE.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/EMLReport/socxbc910PMJ01QGKVGzVvE.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/EMLReport/sstI0F1QMWe9LhhL5JPDucD.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/EMLReport/sstI0F1QMWe9LhhL5JPDucD.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/EMLReport/stA8n33fjMBWrgpgaffxmEC.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/EMLReport/stA8n33fjMBWrgpgaffxmEC.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/Sfunction_stepback/_self/sfun/info/binfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/Sfunction_stepback/_self/sfun/info/binfo.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/Sfunction_stepback/amsi_serial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/Sfunction_stepback/amsi_serial.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/precompile/40AINUu0jtHx6tQTp8eOfC.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/precompile/40AINUu0jtHx6tQTp8eOfC.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/precompile/OrXLW1YDvOiz7Xo1y3hGhB.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/precompile/OrXLW1YDvOiz7Xo1y3hGhB.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/precompile/asaTyfKRNSdP8MYejGFpyD.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/precompile/asaTyfKRNSdP8MYejGFpyD.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/precompile/autoInferAccessInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/precompile/autoInferAccessInfo.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/precompile/evRWH5OJTBskC1teQMmMbF.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/precompile/evRWH5OJTBskC1teQMmMbF.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/precompile/pbIqipBPuPBo5Sz5ynqMwE.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/precompile/pbIqipBPuPBo5Sz5ynqMwE.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/sliding_mode/_self/sfun/info/binfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/sliding_mode/_self/sfun/info/binfo.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/_sfprj/sliding_mode/amsi_serial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/_sfprj/sliding_mode/amsi_serial.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/sim/varcache/Sfunction_stepback/checksumOfCache.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/sim/varcache/Sfunction_stepback/checksumOfCache.mat -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/sim/varcache/Sfunction_stepback/tmwinternal/simulink_cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | oPt3SxcjYDKfK1cmebr9ZNf7CIqYnLjXljmFhUDabNFKZQiJpg+PN5038MoGhar9dfQ9i4w9ByGtwC35wbBuMw== 5 | 6 | -------------------------------------------------------------------------------- /Sfunction_stepback/slprj/sim/varcache/Sfunction_stepback/varInfo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChengleiX/Sliding_Mode_Control_simulink/3422bce39f5159b19b2f869f86d7052a85cca557/Sfunction_stepback/slprj/sim/varcache/Sfunction_stepback/varInfo.mat --------------------------------------------------------------------------------