Problem with code generation using Embedded Coder

15 views (last 30 days)
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 Comments
Swastik Sarkar
Swastik Sarkar on 17 Dec 2024
Will it be possible to share a sample model demonstrating the problem, so that others can reproduce the issue and contribute more effectively ?

Sign in to comment.

Answers (0)

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!