Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make signal names coming from library links unique?

OK, I've been struggling with this for a while. What is the best way to accomplish the following:

enter image description here

where Reaction Wheel 1-4 are links to the same block in a library. When the Speed Counter, Speed Direction and Current signals are added to the final bus output as shown, MATLAB (rightfully) complains:

Warning: Signals 9, 10, 11, 12 entering Bus Creator 'myAwesomeModel' have duplicated names 'Current'. These are being made unique by appending "(signal #)" to the signals within the resulting bus. Please update the labels of the signals such that they are all unique.

Until now I've been using a "solution" like this:

enter image description here

that is, place a size-1-mux/gain-of-1/other-dummy block in the middle, so the signals can be renamed into something unique. However, I really like to believe that The MathWorks has thought of a better way to do this...

What is the "proper" way to construct bus signals like this? It feels rather like I'm being pushed to adopt a particular design/architecture, but what that is precisely, eludes me for the moment...

like image 482
Rody Oldenhuis Avatar asked Sep 22 '14 13:09

Rody Oldenhuis


2 Answers

It was quite a challenge for me but looks like I kinda sorted it out. Matlab R2007a here. I'll do the example with an already done subsystem, with its inputs, outputs, ...

1- In Block Properties, add a tag to the block. This will be done to identify the block and its "siblings" among the system. MY_SUBSYSTEM for this example.

2- Block Properties again. Add the following snippet in CopyFcn callback:

%Find total amount of copies of the block in system

len = length(find_system(gcs,'Tag','MY_SUBSYSTEM'));

%Get handle of the block copied/added and name the desired signal accordingly   

v = get_param(gcb,'PortHandles');                                     
set(v.Outport(_INDEX_OF_PORT_TO_BE_RENAMED_),'SignalNameFromLabel',['BASENAME_HERE' num2str(len)]);

3- In _INDEX_OF_PORT_TO_BE_RENAMED_ you should put the port signal index (starting from 1) that you want to have renamed for each copy of the block. For a single output block this should be 1. BASENAME_HERE should be the port basename, in this case "Current" for you.

4- Add the block to the desired library, and delete the instance you used to create this example. From there on, as you add from the library or copy an existing block, the outport should name Current1, Current2, Current3, and so on. Notice that you could apply any convention or formatting.

Hope this helps. It worked for me, don't hesitate to ask/criticize!

Note: Obviously, as the model grows, this method may be computer-demanding as find_system will have to loop through the entire model, however looks like a good workaround for me in small-medium sized systems.

like image 88
Manex Avatar answered Nov 06 '22 21:11

Manex


Connect a Bus Selector to each Data Output. Select the signals you want and set "Output as bus". Then connect all Bus Selectors to a Bus Creator.

simulink model

like image 24
Daniel Avatar answered Nov 06 '22 22:11

Daniel