How to connect a simscape block with add_line?
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thomas Knapp
am 20 Jan. 2015
Kommentiert: Francisco Williams
am 29 Jan. 2021
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 Kommentare
Akzeptierte Antwort
Steve Miller
am 21 Jan. 2015
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 Kommentare
Francisco Williams
am 29 Jan. 2021
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
am 29 Jan. 2021
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)
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!