# Lateral Control Calibration and Testing in a Co-Simulation Framework for Automated Vehicles
## 2 Vehicle Dynamics and Control
### Calibration Optimization  
* Calibration solution in the state of the art Matrix K is the gain of the LQR controller and can be calculated from Equation (19). The key to the LQR controller lies in the choice of the weight factors of matrices Q and R in Equation (14) and (15). In the previous study [41], [PERSON] et al. chose these weight factors based on the empirical method. First, Q is optimized by setting an intermediate value (arbitrarily chosen to be in the order of \(10^{5}\)) to R and Q is considered diagonal to simply tuning. Q is tested for a small value \(Q_{min}\) (close to 0) and later for a large value of \(Q_{max}\) (in the order of \(10^{6}\)). The two results are compared, and then an intermediate value \(Q_{avg}\) is tested and the process is repeated by considering the new \"small\" and \"large\" limits \(Q_{avg}\) and the value between \(Q_{min}\) and \(Q_{max}\) that yielded the best result. The process is then repeated by choosing a new intermediate value between the two limits until an acceptable result is produced. For R optimization, the same approach is followed, setting Q to the optimized value just found.
* Artificial Bee Colony Algorithm The flowchart of the ABC algorithm [42] and the LQR controller is shown in Figure 3. The employed bees actively seek K values in the vicinity of their remembered food source, all the while communicating information about these K values to the onlooker bees. The onlooker bees are likely to select good K values from those based on the fitness function as well as evaluate K values using the cost function. A few employed bees translate into the scout bees and search for new food sources until the condition is satisfied.
* Genetic algorithm The GA [43; 44] draws inspiration from biological principles such as mutation, crossover, and selection. The GA commences by configuring the parameters of the BMW car, the initial K values, as well as randomly generated individuals, initiating the evolutionary journey. In each generation, the fitness of every individual is evaluated, typically by assessing the value of the fitness function. Stochastic selection is employed to favor fitter individuals from the current population. These selected individuals' genomes are then subject to modifications, such as recombination and possibly random mutations, to generate a new generation of candidate solutions. This cyclic process continues, with the newly formed generation becoming the basis for the subsequent iteration. The GA advances through iterations until it reaches a termination condition. The flowchart of GA-LQR is shown in Figure 4.  
Figure 3: Flow chart of ABC and LQR controller.  
* Particle swarm optimization Figure 5 illustrates the flowchart of the PSO algorithm [45] and LQR controller. The optimal weight factor is found by searching for the global in order to enhance the LQR controller performance. Firstly, the parameters of the BMW car model are configured. Then, we set the initial particles' positions and velocities as well as the initial values of LQR matrices. After that, the algorithm will calculate the fitness function value and find the global best solution. If the condition is satisfied, the algorithm is stopped, otherwise, the algorithm continues to run until satisfies the condition.