What is the correct way to specify s-function output initial value?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason Firth
am 7 Mai 2018
Beantwortet: Arvindhan Sayapathy
am 18 Mai 2018
I have an s-function implemented in c where I wish to specify the initial output of certain ports to non-zero values. I have been using the mdlInitializeConditions function to inititalize the output. However, when generating the code with the rsim.tlc target, I notice in the MdlInitialize() function, my s-function mdlInitializeConditions is called first and then the output ports are initialized to zero. Is there a way to specify that I have already initialized my s-function outputs and I don't need Simulink to do it for me?
The way I have gotten around this is by specifying the configuration parameter "UnderspecifiedInitializationDetection" to classic mode instead of simplified mode. I would really like to use the newer simplified mode.
0 Kommentare
Akzeptierte Antwort
Arvindhan Sayapathy
am 18 Mai 2018
To set your output to an initial value at t=0, you can create a work vector that has an initial value, say 1 (ssSetIWorkValue(S, 0, 1)).
Then in 'mdlOutputs' you can use an if condition (if(ssGetIWorkValue(S, 0) == 1)) to set the initial value of the output to the desired value.
Finally, you can change the value of the work vector in 'mdlUpdate' in such a way that the condition in 'mdlOutput' is not met. This ensures that the initial value is set only once.
You can try to follow the steps given in the link provided below:
https://www.mathworks.com/help/simulink/sfg/mdlinitializeconditions.html?s_tid=doc_ta#f1-127418
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!