Skip to Content
Real World Instrumentation with Python
book

Real World Instrumentation with Python

by John M. Hughes
November 2010
Intermediate to advanced
624 pages
18h 14m
English
O'Reilly Media, Inc.
Content preview from Real World Instrumentation with Python

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python Tools for Scientists

Python Tools for Scientists

Lee Vaughan
Python Workout

Python Workout

Reuven M. Lerner

Publisher Resources

ISBN: 9780596809591Errata Page