The main purpose of the controllers designed here, is to find the operating strategy of the battery storage which leads to a minimum of the costs for the user.
The overall control system works in the following way: First, the controller provides the desired power to be transmitted/received from the grid \(P_{N}^{set}\). Second, the power inverter checks if the setpoint can be reached with the current PV generated power and battery SOC. In the case of a feasible setpoint we have \(P_{N} = P_{N}^{set}\), otherwise there will be a disagreement. Up to some extent, any disagreement will be compensated by adjusting the battery charge/discharge power though this is limited by the SOC. Reasons for infeasible setpoints are incomplete system information for the controller, no precise knowledge of the efficiencies or inaccurate predictions, to name a few.
3.2 Brute force control
The purpose of this controller is to determine the maximum achievable performance in terms of minimum costs for the user in the given setup. The strategy consists of evaluating all possible costs associated with all possible combinations of free variables. Since the controller has perfect system knowledge, it considers the full timescale of a year when computing the optimal battery charging strategy. There is no need for re-computation every \(T_{s}\) minutes (like in the linear optimization described below) although this could be done without major changes to the algorithm. To make this problem computationally tractable, the free variables are usually quantized. Nevertheless, the computational demands are high which makes this an off-line solution which cannot be implemented in a real-time control system.
For our implementation we assume both a quantization of the battery power
\(P_{B}\) and a discretization of the time
\(t\). The smallest increment of the battery power is denoted with
\(\Delta P_{B}\), the time increment (sample time) is
\(T_{s}\). The current time is then
\(t(k) = k T_{s}, k\in\{0,\ldots, T\}\). At any time instant, the battery power is a member of the set
$$\begin{aligned} \mathcal{P}_{B} = \bigl[-P_{B,d}^{max},\ldots,- \Delta P_{B}, 0, \Delta P_{B}, \ldots, P_{B,c}^{max} \bigr]. \end{aligned}$$
(14)
For simplicity of exposition, and without loss of generality, we assume in the following
\(P_{B,d}^{max} = P_{B,c}^{max} = P_{B}^{max}\) and define
\(m\in\mathbb{R}\) such that
\(P_{B}^{max} = m \Delta P_{B}\). The cardinality of
\(\mathcal{P}_{B}\) is then
\(p=2m+1\). A quantization of the battery power automatically leads to a quantization of the stored energy in the battery (e.g. the
\(SOC\)) which is given by the set
$$\begin{aligned} \mathcal{S} = [0,\ \Delta P_{B} T_{s},\ 2\Delta P_{B} T_{s}, \ldots,\ Q_{B}], \end{aligned}$$
(15)
with the total battery capacity
\(Q_{B}\) and cardinality
\(n=1+\frac {Q_{B}}{\Delta P_{B} T_{s}}\).
Knowing the PV generated power
\(P_{PV}\) and the load
\(P_{Load}\), for every element
\(P_{B} \in\mathcal{P}_{B}\) the power to the grid
\(P_{N}\) is well defined and can be calculated using Eqs. (
6a)–(
7d) presented in the last two subsections in Section
2.2. Multiplying with the known electricity costs we obtain the cost vector
$$\begin{aligned} c(k) = \bigl[ c_{m}(k) \ \ldots \ c_{1}(k) \ c_{0}(k) \ \ldots \ c_{-m}(k)\bigr] ^{T} \end{aligned}$$
(16)
which is of dimension
\(\mathbb{R}^{2m+1}\). The first and last element correspond to the costs when the battery is maximally discharged and charged, respectively. Based on the cost vector associated with the current time step, we define a cost matrix
$$\begin{aligned} \varGamma(k)\triangleq \begin{bmatrix} c_{0}(k) & c_{1}(k) & \ldots& c_{m}(k) & & \oslash\\ c_{-1}(k) & c_{0}(k) & & \vdots & \ddots & \vdots \\ c_{-2}(k) & c_{-1}(k) & \ddots& \vdots & & \oslash\\ \vdots & \ddots & & c_{0}(k) & & c_{m}(k) \\ c_{-m}(k) & \ddots & & c_{-1}(k) & \ddots & c_{m-1}(k)\\ \oslash & c_{-m}(k) & & & \ddots & \vdots\\ \oslash & \oslash & \ddots& & & \\ \oslash & \oslash & & c_{-m}(k) & & c_{0}(k) \end{bmatrix} \end{aligned}$$
(17)
which, column-by-column, consists of distinct fragments of the cost vector. The dimension is
\(\varGamma(k) \in\mathbb{R}^{n\times n}\). Every row and column of
\(\varGamma(k)\) is associated with a specific state of charge
\(SOC(k)\) and
\(SOC(k-1)\) respectively. For example, column
\(j\) is based on a state of charge
\((j-1)\Delta P_{B} T_{s}\) of the previous sample time. Then, every row in this column gives the cost when a specific battery power is applied. Moreover, costs in line
\(i\) are then the costs when charging/discharging the battery from a
\(SOC\)
\((j-1)\Delta P_{B} T_{s}\) to
\(SOC\)
\((i-1) P_{B} T_{s}\). Thus,
\(\varGamma(k)\) includes the full information of all possible combinations. Note that entries denoted with “⊘” are incompatible combinations, e.g. when the battery is (almost) empty, even when charging at maximum power, it will not be full within one sample interval
\(T_{s}\).
Consider a vector
\(\kappa(k-1)\in\mathbb{R}^{(1\times n)}\) which contains the (minimal) costs to reach all possible battery states
\(\mathcal{S}\) at time
\(k-1\) starting with an initial state of charge at time
\(k=0\). For the current time
\(k\), we can compute the total costs by
$$\begin{aligned} \hat{\kappa}(k) = \varGamma(k) + v \kappa(k-1),\quad\hat{\kappa}(k) \in \mathbb{R}^{(n\times n)} \end{aligned}$$
(18)
using
\(v= [ 1,\ldots,1 ] ^{T}\). To find the minimal costs, we need to find the minimum alongside the columns of this matrix. A minimum of row
\(i\) of
\(\hat{\kappa}(k)\) in column
\(j\) implies that state of charge
\((i-1)\Delta P_{B} T_{s}\) at time
\(k\) can be reached optimally via the state of charge
\((j-1)\Delta P_{B} T_{s}\) at time
\(k-1\) and a charging/discharging power associated with
\(\varGamma(k)_{(i,j)}\). An updated
\(\kappa(k)\) is thus given by the individual minimum of all rows of
\(\hat{\kappa}(k)\).
The iterative brute force algorithm can be stated now: Starting with
\(k=0\) and an initial state of charge, compute
\(c(k)\) (
16), construct
\(\varGamma(k)\) according to (
17), determine the total costs
\(\hat{\kappa}(k)\) using (
18). Determine the minimum of
\(\hat{\kappa}(k)\) for every row and use those values as for the next time step. Iterate
\(k\rightarrow(k+1)\) until a final time
\(k=T\). At the final time step, find the global minimal cost by the minimum in the vector
\(\kappa(T)\).
Note that this basic algorithm can be easily extended to consider \(SOC\) constraints in the form \(SOC^{min} \leq SOC(k) \leq SOC^{max}\) by adding a high penalty to the rows of \(\varGamma(k)\) which correspond to the prohibited \(SOC\) values.
3.3 Receeding horizon linear optimal control
The previously discussed brute force algorithm leads to the global optimal solution but is computationally intractable for real-time application. In this section, we formulate an optimization based controller which can find a solution very effectively but is only sub-optimal. Also this controller works on a discrete time basis with a sample time of
\(T_{s}\) and considers a window of 24 hours into the future where electricity prices, loads and PV production are assumed to be known (or predicted by a model). The choice of a 24-hour window seems reasonable, since this is the cycle where PV-power can be predicted with high accuracy and the electricity prices are known precisely. The result of the controller at time
\(k\) is an optimal schedule of the grid power for the next 24 hours,
$$\begin{aligned} \mathbf{P}_{\mathbf{N}}^{*}(k) = \bigl\{ P_{N}^{*}(k), P_{N}^{*}(k+1),\ldots,P_{N}^{*}(k+n_{p}) \bigr\} \end{aligned}$$
(19)
where
\(n_{p}\) denotes a prediction horizon. Then, the first element of this optimal sequence is forwarded to the power inverter
\(P_{N}^{set}=P_{N}^{*}(k)\) while the remaining sequence is neglected. At the next time-step
\(k\rightarrow k+1\) new information becomes available since the 24 hour window moves forwards and the subsequent optimization leads to an updated schedule (
19). This receeding horizon control strategy is well understood [
15] and used in many industrial applications [
16].
To formulate the cost function for minimization, we define the energy in a time interval
\(\Delta T\) by
$$\begin{aligned} E(k) = \int_{k\Delta T}^{(k+1)\Delta T} P(t)\, dt. \end{aligned}$$
(20)
Also consider the definition of the following variables: energy into the grid
\(E_{N+}\), energy from the grid
\(E_{N-}\), energy from battery (discharge)
\(E_{B+}\), energy to battery (charge)
\(E_{B-}\), intermediate energy into direction grid (see Fig.
3)
\(E_{x+}\), intermediate energy from grid
\(E_{x-}\), energy from PV generator to AC output of the inverter
\(E_{PV1}\), energy from PV generator to battery
\(E_{PV2}\).
Using those definitions, the following equations need to be satisfied at any time
\(k \in\{0\ldots T \}\):
$$\begin{aligned} E_{x+}(k) - E_{PV1}(k) \eta_{\mathit{PV}-\mathit{AC}} - E_{B+}(k) \eta_{B-AC} &=0 \end{aligned}$$
(21a)
$$\begin{aligned} E_{B-}(k) - E_{PV2}(k) \eta_{PV_{B}} - E_{x-}(k) \eta_{AC-B} &=0 \end{aligned}$$
(21b)
$$\begin{aligned} E_{x+}(k) - E_{x-}(k) - E_{N+}(k) + E_{N-}(k) &= E_{L}(k) \end{aligned}$$
(21c)
$$\begin{aligned} E_{PV1}(k) + E_{PV2}(k) &= E_{PV}(k) \end{aligned}$$
(21d)
which follow directly from the block diagram in Fig.
3.
The prediction of the battery state of charge is
$$\begin{aligned} SOC(k+1)=SOC(k) k_{Batt} + \frac{E_{B-}(k)-E_{B+}(k)}{Q_{B}} \end{aligned}$$
(22)
which can be used iteratively to compute predictions up to the desired prediction horizon.
There are several constraints on the variables which need to be fulfilled:
$$\begin{aligned} E_{N+} & \geq0 \end{aligned}$$
(23a)
$$\begin{aligned} E_{N-} & \geq0 \end{aligned}$$
(23b)
$$\begin{aligned} 0 \leq E_{B+}& \leq E_{B,d}^{max} \end{aligned}$$
(23c)
$$\begin{aligned} 0 \leq P_{B-}& \leq E_{B,c}^{max} \end{aligned}$$
(23d)
$$\begin{aligned} 0 \leq E_{x+}& \leq E_{I}^{max} \end{aligned}$$
(23e)
$$\begin{aligned} E_{x-}& \geq0 \end{aligned}$$
(23f)
$$\begin{aligned} E_{PV1}& \geq0 \end{aligned}$$
(23g)
$$\begin{aligned} E_{PV2}& \geq0 \end{aligned}$$
(23h)
$$\begin{aligned} SOC^{min} \leq SOC & \leq SOC^{max}. \end{aligned}$$
(23i)
Finally, we define a state vector
\(x\) and a gradient
\(f\) using (
9a)–(
9b)
$$\begin{aligned} x &= [E_{N-},\: E_{N+},\: E_{B-},\: E_{B+},\: E_{x-},\: E_{x+},\: E_{PV1},\: E_{PV2}]^{T} \\ f &= [ \mathbf{p},\: - \mathbf{y},\: 0,\: 0, \: 0, \:0, \:0, \:0]^{T} \end{aligned}$$
and state the optimization problem
$$\begin{aligned} \min_{x} & \ f^{T} x \\ &\ \mbox{s.t.}\ (21a)\mbox{--}(21d),\ (22),\ (23a)\mbox{--}(23i) \end{aligned}$$
(24)
in the form of a linear program [
17] which can be efficiently solved using standard tools.
The optimal solution
\(x^{*}(k)\) of the optimization problem contains the optimal schedule for the grid power (
19) and can be obtained by simply dividing the energies by the time interval
\(\Delta T\).
Also note that in the framework of a linear program, only
constant efficiencies can be considered. This means, the functions (
1a)–(
1d) need to be approximated with a value which reflects the average operating conditions of the power inverter. This is a crucial limitation as will be shown in the results section.