Compiled Simulink model giving different results
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matt
el 16 de Oct. de 2013
Comentada: Matt
el 18 de Oct. de 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?
0 comentarios
Respuesta aceptada
Guy Rouleau
el 17 de Oct. de 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:
http://www.mathworks.com/help/simulink/sfg/how-the-simulink-engine-interacts-with-c-s-functions.html
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.
0 comentarios
Más respuestas (2)
Andreas Goser
el 16 de Oct. de 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.
0 comentarios
Matt
el 17 de Oct. de 2013
Editada: Matt
el 17 de Oct. de 2013
2 comentarios
Guy Rouleau
el 17 de Oct. de 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.
Ver también
Categorías
Más información sobre MATLAB Compiler 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!