This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PID Understanding problem HELP!



I have the PID Code like this

float updatePID(float target_Angle, float current_Angle, struct PIDdata *PIDparameters) 
{


float error = target_Angle - current_Angle;


//
//	Calculate the Integral Term.
//
PIDparameters->integratedError += PIDparameters->Ki * error * deltaPIDTime;
PIDparameters->integratedError = constrain(PIDparameters->integratedError, 	PIDparameters->windupGuard, -PIDparameters->windupGuard);
	
//
//	Derivative Term Calculation
//
float dTerm = PIDparameters->Kd * (current_Angle - PIDparameters->last_Angle) * inv_deltaPIDTime; 
	
//
//	Update last angle
//
PIDparameters->last_Angle = current_Angle;
	
		
return (PIDparameters->Kp * error + PIDparameters->integratedError + dTerm);
		
}

I dont understand that the integral term is accumulated over time. Supposed that i use pid to control the level of the quadcopter. if the quadcopter deviates from the desired position and the comes back to the desired position. At that time the integral term has accumulated some error. So i think that although the quadcopter has come back to the desired position PID Output will not be zero for the code above.

Is the way i think is right?

  • "Is the way i think right?"  Yes and no.

    The integral term alone will accumulate and if used alone will generally not lead to a stable system.  the I term almost always must be used with a P term.  

    I very strongly recommend the following article...

    http://www.ece.ucdavis.edu/~spencer/195/datasheets/PID-Without-a-PhD.pdf

    I first saw this in embedded systems design magazine (now embedded.com) article many years ago.  

  • If I term has already accumulated, and the quadcopter comes back to balance, i think the I term will make the PID Out different from zero

  • Did you read the article?

    Tuning is critical.  Gains are critical.  If not done right, then you will not have a stable system.  I think the understanding you seek is pretty textbook.  It has been a long time since I have done PID control.  

    Do some more research and searching.  Learn and study for yourself.  Experiment if you need to.  In the end you will know and understand more than if I or someone else were to just give you answers.

  • INTEGRIS Dexter said:
    Do some more research and searching.  Learn and study for yourself.  Experiment if you need to

    To Dexter's well formed points above - might you be trying too soon - for too much?  Where is KISS?

    A quad copter - when just learning PID & MCU basics - is that a correct path?  Is it even a thought path?  (is it happy?)

    Is there a simpler means by which you can experiment with PID?  And - in many cases - simpler PI (w/out the D) proves more than adequate.  (that D term requires very special handling - over-challenges most beginners)

    Here's a simple way our small group teaches PI (first) and later full PID control.  Acquire a small, low (safe) voltage brushed motor.  Employ PWM to drive the "low-side" of the motor thru an adequate power stage.  (may be FETs or an integrated power driver)  Use the MCU's simple Timer configured as PWM to drive the low-side FET(s).  Motor's + side tied to motor supply +.

    As the PWM duty cycle increases - the brushed motor will receive increased energy - and if the motor voltage and load remain constant - the motor's speed will increase.  But - should you raise the motor's voltage - without a feedback control circuit and proper PI control "loop" to vary the PWM - the motor's speed will increase.  This is called, "Open Loop" operation.  PI and PID are "usual" means to add control to such a system - and to make the motor's speed relatively immune to changes in motor voltage and motor load!  This is, "Closed Loop" and is extremely desirable. 

    As the (quite good) article earlier referenced notes - you start by developing some means to monitor the motor's speed.  You then compare the motor's speed against your, "Commanded or Target Speed."  The difference between these two is measured - and used by the PI/PID control loop - to greatly regulate most any system or process.  (motor speed in this case.)

    Your fundamental flaw (I believe) is attempting, "too much - too soon."  Some here (sometimes) note that the, "devil is in the details."  "Happy smile" describes a pleasant outcome - but avoids any of the methods employed in its achievement. 

    KISS - in stark contrast - seeks systematic (usually small) tightly focused, building block steps - which gradually bring you closer & closer - to your end goal.  These smaller, incremental steps are far easier to devise, then employ & measure, and thus judge and, "course correct."  This resulting series of "pleasant glances" is more likely to build into your desired "smile."  Suspect you'll do better with more focus upon the "process" [KISS] - less upon the result.  [a "happy smile"]