Category Archives: Modeling and Simulation

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 🙂

Modelica Two Tank System

This simulation uses the Modelica modeling language to model two identical tanks connect together by a pipe. The platform used is OpenModelica and the components are from an ‘under development’  library that aims to be a simpler to use alternative to the modelica fluid library.

The tanks are 25 m high and have a radius of 2 m, the pipe is 5 m long and has a radius of 2.5 cm. The OpenModelica diagram of this system is sown in figure 1 below.

TwoTankSystemFigure 1: Two Tank System in OpenModelica Continue reading

Python – Solving Second Order Differential Equations

Dwight Reid

This presentation outlines solving second order differential equations (ode) with python. The solution is obtained numerically using the python SciPy ode engine (integrate module), the solution is therefore not in analytic form but the output is as if the analytic function was computed for each time step. The method is generally applicable to solving a higher order differential equation with python as well.
We will use a series RLC circuit as our ordinary differential equations example.
Continue reading