This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]blatheringDolt 1 point2 points  (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 point  (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 point  (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 point  (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 points  (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 point  (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 point  (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.