当前位置:网站首页>Simulink code generation: variable subsystem and its code
Simulink code generation: variable subsystem and its code
2022-07-24 03:13:00 【chhttty】
This paper studies Simulink Variable subsystem in , And its generated conditional compiled code .
List of articles
1 Problem introduction
Different projects in the work correspond to different needs , Then different requirements may need to be implemented with different model strategies . here , You can use Variant Subsystem modeling , And control the subsystem through which a project outputs results through parameters . also , The generated code can also be expressed in the form of macro definitions .
2 Modeling examples
This chapter demonstrates the modeling method of variable subsystem .
1) First , stay Matlab Create a new workspace Simulink.Parameter Parameter object , Take it as the variable parameter that controls the variable subsystem later ;
among , Who should be StorageClass by Define, Corresponding C Macro definition in code . This is done in order to generate the form of macros later when generating code .
2) Add a variable subsystem to the blank model , Set its properties as follows :
Right click subsystem , Click on Block Parameters, You can open the configuration interface of the subsystem , Set to the following configuration ;

In the table Name Column , Represents different subsystem names in the subsystem , Set as Gain_2 and Gain_3, hinder Variant control Indicates which subsystem runs in the variable subsystem with parameters a system . When P_Condition2 perform Gain_2 Subsystem , When P_Condition3 perform Gain_3 Subsystem . Save and exit .
3) Double click to enter the variable subsystem , You can see that there are two subsystems , And careful observation can be found that the input and output ports are different .

The names of the two subsystems correspond to Name To configure , The input and output ports should be connected with the outside port bring into correspondence with , And the signal line cannot be connected .
4) In the two subsystems Gain modular , But one parameter is 2, The other is 3;

As set in the first step P_Condition Values for 2, So the top Gain_2 The subsystem is solid , Below Gain3 Subsystem is shadow .
5) Here we are , Modeling has been completed . You can verify that , Add an input at the top of the model as a constant 1, Output is display modular ;
When P_Condition Values for 2 when ,Update After the model , Output is 2;
When P_Condition Values for 3 when ,Update After the model , Output is 3;
That means , Which way to go in the variable subsystem , According to the parameters P_Condition Controlled . In practice , For different projects , Revise it P_Condition The value of the parameter , Different control logics and strategies can be implemented .
3 Code generation
Replace the top-level model with Inport and Outport port ,Ctrl + B The generated code .
stay P_Macro.h In file , Generated P_Condition The macro definition of , Values for 2;

stay step Function , By judgment P_Condition To determine which assignment statement to execute , And is #if Conditional judgment of form , instead of C In language if Conditional statements . This has the advantage of , When the compiler compiles this code , You can skip P_Condition == 3 The following statement , Thus saving the controller flash resources .

4 summary
The variable subsystem can judge the condition , To determine the internal implementation of different logic , Generated code can also be generated in the form of macros .
边栏推荐
- Description of relevant resolutions in video on demand
- Ugui source code analysis - imaterialmodifier
- C动态内存管理详解
- 二分查找
- Summernote font displays Chinese
- CMT 注册——Google Scholar Id,Semantic Scholar Id,和 DBLP Id
- Tweenmax+svg Pikachu transformation ball
- Skywalking distributed system application performance monitoring tool - upper
- Gpushare.com | 如何使用TensorBoardX可视化工具?
- (6) Decorator extension [email protected] Principle of use
猜你喜欢

FTP服務與配置

在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架

轮播图van-swipe的报错:cannot read a properties of null(reading width)

CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID

Microsoft win11/10 package manager Winget will support the installation of applications from zip files

summernote富文本编辑器

IDEA Clone的项目报Cannot resolve symbol ‘Override‘

Lcd1602——斌哥51
[email protected] Principle of use"/>(6) Decorator extension [email protected] Principle of use

AcWing 4498. 指针 (DFS)
随机推荐
Open source embedded sig in the openeuler community. Let's talk about its multi OS hybrid deployment framework
SolidWorks cannot reference references
The process of solving a bug at work
FTP服务与配置
WPS前骨干历时10年打造新型软件,Excel用户:我为此改用WPS
198. House raiding
Secondary development of ArcGIS JS API -- loading national sky map
微信公众号在线客服接入发方法和功能详解
Babylon.js cool canvas background animation JS special effects
AcWing 4498. 指针 (DFS)
IDEA Clone的项目报Cannot resolve symbol ‘Override‘
Open source quantum development framework cirq
JS small game running bear and cat source code
在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架
轮播图van-swipe的报错:cannot read a properties of null(reading width)
SkyWalking分布式系统应用程序性能监控工具-上
Is it safe for qiniu to open an account? Is the Commission of 30000 reliable?
PMP first-hand data and information acquisition
Svn: e00002: can't convert string from 'UTF-8' to native encoding problem solving
Honey, we are homeless now