Observe Internal Variables of an FMU
Observers enable wireless access to internal variables of a Functional Mockup Unit (FMU) in Simulink®. Use the Observer Reference and Observer Port blocks to access data and signals, configured as an internal variable, inside an FMU.
Observe Internal Variables to Tune PID Controller Inside an FMU
In this system, the PID controller calculates the force that needs to be exerted on the mass to control its position. The Observer blocks allows you to tune the PID controller by providing wireless access to the control input and tracking errors that are configured as internal variables.
Import FMU With Internal Variables Into Simulink and Add Observer
Use the FMU Import block to import the FMU into Simulink. Input to the FMU is the reference signal specifying the desired position of the mass. Output from the FMU is the actual position of the mass. The PID coefficients and input saturations are tunable parameters of the FMU. The system inside the FMU consists of a cascaded PID and a mass-spring-damper system. The reference signal specifies the desired position of the mass. The PID controller provides the force as input to the mass-spring-damper system to control the position of the mass. Tracking error and control inputs are configured as internal variables of the system.
Add an Observer block to the main model that contains the FMU. The Observer block references an Observer model that contains the observer ports that access signals in the main model. Create the Observer model and specify its name in the Observer Model name of the Observer Block parameter dialog box. Upo can open the observer model by double-clicking the Observer block.
Add Observer Port blocks in the Observer model. Double-click on the observer ports to open the Manage Observer Block dialog box. The internal variables of the FMU are listed under the FMU block.
Connect the observer ports to internal variables of the FMU. For more information on connecting observer ports to observable entities, see Access Model Data Wirelessly by Using Observers.
The outputs of the observer ports can be used to wirelessly access the internal variables of the FMU along with other signals in the main model.
Compare Observer Output and Actual Signals
Open the original model that was used to create the FMU. Compare the tracking error and control inputs with their corresponding observed internal variables for identical controller parameters and reference signals.
Open the scope blocks to check if the tracking errors are identical for the actual and observed signals.
You can now use the observed signals to tune the PID controller inside the FMU in the main model.