top of page
Screenshot from 2020-10-24 13-33-09.png

FOLLOW LINE

In our first exercise, we'll have to get this F1 to go around the circuit following the red line... but how can we succeed in our mission?

First of all, our car has to be able to see the line as we do, what means that it has to distinguish colors: Specifically red color, cause our line is red. We have to put some light in Gazebo to see the red line properly.

​

To obtain this we'll use OpenCV library, which will let us work with the image.

Screenshot from 2020-10-24 12-23-56.png

We have to know that every color can be expressed in different color models. There are lot of color models: RGB, HSL, CMYK...

Bu we will use HSV (Hue, Saturation, Value).

​

HSV let us define a colour in terms of its components, in a range of [0,179] (H), [0, 255] (S), [0, 255](V).

Since we can work with red colour, we have to establish a range for red color. So we'll have two values, lower red and upper red.

Using again OpenCV, we'll convert our image (which initially is in RGB) to HSV, to let us apply our red range and obtain a mask.

The mask is a white and black image, where white is our filtered color (red) and black everything else.

​

We have already filtered our image. So, what is next step?

We have to obtain the middle point of the white line to know if our car has to turn right, turn left or go straight. To obtain this point, we'll use OpenCV moments, and we get this display, where the green point is the middle point of the contour and the right image is the mask.

​

incialmente un solo contorno.png

As we can see, the point is way down, so we'll get information of where we are now, and won't see what are we will to find, which make us oscillate way more.

So, to solve this problem, I've decide to divide the image and obtain the contour of the top. With this, we'll improve the way we approach our goal, because we'll solve the problem where the point is down, and we can work better.

Screenshot from 2020-10-28 14-04-49.png

FIRST IMPLEMENTATION: P CONTROLLER

​

Once we have the image filtered, we can start. We are going to use a proportional controller to adjust the error.

To do that, we just have to apply the formula:

 

u = -Kp * error

​

Where Kp is the constant we have to adjust depending on the speed of our car, the error is the difference between where the green point is (obtained previously filtering the image) and where is supposed to be (middle of the image) and the u value obtained is the turning speed we'll give to our car.

Doing that, we obtain a time of 48 seconds.

SECOND IMPLEMENTATION: PD CONTROLLER

​

We want to increase the speed of our car, so we are going to add a derivative controller to be able to reduce error in a faster way.

We have to apply the formula of PD controller, which is:

 

u= -Kp * error + Kd * de

​

Where the first part before plus sign is the proportional controller, and now we add the derivative one. Kd is the derivative constant, that we have to calculate, de, since we can`t apply derivatives, is the difference between the last error and the actual one. The u value obtained is the turning speed we'll give to our car.

 

So now we can increase our Kp constant and adjust the error with Kd. We can see a big difference between both videos. The car reduces oscillations way faster, which let us to increase the speed. We complete the circuit in 33 seconds.

​

THIRD IMPLEMENTATION: IMPROVING OUR PD

​

We already have a proportional-derivative controller, but... can we improve it?

We can adjust lineal speed depending on the situation: If we are in a curve, we'll have to reduce the speed, but if we are in a straight line, we can go faster. To do this, we have to do it in an inversely proportional way to the error: The more error, the less speed. With this, we are able to increase the speed.

There are two ways to do this, first, I've done the simple one: If the center is out of some limits that we decide aren't the center anymore, the car decreases it lineal speed. If not, go fast with another higher speed.

The next step, is do it a bit more difficult, as I explained it before: If the error is too little, the speed could be practically the same as the car wouldn't be in curve, but if the error is too big, even if is losing the line, it should stop and find the line, so the speed should be 0 or very close to 0.

 

According with this improvements... What happens if the car can't see the line? To solve this, I have added some lines to the recovery mode, where the car turns until see the red line, with 0 linear speed, only turning speed.

You can see the final solution in this video:

©2020 by Isabel Cebollada.

bottom of page