|On this page…|
If your plant is nonlinear, a controller designed to operate in a particular target region may perform poorly in other regions. The common way to compensate is to design multiple controllers, each intended for a particular combination of operating conditions. Switch between them in real-time as conditions change. Gain scheduling is a conventional example of this technique. The following example shows how to coordinate multiple model predictive controllers for this purpose.
The rest of this section is an illustrative example organized as follows:
A Two-Model Plant describes the example application involving two distinct operating conditions.
Animation of the Multi-Model Example explains how to simulate the plant.
Designing the Two Controllers shows how to obtain the controllers for each operating condition.
The figure below is a stop-action snapshot of the plant. It consists of two masses, M1 (upper) and M2 (lower). A spring connects M1 to a rigid wall and pulls it to the right. An applied force, shown as a red arrow, opposes the spring pulling M1 to the left.
In the above, mass M2 is uncontrollable. It responds solely to the spring pulling it to the left.
If the two masses collide, however, they stick together until a change in the applied force separates them.
The control objective is to make M1 track a reference signal. The blue triangle in the above indicates the desired location, which varies with time. At the instant shown, the desired numeric location is -5.
For an animated version of the plant, see Scheduling Controllers for a Plant with Multiple Operating PointsScheduling Controllers for a Plant with Multiple Operating Points.
In order to achieve its objective, the controller can adjust the applied force magnitude (the length of the red arrow). It receives continuous measurements of the M1 location. There is also a contact sensor to signal collisions. The M2 location is unmeasured.
If M1 were isolated, this would be a routine control problem. The challenge is that the relationship between the applied force and M1's movement changes dramatically when M2 attaches to M1.
Define the model.
Define the system parameters.
M1 = 1; % mass M2 = 5; % mass k1 = 1; % spring constant k2 = 0.1; % spring constant b1 = 0.3; % friction coefficient b2 = 0.8; % friction coefficient yeq1 = 10; % wall mount position yeq2 = -10; % wall mount position
Define a model of M1 when the masses are separated. Its states are the position and velocity of M1. Its inputs are the applied force, which will be the controller's manipulated variable (MV), and a spring constant calibration signal, which a measured disturbance (MD) input.
A1 = [0 1;-k1/M1 -b1/M1]; B1 = [0 0;-1/M1 k1*yeq1/M1]; C1 = [1 0]; D1 = [0 0]; sys1 = ss(A1,B1,C1,D1); sys1 = setmpcsignals(sys1,'MV',1,'MD',2);
The call to setmpcsignals specifies the input type for the two inputs.
Define another model (with the same input/output structure) to predict movement when the two masses are joined.
A2 = [0 1;-(k1+k2)/(M1+M2) -(b1+b2)/(M1+M2)]; B2 = [0 0;-1/(M1+M2) (k1*yeq1+k2*yeq2)/(M1+M2)]; C2 = [1 0]; D2 = [0 0]; sys2 = ss(A2,B2,C2,D2); sys2 = setmpcsignals(sys2,'MV',1,'MD',2);
Next, define controllers for each case. Both controllers employ a 0.2 second sampling period (Ts), a prediction horizon of p = 20, a control horizon of m = 1 and default values for all other controller parameters.
The only property that distinguishes the two controllers is the prediction model.
Ts = 0.2; p = 20; m = 1; MPC1 = mpc(sys1,Ts,p,m); % Controller for M1 detached from M2 MPC2 = mpc(sys2,Ts,p,m); % Controller for M1 connected to M2
The applied force also have the same constraints in each case. The lower bound for the applied force is zero because it cannot reverse direction. The maximum rate of change for the applied force is 1000 per second (increasing or decreasing).
MPC1.MV = struct('Min',0,'RateMin',-1e3,'RateMax',1e3); MPC2.MV = struct('Min',0,'RateMin',-1e3,'RateMax',1e3);
The following is the Simulink block diagram for this example.
The upper portion simulates the movement of the two masses, plots the signals as a function of time and animates the plant.
The lower part contains the following key elements:
A pulse generator that supplies the desired M1 position (the controller reference signal). The output of the pulse generator is a square wave that varies between —5 and 5, with a frequency of 0.015 per second.
Simulation of a contact sensor. When the two masses have the same position, the Compare to Constant block evaluates to true and the Add1 block converts this to a 2. Else, the output of Add1 is 1.
The Multiple MPC Controllers block, which has four inputs. The measured output (mo), reference (ref) and measured disturbance (md) inputs are as for the MPC Controller block. The distinctive feature of the Multiple MPC Controllers block is the switch input.
The figure below shows the Multiple MPC Controllers block mask for this example.
When the switch input is 1, the block automatically activates the first controller that is listed (MPC1), which is appropriate when the masses are separated. When the switch input is 2, the block automatically enables the second controller (MPC2).
Simulate the controller performance using Simulink commands.
Tstop = 100; % Simulation time y1initial = 0; % Initial M1 and M2 Positions y2initial = 10; open('mpc_switching'); sim('mpc_switching',Tstop);
The figure below shows the signals scope output.
In the upper plot, the cyan curve is the desired position. It starts at -5. The M1 position (yellow) starts at 0. Under the control of MPC1, M1 moves rapidly towards the desired position. M2 (magenta) starts at 10 and begins moving in the same direction.
At about t = 13 seconds, M2 collides with M1. The switching signal (lower plot) changes at this instant from 1 to 2, so MPC2 takes over.
The completely inelastic collision moves M1 away from its desired position and M2 remains joined to M1. Controller MPC2 adjusts the applied force (middle plot) so M1 quickly returns to the desired position.
When the desired position changes step-wise to 5, the two masses separate briefly, with the controller switching to MPC1 appropriately. But, for the most part, the two masses move together and settle rapidly at the desired location. The transition back to —5 is equally well behaved.
Suppose we force MPC2 to operate under all conditions.
The figure below shows the result.
When the masses are disconnected, as at the start, MPC2 applies excessive force and then over-compensates, resulting in oscillatory behavior. Once the masses join, the move more smoothly, as would be expected.
The last transition causes especially severe oscillations. The masses collide frequently and M1 never reaches the desired position.
If MPC1 is in charge exclusively, the masses move sluggishly and fail to settle at the desired position before the next transition occurs. For more information, see the Scheduling Controllers for a Plant with Multiple Operating PointsScheduling Controllers for a Plant with Multiple Operating Points.
In this application, at least, two controllers are, indeed, better than one.