How can I connect 3 Simscape ports programmatically
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello everyone,
Recently I am having a simulink problem:
I would like to connect 3 Simscape Electrical Ports programmatically.
The result should look something like this:
For that I wrote a MATLAB Code that should create the above:
simulink
open_system(new_system('sys'));
% Add Blocks
add_block('nesl_utility/Connection Port','sys/1');
add_block('nesl_utility/Connection Port','sys/2');
add_block('ee_lib/Passive/Capacitor','sys/C');
% Move Blocks
set_param('sys/1','position',[0,0,30,30]);
set_param('sys/C','position',[0,100,30,130]);
set_param('sys/2','position',[0,200,30,230]);
% Find Position
par1 = get_param('sys/1','PortConnectivity');
parC = get_param('sys/C','PortConnectivity');
par2 = get_param('sys/2','PortConnectivity');
pos1 = par1.Position;
posC1 = parC(1).Position;
posC2 = parC(2).Position;
pos2 = par2.Position;
% Connect Blocks
add_line('sys', [pos1;posC1]);
add_line('sys', [pos2;posC2]);
add_line('sys', [pos1;pos2]);
The problem is, that one connection is always missing, and with the above code I get this:
Is there any solution for this?
댓글 수: 0
채택된 답변
Timo Dietz
2022년 1월 14일
Hello,
you can directly connect via the port pin names, instead of using the position information:
add_line('sys', '1/RConn1', 'C/LConn1')
add_line('sys', '2/RConn1', 'C/RConn1')
add_line('sys', '1/RConn1', '2/RConn1')
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!