> From: Frans Gunawan > I don't understand with this equation(from AN532): > PID equation: > > Eu = Eu + u0; > > out = (kp*u0) + > (ki*Eu) + > (kd*(u0-u1)); > > the integral error is Eu = Eu + u0, means sum of error, > what if the Eu is overflow and back to zero? is it OK? > it means there is no integral(ki*Eu = 0). No it's not OK. For a start, you should be using signed arithmetic - this means an overflow will go to the maximum negative value, not zero. This could cause the motor (or whatever) to start moving in the wrong direction! The proper way to do it is to ensure that the integral term never overflows in either direction. If the addition of the error signal would cause over- or underflow, then limit the integral term to the maximum or minimum possible value respectively. The same applies to all other arithmetic operations. Make sure that overflow cannot happen, or, if it can, then make sure the result is limited correctly. One is reminded of the story (perhaps apocryphal) of the temperature controller which, when a fire broke out, overflowed its 255 degree C sensor limit and thought that the temperature was only zero. It then turned all the heaters up full-bore, assisting the rapidly spreading fire. Even if there is no possibility of the error integral overflowing, it is still a good idea to limit its absolute value. This prevents 'integrator windup'. Example: I once implemented an oven temperature controller. This included an integral term implemented as a large capacitor. When the oven was first turned on, it took a long time for the mass of the oven to heat up. This caused the error integrator to accumulate a very large error by the time the correct temperature was reached. This caused a large overshoot in temperature. To correct this, it was necessary to add a pair of back-to-back diodes across the capacitor, which effectively limited the integrated error term to a reasonable value. PID control is a bit of an experimental art if you don't know exactly how your 'plant' (the system you are trying to control) behaves. When determining the constants kp, ki and kd, one way of empirically determining their values is to start with ki=kd=0, and kp set to a small value. The system will probably oscillate, with damping of the oscillation determined by friction etc. in the plant. Increasing kp will make the plant oscillate at a proportionally higher frequency. kp should be set to the largest value consistent with the available actuator power, and the desired acceleration level. At this point, add a bit of kd, which should assist the plant's natural damping. When the plant is nearly critically damped i.e. just not quite overshooting the mark, start adding ki so that residual error reduces to zero. If oscillation reappears, compensate with additional kd. There is always a tradeoff to be made between response speed and instability (oscillation). Regards, SJH Canbera, Australia