This example shows how to perform optimization-based control design in the Control System Designer (Control System Toolbox) app when you have Control System Toolbox™ software. You design a PID controller for a linearized Simulink® model.
You accomplish the following tasks:
Specify frequency-domain Bode magnitude and phase margin requirements.
Design an initial controller to meet the frequency-domain requirements.
Refine the initial controller design to limit the controller output signal.
The Simulink model, sldo_model2
, contains a
Controller
block, which is a PID Controller. This block
controls the output of the Plant
subsystem.
Using the Simulink
Control Design™ software, the model has been linearized at the operating point
specified in the model. The sldo_model2.mat
file contains a
preconfigured Control System Designer app session, saved after
linearizing the model. To learn more about linearizing Simulink models for control design, see Control System Design and Tuning (Simulink Control Design).
The Plant
subsystem is modeled as a second-order system with
delay. It contains Transfer Function and Transport Delay blocks.
To learn more about the blocks, see the Transfer Fcn and Transport Delay block reference pages.
The compensator you design must meet the following design requirements:
Bode lower magnitude bound of 0 in the frequency range 1e-3 to 1 rad/sec
Phase margin greater than 60 degrees
Controller output bounds in the range [-250 550]
To design a linear controller for a Simulink model, first configure a Control System Designer app session.
Open a Control System Designer app session for the linearized Simulink model.
Type the following command at the MATLAB® prompt:
controlSystemDesigner('sldo_model2.mat')
sldo_model2.mat
file contains a preconfigured
Control System Designer app session. This session was
saved after Simulink
Control Design software linearized sldo_model2
.
The Control System Designer app opens with the following plots:
Closed-loop step response of the system
Output of the Controller
block
To perform response optimization, in the Tuning
Methods drop-down list, select Optimization
Based Tuning
.
In the Response Optimization window, you can specify controller parameters and design requirements, and perform optimization.
To specify the controller parameters that are to be optimized:
In the Response Optimization window, select the Compensators tab.
The Compensators tab displays the following parameter settings:
Value — Current controller parameter value
Initial Guess — Initial controller parameter value
Minimum and Maximum — Controller parameter bounds
Typical Value — Scaling factor for the controller parameter
Note
Compensator elements or parameters cannot have uncertainty when used with frequency-domain based response optimization.
The controller parameters appear as poles and zeros in the Compensator elements column:
Gain — Overall gain of the controller
Real zeros — Zeros resulting from the differentiator and integrator
Real pole — Pole resulting from the low-pass filter of the differentiator
Tip
To view the structure of the Controller
block, right-click the block in the model, and select Mask > Look Under Mask.
Change the PID controller parameters to Simulink block mask parameters format.
Right-click the sldo_model2/Controller row, and select Parameterized format.
The controller parameters now display as Simulink block mask parameters, P
,
I
, and D
. For more
information, see Design Linear Controllers for Simulink Models. To learn more about mask parameters, see Mask Parameters.
Select the controller parameters to optimize.
In the Optimize column, select
P
, I
, and
D
.
Specify the Bode magnitude lower limit requirement:
In the Design requirements tab, click Add new design requirement. A New Design Requirement dialog box opens.
In the New Design Requirement dialog box, in the Design
requirement type drop-down list, select Bode
magnitude lower limit
.
In the Requirement for response drop-down list,
select Open Loop 1
.
Specify the Frequency range as
1e-3
to 1
.
Specify the Magnitude range as
0
to 0
.
Click OK.
The Bode lower magnitude limit is added to the Design requirements tab.
The Control System Designer app window updates to show the Bode plot in a Bode Editor. The design requirement is displayed as the black line segment.
Specify the phase margin requirement:
Right-click within the white space of the Bode plot, and select Design Requirements > New to open the New Design Requirement dialog box.
In the New Design Requirement dialog box, in the Design
requirement type drop-down list, select Gain
& phase margins
.
Select the Phase margin check box, and specify
the phase margin as 60
.
Click OK.
In the Response Optimization window, the Design requirements tab updates to display the phase margin requirement.
In the app, in the Bode Editor, the plot updates to display the phase margin requirement.
To design the controller with specified design requirements:
In the Response Optimization window, in the Optimization tab, click Start Optimization.
At every optimization iteration, the default optimization method,
Gradient descent
, reduces the distance
between the current response and the magnitude requirement line
segment by modifying the controller parameters. Simultaneously, the
software also computes the phase margin and reduces the distance
between the current response and the phase margin. To learn more
about the available optimization methods, click
Optimization Options, and then click
Help in the Options dialog box.
After the optimization completes, the Optimization tab displays the optimization iterations and status.
The status message, Successful termination
,
indicates that the optimization method found a solution that meets
the design requirements. For more information about the outputs
displayed in the Optimization progress table,
see Iterative Display.
Examine the controller parameters and the system response:
In the Compensator tab, view the optimized parameter values in the Value column.
Examine the system response on the following plots:
The Bode plot:
The magnitude of the system, displayed as the blue curve in the top plot, lies outside the yellow region. This indicates that the system has met the Bode magnitude requirement.
The phase plot displays the phase margin (P.M.) value of 86.1 degrees. This indicates that the system has met the phase margin design requirement of greater than 60 degrees.
Closed-loop step response of the system:
The plot shows that the closed-loop response of the system is stable. The system with the designed controller thus meets both the magnitude and phase margin requirements.
Output of the Controller
block:
The plot shows that the peak value of the controller output is about 1100, which is large and can damage the plant. To limit the controller output, apply lower and upper bounds on the signal, as specified in Design Requirements.
To tune the compensator parameters to meet the bounds on the controller output:
Add an upper-bound on the controller output:
In the controller output plot, right-click the white area, and select Design requirement > New.
In the New Design Requirement dialog box, in the Design
requirement type drop-down list, select
Upper time response bound
.
Specify the Time range as
0
to Inf
.
Specify the Amplitude range as
550
to 550
.
Click OK.
Add a lower-bound on the controller output:
In controller output plot, right-click the white area, and select Design requirement > New.
In the New Design Requirement dialog box, in the Design
requirement type drop-down list, select
Lower time response bound
.
Specify the Time range as
0
to Inf
.
Specify the Amplitude range as
-250
to -250
.
Click OK.
In the Response Optimization window, the Design requirements tab updates to display the bounds on the controller output.
The plot of the output of the Controller
block displays
the new design requirements.
Optimize the parameters to meet the design requirements on the controller output:
In the Response Optimization window, in the
Compensators tab, select the rows
containing P
, I
, and
D
, and click Use Value as Initial
Guess.
The values in the Initial Guess column update. When you run the optimization again, the optimization method uses the updated parameter values as the starting point for refining the values.
In the Optimization tab, click Start Optimization. At every optimization iteration, the optimization method reduces the distance between the current response and the upper and lower bounds on the signal. After the optimization completes, the Optimization tab displays the optimization iterations and status.
The status message, Successful termination
,
indicates that the optimization method found a solution that meets
the design requirements.
Examine the response plots.
The Bode plots show that after refining the design, the system continues to meet the magnitude and phase margin requirements specified in Design Requirements.
Verify that the closed-loop response of the system remains stable after refining the controller design.
The plot of the output of the Controller
block shows
that the output lies between 550 and -250, and thus meets the design
requirement on the bounds of the controller output.
Examine the parameter values of the optimized controller.
In the Response Optimization window, in the Compensators tab, view the optimized controller parameter values in the Value column.
Write the optimized controller parameter values to the
Controller
block in the Simulink model.
In the Control System Designer app, click Update Blocks.
Save a session with the optimized controller parameters.
In the Control System Designer app, select Save Session, and specify a name for the session.