Dynamic Simulation Tutorial with DWSIM and Python, Part 3: Adding a PID Controller
|This tutorial requires advanced or above average Python programming skills.|
|You'll need at least DWSIM v5.1 on Windows, Linux or macOS to follow/reproduce the tasks within this tutorial.|
We will add a PID Controller to control the outlet hot water temperature (PV) at 50 C (SP) by changing the cooling water flow using the valve opening as the manipulated variable (MV).
The PID class
Our PID code uses a modified version of the Python PID Class which can be found here: <a rel="nofollow" class="external free" href="https://github.com/ivmech/ivPID">https://github.com/ivmech/ivPID</a>
Create a new script and name it 'PID'. Add the following content to it:
Adding a PID
For illustration purposes, add a new Adjust object to the flowsheet and set its manipulated object to 'FV-01' and controlled object to 'cooled_water'. The actual controlling won't be done by this object calculation routine, but rather by our PID script.
Running the Closed-Loop Dynamic Model
Create a new script and name it 'RunDynamicProcess_ClosedLoop', with the following content:
Notice that our PID variables (SP, PV and MV) are normalized (SP = 1.0).
We will run our PID controller initially with Kp = 0.5, Ki = 0.01 and Kd = 0.1.
Modify the 'GenerateCharts' script to include the following commands before the last one:
Run the closed loop model. You should get the following after a successfull run:
Download the simulation file with what has been done so far: dynamic_part3.dwxmz