MATLAB: How to bumplessly switch between two dynamic controllers in Simulink V8.4 (R2014b)

simulink

I want to use some switching logic to dynamically switch between two controllers to control a plant during simulation. A simplified model can be seen below.
I am facing the issue that, the control signal generated in this way has discontinuity at the switching time points (see the figure below). Is there a way to bumplessly switch between the controllers to eliminate the discontinuity?

Best Answer

The discontinuity is caused by the differences between the outputs of the two controllers. 
One way to achieve bumpless switching between the controllers is to let the controller, which is not being used currently, track the output of the other controller that is being used. This can be done by feeding back the error between the outputs of the two controllers (multiplied by a constant gain) to the input of the used controller.
One implementation is illustrated as follows. Notice that, for example, from t=0 to t=0.5, "Transfer Fcn2" is the controller being used and "Transfer Fcn3" is the one that is not being used. As a result, the error between the output of  "Transfer Fcn3" and the output of "Switch1" is non-zero and is used to drive "Transfer Fc3" such that it can track the output of "Transfer Fcn2". On the other hand, the output of "Transfer Fcn2" is the same as the output of "Switch1", therefore the error between these two signals is zero. 
The display of "Scope1" is as follows, where discontinuity is eliminated.
The attached model is created in Simulink V8.4 (R2014b).