How to use the results calculated by the previous module to control the variant modules in the system composer (software architecture)?

1 view (last 30 days)
I am trying to use variant components to build my software architecture. The plan is to use the signal a calculated by the previous calculation module (Planning) to control the selection of variant components, such as selecting component_1 when v=1, and if v=2, select component_2. At present, after consulting the reference documents, it seems that the control variables for the variants can only be used in MATLAB ® Variables, Simulink Parameter object or Simulink The VariantControl object is used for control. And my quantity is the signal, how should this be achieved?
It should be noted that due to project requirements, I am unable to use programming methods likes M-function or S-function. I can only use the built-in module functions of SIMULINK.

Accepted Answer

Josh Kahn
Josh Kahn on 29 Aug 2024
Edited: Josh Kahn on 29 Aug 2024
Hey @鑫鹏,
What you are modeling appears to be a service-oriented architecture. Are you able to upgrade from R2021b? In R2022a, we introduced client-server ports that can be used to make function calls between components. Your "variants" would then be encapsulated functions that you would call out to conditionally. You can do this using If Action subsystems, example attached.
Using the interface editor, you can design your service interface and function calls:
In the example, the delegator calls the correct function depending on the logic you define and merges the outputs
The Estimation server has two functions that you can then populate with your logic. This model is an export-function style model which means it only runs when called (needs to be integrated with an external scheduler such as Stateflow) because of the root-level client/server ports but the other models can be rate based. You can also split up the Estimator into separate blocks with their own client-server ports, I chose to just use one for simplicity but depending on the complexity of your implementation, you may wish to model the choices as separate components. Alternatively, you can use subsystem reference in the estimation server to divide it out at the implementation layer instead.
Here are some additional resources:
If Action Subsystems
YouTube Livestream on Software Architecture modeling in System Composer
MathWorks Software Architecture Solutions Page
Josh

More Answers (1)

Swastik Sarkar
Swastik Sarkar on 28 Aug 2024
Hi @鑫鹏,
Variant components are used to indicate alternate designs for a component within an architecture. They are not suited for conditional execution of components. More details can be found in the documentation below:
To achieve conditional execution of components, consider creating a wrapper around the components by including them as "Enabled Subsystems" in Simulink. This method allows for control over the execution of components based on specific conditions.
Further information about "Enabled Subsystems" and their implementation can be found in the documentation below:
Hope this information helps.

Categories

Find more on System Composer in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!