# Data-driven identification of vehicle dynamics using Koopman operator

###### Abstract

This paper presents the results of identification of vehicle dynamics using the Koopman operator. The basic idea is to transform the state space of a nonlinear system (a car in our case) to a higher-dimensional space, using so-called basis functions, where the system dynamics is linear. The selection of basis functions is crucial and there is no general approach on how to select them, this paper gives some discussion on this topic. Two distinct approaches for selecting the basis functions are presented. The first approach, based on Extended Dynamic Mode Decomposition, relies heavily on expert basis selection and is completely data-driven. The second approach utilizes the knowledge of the nonlinear dynamics, which is used to construct eigenfunctions of the Koopman operator which are known by definition to evolve linearly along the nonlinear system trajectory. The eigenfunctions are then used as basis functions for prediction. Each approach is presented with a numerical example and discussion on the feasibility of the approach for a nonlinear vehicle system.

## I Introduction

Car is a highly nonlinear dynamical system which has been used for decades without any sort of sophisticated automatic control system. Our goal is to create full-time-full-authority control system, which means that the driver will rather set the reference for the car, and the ultimate control over the car inputs (steering angle, motor torques) will lie with the control system, protecting the driver from himself. However, control of nonlinear systems is not an easy task.

The Koopman operator is becoming an increasingly popular tool for nonlinear control. The Koopman operator is a linear operator which can in theory approximate any nonlinear system. The idea lies in lifting the state space of the nonlinear system to a higher-dimensional space by means of a nonlinear transformation. The lifted system should then be evolving linearly along with the original nonlinear system. The lifted state space is then transformed back with a linear transformation to the original state space and the nonlinear states (or system outputs) are recovered.

Such an approach is suitable for any linear control-design method such as LQG, MPC and .

In this paper, we present the results of application of the Koopman operator framework to vehicle system in an attempt to create a linear representation of a vehicle and use it to control the vehicle optimally with linear MPC.

## Ii Singletrack model

The singletrack model is depicted in Fig.1. The model was derived from 16-state twin-track model described in [1]. The states and parameters of this model are a subset of states and parameters of the full twin-track model.

State vector of the singletrack model is , where is longitudinal velocity, lateral velocity, yawrate and are front/rear wheel angular rates.

This model has 4 wheels, with two wheel always being in the same place. This allows for usage of asymmetric tire models, reduces the work needed to transition to twin-track model and is less error-prone than the standard approach (with only two tires, the user has to remember that each tire should generate twice as much force).

The vehicle body is modeled as a rigid body using Newton-Euler equations.

(1) |

(2) |

(3) |

Where

(4) |

is the vector describing position of each wheel with respect to the center of gravity. The wheels are numbered in this order: front-left, front-right, rear-left, rear-right. is the vehicle mass, is a force acting on i-th wheel along x/y axis in body-fixed coordinates. is a force acting along x axis in wheel coordinate system (direct output of the tire model). The term is an approximation of air-resistance, is a drag coefficient, is air density and is the total surface exposed to the air flow. is the vehicle inertia about z-axis. the wheel inertia about y-axis. Inputs are wheel torques (throttle), (break) and steering angles .

Since this is a 4-wheel singletrack model, the following holds:

(5) |

(6) |

The forces are calculated using the “Pacejka magic formula” [2]

(7) |

The same formula can be used for calculating (tire longitudinal force) and (tire lateral force) with a different set of parameters for each. The argument can be either sideslip angle or longitudinal slip (see [2]) for calculating or respectively. The parameters B,C,D and E are usually time-dependent. This work uses the Pacejka tire model [2] with coefficients from the Automotive challenge 2018 organized by Rimac Automobili.

The transformation of tire forces from wheel-coordinate system to car coordinate system is done as follows

(8) |

### Ii-a 3 state singletrack

### Ii-B 3 state singletrack without tire model

To simplify the model even more, one can omit the tire model and use the tire forces as input, assuming the existence of a higher level control system controlling the tire forces and thus securing the assumption that the car can be controlled directly by force reference.

## Iii The Koopman Operator

### Iii-a Extended Dynamic Mode Decomposition approach

#### Iii-A1 Framework description

The Koopman operator framework for controlled systems, as described in [4] will be reviewed now. Let us assume uncontrolled discrete nonlinear dynamical system with state and dynamics

(9) |

with being the current state and the next state.

The Koopman operator is defined as

(10) |

for each basis function where is the space of basis functions.

is infinite-dimensional linear operator, which can be approximated by EDMD. The approximation is done by solving optimization problem

(11) |

where . The states and are obtained by simulating the nonlinear system model, is the cardinality of the simulated dataset . Note that the states do not have come from some trajectory of the system. When the system model is available, it is sufficient to sample the state space with and perform a one-step simulation to obtain the .

The matrix now defines a discrete linear system which approximates the nonlinear dynamics from (9)

(12) |

where and is the output estimate. The matrix is obtained in a similar fashion

(13) |

For controlled system

(14) |

the approach is similar. The optimization problem (11) changes to

(15) |

while (13) stays the same. The Koopman operator is approximated both by and and acts as a one-step predictor. Note that the learning dataset now consists of . See [4] for more information.

This approach will be showed on the model which does not include the tire nonlinearities, described in II-B, because the selection of and is much more difficult when the tire nonlinearities are present.

#### Iii-A2 Data selection

The learning dataset was selected as follows. The velocities and were uniformly sampled in the interval , yawrate was uniformly sampled in interval . The number of samples was 15 for each state, resulting in 3 1-by-15 vectors.

The input forces to the model were sampled uniformly in the interval with , each interval with 15 samples, resulting in 4 4-by-15 vectors. The columns of sampled vectors were combined into all possible combinations, resulting in values in the dataset .

Note that the tire force of a regular car is usually in order of thousands of Newtons. However, the results were much better with relatively small inputs forces. Large forces were too dominant and their influence on the system overshadowed the system dynamics and since there are no tire nonlinearities, the system can be sufficiently excited with small input forces.

#### Iii-A3 Basis selection

There is unfortunately no general recommendation to determine which basis functions to choose for a given system. Some systems show satisfactory results with thin plate spline radial basis functions (see [5]). In our case, polynomial basis functions yielded much better results. A polynomial basis consists of monomials of the elements of the state vector.

(16) |

where is the order of the basis . Bases with various orders were compared, the comparison was made using averaged root mean square error (RMSE)

(17) |

calculated over 3375 trajectories with the same distribution of initial conditions as the learning dataset . The length of each trajectory was 30 samples, with . The results can be seen in Fig.2.

One might think the error would decrease with adding more basis functions but error grows exponentially as the order increases, which means that one cannot simply add more basis functions and expect the error to diminish. When considering linear Koopman system

(18) |

the more basis functions are in , the more derivatives have to be expressed by . The derivatives of the polynomial basis grow in complexity with increasing order, which makes it harder to express them, so the result makes sense, although it might seem counter-intuitive at first glance.

#### Results

In our experiments, a polynomial basis with order 7 was used. The Koopman operator was approximated using the dataset described above. The results can be seen in Fig. 3.

The yawrate is tracked without error because it is simply an integral of the input force as seen in (2).

### Iii-B Basis functions from data

To deal with the problems of basis function selection, the approach from [5] can be used. The approach consists of creating the eigenfunctions of the Koopman operator from data and using them as basis functions . The matrices and are calculated separately, contrary to the previous approach, which allows for optimizing the resulting system for a multiple-step prediction as opposed to one-step prediction of the previous approach. More in [5].

The basic idea of an eigenfunction will now be established. Let us consider uncontrolled nonlinear continuous system

(19) |

Starting in , the system will get to state in time . The state vector will be transformed with a function , defined as

(20) |

for arbitrary eigenvalue and function . The time derivative of is

(21) |

We see that evolves linearly with the system (19). For we would get

(22) |

(23) |

for . Choosing (20) as basis functions immediately yields the diagonal matrix. Notice that in this case, the Koopman system is derived as continuous system, contrary to the discrete-time derivation in III-A. This is done simply because of the continuous-time definition of (20), the system can be discretized after the whole procedure.

The idea is to select a set of initial conditions for the system (19) and simulate the system for a time with a sampling period . Then for each sampled data point , evaluate a set of eigenfunctions

(24) |

for some , , where is the initial condition of the state .

The values of can be interpolated in order to approximate their values for states which are not in the learning dataset. The approximation will be denoted as

The set should be a non-recurrent set, meaning that the sampled trajectories of the system (19) should not return to the states from set . This condition is not difficult to fulfill with a dissipative system such a car. If, for example, the set consisted of states with the same kinetic energy, none of the trajectories would return to the set , because the system naturally loses its kinetic energy as time progresses. For more information and proofs of the above stated facts, see [5].

The matrix can be obtained in a similar fashion as in the previous case. To approximate the output , solve

(25) |

where is the total number of sampled states.

The controlled case is not considered here, for more information on the derivation of the matrix, see [5].

#### Results

The simulation experiments were performed with the model described in II-A. The non-recurrent set was chosen as set of states with the same kinetic energy, the reasoning for this selection was mentioned above.

The level of the kinetic energy was set to , which is an energy equivalent of a car weighting , riding at . The set is depicted in Fig. 4.

Next, the nonlinear system was simulated from 441 initial states from the set (the set is visualized in Fig.4) for sufficiently long time in order to cover the state space with enough data, in our case . The trajectories were sampled at sampling rate .

Then the eigenfunctions were calculated. The eigenvalues were chosen in a similar fashion as in [5]. By applying Dynamic Mode Decomposition (DMD) algorithm [6] to the dataset, three eigenvalues were obtained. Additional eigenvalues were constructed as linear combinations of elements from , more in [5].

For the functions , thin plate spline radial basis functions were used:

(26) |

The centers were chosen randomly with normal distribution , where and are the mean and standard deviation of the whole dataset. Note that instead of interpolating the functions , nearest neighbour was chosen. This was done for simplicity and it yielded good results.

The approximated system was evaluated using 2000 randomly selected initial conditions, all within the ellipsoid in Fig. 4. Both the Koopman system and the real one were then simulated for (which is unnecessarily long for MPC control, but it demonstrates the capabilities of the approach). The error of each trajectory is again calculated using RMSE, defined in (17).

## Iv Conclusion

This paper presented two algorithms based on the Koopman operator for identifying vehicle dynamics.

## Acknowledgment

This research was supported by the Czech Science Foundation (GACR) under contract No. 19-16772S. We would like to thank Milan Korda for valuable discussions on the topic of eigenfunctions and Koopman theory.

## References

- [1] D. Schramm, M. Hiller, and R. Bardini, Vehicle Dynamics. Springer Berlin Heidelberg, 2014.
- [2] H. Pacejka, Tire and Vehicle Dynamics. Elsevier LTD, Oxford, 2012. [Online]. Available: https://www.ebook.de/de/product/18341528/hans_pacejka_tire_and_vehicle_dynamics.html
- [3] M. O. Williams, I. G. Kevrekidis, and C. W. Rowley, “A data–driven approximation of the koopman operator: Extending dynamic mode decomposition,” Journal of Nonlinear Science, vol. 25, no. 6, pp. 1307–1346, jun 2015.
- [4] M. Korda and I. Mezić, “Linear predictors for nonlinear dynamical systems: Koopman operator meets model predictive control,” Automatica, vol. 93, pp. 149–160, jul 2018.
- [5] M. Korda and I. Mezić, “Learning koopman eigenfunctions for prediction and control: the transient case.”
- [6] P. J. Schmid, “Dynamic mode decomposition of numerical and experimental data,” Journal of Fluid Mechanics, vol. 656, pp. 5–28, jul 2010.