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 watertank_stepinput
includes
the nonlinear Water-Tank System plant and a PI controller in a single-loop
feedback system.
The Step block applies a step input. You can also use other types of input, such as a ramp, to optimize the response generated by such inputs.
This figure shows the Water-Tank System.
Water enters the tank at the top at a rate proportional to the valve opening. The valve opening is 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.
Variables | 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. |
Parameters | 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. |
Differential equation | $$\frac{d}{dt}Vol=A\frac{dH}{dt}=bV-a\sqrt{H}$$ |
States | H |
Inputs | V |
Outputs | H |
The height of water in the tank, H
, must
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 2.5
.
In Settling time (seconds), enter 20
.
In % Overshoot, enter 5
.
In Initial value, enter 1
.
In Final value, enter 2
.
Click OK.
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 dialog box shows model parameters that you can use as design variables and indicates their locations within the model.
Note: In your application, if the model parameters you are interested in optimizing are not listed in the Create Design Variables Set dialog box, first specify these parameters as variables. See, Add Model Parameters as Variables for Optimization. |
Add parameters to the design variables set.
Select Ki
and Kp
, and
click
to
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
your keyboard.
Click OK. A new design variable DesignVars
is
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.
Click Optimize.
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.
The message 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
Preview area.
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. |