Академический Документы
Профессиональный Документы
Культура Документы
PIDforEmbeddedDesignTutorialbyCytron
Live Search
Ex:Arduino,PIC....
Cytron Online
Store
Popular Post
Robot Controller
Getting Started
On Graphical
User Interface
GUI
ByKongWaiWeng
RH2TMag,Vol.4,Mar2010
PIDcontrolsystemisoneofthemostmatureandcommonly
usedcontrolstrategiesintheindustrialfordecadesthanksto
its simple but effective algorithm. In this article, we will
XBee Series 2
Point to Point
Communication
1/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Introduction
Closedloopcontrolsystemisanessentialtopicforembeddedsystems,
bringing together actuators and sensors with the control algorithm in
software.Forexample,motorspeedcanbecontrolledbyvaryingthe
PWMdutycycleusedtodrivethemotor.Thisistheopenloopcontrol.
However, due to the lack of feedback, the actual motor speed could
not be verified. This is important because driving the motor with the
same PWM duty cycle does not guarantee the motor to run at the
Moisture sensor
module (SNMOISTURE-MOD)
same speed under all circumstances. A motor will run faster in load
freeconditionthanunderloadwiththesamePWMsignal.Inorderto
Categories
otherparameterssuchasposition,temperature,waterlevel,stability,
CT UNO
Easy MP3 Shield
etc.Inthisarticle,wewilldiscusshowtoimplementaPIDcontroller
forpositioncontrolbasedonPR24.
Getting Started
Arduino
G15
LCD
PIC
TheProblemDCMotorPositionControl.
BeforewebegintodesignaPIDcontroller,weneedtounderstandthe
problem. In this example, we want to move the shaft of the motor
fromitscurrentpositiontothetargetposition.
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
Programming/Software
Raspberry Pi
Robots
Serial Communication
USB
Wireless
IoT
News
PIR
Product Guides
Projects
Rainbow Strip
rero
Seminars & Events
ThingSpeak
Uncategorized
Useful Tools / External Referen
2/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Find Us on
Facebook
CytronTechnologie
9,287likes
LikePage
Bethefirstofyourfriendstolikethis
CytronTechnologiesS
Bhdaddedanevent
Yesterdayat06:33
Wewanttomovetheoutputshaftofthemotorfromcurrentposition
totargetposition
There are a few terms commonly used to describe the PID control
loops,suchas:
ControlVariable(CV)Thisistheoutputofthecontrolloop.In
IoTHandsOnWorkshop101
UniversitiTeknologiMalaysia(UTM)
15peopleinterested4peoplegoin
thiscase,theCVisthedutycycleofthePWMsignalthatdrives
themotor.
Process Variable (PV) This is the feedback value returned by
the system to the controller. In this example, the PV is the
currentangleofthemotorshaft.
Set Point (SP) Set point is the value that we desire for the
system. In our case, the SP is the target position of the motor
shaftinangle.
Error(E) Error refers to the difference between the set point
andtheprocessvariable.Inanotherwords,itmeanshowfarthe
currentpositionofthemotorshaftfromthetargetposition.
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
3/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
TheHardwarePR24
Note:PR24isalreadydiscontinued.Samplecodecanbedownloadhere.
The Cytrons DIY Project Set PR24 (PID Motor Controller) is the best
platformforbeginnertolearnthePIDalgorithm.Ithasthefollowing
features:
PIC16F876Aasthemaincontroller.
GearedDCmotorastheoutput.
Multiturn variable resistor connected to the motor shaft for
positionfeedback.
216CharacterLCDfortuningandtroubleshooting.
PresetsforPIDtuning.
DIYProjectSetPR24PIDMotorController
The sample source code for the PR24 (PID Motor Controller) can be
downloaded from Cytrons website under the PR24 product page
(GithubCytronTechnologies).
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
4/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
TheImplementationofPIDController
ThePIDcontroller,justlikeitsname,comprisesaproportional(P),an
integral (I) and a derivative (D) part. The controller parts are
introduced in the following sections individually and in combined
operation.
ProportionalController
Whenthecurrentpositionofthemotorshaftisstillfarawayfromthe
target position, we want to apply more power to drive the motor
towards the target position so that we can reach there faster. When
the shaft is getting nearer to the target position, we will reduce the
power to slow it down. At the time the shaft reaches the target
position, the motor needs to be stopped. If the shaft position has
overshot,weneedtoapplynegativepowertothemotor(reversethe
motor)tobringitbacktothetargetposition.
In short, this is called proportional controller because the power we
applytothemotorisproportionaltotheerrorofthesystem.
Theblockdiagramofproportionalcontroller
Fromtheblockdiagramofproportionalcontroller,wecanseethatthe
PWM duty cycle (output) is the result of multiplying the error with a
constant,Kp.
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
5/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Error=SetPointProcessVariable
ControlVariable=Kp*Error
Figurebelowshowstheexampleofproportionalloopimplementedin
Clanguage.
ImplementationofproportionalloopinClanguage
The value of Kp needs to be chosen carefully in order to get the
optimum system response. Lower values for Kp will tend to give
smootherbutslowerresponses.
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
6/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
SystemresponseforproportionalcontrollerwithlowKp
Higher values of Kp will yield much quicker response but may cause
overshoot,wheretheoutputoscillatesbeforesettling.
SystemresponseforproportionalcontrollerwithhighKp
Excessively high values of Kp may even throw the loop into an
unstablestatewheretheoutputoscillateswithouteversettlingatthe
setpoint.
SystemresponseforproportionalcontrollerwithexcessivelyhighKp
IntegralController
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
7/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Steadystateerrorduetothefrictionandgravity
ToovercometheproblemofsteadystateerrorforthePcontroller,I
controller is being introduced. As its name suggests, the integral is
merelyanaccumulatederrorsignalsencounteredsincestartup.
Integral=(Error)
This total is multiplied by a constant, Ki, and is added into the loop
output.UnlikethePcontroller,theIcontrollerisrarelyusedalone,but
mostly in combination with the P or PD controller. When the system
hasalreadysettleddownwithasmallsteadystateerror,theintegral
stillcontinuestoaccumulateuntiltheCVislargeenoughtobringthe
PVinlinewithSP.TheequationsforPIcontrollerareasfollow:
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
8/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Error=SetPointProcessVariable
Integral=Integral+Error
ControlVariable=(Kp*Error)+(Ki*Integral)
Figure below shows the example of PI controller implemented in C
language.
ImplementationofPIloopinClanguage
JustlikethePcontroller,thevalueofKineedstobechosencarefully.
Toolowthevalue,thesteadystateerroriscorrectedveryslowlytoo
highthevalue,thesystembecomesunstableandoscillates.
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
9/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
SystemresponseforPIcontrollerwithnosteadystateerror
Because the integral can grow quite large when the set point cannot
be reached, some applications stop accumulating the error when the
CVissaturated.
DerivativeController
Letssayyouaredrivingacar,andyouneedtostopyourcarexactly
100m from your current position as soon as possible. If you are
travelling at 10km/h, you would want to accelerate your car so that
you can reach the target sooner. In contrast, if you are cruising at
100km/h,youneedtostartbrakingsothatyoucanstopat100mand
will not overshoot. This is where the derivative controller comes into
play.
The derivative of any variable describes how that variable changes
overtime.InaPIDcontroller,thederivativeistherateofchangeof
theerror.Indigitalform,itcanbedescribedas:
Derivative=ErrorLastError
whereErroristhecurrenterrorvalueandLastErroristheerrorvalue
forthepreviousiteration.
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
10/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
11/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
ImplementationofPDloopinClanguage
The damping effect of the D controller allows the system to have a
highervalueofKpand/orKiwithoutovershooting.Inconsequent,this
will give the system a better response time to set point changes.
However,toohighthevalueofKdwillalsohavenegativeeffect.The
Dcontrollertensetoamplifythenoiseexistsinthefeedbackloop.If
theKdistoohigh,thesystemwillbecomejerkyifthefeedbackloopis
noisy.
MainMenu
HOME
PROJECTS
CATEGORIES
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
12/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
SystemresponseforPDcontroller
JoiningThemTogetherPIDController
ByjoiningtheP,IandDcontroller,wecantaketheadvantagesofthe
combined benefits from each controller. We have the P controller for
fastsystemresponse,Icontrollertocorrectthesteadystateerrorand
Dcontrollertodampenthesystemandreduceovershoot.
TheblockdiagramofPIDcontroller
FromtheblockdiagramofPIDcontroller,wecanseethattheoutput
oftheloopismerelythesumofoutputfromP,IandDcontroller.The
equationsforthePIDloopareillustratedbelow:
LastError=Error
MainMenu
HOME
PROJECTS
CATEGORIES
Error=SetPointProcessVariable
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
Integral=Integral+Error
Derivative=ErrorLastError
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
13/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
ControlVariable=(Kp*Error)+(Ki*Integral)+(Kd*Derivative)
Figure below shows the example of PID controller implemented in C
language.
ImplementationofPIDloopinClanguage
MainMenu
HOME
PROJECTS
CATEGORIES
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
SystemresponseforthecorrectlytunedPIDcontroller
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
14/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Summary
PID controller is a simple yet effective control system widely used in
industrial.However,toimplementthePIDcontrollerissimple,butnot
thetuning.TheprocessoftuningthePIDparameters(Kp,KiandKd)
is a continuous trial and error process. There is no exact way to
calculate the value for the parameters unless the whole system is
mathematically modeled and simulated. Experience is an important
factortogettheoptimumPIDparametersbasedontheobservationof
the system behavior during the tuning process. If you have inquiry,
feelfreetodiscussinourtechnicalforum.
References:
DennisClarkandMichaelOwings:BuildingRobotDriveTrains.
Thomas Braunl: Embedded Robotics Mobile Robot Design and
ApplicationswithEmbeddedSystems.
http://en.wikipedia.org/wiki/PID_controller
http://www.expertune.com/tutor.html
http://www.newportus.com/products/techncal/techncal.htm
http://www.dprg.org/tutorials/200310a/motorcontrol.pdf
MainMenu
Related Posts:
HOME
PROJECTS
CATEGORIES
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
15/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
19 5583 views
Prev Post
Next Post
Microcontroller
using Arduino
MainMenu
HOME
PROJECTS
CATEGORIES
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
16/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Related Post
Line-Following
Robot Using
LSA08 in Serial
Mode with PID
Controller
Using MDD10A
with CIKU
Getting Started
with MPLAB X
IDE
Quadrature
Encoder
CATEGORIES
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
Leave a Reply
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
17/18
11/10/2016
PIDforEmbeddedDesignTutorialbyCytron
Name *
Email *
Website
PostComment
CATEGORIES
http://tutorial.cytron.com.my/2012/06/22/pidforembeddeddesign/
LOGIN/REGISTER
SHOP AT CYTRON
FORUM
18/18