{"id":77,"date":"2009-12-24T15:00:40","date_gmt":"2009-12-24T15:00:40","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2009\/12\/24\/pid-control-made-easy\/"},"modified":"2009-12-24T16:17:41","modified_gmt":"2009-12-24T16:17:41","slug":"pid-control-made-easy","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2009\/12\/24\/pid-control-made-easy\/","title":{"rendered":"PID Control Made Easy"},"content":{"rendered":"<p>Today I introduce guest blogger <a\r\nhref=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/32123\">Arkadiy\r\nTurevskiy<\/a> to share some new features in R2009b: the <a\r\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/simulink\/slref\/pidcontroller.html\">PID\r\nController Blocks<\/a> in <a href=\"https:\/\/www.mathworks.com\/products\/simulink\/\">Simulink<\/a>\r\nand a new <a\r\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/slcontrol\/ug\/br684zf.html\">PID\r\ntuning method<\/a> in <a href=\"https:\/\/www.mathworks.com\/products\/simcontrol\/\">Simulink\r\nControl Design<\/a>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/arkadiySmall.jpg\" alt=\"PID Gain Tuner Arkadiy Turevskiy\"><\/p>\r\n\r\n<p><a\r\nhref=\"http:\/\/en.wikipedia.org\/wiki\/PID_controller\">PID\r\n(Proportional-Integral-Derivative) control<\/a> seems easy: you just need to\r\nfind three numbers: proportional, integral, and derivative gains. Many PID\r\ntuning rules exist out there and all you need to do is pick up one and press a\r\nbutton on a calculator. Easy enough, right? Unfortunately, the story is more complicated\r\nthan that. Popular PID tuning methods are restrictive. For example, to use one\r\nof the most popular methods - Ziegler-Nichols - you need a stable, first order\r\nplus dead-time linear time-invariant (LTI) plant model. Even if your model is\r\nof that type, the method does not support tuning of integral or\r\nproportional-derivative controllers, and for the types of PID controllers it\r\nsupports, it only provides one answer with no easy way to fine-tune the design.\r\nMoreover, tuning is not the only challenge. Real-life PID implementation also\r\nneeds to consider such issues as output saturation, integrator wind-up, and\r\ndiscrete-time implementation.<\/p>\r\n\r\n<p>In R2009b we released new blocks\r\nin Simulink and a new PID tuning method in Simulink Control Design that\r\ntogether address these challenges. To see how this works, let\u2019s consider an\r\nexample of designing a PID controller for a dc motor. The model of a closed\r\nloop system uses the new PID Controller block. This block generates a voltage\r\nsignal driving the dc motor to track desired shaft rotation speed. In addition\r\nto voltage, the dc motor subsystem takes torque disturbance as an input,\r\nallowing us to simulate how well the controller rejects disturbances. We also\r\nmodeled analog sensor noise in the speed measurement.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/pidDCMotor.png\" alt=\"DCMotor Model with a PID compensator\"><\/p>\r\n\r\n<p>The PID controller is a discrete-time controller\r\nrunning at 0.02 seconds (the red color shows the sampling time in the model).\r\nLet\u2019s now look at the dialog of the PID Controller block. In the upper half of\r\nthe dialog we specified basic configuration of the PID controller: type (PID,\r\nPI, PD, P, or I), time-domain, integration methods, and sample time. In the\r\nlower part, we specified PID controller form and gains (shown at default\r\nvalues).\u00a0 Block <a\r\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/simulink\/slref\/pidcontroller.html\">documentation<\/a> provides\r\ndetailed information about the block and all its parameters.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/pidControlerDlg.png\" alt=\"PID Controler Block Dialog\"><\/p>\r\n\r\n<p><strong>PID Tuning<\/strong><\/p>\r\n\r\n<p>Our first task is to tune the PID controller. Pressing the\r\n\u201cTune\u2026\u201d button in the PID Controller block dialog, we launch PID Tuner, which\r\nlinearizes the model at the default operating point and automatically\r\ndetermines PID controller gains to achieve reasonable performance and\r\nrobustness based on linearized plant model.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/PIDTuner.png\" alt=\"PID Tuner Interface\"><\/p>\r\n\r\n<p>The grey line shows the system step response for the gain\r\nvalues currently defined in the block dialog, and the blue line shows the\r\nsystem response for the gain values that PID Tuner proposes. We can simply\r\naccept the proposed design and then run our closed-loop Simulink model to check\r\nthe results. In the simulation, we command a step change from 0 to 2 rpm at 1\r\nsecond and a step down to -2 rpm at 7 seconds. Results demonstrate good\r\ntracking with zero steady-state error, fast rise time, low overshoot, and good\r\ntorque disturbance rejection (torque disturbance is modeled as a step change\r\nfrom 0 to 0.2 Newton-meters at 5 seconds). The tuning algorithm we just used\r\nworks on any type of plant model, tunes all forms of PID controllers that can\r\nbe specified in the PID Controller block, and takes sampling effects into account\r\nduring the tuning process.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/ScopeVoltageDisturbance.png\" alt=\"Scope showing a voltage disturbance\"><\/p>\r\n\r\n<p>If system response does not meet our requirements, we could\r\nfurther fine-tune the design by interactively making the controller faster or\r\nslower, using the slider on the bottom of the PID Tuner GUI.<\/p>\r\n\r\n<p><strong>Integrator Anti-Windup Protection<\/strong><\/p>\r\n\r\n<p>We now run a different scenario, assuming no torque\r\ndisturbance and assuming that the amplitude of voltage fed to the dc motor\r\ncannot exceed 10 Volts \u2013 to protect the motor from overheating. We use the \u201cPID\r\nAdvanced\u201d tab of the PID Controller block dialog to specify these saturation\r\nlimits.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/PIDControlerDlgAdvanced.png\" alt=\"Advanced Tab from the PID Controller Block Dialog\"><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/measuredSpeedScope.png\" alt=\"Measured speed scope showing integrator wind-up\"><\/p>\r\n\r\n<p>We see that at the time of the first step change at 1\r\nsecond, voltage signal from the controller saturates at 10 Volts. &nbsp;When\r\ndesired speed drops at 7 seconds, the voltage does not decrease immediately and\r\nstays at 10 Volts for almost 2 more seconds.&nbsp; This is the result of\r\nintegrator wind-up in PID controller, which leads to undesired delay in\r\ntracking the speed command.\u00a0 It can be fixed by enabling integrator anti-windup\r\nin the PID Controller block dialog. Rerunning the simulation with integrator\r\nanti-windup enabled, we see that the controller still cannot achive commanded\r\nspeed value of 2 rpms \u2013it simply does not have enough authority, but when the\r\nspeed is commanded to -2 rpms, controller quickly responds to change in the\r\nrequested speed.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2009Q4\/ScopeWindUp.png\" alt=\"Scope showing effect of turning on anti wind-up\"><\/p>\r\n\r\n<p>As we saw, the new PID tuning method and the new PID\r\nController block helped us quickly tune our PID Controller, and create a\r\ndiscrete-time design that addresses output saturation and integrator wind-up\r\nissues.<\/p>\r\n\r\n<p><strong>Now it is your turn<\/strong><\/p>\r\n\r\n<p>Do you use PID control? How do you address integrator\r\nwind-up?\u00a0 Leave a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=77&amp;#comment\">comment\r\nhere<\/a> and tell us how you tune your controller gains.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Today I introduce guest blogger Arkadiy\r\nTurevskiy to share some new features in R2009b: the PID\r\nController Blocks in Simulink\r\nand a new PID\r\ntuning method in Simulink\r\nControl... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2009\/12\/24\/pid-control-made-easy\/\">read more >><\/a><\/p>","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[115,65],"tags":[117,116],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/77"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}