In addition to these other libraries as per your modeling requirements.
Short description of Demo: - The electrical vehicle is gaining popularity and it is seeing as a technology of the future. Battery pack design is playing very important from the safety and performance point of view. Generally, a separate Battery management control unit is used to manage the performance of the battery. MIL, SIL, HIL, etc method is generally used to verify the algorithm and logic of the Battery management control unit. Simulink is generally used as a graphical language for coding of most of the electronic control units. In this demo, a simplified BMC for battery cell balancing control algorithm is developed in Simulink; the model of the battery pack is implemented in Simcenter AMESim. By coupling between AMESim and Simulink, one can verify the effectiveness of code in the design stage. AMESim can be coupled with Simulink in several ways. In this demo, we will see “How AMESim can be coupled with Simulink to verify your control unit logic”. AMESim model is giving voltages of various cells as an output. This output is sent to the Simulink model. At every time step Simulink processes this output and give the optimum command to each cell so that cell balancing can be achieved.
Before moving ahead, please remember the limitation of MATLAB Simulink FMU: -
Simulink doesn’t comply with the so-called “structured variable naming” of FMUs (also known as “dotted convention” or “Modelica-like convention”). Apparently, Simulink mistakenly treats IO names as bus components. These issues do not arise with 3rd party open-source toolboxes like DS’ FMI Kit for Simulink. Hence, you may face the issue while importing FMU.
Considering the above facts, ‘ame2sl’ is nearly providing similar options with the AMESim. These options will provide you more flexibility with solver selection and a simple process to carry out co-simulation. For more details about these options, please visit the AMESim help file.
We will use the existing demo from Simulink. You can download this demo from the help file. This is also available in the file attached to this article.
Step 01 – Replace the Interface with FMU interface
Right-click on “interface block” and click on the “Edit Interface”. This should open below the window. Change “AME2SL”interface to “FMI” interface
Connect all the ports and complete the model.
If you wanted to change some of the parameters directly from the Simulink, then you can add them in the “watch parameter”. Similarly, you can also add the “Watch variable”. In this way, you can directly change these parameters from Simulink without opening AMESim
Step 02 – Create Model exchange FMU
Compile your model.
Go to Interface >> FMU Export Assistant
FMU type and version – Select the Model exchange 2.0option from here.
Visibility level: Exposed elements – select the required option depending on “how many parameters and variables do you want to expose?
Tick mark required option
Select the output directory, where you wanted to save the .fmu file
Click on the next.
Select the targeted compiler. Please note, you should use the same compiler in Simulink.
Click on Generate.
It should generate the .fmu file in the targeted directory.
Step 03 – Import Model exchange FMU in the Simulink.
Open existing .slx file and delete AME2SL block. This block needs to be replaced with FMU.
Add FMU submodel to the Simulink sketch and double click on the FMU.
It should open the below window. Browse the .fmu file here. It will load the model exchange fmu.
It will display only “1 input” and “1 output” ports instead of your expectation of “10 inputs” and “10 outputs” ports. Here you will have to create a bus in order to overcome this issue.
Run below command to create a bus
>> fmudialog.createBusType('ImportAMEModelexchangeFMU/FMU') Bus Object for Input Port 1: expseu__1 Bus Object for Output Port 1: expseu__2
Connect all signals line properly. Your model is ready for co-simulation.
Step 04 – Run the model
Since it is a Model exchange FMU example, hence, AMESim FMU, as well as the Simulink model, will use Simulink Solver. Double click on FMU. It will open the “Block parameters” window. Since it is a Model exchange FMU, hence you will not see AMESim Solverparameters here.
You can only see the parameters, which you added in the “Watch parameter” list. This would be the difference between cosimulation and Model exchange FMU.
You can directly change these parameters from here without opening AMESim.
Set the proper solver setting for the Simulink model.
Run the model. You can see the results now
Some important instruction
We have tested this FMU in MATLAB 2019b version, hence this instruction may applicable till 2019b or higher version (If MATLAB will not improve on this). If MATLAB will do some improvement in the future version, then, you may not see this issue.
Simulink doesn’t comply with the so-called “structured variable naming” of FMUs (also known as “dotted convention” or “Modelica-like convention”). Apparently, Simulink mistakenly treats IO names as bus components. We would suggest to contact MathWorks directly if it is really needed. These issues do not arise with 3rd party open-source toolboxes like DS’ FMI Kit for Simulink. There are two things user can do to mitigate this issue:
Use Simulink bus extractor components to retrieve the individual signals
Use the two MATLAB commands below: set_param('MyModel/FMU','FMUInputMapping','Flat')
set_param('MyModel/FMU','FMUOutputMapping','Flat') “MyModel” is the name of the Simulink model, “FMU” is the name of the FMU block. Please adapt appropriately. These commands will force the FMU block to switch to the flat naming convention.
Conclusion
"Ame2sl" can provide better options compared to this option provided in this article.
Till 2019b, Simulink doesn’t comply with the so-called “structured variable naming” of FMUs. It will continue in the future versions, till MATLAB will not improve on this.
All process related to the FMU import and export is simple and more interactive in AMESim compare to Simulink.
CLICK HERE to download the Model exchange FMU demo files CLICK HERE to download the cosimulation FMU demo files
If you are interested to know the other method of cosimulation with Simulink, then please visit below VIDEO articles.
CLICK HERE to know about “Cosimulation between Simulink & AMESim (AME2SLCosim) using MinGW-w64 (gcc 64 bit) compiler” CLICK HERE to know about “Model exchange (AME2SL) between MATLAB Simulink and AMESim with MinGw 64bit compiler” CLICK HERE to know about “Import MATLAB Simulink Model to AMESim (SL2AMECOSIM) using MinGW 64-bit compiler”. CLICK HERE to know about “Export the AMESim model Blackbox to MATLAB Simulink using GNU MinGW gcc x64 bit compiler. CLICK HERE to know about “FMU/FMI - Export a cosimulation FMU from the AMESim & Import it in the Simulink” CLICK HERE to know about “Import MATLAB Simulink FMU to AMESim”
If you still need support or clarification, thenclick hereto raise the case on the support portal.