Documentation

Design Optimization-Based PID Controller for Linearized Simulink Model (GUI)

This example shows how to perform optimization-based control design in the Control System Designer 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.

Model Structure

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.

Design Requirements

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]

Configure the Control System Designer App for Optimization-Based Control Design

To design a linear controller for a Simulink model, first configure a Control System Designer app session.

  1. 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

  2. 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.

Design an Initial PID Controller to Meet Bode Magnitude and Phase Margins Requirements

Specify the Controller Parameters

To specify the controller parameters that are to be optimized:

  1. 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.

  2. 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 (Simulink).

  3. Select the controller parameters to optimize.

    In the Optimize column, select P, I, and D.

Specify Bode Magnitude and Phase Margin Design Requirements

Specify the Bode magnitude lower limit requirement:

  1. In the Design requirements tab, click Add new design requirement. A New Design Requirement dialog box opens.

  2. In the New Design Requirement dialog box, in the Design requirement type drop-down list, select Bode magnitude lower limit.

  3. In the Requirement for response drop-down list, select Open Loop 1.

  4. Specify the Frequency range as 1e-3 to 1.

  5. Specify the Magnitude range as 0 to 0.

  6. 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:

  1. Right-click within the white space of the Bode plot, and select Design Requirements > New to open the New Design Requirement dialog box.

  2. In the New Design Requirement dialog box, in the Design requirement type drop-down list, select Gain & phase margins.

  3. Select the Phase margin check box, and specify the phase margin as 60.

  4. 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.

Design the Controller

To design the controller with specified design requirements:

  1. 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 (Optimization Toolbox).

  2. Examine the controller parameters and the system response:

    1. In the Compensator tab, view the optimized parameter values in the Value column.

    2. 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.

Refine the Controller Design to Meet Controller Output Bounds

To tune the compensator parameters to meet the bounds on the controller output:

  1. Add an upper-bound on the controller output:

    1. In the controller output plot, right-click the white area, and select Design requirement > New.

    2. In the New Design Requirement dialog box, in the Design requirement type drop-down list, select Upper time response bound.

    3. Specify the Time range as 0 to Inf.

    4. Specify the Amplitude range as 550 to 550.

    5. Click OK.

  2. Add a lower-bound on the controller output:

    1. In controller output plot, right-click the white area, and select Design requirement > New.

    2. In the New Design Requirement dialog box, in the Design requirement type drop-down list, select Lower time response bound.

    3. Specify the Time range as 0 to Inf.

    4. Specify the Amplitude range as -250 to -250.

    5. 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.

  3. Optimize the parameters to meet the design requirements on the controller output:

    1. 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.

    2. 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.

  4. 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.

  5. 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.

  6. Write the optimized controller parameter values to the Controller block in the Simulink model.

    In the Control System Designer app, click Update Blocks.

  7. Save a session with the optimized controller parameters.

    In the Control System Designer app, select Save Session, and specify a name for the session.

Related Topics

Was this topic helpful?