Best practice for setting Simulink block parameters at initialization?

조회 수: 7 (최근 30일)
Paul
Paul 2025년 4월 15일
편집: Paul 2025년 4월 16일
I'm developing a motor controller in Simulink, and I have more than one motor that I want to simulate with. I'd like to adjust the motor parameters in an elegant way that experienced Simulink developers would recognize the design pattern. When I'm done, I want to be able to hand this simulation off to another engineer and have a non-simulink expert understand how to switch motors and preferrably be able to add a new motor variant in the future. I am considering the following approach, but would like feedback on whether there is a more "Simulink" way to solve it:
I have a subsytem which contains the Simscape Electrical BLDC block and a Hall sensor signal generator. The subsystem block defines the Motor parameters for the variety of motors that I can select. The subsystem mask has a dropdown box to select which motor is being used for simulation. The subsystem InitFcn() updates the BLDC parameter values based on the setting of the dropdown box.
An alternative would be to write a .m file for each motor, and then select which .m script is run during InitFcn(), but I'm not sure I can add a file dialog to the subsytem mask. What I like about this is I can add as many motor variants as I want by just writing another .m file.
Any advice on best practices is appreciated!

채택된 답변

Sabin
Sabin 2025년 4월 16일
If you want easily to switch the system, I will probably use variants. Check out this example as a starting point:
For the controller it is best to use a masked Simulink subsystem, internally you can still use variants if the controllers are very different and then use a dropdown to switch between different variants. You can call different parameterization files using the dropdown callback.
It is good to keep the parameter definition in m files so you can easily change them if needed.
It is also possible to use a project that you can customize:
  댓글 수: 1
Paul
Paul 2025년 4월 16일
편집: Paul 2025년 4월 16일
Thanks Sabin! I am digging into Variants and learning more about how to use them. Right now, I have two .m script files to repesent the parameters of two different motors. Each motor variant calls it's respective script in the InitFcn() callback to update the workspace. I can see that when I compile the model with the two different variants, the parameters in the base workspace get updated.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large-Scale Modeling에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by