Implementing Control Systems in Python

We’ll start off by creating a simple linear closed-loop proportional control function. It may not look like much, but it has everything a basic proportional control requires. Next up is a nonlinear control in the form of a basic bang-bang controller. It has enough functionality to find immediate application as the controller for an air conditioning system, but it doesn’t handle heating. Adding the ability to control heating as well as cooling is straightforward, though, and shouldn’t present any significant challenge (it’s just the inverse of cooling).

Finally, we’ll look at a simple implementation of a basic linear PID controller, and find out how to translate the PID equation in Equation 9-4 into a discrete-time form that can be easily coded in Python.

In Chapter 10 I’ll present a simulator that can be used to obtain realistic data and generate response plots from the output of this function.

Linear Proportional Controller

A proportional controller is straightforward. Recall the basic equation we saw at the start of this chapter:

u(t) = Kpe(t) + P

We can expand this a bit to explicitly incorporate the summing node with its r and b inputs, as shown in Equation 9-7.

Equation 9-7. 

u(t) = Kp(r(t) – b(t)) + P

Here is the code to implement Equation 9-7:

""" Simple proportional control. Obtains input data for the reference and the feedback, and generates a proportional control value using the equation: u = Kp(r – b) + P b is obtained from c * Kb, where c ...

Get Real World Instrumentation with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.