SPIRAL ALGORITHM
The goal of this exercise is to implement an algorithm that allows us to clean the maximum percentage in the minimum time. We can't use global or local navigation, so we are going to use the laser to be able to detect obstacles.
​
Since we implemented the laser in the last exercise, we can use this idea to start our algorithm.
The first step I've decided to do is start in a spiral movement, increasing the linear velocity each n iterations, letting the vacuum increase the spiral each time more.
The vacuum will continue with this movement until the laser detect any obstacle. In that case, we'll do the same as we did in the bump and go: depending on where is the closest obstacle, turn to one side or another. In case that the obstacle is in the middle, turn in a random direction.
As we did, the number of iterations turning is random each time.
​
After turn and avoid the obstacle, we could take the spiral movement back, but this could make the vacuum less efficient in case of being in some place like a corridor.
So, instead of doing that, after avoid an obstacle the vacuum continue going forward, as we did in the bump and go. If it detects another obstacle, will do the same; turn and go forward again.
​
But... are we going to use again the spiral movement?
The answer is yes. In the case of being a considerable number of iterations going forward, we'll do again the spiral movement, so then we'll be sure that the vacuum has been an important number of iterations without colliding.
​
At this point, the vacuum's behavior would be this:
ALGORITHM IMPROVEMENTS
We could think that our vacuum already has a good algorithm: starts with spiral movement until see an obstacle, turn and go forward. If it's been a long time going forward, start again doing the spiral movement.
But... what happens if there isn't any obstacle around?
The vacuum would be doing the spiral all the time, which would increase more and more the velocity, ending with an uncontrollable vacuum.
To avoid this problem, I've decided to put a top velocity. If the vacuum surpasses this number, will stop and continue going forward.
I've done a demonstration to see it:
Another thing that we could see after try different times our code at this point, is that since we have a different turning direction depending on the side where the closest object is, we could have problems in certain places like corners, where is too easy to get right or left all the time, making the vacuum turning in opposite directions each iteration and not being able to solve the corner problem.
In this case, I've created a recovery mode, which is activated in the case of being more than a certain number of iterations (in my case 150) turning. This will mean that the vacuum has problems to continue cause is blocked by some corner or some difficult obstacle.
After activate the recovery mode, the vacuum will only turn in one direction, letting it to find space to continue going forward. Once any obstacle is detected, the recovery mode ends.
We can see it in this video
It seems that everything is ready... let's test our algorithm! With referee, we'll see our algorithm's efficacy after 15 minutes cleaning. The next video shows us the last seconds:
To finish, I'll post more final examples with the percentages that I've obtained after try the final algorithm:

