How to change contents of blocks in multiple instances of referenced model in Simulink?

7 views (last 30 days)
I am representing a certain robot using a Simulink model which contains Matlab function blocks, integrator blocks, etc., and intend to use this model in a main model. In the main model, I need to have multiple instances of the robot model to represent multiple robots interacting. I have found out that this is possible using referenced models.
However, each of these robots is different. Within each robot model, the architecture does not change, but the contents of the blocks do change to represent the different robots. These changes are not only parameters, but also the contents of the Matlab functions themselves. I generate these functions at the beginning of the simulation using initFcn callback, but I am unaware of how I can update the contents of each referenced model according to the generated functions.
Apologies if the question is confusing, it is not a trivial problem. Thank you in advance for the help!

Accepted Answer

Sai
Sai on 13 Oct 2022
I understand that you created many sub Simulink models which you will eventually use in main Simulink model as reference model and you are trying to change the contents of blocks correspondingly.
I hope the following explanation resolves the issue.
  • Open the main Simulink model
  • Double click the reference model, which you want to change or update
  • Navigate to Modelling tab and then Model Properties of Model Settings as shown in below image
  • Click on callbacks and then you can add the corresponding files by clicking on different callbacks as shown in below image.
The above process can be repeated for any reference model.

More Answers (1)

Mark McBroom
Mark McBroom on 15 Oct 2022
Edited: Mark McBroom on 15 Oct 2022
It is possible to have referenced models use different parameter values by setting them up as parameter arguments. However, it is not possible for different isntances of the reference model to have different code in a MATLAB function.
One possible workaround would be to add a switch statement to your MATLAB code that runs different code based on a pameter ( for example, ModelID)... and then make ModelID a model parameter. This will allow you to give each instance of your referenced model and different ModelID and therefore execute differnt MATLAB code in the MATLAB Function Block.

Categories

Find more on Create Large-Scale Model Components in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!