Default Conduct
Let’s take the a part of Man’s mannequin that makes use of the variable space (I will clarify why I’m leaving out the hypotenuse later):
The place space is created utilizing this code:
a = Simulink.Parameter(3);
b = Simulink.Parameter(4);
space = Simulink.Parameter(slexpr(“(a*b)*0.5”));
Specifying Storage Lessons to Protect Expressions
It’s attainable for Embedded Coder to protect the mathematical expression within the generated code by making two adjustments:
- For a and b change the storage class to Outline
- For space, set the storage class to ExportedGlobal
Then within the code, space will present up as a tunable parameter:
And the definition for space accommodates the mathematical expression:
As a result of I used the Outline storage class for a and b, these present up as macros within the mannequin header file:
These are usually not the one storage lessons you should utilize. The final rule is:
- For parameters used within the expression (a and b), the storage class has to generate a macro, similar to Outline and ImportedDefine
- For the derived parameter (space), storage class have to be non-Auto (for instance ExportedGlobal or ExportToFile)
In my instance, I omitted the hypotenuse (sqrt(a^2+b^2)) parameter as a result of solely sure mathematical expressions are supported, and the calculation for the hypotenuse has two unsupported components: the sqrt() perform and the ^ operator