BUMP AND GO
In this exercise we have to implement a simple mechanism for our vacuum cleaner: When it crashes, go backwards, turn and go forward.
​
To do this, we need something that allow us to see if there is some obstacle next to the vacuum cleaner. We can use the laser or the bumpers.
​
BUMPERS
First, we are going to use bumpers.
The vacuum cleaner has three bumpers, one on the right side, other in the left one and the last one in the center.
To obtain if the bumper is pressed or not, we have to be looking at
Once we know if the bumper has been pressed, we have two options. If isn't pressed, it means that there's any obstacle so we can go forward.
If is, it means that there is some obstacle, so we can't go forward; we go backwards.
​
At this point we have two options again. The vacuum cleaner can't be going backwards forever, we need to control how much time. We can calculate it with iterations or with time.
I've decided to do it with iterations.
Once the vacuum cleaner has been turning a number of iterations, it can go forward again.
​
​
SOME IMPROVEMENTS

Having this, we still can improve our vacuum cleaner. For example, when it crashes at the center, choose a random direction to turn, not always the same.
Talking about randomness, we can apply it to the number of iterations that our vacuum is turning. (If we would have done our code with time instead of iterations, we could also apply randomness to time).
Doing this we obtain that our robot will be turning different number of iterations and will be able more easily to go out in complicated areas.
​
The result using bump and go with bumper is:
​
The other option that I've also done is using the laser. The laser give us a list of 180 values. Each value means the distance to the obstacle looked in that angle.
We can convert this list of distances into a list of 180 positions, where each position is a tuple of the distance (first position), same as the first list, but now also the angle in radians (second position) from the robot to the obstacle.
​
It's important to see that after use the laser, the index 0 of the list goes against the intuition: it's the right side of the laser.
Knowing this, the list would show us the information in this way:
LASER

180º
0º
With the same improvements, we can see the result with the laser: