Best practice for setting Simulink block parameters at initialization?

8 views (last 30 days)
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!

Accepted Answer

Sabin
Sabin on 16 Apr 2025
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 Comment
Paul
Paul on 16 Apr 2025
Edited: Paul on 16 Apr 2025
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Large-Scale Modeling in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!