PID Controller Design and Simulation using OpenModelica

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:

tf of systemIf we wanted to design a controller for this systems, then the first step could be to get the closed loop step response.

Closed Loop Response with no Controller

To do this in OpenModelica we would build the system shown in figure 1 below.

 System for Closed Loop Step ResponseFigure 1: System for Closed Loop Step Response

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.

openModelica menu breakdownsFigure 2: Menu Breakdowns Showing Component Locations

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.

plantParameterWindowFigure 3: Plant Parameter Window

We now setup the simulation to have an end time of 0.05 seconds, then run it.

simulationSetupFigure 4: Simulation Setup

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.

closedLoopStepResponseFigure 5: Closed Loop Response of the System

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.

system with controller to designFigure 6: System with Controller

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:

controlledSystemStepResponseFigure 7: Step Response of System with Tuned Controller

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 🙂