Due to the limited resources of embedded microprocessors, it is crucial to reduce the code-size of our proposed embedded software architecture. Hence, we dramatically modified the baseline software designs that have been executed on desktop computer, so that they would fit into the highly constrained embedded microprocessor. In this case, we created the codes to be leaner and simpler in such a way as to fit into the available program memory of the embedded microprocessor, without impacting the basic structure or the functionalities of the PB-EKF-MPC algorithm. Many design decisions for software optimization involved reducing the computation workload of the original baseline software design which in turn facilitated the creation of lean and simpler codes for our proposed embedded software architecture. These design decisions and the corresponding efficient algorithm/code creations are detailed throughout this section.
Since PB-MPC incorporates integral action, PB-MPC operates on the change-in (Δ) state from the current-state to the next-state and computes the change-in (Δ) current, whereas the EKF operates on the current-state. This change-in (Δ) current is added to the control current to produce a change-in (Δ) state for the PB-MPC with the aid of EKF. Then, the PB-MPC outputs an updated control reference signal (), which meets the constraints and φs-e to prevent aging and battery degradation, while satisfying the required performance. In this work, both MPC and EKF use a physics-based model, and can thus be called PB-MPC and PB-EKF.
3.1. EKF
The software functional flow of the PB-EKF algorithm comprises seven stages, and is shown in
Figure 3, along with Equations (a)–(i) utilized for various stages. In Stage 1, the EKF is initialized with a state of charge (SOC) of 0.6 and
Ns is the number of states. With the EKF, the SOC is computed from the current state and the state update, where initial value serves as the current state of the SOC computation. Since the SOC cannot be physically measured, the initial value is often set to be 40–60% charged, to reduce the time taken for the observer to compute the correct SOC value [
2]. In this case, the initial value of 60% = 0.6 performs well for the driving profile [
13] utilized for our experiments in
Section 4.
In Stage 2, the EKF computes the state matrix (
A) (in Equation (a) in
Figure 3). The state matrix (
A) is built using look-up-tables (LUTs) and 2D-interpolation based on the temperature and SOC values. The
A matrix is computed using the following Equation (2):
In Equation (2), the α and β are the weight values based on the temperature and SOC, respectively; Low and High are the SOC floating point values; and
i is the state. The original LUT for
A matrix (
BigA) was a 3D matrix, composed of two temperature values (0 and 25 °C), 20 integer representation of state of charge (SOC) values, and system state values (from 0–4 for the five states), which led to a
2X20X5 matrix. For our software design, we split the LUT into two
20X5 matrices (
BigA0 for 0 °C and
BigA1 for 25 °C). By rearranging the large 3D LUT into two smaller LUTs, we made it easier for our embedded software to store the matrices and reduce the number of LUT calls. The LUTs are further arranged by integer SOC values, derived from linear interpolation. The “High” and “Low” values bound the decimal value and are contiguously located in the LUT. In Equation (2), High and Low are fixed single values, where the decimal values are determined by the weights, α and β, respectively. Hence, the final state (
A) matrix size depends only on the number of states (
i). Since there are only five states, the final state (
A) matrix becomes a
5X5 matrix. The diagonal nature of the state matrix allows
A to be stored as a vector of diagonal values
A[i]. The computation workload and the storage requirements are reduced by modifying and storing the
A matrix as a five-element vector. The matrix (
B) (in Equation (a),
Figure 3) is a constant vector comprising values of all ones.
For the PB-EKF, the control signal (
icell) is denoted by
uk, state is denoted by
xk, and the error covariance and the uncertainty of the current sensors are denoted by σ
x,k and σ
w, respectively. Once the state matrices are computed, the PB-EKF performs the state (
xk), (i.e., Equation (3) corresponding to Equation (a) in
Figure 3) and the error covariance time update (σ
x,k), (i.e., Equation (4) corresponding to Equation (b) in
Figure 3) based on the previous state, control signal, and error covariance matrix, using the following Algorithm 1:
Algorithm 1: Compute state and error covariance time update |
|
In Stage 3, in order to compute the output prediction, the PB-EKF initially estimates the SOC based on the state time update (
xk), and the lithium concentration in the solid surface at the negative electrode (
). For our software design, we use the cell model parameters from the Doyle cell parameters in [
2]. These parameters are held constant for the temperature range (i.e., 0 to 25 °C) used for our software design, allowing the combination of constants and reducing the SOC computation to a linear equation. As a result, our output prediction computation is performed using Algorithm 2. Investigation and discussion on how these parameters would change with varying temperature ranges is beyond the scope of our work, but can be found in [
2].
Algorithm 2: Compute SOC and lithium concentration based on the state time update |
|
Next step of PB-EKF (in Stage 3) is to compute the standard output function (
yvar,k) using Equation (5) (corresponding to the Equation (c) in
Figure 3). In this case, the output matrices (
C and
D), derived from the DRA process (as in [
12]), are entirely linear; thus, EKF requires extra steps to compute the non-linear output predictions. The
C and
D matrices are computed using LUTs and 2D interpolation, similar to
A matrix; however, the internal organization of LUTs are different. The weight values α and β and input indices are updated based on the new SOC value. The size of matrix
C is equal to
number-of-states multiplied by
number-of-outputs, where the outputs depend on the number of electrochemical reactions. In this research work, C is a
5X19 matrix. The
D matrix is a vector, where length is equal to
number-of-outputs, i.e., 19 in this work. These 19 outputs comprise non-linear correction values, which include in sequence: 4 values for concentration in the electrolyte (
); 3 values for potential in the electrolyte (
); 4 values for the solid surface concentration (
); 4 values for the electric potential in the solid (
); and 4 values for the flux (
). Our output function is computed using Algorithm 3:
Algorithm 3: Compute the standard output function, yvar,k |
|
As depicted in
Figure 3, each element of
yvar,k represents the debiased value of an electrochemical reaction at a given position. The debiased value does not represent a physical reaction until non-linear corrections are performed. Hence, in Stage 4, once the non-linear corrections are performed on the five states (as detailed in
Figure 3), the output voltage (
yvolt,k) is computed using Equation (6) as follows:
The above parameters,
,
, and
, are the resistances in the film multiplied by Faraday’s constant and the cell series resistance, and are pre-computed constants, applicable to the temperature range and SOC for the physics based (PB) model [
2]. The terms
and
are outcomes of the non-linear corrections, and are computed using the following Equations (7) and (8).
where,
,
,
,
,
,
.
The final term () in Equation (6), is the open circuit voltage correction based on the SOC. This is also computed using the LUTs, linear interpolation, and weight factor.
In Stage 5, since the output equation (
yvolt,k) (i.e., Equation (9) corresponding to the Equation (d) in
Figure 3) is non-linear, new linearized
C and
D matrices (
and
) are created to facilitate the Kalman Gain computation (i.e., the next step of the PB-EKF) as well as the PB-MPC algorithm. These new output matrices are created using the elements of
yvolt,k. Considering the
matrix as an example, this is computed as follows using Algorithm 4:
Algorithm 4: Compute the linearized matrices, and |
|
The
matrix comprises a term that is derived from
OCV, which is computed similarly to
. After computing the
and
, the former becomes a scalar and the latter becomes a vector, which in turn dramatically reduces the computation complexity of both PB-EKF and PB-MPC. Next, the Kalman Gain matrix (
L) is computed using the following Algorithm 5, corresponding to the Equation (10) (i.e., Equation (e) in
Figure 3):
Algorithm 5: Compute the Kalman Gain matrix, L |
|
In this case,
is the voltage error covariance, which is computed using the Equation (11) (corresponding to the Equation (f) in
Figure 3); and
is the error in voltage measurement, which is a constant in this PB model.
After computing the Kalman Gain matrix (
L), in Stage 6, the PB-EKF computes the state and error covariance measurement update using Algorithm 6 (corresponding to Equation (12), i.e., Equation (g) in
Figure 3) and Algorithm 7 (corresponding to Equation (13), i.e., Equation (h) in
Figure 3), respectively. The error covariance measurement update utilizes
L and the innovation. In this case, the innovation is defined as the difference between the measured cell voltage and the output prediction. The state is computed using Algorithm 6, corresponding to Equation (12) as follows:
Algorithm 6: Compute the state measurement update |
|
The error covariance measurement update is computed as follows using Equation (13):
The above parameter
is a scalar, and the algorithm can be simplified and written using Algorithm 7 as follows:
Algorithm 7: Compute the error covariance measurement update |
|
After computing the measurement update, the PB-EKF algorithm is technically completed. However, in order to support the PB-MPC algorithm as well as to support the SOC compensator, the PB-EKF repeats Stages 3 and 4 (i.e., Equation (14) corresponding to Equation (i) in
Figure 3) to updates the SOC, non-linear corrections, prior to computing Stage 7 for final updates for the PB-MPC.
In Stage 7, the EKF computes the derivative OCV value, two separate and linearized output matrices for both the side reaction overpotential (), and the SOC using the state. Thus, this state becomes the current-state of the PB-MPC.
In our software design, the overall PB-EKF algorithm iterates/loops through the SOC update and the non-linear corrections one more time before exiting the loop in step 4e. This software flow for this iterative process is presented in Algorithm 8 below (which is also based on the stages in
Figure 3). The aforementioned repetition of Stages 3 and 4 (in Equation (14), i.e., Equation (i) in
Figure 3) corresponds to the steps 4a to 4d. Our algorithm constructs reduce the code size for our embedded software architecture, leading to more efficient embedded design.
Algorithm 8: Functional Flow of Extended Kalman Filter |
- 1.
Build A matrix - 2.
Compute the state time update, (x) - 3.
Compute the error covariance update, (σ) - 4.
Loop (for 1 to 2) - a.
Compute the SOC update - b.
Build C and D matrix - c.
Calculate term sandfrom Non-linear corrections - d.
Calculate the predicted output voltage, - e.
If Loop = 2, break - f.
Buildand - g.
Compute the Kalman Gain matrix (L) - h.
Compute the state measurement update, (x) - i.
Compute the error covariance measurement update, (σ)
- 5.
End Loop - 6.
Create terms needed for MPC formation and constraints - a.
Calculate the updated Non-linear φs-e - b.
Compute the derivative of OCV at current state/soc - c.
Create the C and D matrices for MPC SOC and φs-e output equations
- 7.
End EKF
|
The outputs of the PB-EKF are forwarded directly as the inputs of the PB-MPC, which is detailed in the next sub-section.
3.2. MPC
The functional flow of our PB-MPC software is presented in Algorithm 9 as follows:
Algorithm 9: Functional Flow of Physics-Based Model Predictive Control |
1. Calculate next state for the state vector based on current state from EKF 2. Calculate change increment for the state vector and control signals 3. Compute E and F from the cost optimization forms 4. Compute the unconstrained solution 5. Build M and γ based onandfrom Equation (18) 6. If M (DU) ≤ γ is true, END MPC, do nothing. 7. Else execute Hildreth QP to provide constrained solution increment 8. Update control signal, 9. Final constraint check onto insure it stays within operating bounds 10. Update SOCmpc with SOC from EKF |
Although the PB-MPC has some overlapping functions, similar to the ones in traditional MPC ([
2,
4]), the PB-MPC often tracks the current to ensure safe operation, but does not concern itself with the SOC balancing or voltage regulation. In this case, the PB-MPC operates on the difference between the current-state and next-state, mainly due to the embedded integrator, whereas the PB-EKF operates on the amplitude of the control signals. The former (i.e., PB-MPC) requires configuring the traditional MPC algorithm. As a result, the PB-MPC computes the next-state using
A and
B matrices generated from the PB-EKF, and computes the difference between the states using Equation (15) as follows:
In Equation (15), from PB-EKF,
=
. Considering the zero/non-zero
D terms, the final state vector is defined using Equation (16):
Furthermore, the state-space and the output equations are presented as Equation (17) and Equation (18), respectively:
where the state and output matrices are redefined as follows in Equation (19):
In order to initialize our PB-MPC software architecture as stated in steps 1 and 2 of the above software functional flow (in Algorithm 9), we utilize the Algorithm 10 as follows:
Algorithm 10: MPC initialization of state, control signal, and SOC |
|
To compute step 3, it is imperative to understand that the cost function operates on the amplitude of the current, instead of the difference (or increment of change) between states. In order to facilitate this, the increment of change between states (
) is added to the previous control signal (
u0) to create the amplitude (
ig). This process is performed for each time step up to the prediction horizon. As in [
2],
Ig is the vector of
ig values, and Δ
U is the vector of incremental change values, and
U0 is the vector of the previous control signal.
Ig is represented by the following Equation (20):
where Σ is a lower triangular matrix.
Then, in the vector form, the cost function is represented by Equation (21):
The above Equation (21) is converted to the standard form as follows in Equation (22), to use on the Hildreth’s Quadratic programming (HQP) solution:
The PB-MPC uses the primal-dual approach (detailed in [
14]) for optimizing the above cost function. The optimization is solved numerically by the HQP technique. This primal-dual approach incorporates the inequality constraints into the cost equation, and also uses
E and
F in the dual form as follows in Equation (23):
where
and
.
After obtaining the above values, the PB-MPC computes step 4 (in Algorithm 9), which is the unconstrained solution
DU as follows using Algorithm 11:
Algorithm 11: Compute the unconstrained solution for MPC |
|
In the PB-MPC, the main constraint is based on the side-reaction overpotential (
) which is the primary cause of lithium plating and capacity loss as stated in [
2]. The output vector for
is written as follows with Equation (24).
To compute step 5 (in Algorithm 9) of the PB-MPC, the constraint matrix
M and vector
γ are created from
G and
Φ from the above Equation (24). In case if the unconstrained solution
DU violates any of the constraints in step 6, we use the HQP approach to compute the constrained control signs in step 7. From our previous work [
4], it was observed that this iterative approach is suitable for embedded systems. However, the HQP approach does not always converge to an optimal solution, and instead might converge to a useable suboptimal solution [
4]. This suboptimal solution computes a vector of Lagrange multipliers, one λ element at a time, where the λ element is a positive non-zero for an active constraint, and zero otherwise. The HQP converges when the previous λ and current λ are equal or within an acceptable variance. This λ vector is built using the
P and
K vectors detailed above. The summary of the HQP algorithm is presented below in Algorithm 12. The detailed description of this algorithm can be found in [
4].
Algorithm 12: Functional Flow of Hildreth’s Quadratic Programming solution for MPC, constrained solution |
For iterations 1 to 40- 1.
Save λcurrent → λprevious - 2.
LOOP1 to build λ, i = 0 to # elements in M or Msize - a.
w = 0; - b.
LOOP2 to build λ, j starts at 0 - i.
w = w + P[i][j]∙λ[j] - ii.
If j<Msize, repeat LOOP2 else GOTO 2.c
- c.
w = w + K[i]-P[i][i]∙λ[i] - d.
λtest = -w/P[i][i] - e.
if λtest< 0 then λ[i] = 0, else λ[i] = λtest - f.
i<Msize repeat LOOP1 else GOTO 3
- 3.
Check convergence - a.
calculate the Euclidean length of previous λ - b.
calculate the Euclidean length of current λ - c.
Compare ratio to reference value - d.
if converged is false GOTO 1, else GOTO 4.
- 4.
Calculate new Δu - a.
Start loop, j = 0 to j = Msize - i.
Δuc = Δuc +∙λ[j] ME−1[j]
- b.
GOTO 4.a if j<Msize else GOTO 4.c - c.
DU = Δu°-Δuc
- 5.
End
|
The final steps (8, 9, and 10 in Algorithm 9) of the PB-MPC are to update the control signals if needed, then update the SOC in the PB-MPC, followed by updating the PB-EKF. Our software architecture then waits for the next interval.