完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
构建思想
代码原理在word文档中: 逻辑控制器是对人主动开环控制及强时变控制的模拟,预测控制是对师傅经验的模拟,其共同特征是主动时变控制。两者的结合将是对人的控制思维特点的较全面模拟。本文提出的仿人逻辑控制器则是基于这样一种观察:有经验的师傅在系统超出极限时甚至处于危险时会毫不犹豫的切断某些重要通路,而在系统工作处于正常范围时则依照经验控制,使波动尽量小。这样人工处理的结果是:系统在正常区间运行平稳,突发事件瞬间切换,能够确保系统安全,模型失配时也能保证满意运行。虽然这样的处理也许不是全局最优的,但却是在确保强鲁棒性基础上的局部最优,这样一种策略对于某些工业控制至关重要。 控制器的工作原理如下:在系统工作时逻辑控制器和预测控制器同时工作,其控制输出量分别为K(t)和U(t)。逻辑控制设置较宽的误差控制带 ,其作用是用最短的时间将系统带入正常状态,暂且不管小的波动。预测控制的作用是利用预测模型将系统稳定在正常状态,并使控制曲线最优。控制量切换要选择合适的时机对这两种控制信号进行切换。具体而言,当系统远离正常状态,即通过逻辑状态判断其运行状态处于K4+、K3+和K4-、K3-四种状态时,控制量切换到逻辑控制状态。而当运行状态在K+、K-和K时,控制量切换到预测控制器,此时相当于师傅的经验开始起作用。这样一种控制结构充分利用了逻辑控制对模型匹配要求极低的特点,在模型失配的情况下仍然能取得满意效果,而在模型匹配情况下取得最优效果。此控制器的本质是时变开环控制加闭环校正控制,其物理概念清晰,系数整定方便,是将人的思维控制方式融合到模型中的结果。 matlab simulink框图 此处运用matlab simulink模块构建: MPC控制器参数: 结果展示 模型失配时 框图及结果 扰动后框图及结果 扰动值: 更改仿真时间到50s后的结果: 可以对结果分析: 在15秒添加扰动后,MPC+逻辑控制还是可以回到之前的顺滑轨迹,比之前回的慢了。 s函数代码 mpc2.m Ts=.1; % Sampling time p=20; % Prediction horizon m=3; % Control horizon MPC2=mpc(tf(3,[2 3 4]),Ts,p,m); NineState.m %参数e0和de0是设定的相平面误差允许范围。 function [sys,x0,str,ts] = mfile(t,x,u,flag,e0,de0) switch flag, %%%%%%%%%%%%%%%%%% % Initialization % %%%%%%%%%%%%%%%%%% % Initialize the states, sample times, and state ordering strings. case 0 [sys,x0,str,ts]=mdlInitializeSizes; %%%%%%%%%%% % Outputs % %%%%%%%%%%% % Return the outputs of the S-function block. case 3 sys=mdlOutputs(t,x,u,e0,de0); %%%%%%%%%%%%%%%%%%% % Unhandled flags % %%%%%%%%%%%%%%%%%%% % There are no termination tasks (flag=9) to be handled. % Also, there are no continuous or discrete states, % so flags 1,2, and 4 are not used, so return an emptyu % matrix case { 1, 2, 4, 9 } sys=[]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Unexpected flags (error handling)% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Return an error message for unhandled flag values. otherwise error(['Unhandled flag = ',num2str(flag)]); end % end timestwo % %============================================================================= % mdlInitializeSizes % Return the sizes, initial conditions, and sample times for the S-function. %============================================================================= % function [sys,x0,str,ts] = mdlInitializeSizes() sizes = simsizes; sizes.NumContStates = 0; sizes.NumDiscStates = 0; sizes.NumOutputs = 1; % dynamically sized sizes.NumInputs = 2; % dynamically sized sizes.DirFeedthrough = 1; % has direct feedthrough sizes.NumSampleTimes = 1; sys = simsizes(sizes); str = []; x0 = []; ts = [-1 0]; % inherited sample time % end mdlInitializeSizes % %============================================================================= % mdlOutputs % Return the output vector for the S-function %============================================================================= %u(1,1)为输入控制量e %u(2,1)为输入控制量de function sys = mdlOutputs(t,x,u,e0,de0) if (u(1,1)>=e0 & u(2,1)>=de0) sys=15; elseif (u(1,1)>=e0 & abs(u(2,1)) elseif (u(1,1)>=e0 & u(2,1)<=-de0) sys=2; elseif abs((u(1,1)) sys=1; elseif abs(u(1,1)) elseif abs(u(1,1)) elseif (u(1,1)<=-e0 & u(2,1)>=de0) sys=-2; elseif (u(1,1)<=-e0 &abs(u(2,1)) elseif (u(1,1)<=-e0 & u(2,1)<-de0) sys=-15; else error(['my error ']); end % end mdlOutputs switchUK.m %参数e0和de0是设定的相平面误差允许范围。 function [sys,x0,str,ts] = switchUK(t,x,u,flag,K1,K3,tempi) switch flag, %%%%%%%%%%%%%%%%%% % Initialization % %%%%%%%%%%%%%%%%%% % Initialize the states, sample times, and state ordering strings. case 0 [sys,x0,str,ts]=mdlInitializeSizes; %%%%%%%%%%% % Outputs % %%%%%%%%%%% % Return the outputs of the S-function block. case 3 sys=mdlOutputs(t,x,u,K1,K3,tempi); %%%%%%%%%%%%%%%%%%% % Unhandled flags % %%%%%%%%%%%%%%%%%%% % There are no termination tasks (flag=9) to be handled. % Also, there are no continuous or discrete states, % so flags 1,2, and 4 are not used, so return an emptyu % matrix case { 1, 2, 4, 9 } sys=[]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Unexpected flags (error handling)% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Return an error message for unhandled flag values. otherwise error(['Unhandled flag = ',num2str(flag)]); end % end timestwo % %============================================================================= % mdlInitializeSizes % Return the sizes, initial conditions, and sample times for the S-function. %============================================================================= % function [sys,x0,str,ts] = mdlInitializeSizes() sizes = simsizes; sizes.NumContStates = 0; sizes.NumDiscStates = 0; sizes.NumOutputs = 1; % dynamically sized sizes.NumInputs = 2; % dynamically sized sizes.DirFeedthrough = 1; % has direct feedthrough sizes.NumSampleTimes = 1; sys = simsizes(sizes); str = []; x0 = []; ts = [-1 0]; % inherited sample time % end mdlInitializeSizes % %============================================================================= % mdlOutputs % Return the output vector for the S-function %============================================================================= %u(1,1)为输入控制量K(t) %u(2,1)为输入控制量U(t) function sys = mdlOutputs(t,x,u,K1,K3,tempi) if abs(u(1,1))>K3 sys=u(1,1);%如果输入控制量的绝对值比较大,即误差太大。则切换到K(t)逻辑控制 tempi=1; elseif abs(u(1,1)) tempi=0; else if tempi==0 %如果已经是预测控制,则保持,此处保持预测控制优先 sys=u(2,1); else sys=u(1,1);%如果已经是逻辑控制,则保持 end end % end mdlOutputs 注意 运行simulink前需先运行mpc2.m文件。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1614 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1541 浏览 1 评论
970 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
682 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1592 浏览 2 评论
1863浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
644浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
515浏览 3评论
531浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
504浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 01:16 , Processed in 0.704136 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号