当前位置:网站首页>2837xd code generation - stateflow (1)
2837xd code generation - stateflow (1)
2022-07-02 09:43:00 【Quikk】
2837xd Code generation ——StateFlow(1)
stay Command Window Type in sf Can enter the , It can also be done through Simulink In the library StateFlow Sub library entry .
StateFlow Finite state machine , Reuse matlab when , May feel : A simple if Statements or ++ The operation needs to be built too complex . But the introduction of state machine can greatly reduce this situation .
Entering the library function module, you can see that these three components are all state machine modules , Learn one by one : First look at Chart modular .
1 Chart modular
Create a new Chart modular , After opening , Right click to enter Properties Set it up .
On the left side of the interface are some Chart Components used in :
among , There is only mutual exclusion between each module ( Only one can execute ) And parallelism . There will be an execution order identifier in the upper right corner under the parallel relationship .
Which is divided into different levels by modules , The content under the same module is a level , If you need to set parallel and mutually exclusive relationships . Right click the blank space of the level to be set and select Decomposition Choose parallel and mutually exclusive relationships .
State Modules have some keywords that can be used to define the actions to be performed after entering these modules :
Using the above knowledge, we can build a simple model , Take a look at the concept of flow chart .
First, build a simple model as shown in the above figure ,s Is the condition ,light It's the result of action . This is a process that simulates the switching of lights , turn on the light (s=1) Obviously, we need to give ,light The program needs to run to produce relevant results . Now enter Model Explorer The relevant settings are made in .
And then in Simulink Add relevant external modules , Give and display input and output .
The simulation results are as follows . change s Value , Can be changed accordingly light Value .
Transform the above process , Join the event .Open_switch(Close_Switch),b And in Model Exporer Defined in . Here, pay attention to the defined input port and demux The input should be consistent .
Then build a circuit ,Input3 It is used to activate the module . You can know at this time , It's not just about s=1, And need the rising edge (Open_switch The rising edge of the trigger of the event setting ) To trigger light=1. Similar to the rising edge in digital electricity, the corresponding signal can be locked .
In order to better write the process ,StateFlow The concept of connection node is introduced . Click on Parretn The following structures can be set .
You can also add conditions for your connection , When the mouse is placed on the line between the two connection points, the following marks will automatically appear , By default, when one node has multiple branches , Will give priority to the conditional branch .:
Pictured , Set up the following branches , Equate to C Code :
if (x<0)
y=abs(x);
else
y=x;
stay Model Explorer Set relevant... In data Properties of , Given inputs and outputs . The given input here is 1Hz The sine wave of .
Now combine the state of the first switch lamp , If there are two states in the light on state (A、B) Represents different brightness . Then if we set the brightness for the first time , I certainly don't want to adjust the brightness again next time I turn on the light . Therefore, historical nodes are introduced here , That is, you can remember the last exit state , Even though A It's the default state . But the state at this time is determined by the state of the last exit :
2 Model instance construction
2.1 Car status judgment
Build the following logic circuit for judging the car state , Be able to define the events generated above , Run , It can simulate gear shifting and start stop status monitoring :
After the completion of construction , You can click run directly , At this time, because there is no definition of related data and event An automatically defined interface will pop up , Make relevant modifications above to quickly add :
Build peripheral circuits , Set the device runtime triggered by related events , Change the simulation duration to inf( Infinite length ), You can operate and observe experimental phenomena :
2.2 Media playback status detection
The media playing status can be observed through the flow chart , This example introduces historical nodes and state detection , Build as shown in the following figure chart, You can see in the power_on Some of the state transition flow charts in have no trigger conditions ( That means anything can trigger ). for example , If now in USB state , If sent Open_CD(Open_Radio) After that, state transition can be triggered .
Right click on the status to enter the attribute (Properties), Modify the status output , Then you can observe the status at the output port ( Boolean variable output , by 1 It means in secondary state ).
The history node is added , Represents the next entry power_on When the module , It will directly enter the state of the last exit .
Build the external circuit as shown in the figure below :
2.3 2837xd Running water lamp online debugging
First, build the following chart, here led1 and led2 It's all output . Direct connection GPIO Interface .
The picture below is led1 and led2 Output waveform of , Identified in the figure 1.2.3.4 Corresponding to the execution process in the above figure . That's the cycle 3 After that , Out of the loop , Then go out and wait , Enter the next cycle . Here the test found , It will last one step in the state , Act at the node (3、4) It will take another step .[ The step size is set to 0.5s], Setting of relevant parameters , Please refer to the previous blog article .
Program peripheral circuit diagram :
This is a debugging skill , The following figure SIMULATION and HARDWARE There is one in each RUN,SIMULINK Medium RUN Hardware can be disconnected , Run the software running results directly , That is, it can also be easily debugged chart Output module .HARDWARE Medium RUN Is to generate DSP Code burning into DSP And then run .
边栏推荐
- kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
- 2837xd 代码生成——补充(2)
- Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime
- Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
- Methods of classfile
- 攻防世界-Web进阶区-unserialize3
- 2837xd code generation - stateflow (4)
- C语言之判断直角三角形
- Tools used for Yolo object recognition and data generation
- Mysql默认事务隔离级别及行锁
猜你喜欢
Creation and jump of activity
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
MySQL multi column in operation
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
2837xd 代码生成——总结篇
Microservice practice | Eureka registration center and cluster construction
Required request body is missing:(跨域问题)
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
tinyxml2 读取和修改文件
上班第一天的报错(AWVS卸载不彻底)
随机推荐
QT signal slot summary -connect function incorrect usage
C语言之二进制与十进制
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
Matplotlib swordsman - a stylist who can draw without tools and code
Supplier selection and prequalification of Oracle project management system
Record the interesting process of using Xray for the first time
定时线程池实现请求合并
自定义Redis连接池
VIM操作命令大全
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
图像识别-数据增广
PI control of grid connected inverter (grid connected mode)
Chrome browser plug-in fatkun installation and introduction
Creation and jump of activity
Activity的创建和跳转
Knife4j 2. Solution to the problem of file control without selection when uploading x version files
C语言之最小数
上班第一天的报错(Nessus安装winpcap报错)
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
YOLO物体识别,生成数据用到的工具