Simulink: How to hold a if conditional over a period of time

3 views (last 30 days)
Diego Dranuta
Diego Dranuta on 16 Mar 2021
Answered: Arthi Sathyamurthi on 24 Mar 2021
I am building a hybrid system where the engine load is modeled by Simulink, I need to stablish load given battery's State of Charge (SOC). My idea is to start with a percent load lest say 75% and have some kind of control that regulates by load given SOC. Lets say if SOC >80% for 10 seconds then lower engine percent load to 70%. How can I take that 10 second time sample and store it ?
Thanks

Answers (1)

Arthi Sathyamurthi
Arthi Sathyamurthi on 24 Mar 2021
For an easy solution you can use Stateflow and create two states OFF and ON. Get the input SOC and check if it is greater than 80%. If so change the state to ON and run it for 10 iterations by using the ‘during’ function and then store the value by sending it back to Simulink and saving it as a workspace or a local variable. Stateflow also allows you to several condition statements. In case you are new to Stateflow you can take a look at this link.
If you want to use only Simulink then you can try using enabled subsystem block to enable the block for particular amount of time by sending square waveform for the particular duration of time you want and inside the subsystem create a output block and store the variable. But make sure to reset the signal and start over every time the defined seconds have crossed and the simulation comes out of the subsystem. You can also look at other subsystemsblock if it would suit your application.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by