当前位置:网站首页>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 .
边栏推荐
- FTP service and configuration
- Services et configurations FTP
- Open source embedded sig in the openeuler community. Let's talk about its multi OS hybrid deployment framework
- 开源量子开发框架 Cirq
- Type de symbole
- Ways to improve the utilization of openeuler resources 01: Introduction
- Go log package
- Unity 消息推送
- uva1344
- go IO操作-文件写
猜你喜欢

Basic knowledge of trigger (Part 2)

MySQL sub database and sub table and its smooth expansion scheme

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

SolidWorks CAM data cannot be recovered because a processed part has been detected.

微信公众号在线客服接入发方法和功能详解

SolidWorks cannot reference references

Xiaodi and Xiaohui

An introductory example of structure and combinatorial ideas in go language

数据湖:Apache Hudi简介

The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
随机推荐
go IO操作-文件读
Unity 消息推送
[C language] file operation
Hospital PACS source code PACS ultrasonic Department source code DICOM image workstation source code [source code free sharing]
Take you into the world of MySQL mvcc
Babylon.js cool canvas background animation JS special effects
How to write selenium's testng.xml
How to get gait energy map Gei
(6) Decorator extension [email protected] Principle of use
开源量子开发框架 Cirq
Xiaodi and Xiaohui
Unity Message push
Daily gossip (I)
C文件操作详解
Attack and defense world web practice area (webshell, command_execution, simple_js)
数据湖:Apache Hudi简介
How will you answer the "Hello world" challenge written in C language?
Ugui source code analysis - Mask
Symbol类型
Lumberyard game engine of o3de