I have seen that the embedded coder configuration can be set using coder.EmbeddedCodeConfig. However, I can't find the method to link this configuration to the simulink model from which I want to generate code.
Problem with code generation using Embedded Coder
11 ビュー (過去 30 日間)
古いコメントを表示
I have been trying to use Embedded Coder to generate C code of an optimization algorithm. The algorithm use the lsqlin solver to solve the optimization problem. I have tested the Embedded Coder with simpler algorithms, and it yielded good results. I decided to keep up the testing phase with a slightly more complicated algorithm. However, Embedded Coder breaks down with this new algorithm. For example, the inputs that I define in my MATLAB code aren't used in any part of the C code generated. I defined a cost function variable for the optimization algorithm, and the embedded coder reuse the variable multiple times in different contexts. Some declarations of the MATLAB function does not appear in the C code. For example, I have the following declaration:
iap = x_1(1);
ibp = x_1(2);
icp = -x_1(1)-x_1(2);
And the embedded coder produces the following:
/* : iap = x_1(1); */
/* : ibp = x_1(2); */
/* : icp = -x_1(1)-x_1(2); */
Gop = (-x_1[0]) - x_1[1];
It once again assign variables to the cost function. Furthermore, variables iap and ibp aren' t being defined and used in the C code. Just icp is assign to Gop. This happens multiple times in the generated code. I thought that maybe the code was just a bit convoluted, but the outputs would be the same compared to the MATLAB counterpart. However, I tested the code in the S-function builder in MATLAB and it doesn't produce any ouputs. I have tried multiple configurations of the Code Generation tool to no avail. Can we get more control over the Embedder Coder?
Kind regards.
3 件のコメント
Swastik Sarkar
2024 年 12 月 17 日
Will it be possible to share a sample model demonstrating the problem, so that others can reproduce the issue and contribute more effectively ?
回答 (1 件)
Kanishk
2025 年 2 月 10 日
I understand that you are encountering challenges with generating and executing code using Embedded Coder. While it is difficult to diagnose the issue precisely without access to your specific steps and files, here are some potential solutions based on your description.
- It is possible that some variable declarations do not appear in the generated C code because they are optimized away. This can occur if the variables are unused or if the "Default Parameter Behavior" is set to "inlined" in the "Code Generation > Optimization" settings. Inlining can improve the efficiency of the generated code by embedding literal numeric values directly, thereby reducing global RAM usage. For more information, please refer to this MATLAB documentation.
- If your S-Function is not producing any output, it may be due to issues with the function declaration. Please verify that the function is indeed returning an output and ensure that the output variable is correctly assigned a value. Additionally, you can adjust the data types of inputs and outputs using the "Ports and Parameters" tab in the S-Function Builder.
Hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!