Design Optimization to Meet Step Response Requirements (Code)

This example shows how to programmatically optimize controller parameters to meet step response requirements using sdo.optimize.

Model Structure

The model sldo_model1 includes the following blocks:

  • Controller block, a PID controller, controls the output of the Plant subsystem.

  • Unit Step block applies a step input.

    You can also use other types of inputs, such as ramp, to optimize the response generated by such inputs.

  • Plant subsystem is a second-order system with delay. It contains Transfer Function and Transport Delay blocks.

Design Requirements

The plant output must meet the following step response requirements:

  • Rise time less than 2.5 seconds

  • Settling time less than 30 seconds

  • Overshoot less than 5%

Specify Step Response Requirements

  1. Open the Simulink® model.

    sys = 'sldo_model1';

  2. Log the model output signal.

    Design requirements require logged model signals. During optimization, the model is simulated using the current value of the model parameters and the logged signal is used to evaluate the design requirements.

    PlantOutput = Simulink.SimulationData.SignalLoggingInfo;
    PlantOutput.BlockPath               = [sys '/Plant'];
    PlantOutput.OutputPortIndex         = 1;
    PlantOutput.LoggingInfo.NameMode    = 1;
    PlantOutput.LoggingInfo.LoggingName = 'PlantOutput';
  3. Store the logging information.

    simulator = sdo.SimulationTest(sys);
    simulator.LoggingInfo.Signals = PlantOutput;

    simulator is a sdo.SimulationTest object that you also use later to simulate the model.

  4. Specify step response requirements.

    StepResp = sdo.requirements.StepResponseEnvelope;
    StepResp.RiseTime = 2.5;
    StepResp.SettlingTime = 30;
    StepResp.PercentOvershoot = 5;

    StepResp is a sdo.requirements.StepResponseEnvelope object.

Specify Design Variables

When you optimize the model response, the software modifies parameter (design variable) values to meet the design requirements.

  1. Select model parameters to optimize.

    p = sdo.getParameterFromModel(sys,{'Kp','Ki','Kd'});

    p is an array of 3 param.Continuous objects.

  2. To limit the parameters to positive values, set the minimum value of each parameter to 0.

    p(1).Minimum = 0;
    p(2).Minimum = 0;
    p(3).Minimum = 0;

Optimize Model Response

  1. Create a design function.

    evalDesign = @(p) sldo_model1_design(p,simulator,StepResp);

    evalDesign is an anonymous function that calls the cost function sldo_model1_design. The cost function simulates the model and evaluates the design requirements.

      Tip   Type edit sldo_model1_design to view this function.

  2. (Optional) Evaluate the current response.

    1. Compute the model response using the current values of the design variables.

      initDesign = evalDesign(p);

      During simulation, the Step Response block throws assertion warnings at the MATLAB® prompt which indicate that the requirements specified in the block are not satisfied.

    2. Examine the nonlinear inequality constraints.

      ans =

      Some Cleq values are positive, beyond the specified tolerance, indicating that the response using the current parameter values violates the design requirements.

  3. Specify optimization options.

    opt = sdo.OptimizeOptions;
    opt.MethodOptions.Algorithm = 'active-set';

    The software configures opt to use the default optimization method, fmincon. However, because the optimization problem specifies only constraints, you specify the Active Set algorithm for fmincon. The Active Set algorithm is good for solving feasibility (constraints only) optimization problems.

  4. Optimize the response.

    [pOpt,optInfo] = sdo.optimize(evalDesign,p,opt);

    At each optimization iteration, the software simulates the model, and the default optimization solver fmincon modifies the design variables to meet the design requirements. For more information, see Selecting Optimization Methods and How the Optimization Algorithm Formulates Minimization Problems.

    After the optimization completes, the command window displays the following results:

                                   max        Step-size    First-order 
     Iter F-count        f(x)   constraint                 optimality
        0      5            0        201.5
        1     12            0        167.5        0.687            0
        2     19            0       0.8462         1.22         5.86
        3     29            0       0.8169        0.133            0
        4     37            0       0.7819        0.115            0
        5     44            0        3.121        0.265         3.29
        6     52            0        3.328         2.92            0
        7     59            0       0.1413         1.26         2.81
        8     66            0      0.02418        0.443       0.0029
        9     73            0    8.125e-05       0.0563     1.03e-05
    Local minimum found that satisfies the constraints.
    Optimization completed because the objective function is non-decreasing in 
    feasible directions, to within the selected value of the function tolerance,
    and constraints are satisfied to within the selected value of the constraint tolerance.

    The message Local minimum found that satisfies the constraints indicates that the optimization solver found a solution that meets the design requirements within specified tolerances. For more information about the outputs displayed during the optimization, see Iterative Display in the Optimization Toolbox™ documentation.

  5. Examine the optimization termination information, contained in the optInfo output argument. This information helps you verify that the response meets the step response requirements.

    For example, check the following fields:

    • Cleq, which shows the optimized nonlinear inequality constraints.

      ans =

      All values satisfy Cleq0, within the optimization tolerances, which indicates that the step response requirements are satisfied.

    • exitflag, which identifies why the optimization terminated.

      The value is 1 which indicates that the solver found a solution which was less than the specified tolerances on the function value and constraint violations.

  6. View the optimized parameter values.

    pOpt(1,1) =
           Name: 'Kp'
          Value: 1.2364
        Minimum: 0
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    pOpt(2,1) =
           Name: 'Ki'
          Value: 0.3901
        Minimum: 0
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
    pOpt(3,1) =
           Name: 'Kd'
          Value: 2.5937
        Minimum: 0
        Maximum: Inf
           Free: 1
          Scale: 1
           Info: [1x1 struct]
  7. Simulate the model with the optimized values.

    1. Update optimized parameter values in the model.

    2. Simulate the model.


See Also

| | | | | |

Related Examples

Was this topic helpful?