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

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

采纳的回答

Sai
Sai 2022-10-13
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.

更多回答(1 个)

Mark McBroom
Mark McBroom 2022-10-15
编辑:Mark McBroom 2022-10-15
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.

类别

Help CenterFile Exchange 中查找有关 Create Large-Scale Model Components 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by