This example shows how to optimize controller parameters to meet step response design requirements using the Response Optimization tool. You specify the design requirements in a Check Step Response Characteristics block.
The Simulink® model
the nonlinear Water-Tank System plant and a PI controller in a single-loop
The 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.
The Water-Tank System is shown in the following figure.
Water enters the tank from the top at a rate proportional to the voltage, V, applied to the pump. The water leaves through an opening in the tank base at a rate that is proportional to the square root of the water height, H. The presence of the square root in the water flow rate results in a nonlinear plant.
The following table describes the variables, parameters, differential equations, states, inputs, and outputs of the Water-Tank System.
H is the height of water in the tank.
Vol is the volume of water in the tank.
V is the voltage applied to the pump.
A is the cross-sectional area of the tank.
b is a constant related to the flow rate into the tank.
a is a constant related to the flow rate out of the tank.
The height of water in the tank,
meet the following step response requirements:
Rise time less than 2.5 seconds
Settling time less than 20 seconds
Overshoot less than 5%
Open the Simulink model.
sys = 'watertank_stepinput'; open_system(sys);
Add a Check Step Response Characteristics block to the model.
In the Simulink model window, select View > Library Browser. Expand the Simulink Design Optimization node and select Signal Constraints.
Drag and drop the Check Step Response Characteristics block into the model window and connect the block to the output. The block is connected to the signal for which you want to specify design requirements.
Specify step response requirements.
Double-click the Check Step Response Characteristics block to open the Sink Block Parameters: Check Step Response Characteristics dialog box.
In Rise time (seconds), enter
In Settling time (seconds), enter
In % Overshoot, enter
In Initial value, enter
In Final value, enter
Instead of specifying time-domain requirements in the Check blocks, you can specify them in the Response Optimization tool without adding blocks. For an example that uses this approach, see Design Optimization to Track Reference Signal (GUI).
When you optimize the model response, the software modifies the design variable values to meet the design requirements. You specify which model parameters the software can modify.
Open a Response Optimization tool for the model.
In the Simulink model window, select Analysis > Response Optimization.
Alternatively, in the Sink Block Parameters dialog box, click Response Optimization.
The region bounded by black line segments in Time plot 1 shows the step response requirements that you specified in the Check Step Response Characteristics block.
Create a set of design variables.
In the Design Variables Set drop-down list, select New.
The Create Design Variables Set window shows model parameters that you can use as design variables and indicates their locations within the model.
Add parameters to the design variables set.
add the selected parameters.
The design variables list displays the following variable settings:
Variable — Variable name
Value — Current variable value
Minimum and Maximum — Variable bounds
Scale — Scaling factor for the variable
Limit the design variables to positive values. To
do so, enter
0 for the minimum value of each variable
in the corresponding Minimum field and press Enter on
Click OK. A new design variable
created and appears in the Data area of the Response
Optimization tool. You can click the variable to view its contents
in the Variable Preview area.
To view the current response of the model, click Plot Model Response.
The plot shows the model output, depicted by the blue line, lies outside the region of the specified step response.
The default optimization solver
Gradient descent (
fmincon) modifies the design variables
at each iteration so that the simulated response lies within the design
requirement line segments. For more information, see Selecting Optimization Methods and How the Optimization Algorithm Formulates Minimization Problems.
Optimization converged in the
Optimization Progress Report indicates that the optimization solver
found a solution that meets the design requirements within the tolerances
and parameter bounds. For more information about the outputs displayed
in the optimization, see Iterative Display in the Optimization Toolbox™ documentation.
Verify that the model output meets the step response requirements.
The plot displays the last five iterations. The final response using the optimized variable parameter appears as the thick blue line. The optimized response lies in the white region bounded by the design requirement line segments and thus meets the requirements.
View the optimized parameter values. Click
DesignVars in Model
Workspace and view the updated values in the Variable
The optimized values of the design variables are automatically updated in the Simulink model.
After you optimize the model response to meet design requirements, you can save the Response Optimization tool session which includes the optimized parameter values.
In the Response Optimization tool, in the Response Optimization tab, in the Save Session drop-down list, select Save to model workspace.
In the Save Session window, specify the session name in the Session field.
Tip To open the saved session, in the Response Optimization tool for the model, in the Open Session drop-down list, click the Open from model workspace option.