6

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...

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • just to understand the question, you're looking for an alternative to rename the signals? You could create a custom bus selector, a subsystem with a mask, where you can choose the number of inputs and give them names. How does that sound? I think there is really no way around dummys, you can just make them look prettier... – Robert Seifert Sep 22 '14 at 15:04
  • Another option would be regrouping, just create buses "RW1", "RW2" ... and assign a current. They would then have the name `RW1.Current`, `RW2.Current` ... – Robert Seifert Sep 22 '14 at 15:12
  • @thewaywewalk: in the example above, each `RW` model outputs its own bus (`Data Output`). From each of those buses, I select only 3 signals (so the signal names shown in the bus selectors is indeed `RW1.Current` and similar, as you say). However, if you want to group such signals again into a new bus, MATLAB complains about identical signal names, either on the bus input (with individual bus selectors connected to a bus creator, as in the figure), or on the bus output (if you connect `RW1-4` directly to a bus creator, and check "output as bus". I see no way around it without dummies... – Rody Oldenhuis Sep 22 '14 at 15:29
  • I agree, there is no way around. It even gets uglier if you want to display [a dynamic number of signals](http://stackoverflow.com/questions/20424697/how-to-properly-propagate-multiplex-signal-names-to-scope-legend-via-bus-system) in a scope. But it seems you're not intending to do that? So if its a constant number of ports, just create a subsystem with all your dummys and don't think about it again ;) – Robert Seifert Sep 22 '14 at 16:08
  • Regarding this sentence: "if you connect RW1-4 directly to a bus creator, and check "output as bus". I" The bus creator does not have the option, you probably grabbed a bus selector. Try it with a bus creator. – Daniel Nov 04 '14 at 10:26
  • @Daniel yes, sloppy commenting, sorry for that. See my comment on your answer. – Rody Oldenhuis Nov 04 '14 at 13:12
  • I ran into the same issue today. Your question captures the problem perfectly. Have you found a better workaround/solution yet? – mmumboss Feb 16 '16 at 10:28
  • @mmumboss no, sadly not. I still do it the ugly way depicted above, and just hide it in a virtual subsystem. – Rody Oldenhuis Feb 16 '16 at 12:23

2 Answers2

1

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.

Manex
  • 528
  • 4
  • 15
  • Thanks :) I like good hack, but you'll have to admit that this just cannot be what the Mathworks thinks is the best way to design your systems...+1 though for effort, and the smile on my face. – Rody Oldenhuis Nov 04 '14 at 07:31
  • Well, It's just a easy-naming-convention hack, I suppose my lack of deep experience with large model referencing and further modern tech beyond R2007a prevents me from seeing further pitfalls... :-) – Manex Nov 04 '14 at 09:17
1

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

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • As discussed in the comments, that doesn't work: you're still putting non-unique signal names into a single bus. At best, it will only postpone the problem to somewhere outside this subsystem (which is arguably even worse). – Rody Oldenhuis Nov 04 '14 at 07:28
  • It creates a structured bus with signal names like `rw1.current`, the names are unique. – Daniel Nov 04 '14 at 10:24
  • 2
    OK, let me rephrase that: you are right, this works, but only on this level. However, when you connect this output bus to another bus selector, select `rw1.speed` and `rw2.speed` from the signals and select the option `Output as bus`, the structure is not transferred to the new bus, and you get the warning. The model above is small, my "real" models are huge, and the number of signals really justifies the second `Output as bus` option. Therefore, it really has my preference to have really unique names, without *any* risk of naming conflicts. – Rody Oldenhuis Nov 04 '14 at 13:11