Simulink coder: blocks value mapping into memory address
이전 댓글 표시
Dear support,
I'm using Simulink coder to generate an executable for Windows from a simple Simulink model.
Once the .exe is built I would like to change the value of some Simulink blocks, i.e tunable parameter, constans, gain.
Is there a way to get from the Simulink coder a memory mapping of the Simulink blocks, so that I can retrive the memory address of the block and replace its value?
Thank you in advance for your reply!
답변 (1개)
Harsh
2025년 3월 28일
To change Simulink parameters when running an executable without needing to recompile, you can modify the generated code to read data from an external file within the model's step function. Here is how you can achieve this:
- Create a Tunable Parameter: Define a "Simulink.Parameter" object and set its storage class to "ExportedGlobal". This ensures that the parameter appears as a global variable in the generated C code. Below is an example code snippet to create a tunable parameter "myGain" for "Gain" block -
myGain = Simulink.Parameter(2); % Initial gain set to 2
myGain.CoderInfo.StorageClass = 'ExportedGlobal';
set_param('TestModel/Gain', 'Gain', 'myGain');
- Modify the Generated Code to load parameters from an external file: After generating the code from your Simulink model, update the "step" function in the generated "YourModel.c" file. Modify this function to read parameter values from an external source, such as a file. This approach allows you to dynamically update the parameter values without needing to recompile the executable.
I hope this resolves your query. Happy coding!
카테고리
도움말 센터 및 File Exchange에서 Simulink Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!