• No results found

2 Control Theory

2.3 Model Predictive Control

Instead of using simple independent PID-controllers for the multiple control objectives, it might be a better solution to use Model Predictive Control (MPC). One big advantage of using such a controller scheme, is that it can be hard to tune multiple PID-controllers with an assumption of independence. Since the directional controller in the PID case will be affected by tuning the WOB controller, tuning can be hard.

2.3.1 The General Principle of Model Predictive Controller

Implementing an MPC requires a reasonably accurate model and measurements to be able to predict the future outputs of the system. If this is the case, a Multiple-Input, Multiple-Output (MIMO)-system can be controlled with regards to constraints both on the input and the output. The inputs are calculated based on the predicted outputs. Using an MPC while having an inaccurate model can on the contrary make matters worse. The objectives of an MPC can therefore be summarized with the following points:

1. Prevent violation of input and output constraints

2. Drive some output variables to their optimal set points while maintaining other outputs within specified

3. Prevent excessive change of input variables.

4. Control as many process variables as possible when a sensor or actuator is not available.

A block diagram of how an MPC works can be seen in Figure 2.4. As seen, the MPC takes the measured output from the plant, as well as the reference values for the different states at a time stept. At this point, the MPC tests control actions by putting them into a linear model describing the plant. The model then outputs predicted states, which is then fed back to the optimizer that tries new control actions. Based on the optimization, the MPC generates manipulated variables as control inputs for the system, and the process repeats itself.

Figure 2.4: Block diagram better explaining the principle of an MPC.

2.3.2 Cost- and Reward Function in an MPC

The MPC uses a model of the system to make a prediction about future plant output behavior. To make sure the predicted outputs follow the desired reference, the MPC uses an optimizer. The MPC uses the plants model to predict the futureP steps, referred to as the prediction horizon. Simulations are done to find the best possible path closest to the reference. The simulations are done in a systematic order and the best path is chosen by maximizing a reward function or minimizing a cost function. An example of such a function is shown in equation (2.25)

J =

p

X

i=1

ek+1TQek+1+

p−1

X

i=0

∆uk+iTP∆uk+i, (2.25)

whereeis the error vector,∆uis the input increments andQandPare the weights on how much the cost function will take the states and inputs into consideration. By minimizing this particular cost function, the states of the system will tend to the reference and at the same time do this with small increments on input.

This is desirable if the goal is to for example control the heading of a commercial airplane to keep the ride as comfortable as possible. By minimizing the cost functionJ with subject to some constraints, the MPC makes sure that boundaries with regards to the states and inputs are not exceeded.

2.3.3 Weighing of the Q and P Matrices

TheQandPmatrices used in the cost function defined in equation (2.25) describes how much penalization one should give to an error in state and penalization of using higher inputs. Qis a positive-definite matrix, whilePis a positive semi-definite matrix. Usually, they are both diagonal matrices with positive diagonal elements, with the value of the diagonal elements representing how much to penalize the individual states or input and input changes. An example where one has three states given by the state vectorx= [p, q, r]T and possible inputsu= [u1, u2]with cost matrices

an error in stateqwill be penalized with a factor of2higher than statespandr, while a change in the input u2 will cost a factor of5more than an input change inu1.

2.3.4 Prediction and Control Horizon

The MPC predicts the states and the optimal sequence of inputs over the prediction horizon. At the current time step, the control algorithm only applies the first input from the calculated sequence and disregards the rest. After applying the input, the system is taken to its new state at a new time step. This state can deviate from the earlier prediction due to unknown disturbances. The same procedure as described above is done for the next time step, with a shifted prediction horizon. MPC is called an online control algorithm because of the calculations done at each time step in real-time.

The prediction horizon, as mentioned above, decides how far in the future the MPC predicts the states.

Choosing a large prediction horizon can result in a slow system due to limitations in computational power.

A large prediction horizonP means that calculations has to be done from the current steptuntilt=P. If a control input is needed within a timetd, the computation time of each step can not exceed this. Limiting the prediction horizon is therefore necessary, and should be evaluated based on thetdconstraint.

At the same time as the prediction horizon can not be too large, it should not be too small either, as it then will not be able to cover for the most significant dynamics of the system. An example is if an MPC is used for controlling the speed of a car, and the prediction horizonP only predicts2mahead of the car, a traffic light will not be taken account for before it is too late.

Choosing an excessively large control horizon can result in a very aggressive system. This is because the MPC then finds the most optimal inputs to get the current state to the end state as fast as possible. An example is if the end state of a car is100mahead of the current position state, using a large control horizon calculates the most optimal control inputs to get the car to this end state as fast as possible. Using a too low control horizon can also render the system too slow, as it now calculates the optimal inputs for the states that are close to the current state instead of accounting for the states further ahead. After the control horizon, the MPC holds a constant control input for the rest of the prediction. A visualization of how the prediction and control horizon affects the system can be seen in Figure 2.5.

Figure 2.5: Visualization of how the prediction and control horizon affects the response of the system [11].