Optimizing Simscape Generated Code

조회 수: 1 (최근 30일)
Sean Bonaventure
Sean Bonaventure 2020년 10월 18일
댓글: Joel Van Sickel 2020년 12월 1일
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?

답변 (1개)

Joel Van Sickel
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
Sean Bonaventure
Sean Bonaventure 2020년 10월 21일
Thanks for the tips. I wasn't able to use a discrete step solver, as I got the error: The "FixedStepDiscrete" solver cannot be used to simulate block diagram 'AccumulatorModel' because it contains continuous states". The ode3 solver also wasn't good enough and I need to use ode14x.
Changing the solver configuration to fixed cost run time helped, reducing the step time from 150ms to 50ms, but that is still too long.
My model is not accesing any files, but it is using the LUT based battery component. So it's reading look up tables.
I am using gcc on linux as my compiler. I have attacehd a zip file of my model.
Thanks for your help,
Sean
Joel Van Sickel
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 CenterFile Exchange에서 Parameterization Methods에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by