How do I set block parameter value using a Mask property?
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Shivang Menon
2016-11-3
编辑:Shivang Menon
2016-11-3
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Physical Units 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!