Simulink Simulation Does Not Match Simulation With Generated DLL

9 visualizaciones (últimos 30 días)
When I run my model in Simulink (normal mode), I get a result of 200. Then I compile it with grt.tlc to a standalone executable without the capability of accepting inputs, this will still give me the same result 200. But in the final stage when I´m compiling the DLL to be able to introduce the input to the model the result is 100, completely different. Furthermore, temporally speaking the results (the model simulates 1 year each 10 seconds) makes no sense, the output is the first 4 or 5 days repeated along the year.
Several verifications were done such as:
1. Verify that the inputs are the same.
2. Everything in the path is where it should be.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 25 de Abr. de 2019
Editada: MathWorks Support Team el 25 de Abr. de 2019
The issue is being caused because of the large amount of time that the model is simulating for. When simulating, Simulink must allocate memory for a timer that keeps track of the simulation time. By default the amount of memory that gets allocated for this timer is based on a number of factors such as how large the time step for the model is and how long the simulation is scheduled to run for.
When simulating normally Simulink can preallocate enough memory for the simulation since it knows how long the simulation is expected to run for. When deploying code however you can modify this setting to conserve valuable memory based on how long you expect the application to run.
You can find the Application Lifespan in the following location in the Configuration Parameters for the model:
By default, the following behavior is observed:
- If you use Embedded Coder® and select an ERT target for your model, the underlying value for auto is 1. If you are generating production code, you should set the value of this parameter based on your model.
- If you use Simulink® Coder™ and select a GRT target for your model, the underlying value for auto is inf.
- This parameter is ignored when you are operating your model in external mode, have MAT-file logging enabled, or have a continuous sample time because a 64 bit timer is required in these cases.
An example overflow output is seen below
With the Lifespan set to "auto":
With the Lifespan set to "inf":
As you can see the output matches almost exactly for the full duration of the simulation whereas previously it would diverge. A key symptom in diagnosing this kind of issue is seeing divergent output that always occurs at a set time in the simulation.
Modify this parameter and then regenerate the DLL file from the model and this should resolve the discrepancy you are seeing between the regular simulation and the DLL simulation.

Más respuestas (0)

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by