How do I set block parameter value using a Mask property?

3 Ansichten (letzte 30 Tage)
Surojit Sen
Surojit Sen am 30 Okt. 2016
Kommentiert: Surojit Sen am 14 Nov. 2016
I want to convert a Suspension block subset into a generic suspension Mask. This mask would have a few popups. A particular block in the subset (eg. Planar Joint) should modify the value of its parameter (eg. Pz/Spring Constant) based on the popup in the mask. For example, the name of Popup is 'pos', which takes two values, 'Front' or 'Rear'. Based on this value set (in mask) before simulation run, the Spring Constant (in Planar joint block within subset) value should become 'Front_Spring_Stiffness' or 'Rear_Spring_Stiffness', with the 'pos' acting as a proxy for 'Front' or 'Rear'. I have tried to put [pos '_Spring_Stiffness'] but it is throwing this warning: "Vehicle_4WD/Suspension FL/Suspension:The parameter Pz/Spring Constant, defined by: [pos '_Spring_Stiffness'] N/m, can only be evaluated by Simulink. Resolve this issue in order to remove the warning. [8 similar]".
Kindly help. Thanks.

Akzeptierte Antwort

Shivang Menon
Shivang Menon am 3 Nov. 2016
Bearbeitet: Shivang Menon am 3 Nov. 2016
I am not exactly sure why this warning is being thrown. However, there are a few relatively simple alternatives you can try, to get rid of the warning. I am assuming [pos '_Spring_S..'] and [pos '_Damping_...'] are defined in the base workspace and you want to use those values as parameters for the joint.
Alternative 1 - Declare a variable in the mask initialization code that holds the concatenated string and use that in the joint's dialog box.
In the mask initialization code, create new variables like the following:
springString = [pos '_Spring'];
dampingString = [pos '_Damping'];
Now, in the dialog box for the cylindrical joint, instead of using [pos '_Spring'], use springString. springString is defined in the mask workspace and is available to blocks within the subsystem.
Whenever the value for the popup will be changed in the mask, the mask initialization code will execute. This will change the value of springString and dampingString, which will in turn change the name of the parameter being used in the cylindrical joint.
Alternative 2 - Use set_param to set the parameter for cylindrical joint from the mask initialization code.
Refer to the code below:
block = find_system(gcb, 'LookUnderMasks' , 'on', 'FollowLinks','on','Name','Suspension');%or any other name
set_param(block{1},'PySpringStiffness',[pos '_Spring']);
set_param(block{1},'PyDampingCoefficient',[pos '_Damping']);
If you put this code in the mask initialization code, every time the popup is changed, the code will execute and it will set the corresponding parameter in the cylindrical joint(suspension) block. Refer to the following link for more information:
Hope this helps!
  1 Kommentar
Surojit Sen
Surojit Sen am 14 Nov. 2016
That is great Shivang, this works perfectly! Thanks for helping me with this.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Physical Units finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by