滑模教程
DR_CAN滑模教学



function [sys,x0,str,ts,simStateCompliance] = sfuntmpl(t,x,u,flag)
switch flag,%%%%%%%%%%%%%%%%%%% Initialization %%%%%%%%%%%%%%%%%%%case 0,[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;%%%%%%%%%%%%%%%% Derivatives %%%%%%%%%%%%%%%%case 1,sys=mdlDerivatives(t,x,u);%%%%%%%%%%% Update %%%%%%%%%%%case 2,sys=mdlUpdate(t,x,u);%%%%%%%%%%%% Outputs %%%%%%%%%%%%case 3,sys=mdlOutputs(t,x,u);%%%%%%%%%%%%%%%%%%%%%%%% GetTimeOfNextVarHit %%%%%%%%%%%%%%%%%%%%%%%%case 4,sys=mdlGetTimeOfNextVarHit(t,x,u);%%%%%%%%%%%%%% Terminate %%%%%%%%%%%%%%case 9,sys=mdlTerminate(t,x,u);%%%%%%%%%%%%%%%%%%%%% Unexpected flags %%%%%%%%%%%%%%%%%%%%%otherwiseDAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded.  This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 0;
sizes.NumInputs      = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;   % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0  = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts  = [0 0];
% Specify the block simStateCompliance. The allowed values are:
%    'UnknownSimState', < The default setting; warn and assume DefaultSimState
%    'DefaultSimState', < Same sim state as a built-in block
%    'HasNoSimState',   < No sim state
%    'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
sys = [];
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block.  Note that the result is
% absolute time.  Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1;    %  Example, set the next hit to be one second later.
sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate







switch flag,%%%%%%%%%%%%%%%%%%% Initialization %%%%%%%%%%%%%%%%%%%case 0,[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;%%%%%%%%%%%%%%%% Derivatives %%%%%%%%%%%%%%%%case 1,sys=[];%%%%%%%%%%% Update %%%%%%%%%%%case 2,sys=[];%%%%%%%%%%%% Outputs %%%%%%%%%%%%case 3,sys=mdlOutputs(t,x,u);%%%%%%%%%%%%%%%%%%%%%%%% GetTimeOfNextVarHit %%%%%%%%%%%%%%%%%%%%%%%%case 4,sys=[];%%%%%%%%%%%%%% Terminate %%%%%%%%%%%%%%case 9,sys=[];%%%%%%%%%%%%%%%%%%%%% Unexpected flags %%%%%%%%%%%%%%%%%%%%%otherwiseDAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end sfuntmpl

%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded.  This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
%状态节点数
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
%输出节点数
sizes.NumOutputs     = 5;
%输入节点数
sizes.NumInputs      = 3;
%一般设置为1
sizes.DirFeedthrough = 1;
%采样时间数
sizes.NumSampleTimes = 0;   % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0  = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%连续系统,采样时间不设置
ts  = [];
% Specify the block simStateCompliance. The allowed values are:
%    'UnknownSimState', < The default setting; warn and assume DefaultSimState
%    'DefaultSimState', < Same sim state as a built-in block
%    'HasNoSimState',   < No sim state
%    'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';

%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
%因为thd=sin(t),所以dthd=cos(t)
thd=u(1);
th=u(2);
dth=u(3);
dthd=cos(t);
ddthd=-sin(t);
b=133;
epsilon=5;
k=0;
c=15;
e=thd-th;
de=dthd-dth;
s=c*e+de;
f_th=25*dth
% f(th,t)=25dth
sys(1)=1/b*(epsilon*sign(s)+k*s+c*(dthd-u(3))+ddthd+f_th);
sys(2)=e;
sys(3)=de;
sys(4)=s;
sys(5)=k;
% end mdlOutputs

switch flag,%%%%%%%%%%%%%%%%%%% Initialization %%%%%%%%%%%%%%%%%%%case 0,[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;%%%%%%%%%%%%%%%% Derivatives %%%%%%%%%%%%%%%%case 1,sys=mdlDerivatives(t,x,u);%%%%%%%%%%% Update %%%%%%%%%%%case 2,sys=[];%%%%%%%%%%%% Outputs %%%%%%%%%%%%case 3,sys=mdlOutputs(t,x,u);%%%%%%%%%%%%%%%%%%%%%%%% GetTimeOfNextVarHit %%%%%%%%%%%%%%%%%%%%%%%%case 4,sys=[];%%%%%%%%%%%%%% Terminate %%%%%%%%%%%%%%case 9,sys=[];%%%%%%%%%%%%%%%%%%%%% Unexpected flags %%%%%%%%%%%%%%%%%%%%%otherwiseDAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end sfuntmpl

%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded.  This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates  = 2;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 2;
sizes.NumInputs      = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0;   % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0  = [-0.15 -0.15];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts  = [];
% Specify the block simStateCompliance. The allowed values are:
%    'UnknownSimState', < The default setting; warn and assume DefaultSimState
%    'DefaultSimState', < Same sim state as a built-in block
%    'HasNoSimState',   < No sim state
%    'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';
% end mdlInitializeSizes

%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
f_th=25*x(2);
b=133;
sys(1)=x(2);
sys(2)=-f_th+b*u;
% end mdlDerivatives

%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
sys(1)=x(1);
sys(2)=x(2);
% end mdlOutputs

figure(1),
plot(t,th,'r',t,thd,'k','linewidth',2);
legend('theta','theta target');
title('theta and theta target');figure(2),
subplot(211)
plot(t,e,'r','linewidth',2);
title('e')
subplot(212)
plot(t,de,'r','linewidth',2);
title('de');figure(3),
plot(t,s,'linewidth',2);
title('s');figure(4),
c=15;
plot(e,de,'r',e,-c*e,'k','linewidth',2);
legend('s change','s=0')
xlabel('e');
ylabel('de');
title('phase trajectory');






代码下载:
链接:https://pan.baidu.com/s/1it27VLIJel26UHDDBz-1fA
提取码:8cky
复制这段内容后打开百度网盘手机App,操作更方便哦

作于:
2021-3-22
15:18

全网最强滑模控制(SMC)matlab s-function函数实现(1),滑模控制几种趋近律总结(文末附实例下载)相关推荐

  1. hfss matlab联合仿真_一文搞定matlab 与 STK 联合调试仿真环境配置(文末附软件下载链接)...

    最近在做导师给的课题:卫星星座的快速优化设计. 需要用到matlab 和 STK 来进行联合调试仿真,但是这第一步的环境配置就让我头疼了几天.在好几次重装,失败和查找资料之后,我终于成功实现了matl ...

  2. VSC/SMC(一)——基于趋近律的滑模控制(含程序模型)

    目录 1.几种典型的趋近律 1.1等速趋近律 1.2指数趋近律 1.3幂次趋近律 1.4一般趋近律 2.控制器设计 2.1被控对象 2.2选取滑膜面 2.3定义跟踪误差 2.4计算控制律 3.Simu ...

  3. 双馈风力发电机DFIG滑模控制SMC MATLAB/Simulink仿真模型 采用PI调节器为外环滑模控制器SMC作为内环控制,跟传统的双PI环相比,功率的很随性更好

    双馈风力发电机DFIG滑模控制SMC MATLAB/Simulink仿真模型(成品) 1.采用非线性控制滑模控制策略 2.采用PI调节器为外环滑模控制器SMC作为内环控制,跟传统的双PI环相比,功率的 ...

  4. SMC/VSC(十一)——基于趋近律的离散滑模控制(白嫖程序模型)

    目录 前言 1.被控对象 2.控制器设计 3.m语言仿真分析 3.1出图结果 4.S函数仿真分析 4.1控制器设计 ​​4.2调参 4.3s函数编写被控对象 4.4s函数编写控制器 4.5仿真结果 前 ...

  5. matlab里面滑模控制示例,基于趋近律的滑模控制matlab仿真实例(12页)-原创力文档...

    基于趋近律的滑模控制 一.基于趋近律的滑模控制 1.控制器的设计 针对状态方程 (1) 采用趋近律的控制方式,控制律推导如下: (2) (3) 其中slaw为趋近律. 将状态方程式(1)代人(2)得 ...

  6. 滑模控制几种趋近率的对比(hm-2)

    我们以最简单的牛顿第二定律作为被控对象来进行几种趋近率的对比. 滑模面设计为: e(t)为期望位置和实际位置的差,则有: 分别采用等速趋近率.指数趋近率以及幂次趋近率: 代入得到: 在指数趋近中,趋近 ...

  7. 基于趋近律的滑模鲁棒控制simulink仿真

    滑模控制刚入门菜鸟一枚,找个实例练练手.参考刘金琨老师的<滑模变结构控制MATLAB仿真>中的基于趋近律的滑模鲁棒控制,对部分地方做出了修改. 考虑如下的被控对象:,其中,b>0,d ...

  8. 基于积分型滑模控制器的永磁同步电机FOC 转速环基于积分型滑模面设计积分型滑模面结构控制器,采用指数趋近律来提高系统的动态性能

    基于积分型滑模控制器的永磁同步电机FOC 1.转速环基于积分型滑模面设计积分型滑模面结构控制器,采用指数趋近律来提高系统的动态性能. 2.提供算法对应的参考文献和仿真模型 ID:56486774298 ...

  9. MATLAB实战系列(十九)-遗传算法解决TSP(旅行商)问题-应用及解析(文末附MATLAB源码)

    接上篇MATLAB实战系列(十八)-遗传算法解决TSP(旅行商)问题-算法原理 https://wenyusuran.blog.csdn.net/article/details/114060030 感 ...

最新文章

  1. Hashing散列注意事项
  2. 简单工厂、工厂模式初学习
  3. 如何保证两个不同宽高的canvas用同一组坐标正常显示_如何1人5天开发完3D数据可视化大屏 【一】...
  4. python基础语法第10关作业-关于一些Python的一些基础语法训练
  5. java用一张一元票换一分,java测试试卷一
  6. 龙芯开源社区上线.NET主页
  7. Eclipse:如何附加Java源代码
  8. python管理系统web版_Python学生管理系统(web网页版)-Go语言中文社区
  9. [jquery] 删除文章的时候弹出确认窗口
  10. python模拟键盘输入+切换键盘布局
  11. Java语言中:switch语句经典习题
  12. 有时,不做什么比做什么更重要,拒绝比答应更重要
  13. MiPony– 杀手级免费网盘下载工具 可挂机下载支持YunFile
  14. 使用C语言创建顺序表
  15. 适用于Android的最佳本地音乐播放器
  16. matlab coder 安装,MATLAB Coder
  17. 技术前沿与经典文章20:历史上54位伟大物理学家、科学家的专属LOGO(六)
  18. Matlab Shift Arithmetic模块
  19. 不会用PS、Excel更改证件照颜色没关系,用Word更改不用1分钟!
  20. 批量修复自定义标题带来的word题注错误:错误,文档中没有指定样式的文字

热门文章

  1. 常用的区块链数据查询网站
  2. React 系列教程
  3. 2022张宇考研基础30讲 线性代数 第四讲 线性方程组
  4. 中国稀土永磁材料市场供应现状与需求产量预测报告2022版
  5. React初级篇————基础项目搭建以及环境配置
  6. 怎么用计算机打分数,电脑分数怎么打(在PPT里)?
  7. a标签去掉下划线,ul去前面的点。
  8. vs2019编译boost1.55
  9. 汽车共享公司Getaround曲线上市:新公司作价12亿美元 路演PPT曝光
  10. Web前端-JS(三)