Search code examples
matlabfor-loopsimulinkrunnableautosar

Multiple runnables with equal functionality but different port names


I've a basic question regarding autosar with multiple runnables that are basically the same except for different output/input names.

Currently the Simulink model is designed for one tank-module. This single module has inputs and outputs named *_Md0. E.g Filling_level_Md0, outflow/inflow_rate_Md0, valve_open_Md0 ... Though also some inputs/outputs/constants are not module-specific. E.g: tank-volume, real time clock, ...

The goal is to add an "arbitrary" number of tanks.

          -------                   -------               -------
Inputs ->|Module1|-> Outputs     ->|Module2|->   ...   ->|ModuleN|->
          -------                   -------               -------

Obviously it is very tedious to just multiply every tank-module and rename the inputs/outputs that are needed individually per module. Because it is necessary to copy every runnable, fix the libraryies and the arxml file, ...

So the question is if there is a better solution to have multiple runnables that are more or less the same? Is there some kind of for loop available in Simulink?


Solution

  • You have two options.

    1. A single-instance software component having ports containing arrays as port elements and then the respective data below. The number of tanks would be e.g. a system constant as used as the length of all arrays. The good with that is that you might get more efficient code e.g. due to vectorization in the compiler. Also having the arrays might make it easier or efficient regarding communication, diagnostic and measurement interfaces.
    2. A multi-instance software component having "normal" ports and the model in there as you have now. As you wrote that you have different parameters for each tank, you will need per-instance calibration parameters. Your software composition around would then instantiate the multi-instance tank component as often as you have tanks. The benefit here is that it is easier to test and your implementation is fully independent of the number of tanks. Also you might distribute the cpu load better to reduce your peak CPU load.