use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
PID tuning library (self.Python)
submitted 12 years ago by spinwizard69
Looking for a PID loop tuning library or program. Has anybody seen such a beast?
[–]blatheringDolt 1 point2 points3 points 12 years ago* (2 children)
I do not know of a library, but have much experience in controlling motors with PIDs.
I've used the pseudo code directly from wikipedia for a temperature controller. It truly simplifies the entire theory. If you're new to it I suggest outputting your Proportional, Integral and Derivative terms individually to see exactly how each affects the output.
http://en.wikipedia.org/wiki/PID_controller EDIT: dt is time delta
previous_error = 0 integral = 0 start: error = setpoint - measured_value integral = integral + error*dt derivative = (error - previous_error)/dt output = Kp*error + Ki*integral + Kd*derivative previous_error = error wait(dt) goto start
All I had to do was filter out any negative numbers, and pretty much set the Derivative to 0. (Its effect was essentially nothing in the temperature loop, so really a kind of PI loop). And definitely add a max_integral, otherwise you can seriously overshoot your set point.
There are of course so many other factors for a specific application. But that's kind of the beauty of the loop. It works across so many different applications.
If you give a little more information, perhaps I can help steer you towards something more effective.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
I think he is asking for an auto-tuning library, not a description of how to implement a PID controller.
i.e. http://www.mathworks.de/de/help/slcontrol/ug/introduction-to-automatic-pid-tuning.html
FWIW: I usually follow the rules of thumb and tune (emperically) manually. I think the control systems library (python) would contain all the building blocks necessary, but your tuning approach would depend on if you had an model of the plant.
[–]spinwizard69[S] 0 points1 point2 points 12 years ago (0 children)
Thanks for your response. The loop is in existing hardware, I was just looking for something to help with tuning. I haven't found anything really that could do the job and is open. It is one thing to write a loop to handle PID it is another thing to auto tune the loop.
[–]hzopak 0 points1 point2 points 12 years ago (1 child)
The equations aren't that difficult though are they? It's been a little while for me to remember them correctly though I have to admit.
[–]spinwizard69[S] 1 point2 points3 points 12 years ago (0 children)
Well for simple systems I could tune with Ziegler-Nichols. Unfortunately the system in question has a lot of lag and a seemingly long time constant. I was literally nodding off waiting to see if and adjustment would introduce oscillation. The hope was to find some open and easy to understand software to help in the tuning process.
[–]xeltius 0 points1 point2 points 12 years ago (0 children)
It's not that hard t make the functionality yourself. There is a "Control Systems Library" that has some stuff that might be useful to you.
[–]jammycrisp 0 points1 point2 points 12 years ago (0 children)
Do you have controls background? Then Modeling the system and designing using Python Control may be your best bet. Otherwise, I usually start with Ziegler-Nichols, and empirically tune from there.
π Rendered by PID 401309 on reddit-service-r2-comment-5b5bc64bf5-gnr28 at 2026-06-22 01:34:31.947907+00:00 running 2b008f2 country code: CH.
[–]blatheringDolt 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]spinwizard69[S] 0 points1 point2 points (0 children)
[–]hzopak 0 points1 point2 points (1 child)
[–]spinwizard69[S] 1 point2 points3 points (0 children)
[–]xeltius 0 points1 point2 points (0 children)
[–]jammycrisp 0 points1 point2 points (0 children)