Wednesday, 2 November 2022

TASK 2: FOLLOW LINE

INTRODUCTION:

The objective of this task is to perform a PID reactive control capable of following the line painted on the racing circuit.

In my case, I decided to implement a PID controler for the angular speed and  I have left 2 constants speeds: one for straight lines and other for curves.


IMAGE FILTERED: 

In this task the only information we were able to use is the camera and so, I had to obtain all information from it. To obtain that information I decided to use Opencv library:

Using Opencv and HSV values, I was able to get the red mask I was looking for. I have used : cv2.cvtColor, cv2.inRange and cv2.bitwise_or.




CENTER POINT:

After getting the mask where red line was caught, I took cv2.moments to get the moments of the image and draw a green circle. Down below, you can find a snippet of what I am trying to explain:


That point will be our reference between our real center  which is the x coordinate:  329.

Now, after knowing our reference and the center, we can calculate the error to take into account. 

err = (center - reference)/ 100 

I have decided to divide that error by 100 because the resulting values for the angular speed were really high.

Here we are only taking into account x axis since y axis does not change.


LINEAR CONTROLLER:

In my case, I have finally stated that I will leave a constant speed due to I have struggled with inserting a PID controller for that.

Now, you may have doubts about how I have considered  to make the f1 know what is a straight line and what is a curve. To do that I have stated that if the reference (means in x axis)  is higher 339 or lower that 299, means that the reference is really far away from the center and it is a curve. The resulting values are set as straight lines.

To make a difference between straight lines and curves, I have set 2 different values:

- Straight lines: HAL.setV(2)

- Curves: HAL.setV(1)

I know that it exists higher values but for all the ones I have tried, are the ones that follow perfectly the read line in the whole circuit. 


ANGULAR CONTROLLER:

In this part, I have decided to implement a reactive system, called PID controller. Now, I will explain each one:


 - Proportional Controller (P): if the error is high, the response to that error is high too. Otherwise, if the error is low, the response is low. This is its formula: 

To get "e" is the err explained before. The value used for Kp was found by testing. 


- Derivative Controller (D): if the error's tendency is high, the response becomes more agressive. Otherwise, if the error's tendency is low, the response is softer.
To get "de/dt" is the  derivative of err explained before. The value used for Kd was found by testing. 


Integral Controller (I): acumulates all errors performed by the system. 

The value used for Ki was found by testing. Therefore, that integral error I divided that into 100 since the values obtain weren't correct. 

So mixing them, I have obtained a controller which works perfectly for  v = 1 in straight lines and v = 2 in curves; as I said before.
This is the final formula used for creating the PID controller:

 

CONCLUSION:

To conclude I would like to outline that in an average of tries, it takes about 5:30 to do the "Default Line" circuit. Besides, I have had problems with Sim RTF due to its values were about 68 to 80.  The video is taken with the simulator in labs so its Sim RTF values were about 95 and the total time improved. 

Here you can see a picture of the output.


Down below, you can find  a video.

VIDEO: 

I was not been able to upload the video here, so I leave you links were you can find them.  Besides, unfortunately I have struggled with some screen recorders so, the only solution I found is recording the screen with my phone.
 
I hope you like it!

No comments:

Post a Comment

TASK 4: GRADIENT PATH PLANNING

 INTRODUCTION:  The objective of this task is to implement the logic of the Gradient Path Planning algorithm.  The GPP consists of selecting...