Compiled Simulink model giving different results

8 Ansichten (letzte 30 Tage)
Matt
Matt am 16 Okt. 2013
Kommentiert: Matt am 18 Okt. 2013
I have a simulink model (.slx) that I am trying to compile and run in Visual Studio. I'm finding that my results are different than the output of the model in simulink. I've tried compiling under C and C++ with identical results.
For example the first few simulink results are 100 97.1696536696777 94.5212838899871 92.0431905150397 89.7244256574844 87.5547453221953
and visual studio: 97.87 95.18 92.66 90.30 88.09 86.03
If I have a 2 minute simulation with .04 time step my Visual Studio results appear to skip the first step and then be shifted left by .03.
Any ideas?

Akzeptierte Antwort

Guy Rouleau
Guy Rouleau am 17 Okt. 2013
I would bet that this is related to the "Single output/update function" parameter. See this doc page:
Look at the bullet starting with "If you have customized ert_main.c or .cpp to read model outputs after each base-rate model step..."
In this page:
Look at the Simulation Loop image. The Simulation retunrs values just after the first mdlOutputs. With the generated code, the step function runs everything sothe data you see is at the bottom, when the left arrows goes back up.
Both results are good... they are just at different moments in time.
To see identical results,un check the option mentionned above. In the code, call "output", read your signals, then call update.

Weitere Antworten (2)

Andreas Goser
Andreas Goser am 16 Okt. 2013
Beside there are multiple ways to "compile and run a model", this is really something where you should contact Technical Support for and include your example.

Matt
Matt am 17 Okt. 2013
Bearbeitet: Matt am 17 Okt. 2013
Guy,
I put a breakpoint where the output is assigned and it does seem to be taking three steps for every step call in my main. The first of the three is the value I am expecting, which is consistent with what you are saying regarding minor and major steps.
I am using the grt target however and therefore have no option to uncheck Single output/update function. Is there any way to get the answer out of my main using grt target, or will I have to insert code in the generated model.c or .cpp file to return model output values reflecting only the major time steps, as suggested in your first link?
Thanks
  2 Kommentare
Guy Rouleau
Guy Rouleau am 17 Okt. 2013
Three steps... looks like you are using the ode3 solver.
If your model uses ode1, results should match, but accuracy will change.
If you change your model to be fully discrete, results should match.
Inserting a Unit Delay, Rate Transition, or another block that makes your output discrete can make the results match because discrete blocks only execute Output once and Update once.
As you can figure out, those options are changing the simulation so that it generates code that will return identical results. To have more control over the generated control, you need Embedded Coder.
I want to repeat it again to be sure it is clear... the results using you get using GRT are not wrong... they are just extracted from the simulation loop at a different time.
Matt
Matt am 18 Okt. 2013
OK, in the end I did just go with the ert and used the output/update functions.
Thanks again for your help.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by