How to execute subsystem once at startup
18 次查看(过去 30 天)
显示 更早的评论
I am trying to figure out how to do the Simulink equivalent of the Arduino 'void setup' in my program. For my program I want to have a startup mechanism to test my physical system, but it only needs to run once when the program is started. How would I go about doing this?
0 个评论
回答(1 个)
Madhu Govindarajan
2017-10-30
Simulink works on time, so it looks like you need to 1) read the clock time of the simulation model using the clock block - https://www.mathworks.com/help/simulink/slref/clock.html. 2) Use this to enable an enabled subsystem at the appropriate time - https://www.mathworks.com/help/simulink/ug/enabled-subsystems.html 3) Put all your contents that can make the system startup inside this enabled subsystem. 4) Write logic that will disable the subsystem at the appropriate time.
Of course, there could be other possible workarounds.
2 个评论
Andrew Tilmouth
2018-10-16
If you have an atomic sub system which is set to a sample time of 0.02 and the clock is placed inside this system (connected to an If block checking for u1 == 0 and then to an If action subsystem containing the blocks that you want to run once) this will give the error shown below:- But it's not possible to change the clock sample time, there is no option to do that. How can this problem be solved, I am using 2013a so I do not have the new Initialize block although I am not sure if it is designed for that purpose anyway.
Any help would be appreciated, there is plenty of ECU code that needs to only run once at start up, this is a common requirement that needs to be modelled.
thanks
'ModelY/Clock' has an invalid sample time of [0, 0]. Periodic atomic subsystem 'ModelX' may contain only blocks that have constant (inf), inherited (-1), or periodic (0.02) sample times. To resolve this issue, try to change the sample time with one of the following: - Configuring the block 'ModelY/Clock' to inherit the sample time - Configuring the subsystem 'ModelX' to inherit the sample time. If you cannot change the block sample time, remove the problem block from the subsystem.
Madhu Govindarajan
2018-10-16
Maybe you can share a simpler version of your model to help me understand the issue better and then I can help.
MathWorks Technical Support might be a better resource regardless :)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modeling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!