Optimizing Simscape Generated Code
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello. I am using Simulink and Simscape electrical to model an electrical vehicle battery. The model consists of table based batteries along with resistors and mosfets used to model the balancing circuitry for a BMS. The end goal is to export this model to C code to a standalone program that can be used to interface and test our actual BMS code. I am using Simulink Coder to export the code, but the problem I am facing is the exported code is extremely slow. A single step takes around 150ms. This is much slower than when the model runs in Simulink itself. I tried messing around with solver, step size, and compiler settings, but can't seem to speed the code up. Does anyone have any suggestions? Is this a problem with using generated Simscape code?
0 commentaires
Réponses (1)
Joel Van Sickel
le 20 Oct 2020
Hello Sean,
code generation for simscape should not be causing a slow down like this. It is often used for real-time tasks where execution timing is critical. I'm not sure what settings are required for simulink coder to work. I would try to run the model with these settings:
Simulink settings - used discrete step solver if possible, or a fixed step solver like ode3.
Simscape settings - set to fixed step in the solver configuration and check the box for fixed cost runtime.
If these settings don't help, would you be willing to share your model? Is your model accessing files or anything like that?
What are you using for your compiler?
Regards,
Joel
2 commentaires
Joel Van Sickel
le 1 Déc 2020
Hello Sean,
sorry, I haven't had much time to reviewing models lately. I took a look, and it seems like the local solver wasn't turned on for your model. I would recommend using this to set your simscape model to a fixed time step. If your simulation doesn't work with a large enough time step, I would recommend optimizing your battery model to not require as small a time step to simulate accurately..
Regards,
Joel
Voir également
Catégories
En savoir plus sur Parameterization Methods dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!