I gave it a try with the new LEGO MINDSTORMS EV3 Support Package, and I was really impressed by how easy it is to use.
Let's see how it works.
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.
Using External Mode and To Workspace blocks, I acquire experimental data that will be used later.
I want to control the motor in position, so I create the following model:
I open the dialog of the Discrete PID block, I specify the type of controller I want, its sample time, and I click the Tune button to launch the PID Tuner app.
Identifying the plant
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.
To identify a plant based on the data previously acquired, select the Identify New Plant option:
A Plant Identification tab will appear where you will be able to import the previously saved data.
Theoretically, a motor like this one should be modeled using a second-order transfer function, with integrator (See this tutorial for an example). 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 Auto Estimate 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.
Tuning the Controller
Once you are satisfied with the identified plant, click the Save Plant button and switch to the PID Tuner tab. Play with the sliders until you get a satisfying response, and once this is done click Update Block to apply the tuned gains to the controller block in your model.
Deploying the Controller
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:
Now it's your turn
This shows only a small part of what this app can do. Here are a few additional resources for you to learn more:
- For a more detailed explanation of this workflow, watch the PID Controller Tuning Based on Measured Input-Output Data video.
- 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 PID Controller Tuning for a Model with Discontinuities video.
- If you are interested in a more comprehensive overview of PID control design with MATLAB and Simulink, watch PID Control Made Easy webinar.
Try the PID Tuner app with integrated system identification capabilities for yourself and let us know what you think by leaving a comment here.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.