For Each Subsystem and PID Controller Block

5 vues (au cours des 30 derniers jours)
Mariusz Jacewicz
Mariusz Jacewicz le 6 Mai 2023
Réponse apportée : Shivang le 24 Août 2023
Hello.
This is my first post in the community so I appologize for any inconsitencies in the description or language mistakes.
I created a Simulink model with For Each Subsystem block. Inside this block is a very simple control loop with first order transfer function (please see the attached file). I want to use an array of proportional gain coefficients: P_array = [1, 1.1, 1.2]. This variable is created automatically after model opening (I used the option "Model Properties --> Callbacks --> PreLoadFcn"). The only parameter of the system is gain P (this paramater was partitioned, please see the pictures below).
I used the option "For Each Subsystem (right mouse click) --> Mask --> Edit Mask" to define parameter P.
The problem is that after model run the MATLAB displays the following error:
"Function 'eval' cannot be used in mask initialization or icon drawing commands of 'Problem_PID/For Each Subsystem/PID Controller', because it is (or is inside) a For Each subsystem with one or more partitioned mask parameters."
The system works properly only for single value of P (for example when I convert P on number like 1.1). Do you know how to solve this issue? I spent three days using various workarounds but the problem still exists. The model was created in MATLAB R2020b release.

Réponses (1)

Shivang
Shivang le 24 Août 2023
Hi Mariusz,
I understand that you are running into an error while working with a PID Controller block inside a ‘For Each’ subsystem.
Please note that the possible cause behind this error is the 'eval' function which is called in the “icon drawing” commands of the PID Controller block. This function call is creating an error because of the use of partitioned mask parameters for the PID Controller block.
In this case, as a workaround, you can modify the “icon drawing” commands of the block's mask. To do so, please follow the steps below:
  • Note that the PID Controller block contains a locked link to its library. The first step is to disable this link in order to modify the block's mask. Select the PID Controller block in your model and type
set_param(gcb, 'LinkStatus', 'inactive')
in the MATLAB Command Window. This will deactivate the block’s link to its library.
  • The second step is to modify the icon drawing commands of the block's mask. Right click the PID Controller block and select 'Mask' -> 'Edit Mask'. Navigate to the 'Icon' tab inside the Mask Editor. Now comment out the call to the 'eval' function on line 2. To retain the icon on the block you can add a
disp('P(s)')
statement on line 3.
  • Save the mask by clicking on the 'Save Mask' button on the top left. Please note that it may take a few seconds for the mask to be saved successfully.
On running the model now, you should not encounter any error.
Additionally, if you wish to view the response curves for various values of the parameter 'P' in one plot, you should move the ‘Scope’ block out of the Subsystem, and replace the ‘Scope’ block with the ‘Outport’ block inside the Subsystem.
You should obtain a ‘Scope’ plot similar to the one attached below after making the aforementioned changes to your model file:
Hope this helps!

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by