Simulink arduino : compile unmodified code at every run

5 visualizaciones (últimos 30 días)
Delprat Sebastien
Delprat Sebastien el 30 de Nov. de 2022
Respondida: Siraj el 3 de Nov. de 2023
I'm using an arduino MEGA 2650 + simulink model in external mode with the "Simulink Arduino package".
It works fine.
However, simulink is compiling and building the code at every simulation.
For instance, if you run 3 simulations in a row, without any changes (no block have been moved, all the parameters remains the same, etc) it will compile the model 3 times!!
This is long and causes problem for my application : simulation duration is 3 seconds, and compilation time is about 30 seconds.
So to perform 10 simulations, it takes 5 minutes instead of 1 minute (30 second first compilation + 10x3s simulations duration)
How can I ask Simumulink to reuse code if it hasn't been modified?
  2 comentarios
Naga
Naga el 13 de Oct. de 2023
Could you please elaborate on the specific intention behind running the model many times.
Delprat Sebastien
Delprat Sebastien el 13 de Oct. de 2023
The intention: gaining time on unecessary operations. Compiling an already compiled code is useless.
First intention: record pressure signals every time the unstable wake behind a ahmed body in a wind tunnel flips "randomly" from one pos to the other.
Second, I work with students in a lab, they have to perform several test on a systems related to controler synthesis.
With some digital input conntect to buttons, they can choose the input signal to be applied at the input. With a potentimeter, they can tune some parameters (freq & amplitude). So basically, the Simulink program is designed such that they can perform several experiments with some physical input and without modifying the code. The "smoothness" of this approach is broken by unecessary compilations.
Last but not least, the more complex your model is, the more time it takes to compile and why would your do something again and again when you know that it is unecessary?

Iniciar sesión para comentar.

Respuestas (1)

Siraj
Siraj el 3 de Nov. de 2023
Hi!
It is my understanding that you are using an Arduino MEGA 2650 with Simulink in external mode. You are facing an issue where the Simulink model is being compiled and built every time you run a simulation, even if there are no changes to the model. This is causing a significant increase in simulation time.
One possible solution you can consider is utilizing the Model Reference feature in Simulink. Model referencing allows you to include one model within another by using a model block and you can take advantage of the Accelerator mode. In this mode, the C-code for the referenced model is generated only once and won't require re-compilation unless there are structural or dependency changes. This approach can help reduce simulation time by avoiding unnecessary code generation and compilation when there are no modifications to the model.
To learn more about model references and how to effectively use them in Simulink, you can refer to the following link:
For more information on optimizing simulation workflows in Simulink you can refer to the following link.
It covers various techniques, including model referencing, to modularize models and improve simulation speed. Additionally, it provides guidance on leveraging the Simulink cache effectively to reduce simulation time by reusing compiled code.
Hope this helps.

Categorías

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

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by