Go Down

Topic: Arduino PID Library (Read 108276 times) previous topic - next topic


Sounds brill! Look forward to using it.



Oct 25, 2009, 12:50 am Last Edit: Oct 25, 2009, 03:13 am by pacofvf Reason: 1
Before everything... It's just an advice,I don't want to look pretentious... :-[
I don't understand why you have problems making your PID faster....maybe because I've never used it :P . Sometimes the measurement is not at the same frequency than the Computing frequency, maybe you can't achieve the maximum speed because you are not using timer interrupts, and almost every PID ready-to-use software made by big companies uses timer interrupts. When you use timer interrupts the only limit is the clock speed and the timer's pre-escalator, ahh one last thing, the common acronyms are:
Set Point, (SP)
input: PV (Present Value)
output: MV(manipulated variable)
dt : (delta t) that's what you call calc period
Ki,Ti (I prefer Ki than Ti, where Ki=Kp/Ti)
Kd,Td (same with Kd, Kd=Kp*Td)

EDIT: PV: process variable


input: PV (Present Value)

I was taught that PV = Process Variable


Coding Badly

I was taught that PV = Process Variable



Of course you are right, PV is process variable,  there is a present value, but that is not it.  ;) LOL


I don't understand why you have problems making your PID faster

the issue isn't with when the computation occurs, it's with how long the computation takes when it's excecuted.  the computation fires at whatever interval the user desires (set by the SetSampleTime function)  the interrupt idea is interesting.  I'll have to look into that.

what I was talking about when I said "faster" was the computation itself.  the fewer processor cycles it takes to perform its calculation, the more time the arduino has to do other things.  and, just as a point of pride, I want the pid to be as efficient as possible.

as far as abbreviations, some are certainly more common than others, but they do vary from manufacturer to manufacturer.  off the top of my head:
Process Variable: PV, ME
SetPoint: SP, SV
Controller Output: CO,  CV, OUT, OT, OP.

dt is commonly used.  I settled on SampleTime (which is also commonly used) because I felt it was easier to understand.  

at any rate, give the library a shot!  I'd love to hear any more suggestions you might have.



I've just looked at the source, and it looks very well, I can see that you have done something to prevent windup, I also preffer the Ideal form of the PID algorithm, everything is done efficiently (computing time-speaking), maybe millis() is taking too much, I don't see where else the code could be made more efficient, I will try to do it with interrupts and I will let you know if it works better, also I'm going to implement a kalman filter, so maybe that will be my first contribution to the arduino project, for those who don't know what I'm talking about, a kalman filter must be used with accelerometers and many other sensors..


Thanx for an splendid lib, just the interrupt part missing for me to be 100% satisfied  8-) and maybe a Tracking value/Tracking active.

By the way PV is often referred as "Process Value" in engineering terms  ::)


oh! and i wanna ad one more thing to my wish list, Master/Slave config for cascade regulation. :D


There is no problem to run it in master slave configuration. Just run it twice with different inputs. We have used this successfully.


ok nice. I had some ideas that master needed feedback from slave.


Last year I have trained a student during 3 month in order to make a complex regulation, for this purpose we have developed and implemented the Broïda method that allows to identity PID coefficient by measuring the response of the open loop system to square by measuring an amplitude and two time (at 0.28*deltaA* and 0.40*deltaA) it gives parameters depending of the kind of PID you want (with or without overshoot). This method seems to work up to the 6th order.
What do you think about coding this into the arduino platform ?
I think it can works on a lot of cases !


I am having trouble getting this PID to work with my application.

I am doing a research project where I am required to have a trough fill with water to sub - millimeter accuracy. I have determined the best way for me to do this is to use a laser pointing horizontally across the trough with a photodiode on the other side that the laser will be pointed at. When the water level becomes high enough the light beam will be broken and the voltage reading from the photodiode will drop.
I have a test circuit built (just the photodiode and a LED). With no obstruction between the LED and photodiode I get .013V from the photodiode, and that drops to .03V when you put an obstruction between the two.

So I edited the example code to this
Code: [Select]

#include <PID_Beta6.h>

* PID Simple Example
* Reading analog input 0 to control analog PWM output 3

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,5,1,1);

void setup()
 //initialize the variables we're linked to
 Input = analogRead(0);
 Setpoint = 100;

 //turn the PID on

void loop()
 Input = analogRead(0);
 Serial.print("Output value: ");

I have this hooked up to an oscilloscope and I can see that the voltage will pulse, but I only see that happen right when I turn the Arduino on.
I am brand new to PID and Arduino, I spent all day reading with no luck.
Can anyone give me some advice on how to get this to work? I can't get the right tuning parameters or even know what they mean entirely or approximate values to use.
I am also unsure about the setpoint... does everyone else just randomly enter in values for these until they get the appropriate results or is there some method of finding the tuning parameters I need?


Jun 10, 2010, 07:59 pm Last Edit: Jun 10, 2010, 08:01 pm by pwillard Reason: 1

Setting PID values correctly is truly an art/science that does seem to get the experts some nice paychecks...

Your application seems more like an ON OFF design from what I can tell... the PID library works best if the feedback about what you are trying to measure/control is changing as it get close to set point.  Like a temperature reading, for example.

A PID tries to adjust it's output based on the input error...   but in your case... it sort of like playing 1...2...3... RED LIGHT!  if you have ever played that game... you might know what I mean...

You have an action with inertia... water feed.... and you want it to stop at an instant in time with little warning...  which sounds pretty hard to do to me...

I'm not claiming to be a PID expert though... maybe I can be corrected by one of the guru's here...


You are wanting to fill with very much accuracy - does the tank drain any during this time?

You might consider measuring the level, then as the level approaches setpoint, start slowing the fill, until as setpoint is reached, the fill rate is at zero.  This method would use a PID controller.

BTW, this deserves a thread of it's own.

Good luck and have fun.

Ken H>

Go Up