Troubleshooting an embedded MATLAB function in a compiled Simulink model

2 ビュー (過去 30 日間)
Matt Butts
Matt Butts 2020 年 9 月 24 日
コメント済み: Matt Butts 2020 年 9 月 25 日
Some background on my setup:
MATLAB version: 2010a (yes, I must be on this version because I am compiling for a 32-bit Linux target)
Simulink model with only an embedded MATLAB Function
The enbedded MATLAB function calls some other custom functions (all functions are on the MATLAB path)
The embedded MATLAB function also uses a parameter that is a structure. This structure is loaded into the base workspace.
Compilation uses a custom tlc file for the target and is done with rtwbuild.
Now this issue. I can run this model in Simulink and it works as expected. I then compile the model and that completes successfully. However, once I run the compiled model, I am not getting valid outputs from the embedded MATLAB function. Is there a good way to debug this in the compiled model? Are there some key things to check when using an embedded MATLAB function in a compiled model?
  2 件のコメント
Peter O
Peter O 2020 年 9 月 25 日
When and how is the structure loaded? Is the structure loaded as part of Simulink's OnRun or OnModelLoad (or whatever they're called) hooks? Is it done manually?
Can you verify the embedded fcn runs properly on the target with two simple MWEs?
  1. Check Fcn Compilation: Return input u + 1.
  2. Check Struct Load/Access. Load struct s at start of sim. Return s.a + u.
Matt Butts
Matt Butts 2020 年 9 月 25 日
Thanks Peter. I started down this path yesterday as well.
The structure is manually loaded into the workspace before I open the model. The structure is also defined as a parameter in the model.
I then tried both of your suggestions as well.
  1. I compiled the model with very simple arithmetic operations on the inputs in the embedded function. This worked as expected.
  2. I compiled the model with simple arithmetic operations and included values from the parameter structure (to verify the structure was getting included). This worked as expected.
So I know that a simple embedded function works, and I know that the structure is being read and included in the compiled model.
I am left needing to debug the more complex embedded function. For this, my first thought was to make sure it was calling all of the dependent functions, so I edited each dependent function to just return some constant values and exit. This compiled and worked as expected, so all dependencies are being included and called properly.
So finally, how do I debug code logic that behaves differently when compiled than it does when in native Simulink?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

製品


リリース

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by