Model initialization inputs vs RTW C code
Show older comments
Hello,
I have a model in Simulink and several constants of the model (e.g. gains) are computed in a dedicated initialization m-file. The computed values are based on a few values that should be tunable. Now a user can tune them using workspace variables. Then the m-file computes the desired constants and the model can be started.
The problem is I need to covert this model (including the initialization) into a corresponding C code using RTW. I know how to set a variable of a model to be tunable in a resulting C code, but I really don’t know, whether there is a way to make a variable of initialization m-file tunable.
Is there any other solution than to remove the m-file and put all its computations directly into the model? (That’s exactly the thing I’d like to avoid since it would mean lots of changes and thus lots of possible mistakes.)
Thank you very much!
BR, Ladi
4 Comments
Kaustubha Govind
on 20 May 2011
Do the (tunable) constants in your model refer back to workspace variables, or do you directly perform a set_param to set the gain values? If it is the former, you should simply have to configure them as tunable parameters
Ladi
on 23 May 2011
Kaustubha Govind
on 23 May 2011
Even if you are defining the variables in the MATLAB-file, when you update the model (Ctrl+D), aren't these variables created in the base workspace? If yes, these should show up in the "Referenced workspace variables" list when you attempt to configure tunable parameters using the "Configure" button next to the "Inline parameters" checkbox in the Configuration Parameters window. Do you not see them?
Ladi
on 23 May 2011
Answers (1)
Fangjun Jiang
on 20 May 2011
0 votes
Let's say you have K1 and K2, two tunable constants for the gain value of two Gain blocks. You have K3=ComplexFunction(K1,K2) as the gain value for a third Gain block. You K3 value is updated manually every time K1 or K2 is changed for simulation.
I don't see a solution without putting ComplexFunction(K1,K2) in the model. Check out the "Embedded MATLAB Function" block. Maybe you can just copy your m-file over and it is supported by RTW.
5 Comments
Ladi
on 23 May 2011
Fangjun Jiang
on 23 May 2011
If you want the calculation of ComplexFunction be executed only once, that is fine. There are ways to make it execute only once in Simulink as well as in C code. Let's say you've made your C code compiled and running, when K1 or K2 is changed (any time for calibration purpose, not just for initialization), does K2 need to be changed accordingly?
Ladi
on 23 May 2011
Fangjun Jiang
on 23 May 2011
You are right. I meant "K3".
Think of this way, if you were developing your algorithm by writing C code manually, the initialization of K3 needs to be written even though it is executed only once. Right now, your m-file could be completely separated from your model. You set the value of K1 and K2, run your m-file to calculate the value of K3 and then run your model file. I don't think you can expect that RTW can include your m-file.
Again, check out the "Embedded Matlab Function". It might be able to solve your problem.
Ladi
on 24 May 2011
Categories
Find more on Simulink Environment Customization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!