- Open QLabs. Click on QUBE 2 – DC Motor, then click on the Servo Workspace.
- Download the supplied Simulink model, self_tuning_PI_controller.slx
- The Simulink model implements a PI speed controller. A square wave with a frequency of 0.4 Hz is commanded to the digital twin to alternate the speed of the load shaft between 10 rad/s and 50 rad/s. The model starts off by using kp and ki values of 0.2 and 0.1, respectively. These initial gains were selected such that they would not result in an unstable system.
- The Autotuner block is configured with a desired bandwidth and phase margin values of 75 rad/s and 60 deg respectively. With the Start Tuning manual switch set to 0 (effectively bypassing the Autotuner block), run the model. Below is the untuned response that you should observe.
- Toggle the Start Tuning manual switch block. The Autotuner block will started to interject test signals int the digital twin plant. The sine amplitude of the test signals is set to 0.1. You can change that value to see how it affects the results. Below is the response of the digital twin while being subjected to the test signals.
- The One Shot block is used to produce a pulse signal that would run the Autotuner block for 4 seconds. During this time, the model monitored the %conv output of the Autotuner block. Once the value converged to 98%, tuning is considered complete, and the Simulink diagram displayed the tuned gains as well as the estimated phase margin. Additional logic is implemented to transfer the tuned gains generated by the autotuning block to the PI controller. This means that you do not have to stop my model to apply the tuned gains to the plant.
- Below is the system response upon completion of the autotuning process and applying the new controller gains. You can see a far better response compared to the untuned controller we started with. The resulting estimated phase margin was 58 deg (very close to the desired 60 deg) and the calculated tuned gains were kp = 0.38 and ki = 2.68.
Quanser (2023). Online Tuning using the Closed-Loop PID Autotuner Block (https://www.mathworks.com/matlabcentral/fileexchange/101874-online-tuning-using-the-closed-loop-pid-autotuner-block), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Updated text for clarity.
Fixed heading formatting
Update section headings and added instructions related to QLabs.
Fixed hyper links
Added instructions on how to open the Virtual QUBE-Servo 2 in QLabs
Changed cover image
Left aligned images and captions.