This example shows how to obtain bumpless transfer when switching a model predictive controller from manual to automatic operation or vice versa.
During startup of a manufacturing process, before switching to automatic control, operators adjust key actuators manually until the plant is near the desired operating point. If not done correctly, the transfer can cause a bump; that is, a large actuator movement.
In this example, you simulate a Simulink® model that contains a single-input single-output LTI plant and an MPC Controller block.
A model predictive controller monitors all known plant signals, even when it is not in control of the actuators. This monitoring improves its state estimates and allows a bumpless transfer to automatic operation.
In particular, it shows how the
ext.mv input signal to the MPC block can be used to keep the internal MPC state up to date when the operator or another controller is in control.
Define linear open-loop dynamic plant model.
num = [1 1]; den = [1 3 2 0.5]; sys = tf(num,den);
The plant is a stable single-input single-output system as seen in its step response.
Create an MPC controller, specifying the:
Ts = 0.5; p = 15; m = 2; mpcobj = mpc(sys,Ts,p,m);
-->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000.
Define constraints on the manipulated variable.
Specify the output tuning weight.
Open the Simulink model.
mdl = 'mpc_bumpless'; open_system(mdl)
In this model, the MPC Controller block is already configured for bumpless transfer using the following controller parameter settings.
The External manipulated variable parameter is selected. This parameter enables the use of external manipulated variables by adding the
ext.mv inport to the block.
The Use external signal to enable or disable optimization is selected. This parameter adds a
switch inport for switching off the controller optimization calculations.
To achieve bumpless transfer, the initial states of your plant and controller must be the same, which is the case for the plant and controller in this example. However, if the initial conditions for your system do not match, you can set the initial states of the controller to the plant initial states. To do so, extract the
mpcstate object from your controller and set the initial state of the plant.
stateobj = mpcstate(MPC1); stateobj.Plant = x0;
x0 is a vector of the initial plant states. Then, set the Initial Controller State parameter of the MPC Controller block to
To simulate switching between manual and automatic operation, the Switching block sends either 1 or 0 to control a switch. When it sends 0, the system is in automatic mode, and the output from the MPC Controller block goes to the plant. Otherwise, the system is in manual mode, and the signal from the Operator Commands block goes to the plant.
In both cases, the actual plant input feeds back to the controller
ext.mv inport, unless the plant input saturates at -1 or 1. The controller constantly monitors the plant output and updates its estimate of the plant state, even when in manual operation.
This model also shows the optimization switching option. When the system switches to manual operation, a nonzero signal enters the
switch inport of the controller block. The signal turns off the optimization calculations of the controller, which reduces computational effort.
Simulate closed-loop control of the linear plant model in Simulink.
-->Converting the "Model.Plant" property of "mpc" object to state-space. -->Converting model to discrete time. -->Assuming output disturbance added to measured output channel #1 is integrated white noise. -->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.
For the first 90 time units, the Switching Signal is 0, which makes the system operate in automatic mode. During this time, the controller smoothly drives the controlled plant output from its initial value, 0, to the desired reference value, -0.5.
The controller state estimator has zero initial conditions as a default, which is appropriate when this simulation begins. Thus, there is no bump at startup. In general, start the system running in manual mode long enough for the controller to acquire an accurate state estimate before switching to automatic mode.
At time 90, the Switching Signal changes to 1. This change switches the system to manual operation and sends the operator commands to the plant. Simultaneously, the nonzero signal entering the switch inport of the controller turns off the optimization calculations. While the optimization is turned off, the MPC Controller block passes the current
ext.mv signal to the Controller Output.
Once in manual mode, the operator commands set the manipulated variable to -0.5 for 10 time units, and then to 0. The Plant Output plot shows the open-loop response between times 90 and 180 when the controller is deactivated.
At time 180, the system switches back to automatic mode. As a result, the plant output returns to the reference value smoothly, and a similar smooth adjustment occurs in the controller output.
To examine the controller behavior without manipulated variable feedback, modify the model as follows:
Delete the signals entering the
ext.mv and switch
inports of the MPC Controller block.
Delete the Unit Delay block and the signal line entering its inport.
For the MPC Controller block, clear the External manipulated variable and Use external signal to enable or disable optimization parameters.
To perform these steps programmatically, use the following commands.
delete_line(mdl,'Switch/1','Unit Delay/1'); delete_line(mdl,'Unit Delay/1','MPC Controller/3'); delete_block([mdl '/Unit Delay']); delete_line(mdl,'Switching/1','MPC Controller/4'); set_param([mdl '/MPC Controller'],'mv_inport','off'); set_param([mdl '/MPC Controller'],'switch_inport','off');
Adjust the limits of the response plots, and simulate the model.
set_param([mdl '/Yplots'],'Ymin','-1.1~-0.1') set_param([mdl '/Yplots'],'Ymax','2~1.1') set_param([mdl '/MVplots'],'Ymin','-0.6~-0.5') set_param([mdl '/MVplots'],'Ymax','1.1~1.1') sim(mdl)
The behavior of the system is identical to the original case for the first 90 time units.
When the system switches to manual mode at time 90, the plant behavior is the same as before. However, the controller tries to hold the plant at the setpoint. So, its output increases and eventually saturates, as seen in Controller Output. Since the controller assumes that this output is going to the plant, its state estimates become inaccurate. Therefore, when the system switches back to automatic mode at time 180, there is a large bump in the Plant Output.
Such a bump creates large actuator movements within the plant. By smoothly transferring from manual to automatic operation, a model predictive controller eliminates such unwanted movements.