How to connect a simscape block with add_line?
조회 수: 14 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
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
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!