CENG 4480 Lecture 06: PID Control Bei Yu CENG4480: feedback control V5a 1
CENG4480Lecture06:PIDControl
BeiYu
CENG4480: feedback control V5a 1
Objectives
1) StudyDCmotors
2) Studyopen-loopandclosed-loop control
3) Controlmethods– I)Proportional feedbackcontrol
– II)PID(proportional-integral-derivative) control
CENG4480: feedback control V5a 2
1)DCmotors
Forrobots
CENG4480: feedback control V5a 3
Motors
• DCmotors:Directcurrentmotor,easytocontrolanduse.Formakingwheeledrobots
• Servomotorsformakingrobotlegshttp://www.lynxmotion.com/
CENG4480: feedback control V5a 4
SmallDirectCurrentD.C.motors
• Speed(~1200-2000rpm).• Operatesona3~5Volt,Canusegearbox(e.g.ratio58:1)toincreasetorque
• UseH-bridgecircuittoboostupcurrentfromtheTLLleveltomotordrivinglevel.
CENG4480: feedback control V5a 5
������15351 PRO����� ,picture from
http://item.taobao.com/item.htm?id=1606576457&tracelog=newcardfavirate
Motorcontrolchip
• H-bridgeChips
• L293D:H-bridgecircuit,up2A
• LDIR:leftmotordirection;RDIR:rightmotordirection
• LEN:leftmotorenable;REN:rightmotorenable
CENG4480: feedback control V5a 6
LEN
LDIR
REN
RDIR
2 (1A)1Y(3)
1(EN1/2)
7(2A) (2Y)6
10(3A)(3Y)11
9(EN3/4)
15(4A)(4Y)14
Left-motor
Right-motor
2)open-loopandclosed-loopcontrol
FeedbackcontrolPIDtheoryandimplementation
CENG4480: feedback control V5a 7
Open-loopmotorcontrolanditsproblems
• Changemotorsupplypowerchangespeed• Problem:Howmuchpowerisright?
– Ans:don’tknow,dependsoninternal/externalfrictionsofindividualmotors.
• Problem:Howtomaketherobotmovestraight?• Howtocontrolpower(Ton)byISR&anMCU?
– Solution:Usefeedbackcontroltoreadactualwheel:– Slower,increasepower(+Ton)– Faster,reducepower(- Ton)
CENG4480: feedback control V5a 8
PWMSignal• PulseWidthModulation• Analogresultswithdigitalmeans• asquaresignalswitchedbetweenonandoff• changingtheportionthesignalon
CENG4480: feedback control V5a 9
Exercise
• Whenusingtheopen-loop controlmethodwithaconstantPWMsignalforbothwheels,explainwhytherobotwouldslowdownwhenclimbinguphill.– Ans:Whenclimbinguphill,energyisusedtoactagainstgravity,hencetherobotisrunningslower.
CENG4480: feedback control V5a 10
Feedbackcontrol
• Therealsolutiontorealspeedcontrolisfeedbackcontrol
• Requirespeedencodertoreadbacktherealspeedofthewheelatrealtime.
CENG4480: feedback control V5a 11
Firstyouneedtohavespeedencoders
• Readwheelspeed.• Usephotointerrupter• Usereflectivedisktosavespace• Basedoninterrupts
CENG4480: feedback control V5a 12
Wheelencoder
CENG4480: feedback control V5a 13
Our motor and speed encoder
Each wheel rotation=88 on/off changes
IR receiver
IR light source
Darkenedpart blocks light
CENG4480: feedback control V5a 14
Newspeedencoder
•
CENG4480: feedback control V5a 15
Demomovie
������15351 PRO����� ,picture from
http://item.taobao.com/item.htm?id=1606576457&tracelog=newcardfavirate
3)Controlmethods
I)ProportionalfeedbackcontrolII)PID(proportional-integral-derivative)control
CENG4480: feedback control V5a 16
I)Proportionalclosed-loopfeedbackcontrolsystem
• Showtheleftmotorcontrolonly
CENG4480: feedback control V5a 17
Required speed=leftRPMset
leftRPM
+
-
leftErr Motor
Alter PWM for driver L293
leftPWM
if (leftErr >deadband)leftPWM increase by (Pgain * leftErr)
II)PID(proportional-integral-derivative)control
AmoreformalandprecisemethodUsedinmostmodernmachines
CENG4480: feedback control V5a 18
HistoryofPID
• By NicolasMinorskyin1922• observationsofa helmsman• steeredtheshipbasedon
– thecurrentcourseerror– pasterror– thecurrentrateofchange
CENG4480: feedback control V5a 19
Introduction• Controlforbetterperformance• UsePID,choosewhateverresponseyouwant
CENG4480: feedback control V5a 20
Good performanceCriteria depends on users and applications
Too much overshoot/undershoot, not stable
Response too slow
time
Motor speed (w)
required
ValuestoevaluateacontrolsystemExercise2:Describethetermsnthefollowing
diagrams•
CENG4480: feedback control V5a 21
Typicallyvalue=10%Depends on application
Rise time Settling time0 time
Target value
overshoot
Steady state error
undershoot
PIDControl
CENG4480: feedback control V5a 22
PIDControl
CENG4480: feedback control V5a 23
UseofPIDcontroltermsareintertwined
http://en.wikipedia.org/wiki/PID_controller
• Kp(Pgain):ProportionalGain - LargerKptypicallymeansfasterresponse sincethelargertheerror,thelargertheProportional termcompensation.Anexcessivelylargeproportionalgainwillleadtoprocess instabilityandoscillation.
• Ki(Igain):IntegralGain - LargerKiimpliessteadystateerrorsareeliminatedquicker.Thetrade-off islargerovershoot:anynegativeerrorintegratedduringtransientresponsemustbeintegratedawaybypositiveerrorbeforewereachsteadystate.
• Kd(Dgain):DerivativeGain - LargerKddecreasesovershoot,butslowsdowntransientresponse andmayleadtoinstabilityduetosignalnoiseamplificationinthedifferentiationoftheerror.
CENG4480: feedback control V5a 25
Effectsofincreasingparametershttp://en.wikipedia.org/wiki/PID_controller
•
Parameter Rise Time Overshoot Settling Time
Steady state error
Kp (Pgain) Decreasestep1
Increase Small Change
Decrease
Ki (Igain) Decrease Increase Increase Eliminatestep3
Kd (Dgain) Small Change
Decreasestep2
Decrease Small Change
CENG4480: feedback control V5a 26
Software
PIDrobotdemo.c(atcoursewebpage)
http://www.cse.cuhk.edu.hk/~khwong/www2/ceng2400/PIDRobotDemo093.c
CENG4480: feedback control V5a 27
controlmethod:PID(proportional-integral-derivative)control
•
CENG4480: feedback control V5a 28
Required speed=
leftRPMset
IR wheelSpeedencoder
LeftRPM
+
-
leftRPM
Motor
generates PWM for driver L293
leftPWM
integral control
Igain* leftErr dt
Proportional control
Pgain*leftErr
Derivative control
Dgain*[d(leftErr)/dt]
sumleftErr
leftPWM
PIDcontrolalgorithmusinginterrupt
CENG4480: feedback control V5a 29
IR receiver Speed Encodersensor
interruptstime
Main( ){Setup( );::}
_IRQ( )//1000Hz{:read wheel speedPID:}
1000 interrupts per second
Overview• //////////////main//////////////////////////////////////• Main()• {setup()• forward(Lstep,Rstep,Lspeed,Rspeed)…..• }• ////////////subroutine //////////////////////////////////////////• forward(Lstep,Rstep,Lspeed,Rspeed)• {lcount=0• if(lcount>=Lstep)• Stopleftmotor• …sameforrightmotor…• .}• //////////timertriggered,interruptserviceroutine,1000Hz///////• __irqexception//Interrupt()runningat1000HZ• {lcount++• readwheelspeeds• PIDcontroltoachieveL/Rspeed• ….sameforrightmotor….• }
CENG4480: feedback control V5a 30
_IRQ see next slide
Interrupt rate 1000Hz
Speedencoderinterfacing(showleftmotoronly)
• Blockdiagram
CENG4480: feedback control V5a 31
IR transmitter
IR receiver(speed encoder sensor)
GPIOParallel interface
/int0
CPU
1000Hz timer interrupt
ARM7-microcontrollerLPC2131
In our robot88 pattern changesin one rotation
Exercise3_irqinterruptprogrammingmethodforthemainPIDloop,usingacounter(intcount)
• __irq()exception//timer interrupt1000HZ,• {intcount++;//intcount• //increasesat1000times/sec• //readmotorspeed:• //updatethemotorspeedinevery1/4seconds• if(intcount==250)//happensatevery¼seconds• {• readwheelspeed• ControlthePWMusingPID• intcount=0;• }• }• Question:If“if(intcount==250)“ischangedto“if(intcount==500)“• Whathappens? CENG4480: feedback control V5a 32
PID CORE
Theinterruptserviceroutineenablesthelooptorun4timesinasecond
•
CENG4480: feedback control V5a 33
Loop once in ¼ seconds
Speedcontrolinterruptcore_irq()part1:Findmotorspeed,leftRPM
• void__irqIRQ_Exception()• {ms++; intcount++;• //getthecurrentwheelsensorvalues• lcur=IO0PIN&LWheelSen;rcur=IO0PIN&RWheelSen;• if(lcur!=lold) { lcount++;lold=lcur;lefttimeval++;}• :• //updatemotor speedbyPIDfeedbackcontrolinevery¼Seconds• if(intcount==250) {//calculatethespeedofleftmotor inRPM• leftRPM=lefttimeval;• :
• intcount=0;• lefttimeval=0;• }• }
CENG4480: feedback control V5a 34
PID core : See following slides
Speed encodersensor
timeInterrupts 1000 Hz
lefttimeval
•lcount :steps of wheel •lcur : sensor read 1 or 0•lefttimeval: time lapsed since sensor last change of state•leftRPM : left wheel RPM
Part 2PID control
Part1Read Wheelspeeds
Part2:AlgorithmforPIDcore
• Forevery¼seconds– Finderror=(desired value- measuredvalue)– {If(error>deadband)
• {find– Error,– Accumulatederror(addupallpreviouserrors)– Derivativeerror(currenterror– previouserror)– PWM+=Kp*Error+– Ka*(Accumulatederror)+– Kd*Derivativeerror;
• }• Else
– Error<=dead_band,errortoosmalldonothing
CENG4480: feedback control V5a 35
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
Set_point
part2:PIDcore1) if(intcount==250){//forevery¼seconds2) //caculatethespeedofleftmotorinRPM3) leftRPM=lefttimeval;4) leftErr=leftRPMset- leftRPM; //caculatelefterror5) if((leftErr<DeadBand*(-1))||(leftErr>DeadBand))//seenextslide6) { //if|lefterror|>deadband7) leftP=Pgain*leftErr; //calculatePProportionalterm8) leftI=Igain*leftaccErr; //calculateIIntegralterm9) leftD=Dgain*(leftErr- leftlastErr); //calculateDDerivativeterm10) leftPWM+=(leftP+leftI+leftD);//update leftmotorPWMusingPID11) if(leftPWM>PWM_FREQ)12) leftPWM=PWM_FREQ;//preventoverrange(max.=PWM_FREQ)13) if(leftPWM<0)leftPWM=0;//(min.=0)14) leftaccErr+=leftErr; //accumulateerror15) leftlastErr=leftErr;//update leftlasterror16) :17) ://handlerightmotorsimilarly…….18) current_leftRPM=leftRPM*240/88;19) current_leftPWM=leftPWM;//20) lefttimeval=0;21) }
CENG4480: feedback control V5a 36
PID core
P=Proportional
I Integral
D Derivative
Pgain, Igain, Dgain are constants found by a trial and error method, here we havePgain = 8000; Igain = 6000; Dgain = 5000;
because each rotation has 88 counts, the ISR loop is in ¼ seconds, each minutes 60 seconds. see line 18
controlmethod:PID(proportional-integral-derivative)control
•
CENG4480: feedback control V5a 37
Required speed=
leftRPMset
IR wheelSpeedencoder
LeftRPM
+
-
leftRPM
Motor
generates PWM for driver L293
leftPWM
integral control
Igain* leftErr dt
Proportional control
Pgain*leftErr
Derivative control
Dgain*[d(leftErr)/dt]
sumleftErr
leftPWM
InsidethePIDcore,wewillstudytheselines
• 5)if((leftErr<DeadBand*(-1))||(leftErr>DeadBand))• :• :• 7)leftP=Pgain*leftErr;//calculatePProportionalterm• 8)leftI=Igain*leftaccErr;//calculateIIntegralterm• 9)leftD=Dgain*(leftErr- leftlastErr);//calculateDDerivativeterm• 10)leftPWM+=(leftP+leftI+leftD);//updatemotorPWMbyPID• :• :• 14)leftaccErr+=leftErr; //accumulateerror
CENG4480: feedback control V5a 38
Deadbandline5)if((leftErr<DeadBand*(-1))||(leftErr>DeadBand))
• Dead-band :ADead-band (sometimescalledaneutralzone)isanareaofasignal range orbandwherenoactionoccurs :
• onlyenablemotorwhenleftErr>asmallvalue(deadband,ie=1inourrobot)
• OtherwisemayoscillatewhenleftErrissmall
CENG4480: feedback control V5a 39
Dead-band
leftErr = leftRPM - leftRPMset; //calculate left errorif(leftErr>DeadBand ){ activate motor}
Exercise4:Discusswhatwillhappenifdead-bandischanged,say(a)0.5or(b)2.
Exampleofadeadband;donothing“if10-1<leftPRM<10+1
•
CENG4480: feedback control V5a 40
Typicallyvalue=10%Depends on application
Rise time Settling time0 time
overshoot
Steady state error
undershoot
Dead band+/- 1
Target speed=leftRPMset =10
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
When leftRMPset=10, the real RPM is RPM*240/88=27.3., because each rotation has 88 counts, the ISR loop is in ¼ seconds, each minutes 60 seconds.see line 18
Parametersforevaluatingacontrolsystem
•
CENG4480: feedback control V5a 41
Typicallyvalue=10%Depends on application
Rise time Settling time0 time
Target value
overshoot
Steady state error
undershoot
near steady stateSee next slide
(line7)EffectsofincreasingKp(P)http://en.wikipedia.org/wiki/PID_controller
•
Parameter Rise Time Overshoot Settling Time
Steady state error
(1) Kp (Pgain)
Decreasestep1
Increase Small Change
Decrease
Ki (Igain) Decrease Increase Increase Eliminatestep3
Kd (Dgain) Small Change
Decreasestep2
Decrease Small Change
CENG4480: feedback control V5a 42
Example:t0àt1,Theproportionaltermwhenthemeasurementisbelowthesetpoint(leftRPMset),
proportionalPtermis+ve•
CENG4480: feedback control V5a 43
leftP = Pgain * leftErr;leftP= 8000* (10-6)= 8000*4 is positiveThis term pushing up “leftPWM” (more energy delivered to the wheel).
leftErr=leftRPMset –leftPRM=10-6=4
Rise time0 time
overshoot
undershoot
t1 t3t2 t4
6
P is +ve
Target speed=leftRPMset =10
Usage of the P proportional termEach ¼ seconds a new left RPM (speed of wheel) is measured
leftErr=leftRPMset –leftPRM=30-28=2
leftP = Pgain * leftErr;leftP= 8000* (0-8)= 8000*2 is positiveThis term pushing up “leftPWM” (more energy delivered to the wheel).
P is +ve
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000; In our experiment leftPWM=276000 at the beginning and 192800 at steady state
8
(leftErr = leftRPMset-leftRPM )
Exercise5:Fillin?__:t0àt1,Theproportionaltermwhenthemeasurementisbelowthesetpoint(leftRPMset),
proportionalPtermis+ve•
CENG4480: feedback control V5a 44
leftP = Pgain * leftErr;leftP= 8000* (10-6)= 8000*4 is positiveThis term pushing up “leftPWM” (more energy delivered to the wheel).
leftErr=leftRPMset –leftPRM=10-6=4
Rise time0 time
overshoot
undershoot
t1 t3t2 t4
6
P is +ve
Target speed=leftRPMset =10
Usage of the P proportional termEach ¼ seconds a new left RPM (speed of wheel) is measured
leftErr=leftRPMset –leftPRM=10-8=2
leftP = Pgain * leftErr;leftP=?___________ ,is +ve or -ve?“leftPWM” is increasedor decreased?__more/less energy delivered to wheel?__
P is +ve
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000; In our experiment leftPWM=276000 at the beginning and 192800 at steady state
8
Example:t1àt3,Theproportionaltermwhenthemeasurementisbelowthesetpoint(leftRPMset),the
proportionalPtermis+ve•
CENG4480: feedback control V5a 45
leftP = Pgain * leftErr;leftP= 8000* (10-13)= 8000*(-3) is negativeThis term lowering down “leftPWM” (less energy delivered to the wheel).
leftErr=leftRPMset –leftPRM=10-13= -3
Rise time0 time
overshoot
undershoot
t1 t3t2 t4
13
P is +ve
Target speed=leftRPMset =10
Usage of the P proportional termEach ¼ seconds a new left RPM (speed of wheel) is measured
P is -ve
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
UnderstandingPID–alittlesummaryforthePproportionalterm
• Whenthemeasurementisbelowthesetpoint(leftRPMset)– Themotoriscurrentlytooslow– ThePtermcalculatedis+ve,needtopushthespeedhigher
• Whenthemeasurementisabovethesetpoint(leftRPMset)– Themotorisrunningtoofast– ThePproportionaltermis-ve,loweringdownthespeed.
• IncreaseinPgain(Kp)willdecreaserisetime(meaningfastertoreachsetpoint),decreasesteadystateerror(studyitlater)– Italsoincreasesovershoot
CENG4480: feedback control V5a 46
(line9)EffectsofincreasingKd(D)http://en.wikipedia.org/wiki/PID_controller
•
Parameter Rise Time Overshoot Settling Time
Steady state error
Kp (Pgain)Igain
Decreasestep1
Increase Small Change
Decrease
Ki (Igain)gainI
Decrease Increase Increase Eliminatestep3
Kd (Dgain) Small Change
Decreasestep2
Decrease Small Change
CENG4480: feedback control V5a 47
Derivativeterm
• Derivativecontrol– Dgain*[d(leftErr)/dt]
• d(leftErr)/dt =– =Derivativeterm– =current_Err- last_Err– =leftErr– leftlastErr;inourprogram
CENG4480: feedback control V5a 48
Example:time0à t1,theDerivativeterm(=current-previous)Whenthemeasurementisrising,theDerivativetermis-ve
•
CENG4480: feedback control V5a 49
leftD = Dgain * (leftErr – leftlastErr); leftD= 5000* (3-7)= 5000*( -4) is negativeTo do:This term lowering down “leftPWM” (less energy delivered to the wheel).
leftlastErr=leftRPMset –eftlastPRM=10-3=7
leftErr=leftRPMset –leftPRM=10-7=3
Rise time0 time
Target Value=leftRPMset=10
overshoot
undershoot
¼ seconds
t1 t3t2 t4
3
7
D is -ve
leftRPMset =10
Usage of the D Derivative termEach ¼ seconds a new left RPM (speed of wheel) ismeasured
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
Example:timet1àt2,theDerivativetermWhenthemeasurementisrising,theDerivativetermis-ve
•
CENG4480: feedback control V5a 50
Rise time0 time
overshoot
undershoot
leftD = Dgain * (leftErr – leftlastErr); leftD= 5000* (-5- (-2))= 5000*(-3) is negativeThis term lowering down “leftPWM” (less energy delivered to the wheel).
leftlastErr=leftRPMset -leftlastPRM=10-12= -2
¼ secondsleftErr=leftRPMset -leftPRM=10-15= -5
t1 t3t2 t4
leftRPMset =10
D is -ve
1512
leftPRM
D is -ve
Usage of the D Derivative termEach ¼ seconds a new left RPM (speed of wheel) ismeasured
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
LittleSummary:NegativeDDerivativeterm• Whenthemeasurement(leftRPM)isrising,thechange
(change=current-previous)oferror(error=setpoint-leftRPM)is-ve=d(Err/dt)=-ve
• DDerivativeterm=Kd*d(Err/dt)is–VE• Decreaseenergytomotorà decreaseovershoot
CENG4480: feedback control V5a 51Rise time0 time
undershoot
t1 t3t2 t4
D is -ve
D is -ve
Setpoint��
overshoot
Example:timet2àt3,theDerivativetermWhenthemeasurementisfalling,theDerivativetermis+ve
•
CENG4480: feedback control V5a 52
Rise time0 time
overshoot
undershoot
leftD = Dgain * (leftErr – leftlastErr); leftD= 5000* (-1- (-4))= 5000*3 is positiveThis term pushing up “leftPWM” (more energy delivered to the wheel).
Usage of the D Derivative termEach ¼ seconds a new left RPM (speed of wheel) ismeasured
leftlastErr=leftRPMset -leftlastPRM=10-14= -4
¼ seconds
leftErr=leftRPMset -leftPRM=10-11= -1
t1 t3t2 t4
leftRPMset =10
D is -ve
1411
leftPRM
D is +ve
D is -ve
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
Exercise6:Fillin?_timet2àt3,theDerivativetermWhenthemeasurementisfalling,theDerivativetermis+ve
•
CENG4480: feedback control V5a53
Rise time0 time
overshoot
undershoot
leftD = Dgain * (leftErr – leftlastErr); leftD= ?___________, which is +ve or –ve?____“leftPWM” increased or decreased?____More/less energy delivered to the wheel?___
Usage of the D Derivative termEach ¼ seconds a new left RPM (speed of wheel) ismeasured
leftlastErr=leftRPMset -leftlastPRM=10-9= 1
¼ seconds
leftErr=leftRPMset -leftPRM=10-7= 3
t1 t3t2 t4
leftRPMset =10
D is -ve
97
leftPRM
D is +ve
D is -ve
D is +ve
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
LittleSummary:PositiveDDerivativeterm• Whenthemeasurement(leftRPM)isfalling,thechange
(change=current-previous)oferror(error=setpoint-leftRPM)is+ve
• DDerivativeterm=Kd*d(Err/dt)is+VE• Increaseenergytomotorà decreaseundershoot
CENG4480: feedback control V5a 54Rise time0 timet1 t3t2 t4
D is +ve
D is +ve
Setpoint��
overshoot
undershoot
UnderstandingPID–alittlesummaryfortheDderivativeterm
• Whenthemeasurement(leftRPM) isrising,– Themotor isgainingspeed– TheDderivativetermis–ve,solowering themotorspeedà decrease
overshoot
• Whenthemeasurement(leftRPM) isfalling,– Themotor isreducingspeed– TheDerivativetermis+ve,sopushing themotorspeedhigherà decrease
undershoot– Inconclusion,thegradientoftheerror(Err)determinesthe
adjustment.Dependsonwhetherd(Err)/dtis+veor–ve.• IncreaseinDgain(Kd)willdecreaseovershoot/undershootand
settlingtime(systemmorestable)
CENG4480: feedback control V5a 55
(line8)EffectsofincreasingKi(I)http://en.wikipedia.org/wiki/PID_controller
•
Parameter Rise Time Overshoot Settling Time
Steady state error
Kp (Pgain) Decreasestep1
Increase Small Change
Decrease
Ki (Igain) Decrease Increase Increase Eliminatestep3
Kd (Dgain) Small Change
Decreasestep2
Decrease Small Change
CENG4480: feedback control V5a 56
controlmethod:PID(proportional-integral-derivative)control
•
CENG4480: feedback control V5a 57
Required speed=
leftRPMset
IR wheelSpeedencoder
LeftRPM
+
-
leftRPM
Motor
generates PWM for driver L293
leftPWM
integral control
Igain* leftErr dt
Proportional control
Pgain*leftErr
Derivative control
Dgain*[d(leftErr)/dt]
sumleftErr
leftPWM
At steady state, leftErrà0, soSo, Pgain*leftErr=0
also Dgain*[d(leftErr)/dt] =0
And if no Integral { Igain* leftErr dt} term, left PWM à0
It is a problem.
Timeà nearsteadystateleftRPMset=leftRPM
henceleftErr=0,leftlastErr=0à leftP=0,leftD=0
• leftErr=leftRPMset– leftRPM=0• SoasleftlastErr=0• Therefore• Steps• 7)leftP=Pgain*leftErr//=0 //calculatePProportional term• 8)leftI=Igain*leftaccErr; //calculateIIntegralterm• 9)leftD=Dgain*(leftErr - leftlastErr)//=0 //calculateDDerivativeterm• 10)leftPWM+=(leftP+leftI+leftD);//update leftmotorPWMusingPID
Theonlyvalidtermistheintegralterm“leftI”• leftPWM+=leftI• Themainideaistocreateasmallterm(leftI)tomaintaintheleftPWMvalue
CENG4480: feedback control V5a 58
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
near steady state : leftP=0 leftD=0
Theintegraltermisfoundbyaddingallpreviouserrors
sameasleftaccErr=sum{leftErr(t=0)+leftErr(t=1)+.. +leftErr(t=now)}• 14)leftaccErr+=leftErr;//LeftaccErristhesummationofallpreviouserrors• 8)leftI=Igain*leftaccErr//integralterm,• :• 10)leftPWM+=leftI//nearsteadystate,onlyleftIisvalid• :
• Don’tworryitwillnot becomeinfinitive,onemeasuretosafeguardthisis:• 11)if(leftPWM>PWM_FREQ);// PWM_FREQ=maximumPWMallowed• 12)leftPWM=PWM_FREQ;//preventoverrange• (max.=PWM_FREQ)
• Also,becausenearsteadystate,leftaccErrwilladjustitselfautomatically,seenextslide
CENG4480: feedback control V5a 59
e.g.Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
Howtheintegraltermadjustsitselfautomaticallynearsteadystate
• Nearsteadystate– 8)leftI=Igain*leftacceErr– 10)leftPWM+=leftI
• Ifmeasuredspeed(leftRPM)>setpoint– leftErris-ve– leftaccErr(Acculumation)decreases,
hencereducingleftaccErratasuitablevaluetomaintainleftPWM
• Ifmeasuredspeed(leftRPM)<setpoint– leftErris+ve– leftaccErr(Acculumation)increases,
henceincreasingleftaccErratasuitablevaluetomaintainleftPWM
CENG4480: feedback control V5a 60
Pgain = 8000; Igain = 6000; Dgain = 5000;
In our experiment leftPWM=276000 at the beginning and 192800 at steady state
UnderstandingPID–alittlesummaryfortheIIntegralterm
• Whenthemeasurementisbelowthesetpoint(leftRPMset)– Themotorisslow– TheIIntergraltermis+ve,pushingthespeedhigher
• Whenthemeasurementisabovethesetpoint(leftRPMset)– Themotorisrunningtoofast– TheIintergraltermis-ve,loweringdownthespeed.
• IncreaseinIgain(Ki)willresultin– ItissimilartothePterm(seeabovetwopoints)– Soincreaseovershoot, settlingtime– anddecreaserisetime– Note:themainfunction ofIntegralcontrolistoreducesteadystateerror
CENG4480: feedback control V5a 61
PIDTuning(usuallydonebytrailanderror)
• Tune(adjustmanually)– step1)Pgainproportional_gain(Kp),– step2)Dgainderivative_gain(Kd),– step3)Igainintegral_gain(Ki)
• SetconstantspeedV1forawhile(5seconds)andreducedto(V1)/2atT1
– RecordthespeedbythecomputerafterT1andseeiftheperformanceisokornot• Yes(acceptKp,Ki,Kd)• No(tuneKp,Ki,Kd again)
CENG4480: feedback control V5a 62
Motor speed
V1
(V1)/2
Accepted performance
unstable
done
T1 time
Summary
• StudiesPIDcontroltheoryandimplementation
CENG4480: feedback control V5a 63