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!

Wednesday, 19 October 2022

TASK 1: VACUUM CLEANER


INTRODUCTION:

The objective of this task is to clean the house using a finite state machine to prove the reactive behaviour of the vacuum cleaner. Besides, it is main goal is to cover the largest area of a house using the programmed algorithm.

In my case I decided to implement the following finite state machine: 

 FINITE STATE MACHINE DESIGN:     

                    

 

In this GIF you can see that there are 5 states but I use mainly 4 since spiral it is only used at the beginning. 

SPIRAL:

I believe all states are clear but it can be quite confusing the initial state called spiral.

This initial state's purpose is to start with a static angular (to the right side since the vacuum start really close to a cupboard and it would detect it and would not cover much of the goal at the beginning) and a random linear speed to have a random spiral. If not, the spiral would always be the same and the vacuum would detect the same obstacle every time. Its interval is between 0 to 3

When it reaches to its first obstacle, then it starts the infinitive loop that will not longer take into account of the spiral state. 

I decided to do that since there are many furnitures and after many tries, I did not find any advantages keeping the spiral into the infinite loop.

REACTIVENESS OF THE SYSTEM:

We have learnt that using sleeps (in our case rospy.sleep) break the reactiveness of the system. So, to avoid that I have included a boolean variable for back and turn state when the vacuum gets to one of these states, iterations start running and when it achieves certain amount of iterations, goes to the next state. 

Of course if it is for example turning and detects an obstacle it goes backward to demonstrate a reactive behaviour. The system will not be stuck on a state as if we used a sleeps and in that case it would not detect an obstacle until sleep finishes.

SENSORS:

In this task, I decided to use both sensors: Laser and Bumper so the vacuum would detect more obstacles like legs of chairs and tables. Besides, including the laser sensor, the vacuum will not force movements against obstacles.
  
- LASER:
 
To have a correct data of the laser I have included in my program the function provided in the statement called: "parse_laser_data(laser_data)" which I found really useful.  
After obtaining that array, I separate the measures and angles in three parts:
 
    * From 0 to 60 degrees I assume that is Vacuum's Left side.
    * From 60 to 120 degrees I assume that is Vacuum's Front side.
    * From 120 to 180 degrees I assume that is Vacuum's Right side.
 
Here you can see a diagram if my explanation has not been clear:


After storing in three different arrays the measures of the three ranges told above, I calculate the mean of each one to have a consistent algorithm and avoid if just one light fails and it's distance given is not the real one. However, I had to add the minimum value of each array since many obstacles are thin and knowing the mean values was not enough.
 
- BUMPER:
 
This sensor is used as a complement with the laser. I found it really useful for chair's legs and obstacles like these ones.
If the bumper is pushed then, it goes forward.  (it is backward the laser)
  
MOVEMENTS:
 
 - Forward: linear speed positive.
 - Backward: linear speed negative.
 - Left : angular speed positive.
 - Right: angular speed negative. 
 
I have stated that if an obstacle is detected by its left, turns to its right. 
If an obstacle is detected by its front or right, turns to its left. 
 
Another thing to outline is that I decided to use a random angle instead of turning to a random time. My angle is between 30 to 90 degrees. I have stated that range due to after many tries it tent to turn more than 90 degrees and came back to its obstacle.
 



CONCLUSION:

To conclude I would like to outline that in an average of tries, it cleans about 80 percent of the house in about 30 mins. 

Here you can see a picture of the evaluator.

Down below, you can find videos.

VIDEOS: 


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 them!

- Random Start: random start.
- Running: vacuum running.



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...