How to connect a simscape block with add_line?

19 ビュー (過去 30 日間)
Thomas Knapp
Thomas Knapp 2015 年 1 月 20 日
コメント済み: Francisco Williams 2021 年 1 月 29 日
Hey there, I want to connect a PMC port in SimMechanics automatically with a Matlab-Script. Using the 'add-line' command works fine for common simulink-connections, but not for Simscape-ports. For example if I want to connect the block 'World Frame' with 'Rigid Transform' I use
% code
add_line('mysystem','World Frame/1','Rigid Transform/1')
But then I always get the message:
Invalid Simulink object name: World Frame/1
Does anbody know how to connect these ports in a good way?
Thanks in advance, Thomas

採用された回答

Steve Miller
Steve Miller 2015 年 1 月 21 日
Hi Thomas,
add_line() works with Simscape ports. You have to refer to the ports differently. Try this command:
add_line('mysystem','World Frame/RConn1','Rigid Transform/LConn1');
There is a submission on the MATLAB Central File Exchange that shows how to use MATLAB to automate the construction of a SimMechanics model. The submission "SimMechanics Model from MATLAB Code" shows how to add blocks and connect them using MATLAB commands. The same commands work for Simscape blocks, too.
Hope this helps! --Steve
  2 件のコメント
Francisco Williams
Francisco Williams 2021 年 1 月 29 日
Hi,
I know this is an old question but I can't find a newer thread.
I'm having the same problem with Matlab2020b. Is there a way to query the names of the blocks?
I created a Subsystem (With Simscape multibody blocks inside) and I want to connect it to another block. But I can't manage to get the proper name of the ports.
Thanks in advance
Francisco Williams
Francisco Williams 2021 年 1 月 29 日
Oh I found a workaround for this:
% Select the first subsystem
>>h1 = get_param(gcb,'PortHandles')
struct with fields:
Inport: []
Outport: []
Enable: []
Trigger: []
State: []
LConn: 333.0016
RConn: []
Ifaction: []
Reset: []
% Select the second subsystem
>>h2 = get_param(gcb,'PortHandles')
struct with fields:
Inport: []
Outport: []
Enable: []
Trigger: []
State: []
LConn: 572.0040
RConn: 974.0093
Ifaction: []
Reset: []
% Or instead of entering gcb, enter the path of the subsystem. The first
% subsystem has only 1 output port and the second one 2
% add the connection between blocks with:
add_line(gcs,port_h1.LConn,port_h2.LConn)

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

その他の回答 (1 件)

Thomas Knapp
Thomas Knapp 2015 年 1 月 21 日
Hi Steve,
thank you very much! Now everything works fine :)
Thomas

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by