1 Introduction

Increasing safety, reducing road accidents, improving energy efficiency and enhancing comfort and driving experience are the major motivations behind equipping modern cars with Advanced Driving Assistance Systems (ADAS) [1,2,3,4,5]. In the past couple of decades, major car manufacturers introduce many sophisticated ADAS functions like Lane Departure Warning (LDW), Lane Keep Assist (LKA), Electronic Stability Control (ESC), Anti-lock Brake System (ABS), etc. Both LKA and ESC functions are examples of how important for the car to follow and track the lane or road boundaries accurately and on time.

Future ADAS functions like Collision Avoidance, Automated Highway Driving (Autopilot), Automated Urban Driving [6], Automated Parking, Connected Vehicles [7] and Cooperative Maneuvering requires more and more fast and reliable road boundaries follower functionalities, which should be designed to maintain the control over the vehicle in extreme circumstances, and being very effective at high speeds [8]. The road boundaries follower functionality requires the localization of the road, the determination of the relative position between vehicle and road/lane centerline, and the analysis of the vehicle’s heading direction. The mentioned systems represent incremental steps toward a hypothetical future of safe fully self-driven vehicles [9, 10].

There are two categories of vehicle control [11]. The first category is the longitudinal control which deals with the movement of the vehicle in the forward and backward directions (responsible for regulating the vehicle cruise velocity) [12]. The second one is the lateral control which deals with sideways movements perpendicular on the vehicle’s heading, in other words, the steering of the vehicle to follow a given trajectory [13]. Usually, two separate controllers are employed to deal with each of them. The focus of this paper is on the second category with the objective of minimizing the tracking error.

In previous literature, various studies have been carried out to explore different hypotheses and techniques. These studies incorporate the PID control strategies [14, 15], the predictive control paradigms [16] and the model reference adaptive control methods [17, 18].

Moreover, some of these studies focused on intelligent approaches like fuzzy control techniques [19, 20] and neural-network based control strategies [21, 22]. In addition to that, some unpopular techniques are also been exercised such as the SVR (support vector regression) method [23], the fractional-order control method [24], etc.

However, even though, as mention above, there are a variety of control techniques with good performance, still, the PID control is the most popular as still attracting attention. The PID control has several points of strength such as a straightforward structure, overall good control performance, robust design and simple implementation [25]. Moreover, the control methods introduced above do not consider the real-time environment of the driving, the constraints of the automotive applications and deals with it as a hypothetical problem. The controller performance should be fast enough in real-time without much overhead that consumes computational resources (big software footprint) and may suffer from stability problems, therefore, offline-tuning methods are advantageous in this regard than adaptive or intelligent techniques.

However, the PID method needs supportive algorithms to find and fine-tune its hyper-parameters. It is challenging to find good optimized values for these hyper-parameters that well fit the environment caused by the complexity of vehicle dynamics, uncertainty of the external disturbances and the non-holonomic constraint of the vehicle [9].

Here in this paper, a further step towards the prospects of autonomous driving is presented. The main objective is to attain a car capable by itself of following a pre-defined trajectory or route generated by the prospected path planner of the autonomous car, in both highway and urban traffic with the highest comfort level. Accordingly, the developed PID controller is suitable to be employed at level of autonomy of three and above.

The proposed control system uses sensors to provide the actual speed of the controlled car and the relative position of the car with respect to the supplied trajectory. The controller then calculates the optimized actions on the steering wheel. These actions are controlling the direction of the vehicle, and a Proportional-Integral-Derivative (PID) control algorithm is employed to compute them.

2 Overview of PID Control

The Proportional Integral Derivative (PID) control technique [24] is a mechanism widely used in various industrial control applications. As an example, one of these uses is in robotics, where its main function is to smoothen the robot’s movement inputs in a way that it allows the robot to reach its objective state with as little vibration or jitter as possible.

The output of a PID depends on three hyperparameters, one for each term of the controller abbreviation (P-I-D). These hyperparameters are specific to each application, which in our case is driving a car smoothly around a test track.

The Proportional Term

The proportional term [25, 26] produces an output value that is proportional to the current error value. The proportional response can be adjusted by multiplying the error by a constant Kp, called the proportional gain constant. The proportional term is given by:

$$ {P}_{out}={K}_p\ast Error $$
(1)

A high proportional gain results in a large change in the output for a given change in the error. If the proportional gain is too high, the system can become unstable. In contrast, a small gain results in a small output response to a large input error, and a less responsive or less sensitive controller. If the proportional gain is too low, the control action may be too small when responding to system disturbances. Tuning theory and industrial practice indicate that the proportional term should contribute to the bulk of the output change. The chart in Fig. 1 shows how different values of Kp would impact the system response.

Fig. 1
figure 1

The KP effect in the system response [22]

The Integral Term

The contribution from the integral term [26] is proportional to both the magnitude of the error and the duration of the error. The integral term contribution is the sum of the instantaneous error over time and gives the accumulated offset that should have been corrected previously. The accumulated error is then multiplied by the integral gain (KI) and added to the controller output.

$$ {I}_{out}={K}_I\ast \int Error\ dt $$
(2)

The chart in Fig. 2 shows how different values of KI would impact the system response.

Fig. 2
figure 2

The KI effect in the system response [27]

The Differential Term

The derivative of the process error is calculated [25, 26] by determining the slope of the error over time and multiplying this rate of change by the derivative gain KD. The magnitude of the contribution of the derivative term to the overall control action is termed the derivative gain, KD. The derivative term is given by:

$$ {D}_{out}={K}_D\ast \frac{d}{dt}(Error) $$
(3)

The chart in Fig. 3 shows how different values of KD would impact the system response.

Fig. 3
figure 3

The KD effect in the system response [24]

In vehicle control, the velocity and steering set-points are picked up by the vehicle’s low-level PID controllers. Separate PID loops for speed and heading control are implemented in the current vehicles platform. The steering PID controller determines the steering angle based on the input heading angle in human-driven vehicles or the cross track error in self-driven vehicles. While two separate PID controllers for the accelerator and the brake works together to maintain the desired velocity. Additionally, all low-level hardware controller PID’s are written in C/C++ languages with an average update rate of around 100 Hz.

The overall control action is shown in Fig. 4 can be given as

$$ {PID}_{out}={P}_{out}+{I}_{out}+{D}_{out} $$
(4)
Fig. 4
figure 4

Stucture of the PID controller

3 The Vehicle Model

In this paper, the Kinematic Bicycle Model [9] is used to simulate the behavior of the self-driving car. The nonlinear continuous time equations that describe a kinematic bicycle model shown in Fig. 5 in an inertial frame are:

$$ \dot{x}=v\ast \cos \left(\psi +\beta \right) $$
(5a)
$$ \dot{y}=v\ast \sin \left(\psi +\beta \right) $$
(5b)
$$ \dot{\psi}=\frac{v}{l_r}\ast \sin \left(\beta \right) $$
(5c)
$$ \dot{v}=a $$
(5d)
$$ \beta ={\mathit{\tan}}^{-1}\left(\frac{l_r}{l_f+{l}_r}\ast \mathit{\tan}\left({\delta}_f\right)\right) $$
(5e)

where x and y are the coordinates of the center of mass in an inertial frame (X, Y) [21]. ψ is the inertial heading and v is the speed of the vehicle. lf and lr represent the distance from the center of the mass of the vehicle to the front and rear axles, respectively. β is the angle of the current velocity of the center of mass with respect to the longitudinal axis of the car. a is the acceleration of the center of mass in the same direction as the velocity. The control inputs are the front and rear steering angles δf, and δr. Since in most vehicles the rear wheels cannot be steered, we assume δr = 0.

Fig. 5
figure 5

The Kinematic Bicycle Model

Compared to higher fidelity vehicle models [28], the system identification on the kinematic bicycle model is easier because there are only two parameters to identify, lf and lr. This makes it simpler to port the same controller or path planner to other vehicles with differently sized wheelbases.

4 The Proposed PID Tunning Method

In order to design and implement the proposed Proportional-Integral-Differential (PID) controller for an autonomous vehicle to successfully maneuver around a complex track which has lots of sharp turns, the following measurements are received by the controller:

  1. 1)

    The CTE (the cross track error) which represents the misalignment of the vehicle with respect to the center of the track at a given instance and can be given by:

$$ CTE= desired\ position- vehicle\ position $$
(6)
  1. 2)

    The vehicle speed at the given instance.

  2. 3)

    The instantaneous vehicle orientation angle (−ve for left and + ve for right).

The PID controller then uses some of the above information to produce a steer (angle) command to the vehicle in addition to a throttle command (speed) if required.

The steering command is produced after applying proportional, integral and differential control to it in terms of Kp, KIand Kd coefficients respectively. Therefore, the main design effort is to carefully tune these three coefficients to get the best possible performance. The performance can be simply defined as to let the vehicle to follow the track centerline as closely as possible with the lowest aggregated CTE throughout the entire trip. Therefore, the main goal of the controller is to minimize the aggregated CTE (the objective function) as given by eq. (7):

$$ Objective\ Function=\mathrm{mininmize}\left\{ MSE\right\}=\mathit{\min}\frac{1}{N}{\sum}_{i=0}^{i=N}{CTE}_i^2 $$
(7)

The PID coefficients are tuned using a proposed tuning method given the name “WAF-Tune”. The following procedural steps illustrate this method:

  1. 1)

    The tuning will be done through the ad hoc technique “trial and error” which makes it a transparent procedure, unlike other automating algorithms like “Twiddle” [29] (will be described later) that is considered a kind of opaque approach (it is not known exactly, how each change in a hyperparameter affects the performance). This manual transparent approach incorporates the intuition as well as the experience in the tuning process.

  2. 2)

    The time span at which the objective function is evaluated is selected to be considerably big (N = 10,000). Ten thousand samples (individual CTE measurements) are used to evaluate the performance indicator (given in eq. (4)). The number of samples is big enough to get a sufficiently accurate evaluation. It represents the measurements from the vehicle while going around the designated track more than once (several times in case of the high enough speeds).

  3. 3)

    At first, the throttle value is kept constant throughout the performance measurement.

  4. 4)

    The tuning process starts by setting the throttle value at a low value (= 0.1 in our case) and the controller coefficients as follows (Kp = 0.1, KI = 0.0 and KD = 0.0).

  5. 5)

    The simulation for several iterations (at least two) in which each iteration produces an individual measurement of the objective function has been run. Then, the average of these measurements is taken to produce the designated performance indicator (average Mean Squared Error “MSE”).

  6. 6)

    In the next set of iterations, the Kp has been then incremented small amounts based on intuition while keeping the other coefficients constant. Afterward, the new performance indicator is then calculated. If the performance gets better, Kp is kept incremented, otherwise; return back to the previous value and move on to the next coefficient KI by incrementing it a small amount (based on intuition as well).

  7. 7)

    After the performance stops improving with the increment of KI, then KD will be picked and getting step by step incremented until the performance indicator stops improving.

  8. 8)

    After tuning the three coefficients for the throttle value = 0.1, their reached values will be the starting point of the next throttle increment iteration.

  9. 9)

    The next throttle value iteration: the throttle value got incremented to say (=0.15), and steps from 5 → 8, got repeated while holding the throttle value constant at 0.15.

  10. 10)

    Keep repeating steps 5 → 9 while incrementing the throttle value (= > 0.2, 0.25, 0.3, 0.35, 0.4 … etc.).

  11. 11)

    The tuning stops when PID coefficients fail to control the vehicle (the vehicle jumps out of the track) at an upper throttle value and the performance indicator shows a large unacceptable value of MSE.

  12. 12)

    The final stet of coefficients {Kp, KI and KD} that keep the vehicle within the track and an utmost reached value of throttle are considered the accepted tuned design of the PID.

  13. 13)

    These values are then used at all levels of throttle up to the utmost reached value.

5 The Twiddle Algorithm

The Twiddle algorithm [30] is a search algorithm that tries to find a kind of optimized selection of the hyper-parameters values of the PID controller based on the returned track error. The pseudo code for the implementation of the Twiddle algorithm is as follows:

figure b

6 The Ziegler–Nichols Algorithm

The Ziegler-Nichols tuning method [31] is a heuristic method of tuning a PID controller. This method requires to set KD and KI to 0 and gradually increase KP until it reaches the ultimate gain Ku before the vehicle runs with stable and consistent oscillations as shown in Fig. 6. KP and the oscillation period Tu are used to set the KP, KI, and KD gains based on the type of controller used as shown in Table 1.

Fig. 6
figure 6

Fine tuning the PID using “Ziegler–Nichols”

Table 1 Ine tuning the PID using “Ziegler–Nichols”

7 Tuning and Testing Results

The tuning of the PID controller is carried out using the upper three algorithms by driving the car (simulated using the presented model in Section III) around the test track shown in Fig. 7. Table 2 shows samples of the endeavors of the “WAF-Tune” (SectionIV) to reach fine-tuned values for the controller coefficients {KP, KI and KD}.

Fig. 7
figure 7

The test track

Table 2 Fine tuning the PID controller using “WAF-Tune”

The final tuning of PID controller is given in trial #39 where (Kp = 0.35, KI = 0.0005 and KD = 6.5). Using these coefficients the controller is tested under different throttle values and the performance results are showing in Table 3 below.

Table 3 Testing results for the PID controller at different speeds

To tune the PID using Twiddle (SectionV), the hyper-parameters have to be tuned manually at first. This was necessary because the narrow track left little room for error, and when attempting to automate parameter optimization it was very common for the car to leave the track, thus invalidating the optimization. Once the initial preliminary parameters were found that were able to get the car around the track reliably, Twiddle is then implemented. It was necessary to complete a full lap with each change in parameter because it was the only way to get a decent “score” (total error) for the parameter set. For this reason, the changes in each parameter are allowed to “settle in” for 100 steps and are then evaluated for the next 2000 steps. In all, Twiddle is allowed to continuously run for over 1 million steps (or roughly 500 trips around the track) to fine tune the parameters to their final values {KP: 0.134611, KI: 0.000270736, KD: 3.05349} with an MSE of 0.1823.

Furthermore, to tune the PID using the Ziegler-Nichols method, the PID is initialized with hyperparameters values that just allowed the car to drive around the track even with a lot of wobbles. Then Kp is getting increased till the car makes approximately full swings between the borders (lane lines) of the track at which the value of Kp is captured and set to given the name Ku, while the period of the oscillations at this point is called Tu. The experimentations with different values of Ku & Tu is shown in Table 4 below to arrive at the final optimal values of {KP: 0.09, KI: 0.00144, KD: 1.40625}. Unfortunately, the PID controller with resulted parameters was able to drive the car around the track but with a still lot of wobbling. That is why parameters should further tuned manually by a trial-and-error process. The same process is applied for different speeds (throttle values), so different PID parameters were found for different speeds. However, the overall performance is still inferior to that of the “WAF-Tune” and the “Twiddle” algorithms.

Table 4 Experimentation with KU & TU to find Optimized KP, KI and KD

Table 5 summaries the performance comparison among the three algorithms showing the best performance is achieved by WAF-Tune.

Table 5 Comparison between the three techniques

8 Discussion

The following are some conclusive remarks on the proposed controller and the work done:

  1. 1.

    The PID controller has a very simple structure, however, it very effective in many control problems. Therefore, it is the most widely used approach by far in the industry (>90%).

  2. 2.

    The main problem with the PID is its tuning. There is no theory or criteria that proves that the optimal value for the coefficients {Kp, KI and KD} have been reached. All the methods of tuning are mainly based on an extensive search with the incorporation of intuition and experience.

  3. 3.

    From the author point of view, using transparent methods based on extensive “trial and error” endeavors guided by numerical performance indicators is the best approach; as it lets the problem at hand been understood much deeper. Furthermore, it allows the incorporation the intuition and experience of the designer which reduces a lot of the search space; and consequently allows the designer at the end to be more effective.

  4. 4.

    The problem at hand is a tracking problem in which the set-point (the track center position) keeps changing continuously with time. In such kind of problems, the differential controller (KD) proved to be very effective and it is designed in principle to track changes. In the presented case, it played the dominant role. The differential component counteracts the tendency for oscillation or overshoot around the track center line. By properly tuning KD, it will cause the vehicle to approach the center line smoothly with much lower oscillations, which interns results in lower CTE values as presented in Table 2.

  5. 5.

    The proportional controller (Kp) is necessary to feedback the error to the controller with corrective action but it is not playing the principal role in improving the performance in this problem. The proportional component had the most directly observable effect on the vehicle’s behavior. It causes the vehicle to steer back to the track trying to reduce the CTE.

  6. 6.

    However, the integral controller (KI) shows to be ineffective is our case (due to the continuous change of the setting point) and in many scenarios, it has a detrimental effect. The integral component in general counteracts any bias in the CTE and speeds up the approach to the center line, however, in our case, the center line keeps moving with respect to the vehicle which in many cases may cause the integral controller to produce oscillations.

9 Suggested Improvements

The following list summaries the suggested improvements:

  1. 1.

    Adding another PID controller to control the throttle in such a way to reduce the speed in sharp curves and to allow full thrust in straight portions of the track. This controller should take the vehicle angle as an input and produces the “throttle value”.

  2. 2.

    Use of Adaptive PID control approaches to accommodate the wide range of vehicle speed. One of the popular approaches is the Gain Scheduling (GS) adaptive control, where we use several gain sets (3 or 4 sets), each will be used at a specific speed range.

  3. 3.

    Applying “Twiddle” algorithm to the results of the proposed “WAF-Tune” to further optimize the hyper-parameters. However, caution should be taken in in order not to overfit the results to specific test tracks.

  4. 4.

    Investigating the incorporation of the state-of-the-art concepts of optimized adaptive tracking of micro-robotic systems [32,33,34] that can enhance the maneuvering capabilities of autonomous cars.

  5. 5.

    Exploring the real-world connected vehicles data [35] (such as Safety Pilot Model Data (SPMD)) to be used for validating the controller and fine-tuning its parameters. The majority of the required data are available in the SPMD through vehicle On-Board Units and sensors.

10 Conclusion

In this paper, a PID controller is designed to efficiently steer an autonomous car following a pre-calculated track from a path planner. Three different methods are presented as design approaches, one of them is newly proposed in this paper. The proposed controller uses on the cross-track-error as an input and outputs the steering commands. The method used to tune and minimize the suggested objective function is described in details. The performance of testing the PID controllers at different vehicle speeds (throttle setting) is also shown in details. A comprehensive discussion and analysis regarding the design of the PID as well as suggestions for improvements and future work are presented.