The Modelica language is intended for the modelling and simulation of complex multi-domain systems but can also be used for the classical controller design and simulation for control systems. This tutorial will use openModelica to demonstrate this by using transfer function models, step responses and PID controllers found in the standard Modelica library.
Example System for Our Controller Design
Consider the system represented by the following transfer function:
Closed Loop Response with no Controller
To do this in OpenModelica we would build the system shown in figure 1 below.
The components we need would be the transfer function block (for the plant), the feedback summation and the step response source. The locations of these are shown in the menu breakdowns shown in figure 2 below.
Drag and drop the points to make the connections then double click the components to change the parameters. In this case we change the parameters of the transfer function to match the plant and leave everything else at default. You can right click the transfer function and change its attributes to make it say “plant” instead of “tranferfuntion1”.
The parameter window for the plant is shown in figure 3 below.
We now setup the simulation to have an end time of 0.05 seconds, then run it.
Now we go to the plotting window and the select the ‘y’ variable of our plant, which represents it’s output. This is the closed loop step response and is shown below.
Add a PID Controller
Now we can add the controller. This is a PID controller and can be added from the same menu as the transfer function. We insert the controller in the loop as shown in figure 6.
The PID controller is represented in the standard form and the parameters we will use are Kp = 0.309, Ti = (0.309/4.5) and Td = (0.0006/0.309), these were already determined from tuning. The step response of this new system is then:
With this basic setup you can experiment with different plants and different controller parameters and different control laws as you carry out your controller design.
Don’t forget to share with interested friends and colleagues. Happy coding 🙂