I'm using R2013b or earlier. I want to use a Variant Subsystem to model child subsystems which have differing numbers of inputs and outputs. Can these systems be modeled using a Variant Subsystem?
MATLAB: How to use variant subsystems to model components with different numbers of inputs/outputs
simulink
Related Solutions
As your referenced model has the 'Invalid root Inport/Outport block connection' diagnostic set to error, Simulink will not automatically fix any problems regarding Inport/Outport connections. Your model violates one of the rules by muxing the outputs of two different blocks and feeding it directly to the outport. As stated in the documentation it is now allowed to have the following situation in your model: "A root Output port is connected directly or indirectly to more than one nonvirtual block port".
In order to resolve this problem, you can use one of the following approaches:
1) Set the diagnostic 'Invalid root Inport/Outport block connection' to 'none', which will cause Simulink to automatically handle this kind of situations by inserting additional blocks. The diagnostic can be found under: Simulation > Configuration Parameters... > Diagnostics > Model Referencing
2) Insert a gain block with value 1 between the Mux and Outport block. This will make sure only one block is directly fed into the Outport
This can be done by setting all the outports starting from the 'If Action SubSystems' to the 'Merge' block as virtual. This can be done in the following manner -
1. Starting from the '/Runnable2_subsystem/ExplicitWrite/If Action Subsystem', double click on the 'Out1' outport block and check the 'Ensure outport is virtual' option in the 'Main' tab.
2. Following along this signals path, set the '/Runnable2_subsystem/Subtracter' outport as virtual using the above procedure.
3. Similarly starting from the 'Out1' outport in the '/Runnable3_subsystem/ExplicitWrite/If Action Subsystem' we set the outports along the other signal to the merge block as virtual.
4. We also set the '/Runnable3_subsystem/Multiplier' outport as virtual.
Please find the attached updated Simulink model ("autosar_multirunnables_virtual_outports.slx"). If we generate the code for this model, we can see that the *Rte_IWrite** function calls are present within conditional statements as follows -
The call corresponding to the Runnable2 write -
161 if (rtDWork.Output_DSTATE_d >= rtb_Subtract) {162 /* Outputs for IfAction SubSystem: '<S6>/If Action Subsystem' incorporates:163 * ActionPort: '<S9>/Action Port'164 */165 /* Outport: '<Root>/PPort_DE4' incorporates:166 * DataTypeConversion: '<S2>/Data Type Conversion'167 * Inport: '<S9>/In1'168 */169 Rte_IWrite_Runnable2_PPort_DE4(rtDWork.Output_DSTATE_d);170171 /* End of Outputs for SubSystem: '<S6>/If Action Subsystem' */172 }
The call corresponding to the Runnable3 write -
236 if (rtDWork.Output_DSTATE >= rtb_TmpSignalConversionAtIn1Out * tmp[0]) {237 /* Outputs for IfAction SubSystem: '<S11>/If Action Subsystem' incorporates:238 * ActionPort: '<S14>/Action Port'239 */240 /* Outport: '<Root>/PPort_DE4' incorporates:241 * DataTypeConversion: '<S3>/Data Type Conversion'242 * Inport: '<S14>/In1'243 */244 Rte_IWrite_Runnable3_PPort_DE4(rtDWork.Output_DSTATE);245246 /* End of Outputs for SubSystem: '<S11>/If Action Subsystem' */247 }
Please note that the checkbox option ('Ensure outport is virtual') in the 'Outport' block was introduced in Simulink R2016b. Therefore, this workaround can be used to generate code as shown above from Simulink version R2016b.
Best Answer