Access to defaultParam struct

4 Ansichten (letzte 30 Tage)
Ton van der Post
Ton van der Post am 12 Jan. 2024
Kommentiert: Ton van der Post am 15 Jan. 2024
Using the Matlab/Simulink Coder functionality, coming from an older version of Matlab (2015) where access to the model Parameters could be realized through a C++ data structure, I ran into trouble when trying to disclose this data under Matlab2023. Previously the RTW/Coder generated code that gave access to the parameter struct with a function like:
# define rtmGetDefaultParam(rtm) ((rtm)->ModelData.defaultParam)
It looks like this function was generated as parameters were declared with StorageClass = SimulinkGlobal. Changing the setting to “Model default”, did not bring the access to the defaultParam struct. I am looking at the alternative setting so that the model parameters are still present under a struct that can be accessed through a function similar to the above. Can someone give me some guidance on this?

Akzeptierte Antwort

Hassaan
Hassaan am 12 Jan. 2024
Bearbeitet: Hassaan am 12 Jan. 2024
To regain access to model parameters in a structured way in MATLAB R2023 using MATLAB/Simulink Coder, you may need to adjust the code generation settings and possibly use new functionality to achieve a similar outcome as was available in MATLAB R2015. Here's a some of steps you could take:
  1. Review Code Generation Settings: Check "Code Generation" settings in the Model Configuration Parameters for parameter data and tunable parameters. Make sure they are configured to match your desired output.
  2. Use Simulink Data Dictionary: Manage parameters and signals through a Simulink Data Dictionary for more accessible data control.
  3. Define Custom Storage Classes: Create a custom storage class in the Simulink Coder Dictionary to store parameter data in a global structure.
  4. Check for Deprecated Features: Use the provided MATLAB command to review deprecated features and update your model accordingly.
  5. Employ Post-Code-Generation Command: Use the PostCodeGenCommand to manipulate the generated code to include functions or structures for accessing parameters.
  6. Seek Help from MATLAB Answers or MathWorks Support: For specific guidance on changes in code generation from older to newer MATLAB versions.
  7. Examine Generated Code: Look into the generated code for the current method of parameter storage and modify if necessary.
  8. Use Legacy Code Tool: Integrate old code with new models if certain functionalities are no longer supported directly.
  9. Consider Backward Compatibility: Make sure your model updates consider any backward compatibility issues.
Here's an example of how you might define a custom storage class to generate a global structure for parameters:
% Define a package for custom storage classes
pkg = Simulink.data.createCustomStorageClassPackage('MyPackage', ...
'Description', 'A package of custom storage classes');
% Define a custom storage class
csc = Simulink.data.createClass(pkg, 'MyStorageClass', ...
'Description', 'A custom storage class for parameters', ...
'DataScope', 'Exported', ...
'HeaderFile', 'myParameters.h', ...
'GetFunction', 'myModel_GetParameters');
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  1 Kommentar
Ton van der Post
Ton van der Post am 15 Jan. 2024
Thanks Muhammad for the guidance.
After setting it up properly, it appeared that I overlooked one line in the generated code:
extern P_MyModel_T MyModel_P;
This exported the struct with parameters and solved my problem.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by