{"id":3756,"date":"2014-05-30T15:27:25","date_gmt":"2014-05-30T20:27:25","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=3756"},"modified":"2017-01-04T16:04:23","modified_gmt":"2017-01-04T21:04:23","slug":"plant-identification-using-the-pid-tuner","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2014\/05\/30\/plant-identification-using-the-pid-tuner\/","title":{"rendered":"Plant Identification Using the PID Tuner"},"content":{"rendered":"<!--introduction-->\r\n<p>In R2014a, <a href=\"https:\/\/www.mathworks.com\/products\/sysid\/\">system identification<\/a> capabilities have been added to the <a href=\"https:\/\/www.mathworks.com\/discovery\/pid-tuning.html\">PID Tuner app<\/a> to create a plant model, allowing you to do the plant identification and controller tuning all in one app.<\/p>\r\n<!--\/introduction-->\r\n\r\n<p>I gave it a try with the new <a href=\"https:\/\/www.mathworks.com\/hardware-support\/lego-mindstorms-ev3-simulink.html\">LEGO MINDSTORMS EV3 Support Package<\/a>, and I was really impressed by how easy it is to use.<\/p>\r\n\r\n<p>Let's see how it works.<\/p>\r\n\r\n<p><strong>Acquiring Data<\/strong><\/p>\r\n\r\n<p>To identify a plant model, your first need experimental data. In my case, I created the following simple model that applies power to a motor and measures the resulting motion.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/SysIDModel.png\" alt=\"Model to Acquire Data for System Identification\" \/><\/p>\r\n\r\n<p>Using External Mode and <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/toworkspace.html\">To Workspace<\/a> blocks, I acquire experimental data that will be used later.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/acquiredData.png\" alt=\"Acquired Data for System Identification\" \/><\/p>\r\n\r\n<p><strong>Control Model<\/strong><\/p>\r\n\r\n<p>I want to control the motor in position, so I create the following model:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/tunedModel.png\" alt=\"Control Model\" \/><\/p>\r\n\r\n<p>I open the dialog of the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/pidcontroller.html\">Discrete PID<\/a> block, I specify the type of controller I want, its sample time, and I click the Tune button to launch the PID Tuner app.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/pidDialog.png\" alt=\"Dialog of the PID Controller block\" \/><\/p>\r\n\r\n<p><strong>Identifying the plant<\/strong><\/p>\r\n\r\n<p>As first guess, the PID Tuner tries to obtain a plant model by linearizing the blocks present in the model. Obviously, in this case this will not work because the Simulink model does not contain a plant.<\/p>\r\n\r\n<p>To identify a plant based on the data previously acquired, select the <em>Identify New Plant<\/em> option:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/identifyNewPlant.png\" alt=\"Identifying new plant\" \/><\/p>\r\n\r\n<p>A Plant Identification tab will appear where you will be able to import the previously saved data.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/importData.png\" alt=\"Import Data\" \/><\/p>\r\n\r\n<p>Theoretically, a motor like this one should be modeled using a second-order transfer function, with integrator (<a href=\"http:\/\/ctms.engin.umich.edu\/CTMS\/index.php?example=MotorPosition&section=SystemModeling\">See this tutorial for an example<\/a>). However, based on past experience I know that the effect of the second pole is almost negligible for this Lego motor. In the Plant Identification tab I specify a one pole system with integrator and click the <strong>Auto Estimate<\/strong> button. As you can see, this does a pretty good job. I zoomed in on one of the transitions to show that the plant output is not exactly identical to the experimental data... which would be impossible.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/identifiedPlant.png\" alt=\"Identified Plant\" \/><\/p>\r\n\r\n<p><strong>Tuning the Controller<\/strong><\/p>\r\n\r\n<p>Once you are satisfied with the identified plant, click the <strong>Save Plant<\/strong> button and switch to the PID Tuner tab. Play with the sliders until you get a satisfying response, and once this is done click <strong>Update Block<\/strong> to apply the tuned gains to the controller block in your model.<\/p>\r\n\r\n<p><a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/plantTuningLarge.png\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/plantTuningSmall.png\" alt=\"Tuned Controller\" \/><em>(Click to enlarge)<\/em><\/a><\/p>\r\n\r\n<p><strong>Deploying the Controller<\/strong><\/p>\r\n\r\n<p>I tried running the control model on the EV3 and I was really impressed to see that the results were almost identical to what I could see in the PID Tuner:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/finalResult.png\" alt=\"Experimental results from tuned controller\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>This shows only a small part of what this app can do. Here are a few additional resources for you to learn more:<\/p>\r\n\r\n<ul>\r\n\t<li>For a more detailed explanation of this workflow, watch the <a href=\"https:\/\/www.mathworks.com\/videos\/pid-controller-tuning-based-on-measured-input-output-data-89348.html\">PID Controller Tuning Based on Measured Input-Output Data<\/a> video.<\/li>\r\n\t<li>To see how this workflow can help if you are designing PID controller for a Simulink model with discontinuities such as MOSFETs and PWMs, watch the <a href=\"https:\/\/www.mathworks.com\/videos\/pid-controller-tuning-for-a-model-with-discontinuities-89347.html\">PID Controller Tuning for a Model with Discontinuities<\/a> video.<\/li>\r\n\t<li>If you are interested in a more comprehensive overview of PID control design with MATLAB and Simulink, watch <a href=\"https:\/\/www.mathworks.com\/videos\/pid-control-made-easy-81646.html\">PID Control Made Easy<\/a> webinar.<\/li>\r\n<\/ul>\r\n\r\n<p>Try the PID Tuner app with integrated system identification capabilities for yourself and let us know what you think by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=3756&#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2014Q2\/finalResult.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction-->\r\n<p>In R2014a, <a href=\"https:\/\/www.mathworks.com\/products\/sysid\/\">system identification<\/a> capabilities have been added to the <a href=\"https:\/\/www.mathworks.com\/discovery\/pid-tuning.html\">PID Tuner app<\/a> to create a plant model, allowing you to do the plant identification and controller tuning all in one app.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2014\/05\/30\/plant-identification-using-the-pid-tuner\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[115,30,16],"tags":[389,388],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3756"}],"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\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=3756"}],"version-history":[{"count":31,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3756\/revisions"}],"predecessor-version":[{"id":6277,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/3756\/revisions\/6277"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=3756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=3756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=3756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}