Basic Slider Switch question

7 ビュー (過去 30 日間)
Matthew Mishrikey
Matthew Mishrikey 2021 年 12 月 20 日
編集済み: Matthew Mishrikey 2022 年 2 月 9 日
I was curious if it was possible to make a slider switch dashboard element control more than one block simultaneously. Alternately, can I use a switch to somehow set a global parameter that the whole sim can access?

採用された回答

Benjamin Thompson
Benjamin Thompson 2022 年 2 月 8 日
Looks like you can only connect the Slider Switch to one block. But if that was a Constant block connected to a Data Store Write, then you could put Data Store Reads throughout your model and in that way redistribute your parameter change to more points.
  4 件のコメント
Matthew Mishrikey
Matthew Mishrikey 2022 年 2 月 8 日
Is it possible to interface a data store read with a workspace variable?
I think your suggestion would probably work, but it would be preferable not to clutter these blocks with so many inputs.
Benjamin Thompson
Benjamin Thompson 2022 年 2 月 8 日
You can also use set_param to change parameters on blocks. If you go to Model Properties you can add M-code to be called at certain times, like during model init or simulation start. Perhaps there, you could read your data value from the workspace or something like that, then use it to set block parameters in different places in the model. This would not change when you move your slides as you originally wanted.
If you can put all blocks that depend on the slider in a masked subsystem, then your slider could just change a parameter in the mask. Then through the parameter promotion mechanism you can assign block parameters within the mask to one parameter that is set by the user in the mask.

サインインしてコメントする。

その他の回答 (2 件)

Matthew Mishrikey
Matthew Mishrikey 2022 年 2 月 9 日
I think I'm getting closer to an answer here.
I setup slider switch to control a constant block, which feeds a data store write, which writes to a data store memory.
A data store read then writes this value to the base workspace.
To access this value in a matlab function, I can do it two ways -
first, I can use a data store read to feed an input to a matlab function (rmathfunc in image).
second, I can declare the data store variable as global inside a matlab function (tmathfunc) and access it without an input to the function.
In the simscape LOAD element, to access R_ohms, I tried to set the resistance to resval. I have to run the sim two times though after changing the slider before the updated value makes it to the simscape component. That's not so nice.
Sim attached.

Matthew Mishrikey
Matthew Mishrikey 2022 年 2 月 9 日
編集済み: Matthew Mishrikey 2022 年 2 月 9 日
I think I figured out a way. I hope there's a better solution because this seems like a royal pain.
1) in the simscape component, set the parameter to a base workspace variable.
2) slider switch controls a constant block.
3) constant block sets a data store write, and also a to_workspace block.
4) to control the simscape component with the slider switch, you need to create the workspace variable before the block loads. Do this with model level Callbacks. In this case I do
resval = str2num(get_param(strcat(bdroot,'/Constant'),"Value"));
in PostLoadFcn, InitFcn, and also StartFcn.
5) Matlab Function blocks can access the data store memory (either by a data store read, or by Edit Data | add global variable - must declare data store memory as global in function).
I played around with ways to have the matlab function blocks access the workspace variable directly, to elminate the data store memory middleman, but didn't have any luck.
Anyway, thanks for your comments Benjamin, helped me get across the finish line here.

カテゴリ

Help Center および File ExchangeComposite Components についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by