Lane Following#

Lane Detection#

The lane detection algorithm focuses on detecting the center of the lane and outputting one value: the difference between the center of the image and the center of the lane (an ‘error’, ideally in a simplified form of lane following, that value would be 0).

Algorithm#

The lane following algorithm follows the approach of this article.

It can be summed up by these steps:

  1. Preprocess the image (handle harsh lighting conditions, e.g. light reflecting from the ground; remove the front of the car that is visible in the bottom; etc).

  2. Obtain the bird’s eye view of the road ahead.

  3. Start two sliding windows from the bottom of the image. The start position of the sliding windows is determined by the X value of the colum of pixels that contains the highest amount of white pixels (that is the most probable to have a lane marking). The sliding windows will go upward from their start positions, while shifting left or right for the area that has the most white pixels, effectively tracing the curvature of the lane marking.

  4. Once the lane markings are traced by the sliding windows, we fit a polynomial to each of them.

  5. We calculate the center of the lane (trajectory that the car should follow) by subtracting the lane markings polynomials from the other. If only one lane marking is present, we use a predefined width value to find the center of the lane.

  6. We take the current lookahead value (how in the future the car is looking at the trajectory) and retrieve the X value of the pixel of the obtained trajectory that is at the Y value MAXY - LOOKAHEAD, where MAX_Y is the maximum possible value of Y (height of the image).

  7. We finally calculate the output of the algorithm, the error value, by subtracting the obtained X value in the last step from MAX_X/2.

Steering#

To steer the car, we implemented a PID controller that tries to minimize the distance to the center of the lane. We achieved good results, but one disadvantage is that the steering PID controller is tuned for a certain speed. If the car wants to switch speeds, the controller should change the values to the ones tuned to that speed.

Velocity#

We keep the car at a constant velocity. At first we experimented with a velocity that was inversely proportional to the current steering angle, but didn’t achieve great results. Different approaches could be explored.