top of page

Visual Follow Line

Here you will find my solution to the "follow the line" exercise. The goal of this one is to realize an algorithm allowing a formula 1 to be autonomous

formula1.png

Project details

We are going to solve this exercise using the Unibotics website (unibotics.org). This gives us access to a code editor and a simulator where we can see the result of it. You can find the exercise link below.

We therefore have a Formula 1 simulator available. The goal is to finish the circuit as quickly as possible while following a red line drawn on the ground. For this we have access to the images of a camera equipped on formula 1. To direct formula 1 we can also change two parameters which are: the speed and the rotation of formula 1

There is two important aspects of robotics which are: the robustness of the program and its execution time (should be real time).

The simulator

My solution

1. Detect the line

To begin with, I therefore decided to use a color filter to detect the red line that formula1 must follow. For that I have to recover the image of the camera placed on the car. I then pass this image in HSV format and use a color filter with the parameters : 0 < H < 179, 195 < S < 255 and 200 < V < 230.

To find these parameters I used a program that I made. This program allows you to play with the hsv parameters and to see the rendering live, like so :

screen1.png

2. Detect the optimal path

In this second step my goal is to find the optimal path that the car should take.

I decided to represent this optimal path with a straight line. From a point called "start" to a point called "end". The "start" point will represent the front middle of formula 1. And the "end" point will represent where the car should go.

For the "end" point I decided to take as reference the furthest point of the line that we can see. To do so I analyze the image from top to bottom (line by line) and stopped when a group of pixels representing the line is found.

I decided to take a minimum pixel size and not one single pixel to avoid detecting possible errors due to the color filter. What makes my robot more robust.

During the development of this step I choosed to represent this line in order to verify that my calculations were correct.

WhatsApp Image 2022-03-22 at 17.54.30.jpeg

Here the blue line is representing the optimal path

and the dots are representing the "start" and "end" point

3. Controling the car

This simulator gives us acces to two parameters : the speed and direction of the car (the steering wheel). For the direction (which we will denote W) we will use a PID controller

PID controller stands for Proportional Integral Derivative and it is a type of device used to control different process variables such as pressure, flow, temperature and speed in industrial applications. In this controller, a control loop feedback device is used to regulate all process variables.

Here we will only use the P and D controllers of the PID controller.

For the PD controller we used this formula :

download.png

The result obtained from this formula will be used to control the steering wheel direction. Thanks to the PD controller we can adjust the intensity of the rotation of the car.

Once the rotation of the car has been calculated, we will deduce its speed (named v). Here is a representative formula of this one :

download (1).png

As we can see the speed depends on the rotation of the car (v depends on the parameter w).
This means that the more the car turns, or plans to turn, the more its speed will decrease. And on the contrary, the straighter the line is (the wheels are straight), the more the speed increases.

4. Exceptions

When developing a robot, there are two characteristics that should not be overlooked: Speed ​​and robustness. In order to increase the robustness of this algorithm, I decided to implement an error handling when the camera does not detect a line. When this happens the car slows down and turns on itself until it finds a line.

5. Results

I used python3 to develop this algorithm. I tried to do a code that can be understood by anyone. You can find my code on github, down bellow. Here are the results I got based on the circuit:

The results

Default Line

The best time on the Default line circuit is : 0:01:02.702669

bottom of page