tune gain-凯发k8网页登录
this example shows how to use the closed-loop pid autotuner block to tune a gain-scheduled controller in one simulation.
water-tank system model
this example uses a gain-scheduled controller to control the water level of a nonlinear water-tank system plant. the water-tank system plant is originally controlled by a single pi controller in the watertank
simulink® model. for more details on the nonlinear water-tank system plant, see watertank simulink model.
the following sections describe how to modify the watertank
model for tuning and validating gain-scheduled controller. alternatively, use the watertank_gainscheduledcontrol
model provided with this example.
connect closed-loop pid autotuner block with plant and controller
insert the closed-loop pid autotuner block between the controller and plant as shown in the following diagram. the start/stop signal starts and stops the closed-loop experiment. when no experiment is running, the closed-loop pid autotuner block behaves like a unity gain block, where the u signal passes directly to u δu.
connect blocks to store tuned gains
to create a gain schedule, the autotuned gains are recorded at each operating point. in this example, a triggered subsystem is used to write the reference heights and controller gains to the workspace upon falling edges of the autotuner start/stop signal. simulating this model produces an array of tuned gains and breakpoints for easy use with dynamic lookup tables to test the controller.
validate performance of gain-scheduled controller
after you obtain a set of breakpoints and tuned gains, test the tuned gain-scheduled controller with the water-tank system plant. to do so, remove the autotuner block, change the source of the pid controller block to external, and insert blocks as shown in the diagram.
integrate both tuning and testing in example model
in this example, a gain-scheduled controller is tuned using the closed-loop pid autotuner block and its performance is then tested in the same model. the example model uses a variant subsystem to organize the tuning and testing workflows.
to switch between tuning and testing modes, double-click the variant subsystem block.
tune controller at single operating point
before tuning the gain-scheduled controller at multiple operating points, tuning at single operating point helps you configure the closed-loop pid autotuner block. open the example model watertank_gainscheduledcontrol
with controller gains used by the watertank
simulink model.
mdl = 'watertank_gainscheduledcontrol'; kp = 1.599340; ki = 0.079967; open_system(mdl); set_param([mdl,'/variant subsystem'],'simmode','tuning');
configure closed-loop pid autotuner block
after connecting the closed-loop pid autotuner block with the water-tank system plant model and block, use the block parameters to specify tuning and experiment settings. this example uses the same design requirements found in the example . these design requirements are in the form of closed-loop step response characteristics.
overshoot less than 5%
rise time less than 5 seconds
to tune the pid controller to meet the above design requirements, parameters of the closed-loop pid autotuner block are pre-populated. the tuning tab has three main tuning settings.
target bandwidth — determines how fast you want the controller to respond. the target bandwidth is roughly 2/desired rise time. for a desired rise time of 4 seconds, set target bandwidth = 2/4 = 0.5 rad/s.
target phase margin — determines how robust you want the controller to be. in this example, start with the default value of 60 degrees.
experiment sample time — sample time for the experiment performed by the autotuner block. use the recommended 0.02/bandwidth for sample time = 0.02/0.5 = 0.04s.
the experiment tab has three main experiment settings.
plant type — specifies whether the plant is asymptotically stable or integrating. in this example, the water-tank system plant is integrating.
plant sign — specifies whether the plant has a positive or negative sign. the plant sign is positive if a positive change in the plant input at the nominal operating point results in a positive change in the plant output when the plant reaches a new steady state. in this example, the water-tank system plant has a positive plant sign.
sine amplitudes — specifies amplitudes of the injected sine wave perturbations. in this example, specify a sine amplitude of 0.3.
simulate at one operating point
start the experiment at 140 seconds to ensure that the water level has reached steady-state . the recommended experiment duration is 200/bandwidth seconds = 200/0.4 = 500s. with start time of 140 seconds, the stop time is 640 seconds. the simulation stop time is further increased to capture the full experiment.
set_param([mdl,'/variant subsystem/tuning/closed-loop pid autotuner1'],'targetpm','60'); set_param([mdl,'/signal editor'],'activescenario','tuningsignal_onepoint'); simout = sim(mdl,'stoptime','800'); simout.kp_tuned
ans = 1.8254
simout.ki_tuned
ans = 0.2037
in the watertank
simulink model, initial pi controller gains are kp = 1.599340 and ki = 0.079967. after tuning, the controller gains are kp = 1.82567 and ki = 0.20373.
check tuning result and adjust autotuning parameters
replace controller gains with the new autotuned gains and validate the design requirements.
kp = simout.kp_tuned; ki = simout.ki_tuned; simout = sim(mdl,'stoptime','100'); figure; plot(simout.scopedatags.time,simout.scopedatags.signals.values); grid on title('step response of controller tuned with 60-degree target phase margin');
stepperformance_onepoint = stepinfo(simout.scopedatags.signals.values(:), ...
simout.scopedatags.time(:),10,1)
stepperformance_onepoint = struct with fields:
risetime: 3.6254
transienttime: 22.5227
settlingtime: 22.5227
settlingmin: 9.1086
settlingmax: 10.7822
overshoot: 8.6912
undershoot: 0
peak: 9.7822
peaktime: 9.5500
the step response has a rise time of 3.6251 seconds and overshoot of 8.6895%. the overshoot is larger than desired; increase target phase margin to 75 degrees to improve the closed-loop transient response.
set_param([mdl,'/variant subsystem/tuning/closed-loop pid autotuner1'],'targetpm','75');
examine the simulation result. the system is at steady-state when experiment starts and returns to steady-state after tuning is completed. as an indication of controller tuning performance, the closed-loop pid autotuner block reaches 100% convergence level sooner than the recommended 500 seconds. as a result, reduce experiment duration to 300 seconds, meaning a stop time of 440 seconds. accordingly, decrease the simulation stop time from 800 seconds to 500 seconds.
kp = 1.599340; ki = 0.079967; set_param([mdl,'/signal editor'],'activescenario','tuningsignal_onepointadjusted'); simout = sim(mdl,'stoptime','500'); simout.kp_tuned
ans = 1.9348
simout.ki_tuned
ans = 0.1142
simulating with new experiment parameters produces tuned gains of kp = 1.93514 and ki = 0.11415. examine the step response again using gains tuned with the increased target phase margin value.
kp = simout.kp_tuned; ki = simout.ki_tuned; simout = sim(mdl,'stoptime','100'); figure; plot(simout.scopedatags.time,simout.scopedatags.signals.values); grid on title('step response of controller tuned with 75-degree target phase margin');
stepperformance_onepointadjusted = stepinfo(simout.scopedatags.signals.values(:), ...
simout.scopedatags.time(:),10,1)
stepperformance_onepointadjusted = struct with fields:
risetime: 4.1402
transienttime: 21.4152
settlingtime: 21.4152
settlingmin: 9.1041
settlingmax: 10.2832
overshoot: 3.1463
undershoot: 0
peak: 9.2832
peaktime: 12.1100
the step response has a rise time of 4.1398 seconds and overshoot of 3.1438%, both of which meet the design requirements.
simulate the model with tuned gains for multiple operating points = [5, 10, 15, 20].
set_param([mdl,'/signal editor'],'activescenario','tuningsignal_singlepid'); simout_single = sim(mdl,'stoptime','2400');
tune gain-scheduled controller at multiple operating points
the set of tuned gains produces a desired response. you can now perform tuning at multiple operating points to create a gain-scheduled controller.
create input tuning signal
the operating range of scheduling variable from 1 to 20 is covered by the operating points for autotuning. in this example, the gain-scheduled controller gains are tuned at four operating points with = [5, 10, 15, 20]. to tune at multiple operating points, use the block to create the reference and autotuner start/stop signal
simulate multiple operating points
using the input signal, simulate the watertank_gainscheduledcontrol
model for the entire length of the autotuning process. at the end of simulation, save both tuned gains and breakpoints as vectors in the matlab® workspace.
kp = 1.599340; ki = 0.079967; set_param([mdl,'/signal editor'],'activescenario','tuningsignal'); simout = sim(mdl,'stoptime','2400'); kp_tuned = simout.kp_tuned
kp_tuned = 4×1
1.9279
1.9327
1.9358
1.9380
ki_tuned = simout.ki_tuned
ki_tuned = 4×1
0.1277
0.1183
0.1122
0.1078
breakpoints = simout.breakpoints
breakpoints = 4×1
5
10
15
20
performance improvements of gain-scheduled controller
to examine the performance of the gain-scheduled controller, set the variant subsystem to testing mode and simulate the model.
set_param([mdl,'/variant subsystem'],'simmode','testing'); simout_gs = sim(mdl,'stoptime','2400');
using the gain-scheduled controller, step responses of the water level in the water-tank system plant are much faster and have less overshoot than the untuned controller used in watertank simulink model.
use the comparecontrollers_watertank
script to compute the step-response characteristics for the pid controller tuned at = 10 and the gain-scheduled controller. the script generates two tables, which contain the rise time (in seconds) and percentage overshoot for the gain-scheduled controller and a single set of controller gains.
comparecontrollers_watertank
risetime=2×4 table
h = 1 to 5 h = 5 to 10 h = 10 to 15 h = 15 to 20
__________ ___________ ____________ ____________
single pid 4.6725 3.7822 3.7154 3.683
gain-scheduled 4.5097 3.7557 3.7275 3.7208
overshoot=2×4 table
h = 1 to 5 h = 5 to 10 h = 10 to 15 h = 15 to 20
__________ ___________ ____________ ____________
single pid 0.69826 5.258 5.8907 6.2264
gain-scheduled 1.5212 5.5034 5.7731 5.8532
compared to a single set of gains tuned at one operating point, the gain-scheduled controller:
leads to a larger overshoot and a faster rise time for the step = 1 to 5.
achieves similar performance for the step = 5 to 10 because the single set of gains were tuned at = 10.
leads to smaller overshoots and slower rise times for the steps = 10 to 15 and = 15 to 20.
this workflow is useful when you want to tune a gain-scheduled controller using the closed-loop pid autotuner block.
close the model.
close_system(mdl,0);
see also
closed-loop pid autotuner | | | |