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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157505/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157506/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157507/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157508/image.png)
댓글 수: 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에서 Brakes and Detents에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!