Best practice for setting Simulink block parameters at initialization?

7 次查看(过去 30 天)
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