Unable to use Localizable/FileScope storage for signal state variables while generating C++ code generation. For C code generation I am able to use it.

51 次查看(过去 30 天)
I am using Matlab 2024a and with Embedded coder I am generating C++ code for our application.
I am trying to generate a code where model signal, state variables have storage class of Localizable/FileScop which have unstructured representation of variables. In Embedded coder dictionary I make these changes it does not reflect for C++ code generation. But it is applied for C code generation only. Could you please provide its solution? Kindly let me know if any more inputs needed from my side.

回答(2 个)

Abhas
Abhas 2024-10-28,6:32
编辑:Abhas 2024-10-29,4:22
I was also facing the issue while generating code in C++, and after going through the bug reports and documentation, I found some insights that might help you with your C++ code generation using Embedded Coder in MATLAB 2024a.
  1. Configuration Parameters: First, make sure the "TargetLang" parameter is set to 'C++' in your Model Configuration Parameters. This setting is essential for generating C++ code instead of C.
  2. Array Container Type: If you’re using "std::array" for the "ArrayContainerType", be aware that this might cause numerical differences between software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulations and normal mode simulations. This happens especially if you're logging non-scalar signals, as the generated code uses "std::array" for these signals, which might behave differently. You may refer to the below bug reports link to know more about it: https://www.mathworks.com/support/bugreports/details/3419440
  3. External Mode Considerations: Be cautious if you enable the External mode configuration parameter, as it may lead to uncompilable C++ code. Starting in R2024b, there’s a change where Embedded Coder uses member methods instead of macros to access real-time model (RTM) data structures, so you might need to update your code accordingly. You can read more about the same in the R2024b release notes: https://www.mathworks.com/help/ecoder/release-notes.html?startrelease=R2024b&endrelease=R2024b&rntext=embedded+coder&groupby=release&sortby=descending&searchHighlight=embedded+coder#:~:text=%C2%A0Replace%20real%2Dtime%20model%20macros%20with%20member%20methods
  4. Custom Storage Classes: It might be helpful to define custom storage classes in the Embedded Coder Dictionary that are specifically designed for C++ code generation. This can give you more control over how variables are managed and represented in the generated code.
I hope this helps!

Priyanka
Priyanka 2024-10-29,7:08
编辑:Priyanka 2024-10-29,7:29
Thank you Abhas for replaying. The TargetLang settings were correct. I tried with Array std::array, but still facing same issue. Could you please elaborate on point 3 External Mode Considerations, what i should do to disable external mode?
I have attached my project configuration setting file for reference.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by