Avoid reuse of local variables in Embedded coder

46 visualizaciones (últimos 30 días)
Felipe Herrera
Felipe Herrera el 10 de Dic. de 2024 a las 20:28
Comentada: Felipe Herrera el 13 de Dic. de 2024 a las 13:51
I'm generating code for an m-function in the simulink enviroment which solves an MPC algorithm. When the C-code is generated, some variables are used multiple times in the generated code, in different contexts. This behaviour breaks down my algorithm, and the resulting C-code does not produce the desired output (in this particular case, it does not produce an output at all). I have seen that using 'config.PreserveVariableNames = "UserNames"' produce code which does not modify the local variables. However, the configuration has to be applied using the codegen command. I have tried to pass this configuration to simulink without luck. Is there a way to tell the Embedded Coder to not modify the local variables in the m-function when generating code from Simulink?

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 10 de Dic. de 2024 a las 21:34
Editada: Fangjun Jiang el 10 de Dic. de 2024 a las 21:40
That is probably not the correct option. You should try to disable the "Reuse local block outputs" option.
There is a "PreserveName" option in Simulink Coder but it is reserved by the Mathworks. https://www.mathworks.com/help/rtw/ref/code-generation-pane-general.html
  5 comentarios
Fangjun Jiang
Fangjun Jiang el 13 de Dic. de 2024 a las 13:33
Yes. Controlling the code generation exactly as what you want regarding number of files, variable names etc. is sometimes difficult. I would think your best shot is still using the MATLAB Function block in Simulink and generating code as a whole from Simulink. Did you try that "PreserveVariableNames" in the embedded coder configuration? https://www.mathworks.com/help/coder/ref/coder.embeddedcodeconfig.html
Contact the Mathworks tech support for direct assistance.
Felipe Herrera
Felipe Herrera el 13 de Dic. de 2024 a las 13:51
Yes, I tried to control code generation in simulink using Embedded Coder Config options. However, I couldn't find a way to tell simulink to actually use those configuration parameters. I tried using SwitchTarget, and it did apply the parameters but it didn't last long. When the m-script used to inicialize the parameters stop executing, simulink configuration returns to its previous values.
I will contact Mathwords tech support, thank for your assistance.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by