Optimizing Simscape Generated Code
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Joel Van Sickel
2020-10-20
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 个评论
Joel Van Sickel
2020-12-1
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parameterization Methods 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!