| Contents | Index |
This example shows how to optimize controller parameters to meet step response requirements using sdo.optimize. You programmatically modify the default step response requirements specified in a Check Step Response Characteristics block.
The model sldo_model1_stepblk includes the following blocks:

Controller block, which is a PID controller. This block controls the output of the Plant subsystem.
Unit Step block applies a step input and produces the model output that should meet step response requirements.
You can also use other types of inputs, such as ramp, to optimize the response to meet step response requirements generated by such inputs.
Plant subsystem is a second-order system with delay. It contains Transfer Function and Transport Delay blocks.

The Step Response block is a Check Step Response Characteristics block from the Simulink Design Optimization Signal Constraints library with default step response 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%
Open Simulink model.
sys = 'sldo_model1_stepblk'; open_system(sys);

To learn more about the model, see Model Structure.
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 = 'sldo_model1_stepblk/Plant'; PlantOutput.OutputPortIndex = 1; PlantOutput.LoggingInfo.NameMode = 1; PlantOutput.LoggingInfo.LoggingName = 'PlantOutput';
Store the logging information.
simulator = sdo.SimulationTest('sldo_model1_stepblk'); simulator.LoggingInfo.Signals = PlantOutput;
simulator is a sdo.SimulationTest object that you also use later to simulate the model.
Get the default requirements specified in Step Response block.
allBlkReq = getbounds('sldo_model1_stepblk/Step Response'); StepResp = allBlkReq{1};
StepResp is a sdo.requirements.StepResponseEnvelope object.
Note You do not need Check blocks in the Simulink model to specify design requirements. You can specify requirements directly using requirement objects. |
Specify step response requirements.
StepResp.RiseTime = 2.5; StepResp.SettlingTime = 30; StepResp.PercentOvershoot = 5;
Changing the values does not update them in the block.
Before you begin this task, specify the design requirements as described in Specify Step Response Requirements.
When you optimize the model response, the software modifies parameter (design variable) values to meet the design requirements.
Select model parameters to optimize.
p = sdo.getParameterFromModel('sldo_model1_stepblk',{'Kp','Ki','Kd'});
p is an array of 3 param.Continuous objects.
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;
Before you begin this task, you must have already specified the design requirements and design variables as described in Specify Step Response Requirements and Specify Design Variables, respectively.
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.
(Optional) Evaluate the current response.
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.
Examine the nonlinear inequality constraints.
initDesign.Cleq
ans =
-0.2578
-0.4968
-0.5028
-1.0000
0.7297
0.5095
0.4964
202.3590Some Cleq values are positive which indicates that the response using the current parameter values does not satisfy the design requirements.
Specify Simulink model to optimize.
opt = sdo.OptimizeOptions; opt.OptimizedModel = 'sldo_model1_stepblk';
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:
Iter F-count f(x) constraint Steplength derivative optimality Procedure
0 5 0 202.4
1 14 0 200.7 0.341 0 0 infeasible
2 21 0 105 2.24 0 7.51
3 29 0 117.2 1.57 0 0.521
4 36 0 79 3.34 0 0 infeasible
5 43 0 27.55 0.632 0 0.152
6 50 0 50.85 1.06 0 1.14
7 57 0 11.58 3.52 0 9.5
8 64 0 3.124 2.48 0 13.9
9 71 0 0.3022 1.57 0 2.91
10 78 0 0.1289 0.715 0 7.12
11 85 0 0.02747 0.489 0 0.199
12 92 0 0.005082 0.184 0 0.0389
13 99 0 0.0004325 0.0513 0 0.0092 Hessian modified
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 the parameter bounds. For more information about the outputs displayed during the optimization, see Iterative Display in the Optimization Toolbox documentation.
Examine the optimization termination information. This information helps you verify that the response meets the step response requirements.
optInfo
For example, check the following fields:
Cleq, which shows the optimized nonlinear inequality constraints.
optInfo.Cleq
ans =
0.0001
-0.0099
-0.0099
-1.0000
0.0004
-0.0100
-0.0101
-0.1997All values are negative 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.
View the optimized parameter values.
pOpt
pOpt(1,1) =
Name: 'Kp'
Value: 1.2425
Minimum: 0
Maximum: Inf
Free: 1
Scale: 1
Info: [1x1 struct]
pOpt(2,1) =
Name: 'Ki'
Value: 0.4037
Minimum: 0
Maximum: Inf
Free: 1
Scale: 1
Info: [1x1 struct]
pOpt(3,1) =
Name: 'Kd'
Value: 2.6710
Minimum: 0
Maximum: Inf
Free: 1
Scale: 1
Info: [1x1 struct]
Simulate the model with the optimized values.
Update optimized parameter values in the model.
sdo.setValueInModel('sldo_model1_stepblk',pOpt);
Simulate the model.
sim('sldo_model1_stepblk')Although the requirements are satisfied, the model throws assertion warnings at the MATLAB prompt because the signal does not lies within the assertion tolerance which are tighter than the optimization tolerances. Try the following to eliminate the warnings:
Continue to search for solutions that are typically located further inside the constraint region.
opt.StopIfFeasible = 'off'
Increase the optimization solver tolerance.
opt.MethodOptions.TolX = 1.5e-3
![]() | Optimize Controller Parameters to Meet Step Response Requirements (GUI) | Optimize Controller Parameters to Track Reference Signal (GUI) | ![]() |

Learn more about resources for designing, testing, and implementing control systems.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |