• Keine Ergebnisse gefunden

6.2 Receding Horizon Controller

6.2.4 Class Discretization

The class Discretization can be used to create a class Discretization object which transforms a possibly continuous–time optimal control problem into a discrete–time one.

Although this class can also be used outside a class MPC object, the underlying problem still has to meet the specifications mentioned in Section 6.2.1.

Since we focus on solving a receding horizon control problem, we restate the discretization in this context, i.e. we transform the optimal control problem from Section 6.2.1 to a discrete problem of the following form:

6.2 Receding Horizon Controller 155 Findu[0,N1] = argmin

uN∈UN

JN(x0, uN) ST. JN(x0, uN) =

NX1

i=0

li(xuN(i, x0), uN(x0, i)) +F(xuN(N, x0))

xuN(i+ 1, x0) = f(xuN(i, x0), uN(x0, i)) ∀i∈ {0, . . . , N −1}

xuN(0, x0) = x0

xuN(i, x0) ∈ X ∀i∈ {0, . . . , N} uN(x0, i) ∈ U ∀i∈ {0, . . . , N −1}

Here, the functions li(·,·) correspond to the integrated Lagrangian term L(·,·) plus the summation term l(·,·) which is to be evaluated at the sampling instants, i.e.

li(x, u) :=

ti+1

Z

ti

L(x(τ), u(τ))dτ +l(x(ti), u(ti)). (6.1) The classes MPC and Discretization are handled separately since one class MPC object may use discretizations of several optimal control problems or several discretizations of one optimal control problem.

Within the class Discretizationwe use the recursive discretization technique with mul-tiple shooting nodes, see Sections 5.1.2 and 5.1.3. Hence, we obtain a discretized optimal control problem stated in Definition 5.7 which is given in standard form for nonlinear optimization

Minimize F(x) ∀x∈Rn ST. Gi(x) = 0, i∈ E

Hi(x)≥0, i∈ I with optimization variable

x:= u[0], . . . , u[N1], sx Remark 6.15

Even if the underlying dynamic within a classMPC object is already given in discrete–time, the discretization step is still necessary for memory allocation purposes.

6.2.4.1 Constructor / Destructor

Similar to a class MPC object, a class Discretization object is set up by calling btmb :: MPC2 ::D i s c r e t i z a t i o n * problem = new btmb :: MPC2 ::

D i s c r e t i z a t i o n ( o b j e c t _ o de mana ger , object_minimizer , object_model , length_horizon , infinity ) ;

Listing 6.23: Constructing call of a class Discretization object

Due to the separation of the discretization from the receding horizon control problem itself, the memory allocation necessary to handle variables and constraints is done within this object. Background for this is the consideration of a possibly continuous–time optimal control problem in a class MPC object and a discrete–time transformation within a class Discretization object. The resulting optimization problem is of the general form

Minimize F(x) ∀x∈Rn ST. Gi(x) = 0, i∈ E

Hi(x)≥0, i∈ I

Moreover, no computation of any kind is performed during this construction. In partic-ular, it does not make sense to calculate any trajectory within a class Discretization object itself since it cannot compute an optimal control sequence. This is the job of the supplied class MinProg object. Hence, a class Discretization object makes use of an classSqpFortran,SqpNagCorBtIpOpt object from one of the subclasses of classMinProg, see Section 6.3.1, to solve this task. To this end, it manages the necessary memory and provides procedures for the class MinProg object to compute the cost functional, its gra-dient and the restriction function as well as the Jacobian of the restriction function.

6.2.4.2 Initialization

The initialization method of the class Discretization object is implemented identically to a class MPCobject and supplied for external use of this class only.

6.2.4.3 Calculation

After creating and initializing a class Discretization object, the underlying minimiza-tion method from class MinProg can be called to solve the minimization problem. De-pending on the choice of the minimizer the procedure

problem - > calc ( x ) ;

Listing 6.24: Calculation call for a class Discretization object

executes this calculation. Here, a class Discretization object supplies the mentioned private methods for computing thecost functional, itsgradientand therestriction function as well as the Jacobian of the restriction function at the discretization instances to the class MinProg object. This defines the abstract minimization problem stated in Section 6.2.4.1.

For solving the abstact optimization problem, this results in the following:

A classDiscretizationobject defines the abstract optimization problem by setting func-tion pointers for the cost funcfunc-tion, restricfunc-tions and the dynamic of the control problem.

Then, the method calc triggers the minimization routine to start the optimization. In turn, the corresponding method of a class MinProg object calls a class IOdeManager ob-ject to evalutate all required functions. Then, the class IOdeManager object passes the function pointers and required evaluation data over to the differential equation solver which is a class OdeSolve object.

Once all evaluations are done, the minimization routine computes a new set of optimiza-tion variables. Since the implemented minimizaoptimiza-tion methods are iterative solvers, the predescribed process is repeated within every step until the minimization is terminated.

Remark 6.16

The advantage of this setting is not only the modularity of the considered components of the algorithm, but also the separation of the allocated memory. In particular, once all required objects are initialized, no further allocation or deletion of memory is triggered

— except for user modifications. This allows for an effective allocation of the memory regarding the subproblems and increases the performance of the computation.

6.2 Receding Horizon Controller 157

RHC

Discretization

Minimization Routine

Differential equation manager

Differential equation solver Differential equation configurator Abstract

Optimization Problem

defines

Cost function Gradient Restrictions

Jacobian

evaluates

solves

Figure 6.8: Definition of the abstract optimization problem

Here, the vector x represents the initial value for the state trajectory to be controlled.

This allows us to implement the receding horizon controller independently from the actual state and time of the plant. This is necessary since we cannot expect the optimal control to be computed instantaneously, i.e. we have to use some kind of external prediction to a future state when the computed control will be applied.

Actuator A Controller C Sensor S

T Optimization horizon

Sending measurement

Computational timeτC

τCmax

Sending new control sequence

Implementing new control sequence

Figure 6.9: Timescale of the closed–loop system

Remark 6.17

The timescale in Figure 6.9 indicates that the calculating procedure calc can/should be initialized with a prediction of the state vector x at the implementation time instant. In order to be applicable, this time instant should correspond to one of the sampling instants after the new control sequence has arrived at the actuator.

Remark 6.18

Since the receding horizon control algorithm relies on an input initial state, the usage of estimation procedures, sensor data or other input methods is possible and allows the software to be used as a black box within a control setting.

6.2.4.4 Other functions

The functions to compute the cost functional, its gradient and the restriction function as well as the Jacobian of the restriction function are for internal use of minimization object object_minimizer of class MinProg only. Calling these functions results in solving a series of differential equation problems using a class OdeSolve object. The sequencing of this series of calls is organized by class IOdeManager objects which we treat in the following Section 6.2.5. For further details of the interaction of the classes, see Section 6.2.4.3.