22 April 2023
Suppose a system with one tank that has one inlet and outlet. Assume the outlet flow is proportional to the height. The ordinary differential described by Equation 1 characterizes the dynamics of the tank.
Suppose the height is controlled with a PI controller like the one described by Equation 2.
Rewrite the state space model to incorporate the PI controller.
Error is described by Equation 5.
Substitute the error and factor.
Create matrices.
To simulate this sytem in python, install the control systems library. Import ss which is just like the MATLAB ss function which creates an LTI system from A, B, C, and D matrices. Suppose everything is 1 except integral gain which is 0.5.
Define the A, B, C, and D matrices using numpy arrays.
Define the LTI system with ss.
Simulate a step response with step_response.
Plot the response with matplotlib to see what it looks like.
Figure 1. Step response in the tank system.
Note that the response in Figure 1 is a response to a step input in both the set point and disturbance. To simulate a response to just one of the inputs, use the function input_output_response from control.
Use numpy to define the time and input arrays. These follow the same convetion as lsim in MATLAB. In the following code, a step change in set point is simulated.
Now simulate with input_output_response.
Notice that because one of the inputs is zero, the response array only contains the response for the output variable. In this case, that is the height. Observe that, in Figure 2, the height goes up by one.
Figure 2. Change in set point of the tank system.
Repeat the above steps but for a disturbance change.
In Figure 3, the height goes up but returns to zero as expected.
Figure 3. Disturbance response in the tank system.
View the code for this example. Read the documentation for python control. There are numerous useful functions in this library for control systems analysis. Additionally, there are implentations of MATLAB-like interfaces.