FMI-based Co-Simulation
with AutoFOCUS3, OpenModelica and Overture
The following example illustrates the co-simulation capabilities of AutoFOCUS 3 and shows how this feature can be leveraged for tool-interoperability.
To highlight the potential of the Functional Mock-up Interface (FMI) standard, the following example considers a controlled inverted pendulum.
On the one hand, both the pendulum's dynamics and the PID controller are modeled using OpenModelica - a tool dedicated to the development of continuous systems.
The input and environment models, on the other hand, have been developed in AutoFOCUS 3 and Overture respectively - both representing models with a discrete notion of time.
Setup
AutoFOCUS 3
Download the following AutoFOCUS 3 model: Input Model
Import the project: 'File → Open Model/Library Files(s)'
FMU Export
AutoFOCUS 3
Export the Input component as FMU: '[Right-click on component] → Export to FMU 2.0'
Set the component to be executed at a frequency of 100 Hz and store it in the root folder of your workspace.
Overture
Export the NoiseGenerator project as FMU: '[Right-click on project] → Overture FMU → Export Tool Wrapper FMU'
The FMU will be stored in './generated' within the project directory.
OpenModelica
Export the model as FMU: 'File → Export → FMU'
The location of the newly generated FMU will be displayed in the console.
FMI-based Co-Simulation
OpenModelica
Create a new simulation: 'OMSimulator → New OMSimulator Model'
Make sure to set its type to Weakly Coupled (usually selected by default).
Open the top-most component called Root by default and marked with a WC-icon (which stands for Weakly Coupled): Double-click on the component within the Libraries Browser.
Add the tree FMUs previously exported like so: 'OMSimulator → Add SubModel'
Connect the output of the input model (exported from AutoFOCUS 3) to the setpoint input of the system model (exported from OpenModelica).
Connect the output of the environment model (exported from Overture) to the disturbance input of the system model (exported from OpenModelica).
Instantiate the model by setting the Fixed Step Size to 0.01 and the Stop Time to 5: 'OMSimulator → Instantiate Model'
Simulate the model: 'OMSimulator → Simulate'
Switch to the 'Plotting' view (should happen automatically).
Visualize the results by selecting the variables of interest in the Variables Browser:
'[Name of the OMSimulator Model] → [Name of the root component] → System → angle'
'[Name of the OMSimulator Model] → [Name of the root component] → System → setpoint'
'[Name of the OMSimulator Model] → [Name of the root component] → System → acceleration'
'[Name of the OMSimulator Model] → [Name of the root component] → System → disturbance'
With everything working correctly the following plots should be visible: