Vacuum Cleaner
Introduction.
You have probably heard of Roomba and other house cleaning robots. Well, for this exercise we are going to implement the algorithm of a vacuum-cleaning robot. The aim is to clean as much surface of the house as possible, time not being a restriction. Our robot is equipped with 180 lasers displayed in a semicircle at its front that will let it sense when it has reached near a wall. This way it can avoid collision.
Laser measurement processing.
As we've seen in the previous exercise, lasers output a single number that represents the distance to the first obstacle in that direction. This information is key for sensing our surroundings. Nonetheless, we won't be using this raw data just like that –there's some math we must do–.
First of all, we will translate these numbers to polar coordinates. We know there are 180 lasers displayed in a 180-degree semicircle, so we know at which angle each laser is pointing. With this information we can build a polar expression for every laser in the array. We will be using polar vectors to determine at what distance we are from any wall.
Take for instace there's a wall at our left. We want to use as many lasers as possible to measure its distance from us, not just one. Laser number 0 will measure the perpendicular distance, but all the other lasers are at a certain angle that is not perpendicular to the wall, so the number they give us will be greater than the actual distance we are from the wall. But that's no problem: since we know those angles we can just do some basic trigonometry. We multiply each measurement from its angle's cosine, so we get the horizontal distance to the obstacle. In the case of the front lasers we use the sine instead because we are looking for the vertical distance (being 0 degrees the horizontal reference).
Avoiding collision.
We already know a lot about our surroundings. Now its time to react to this information (hence called reactive-control method). You could say the wall is at about the mean distance of our left lasers output (I've considered 0 to 44 as left). That consideration might seem accurate, but what if the wall is not flat but spiky? What if the obstacle to our left isn't even a wall but some sort of vertical pole? Then the mean would say its far from us and we would crash directly into it. For that reason you have to consider the minimun distance of all your measurements as the obstacle to avoid.
You have probably heard of Roomba and other house cleaning robots. Well, for this exercise we are going to implement the algorithm of a vacuum-cleaning robot. The aim is to clean as much surface of the house as possible, time not being a restriction. Our robot is equipped with 180 lasers displayed in a semicircle at its front that will let it sense when it has reached near a wall. This way it can avoid collision.
Laser measurement processing.
As we've seen in the previous exercise, lasers output a single number that represents the distance to the first obstacle in that direction. This information is key for sensing our surroundings. Nonetheless, we won't be using this raw data just like that –there's some math we must do–.
First of all, we will translate these numbers to polar coordinates. We know there are 180 lasers displayed in a 180-degree semicircle, so we know at which angle each laser is pointing. With this information we can build a polar expression for every laser in the array. We will be using polar vectors to determine at what distance we are from any wall.
Take for instace there's a wall at our left. We want to use as many lasers as possible to measure its distance from us, not just one. Laser number 0 will measure the perpendicular distance, but all the other lasers are at a certain angle that is not perpendicular to the wall, so the number they give us will be greater than the actual distance we are from the wall. But that's no problem: since we know those angles we can just do some basic trigonometry. We multiply each measurement from its angle's cosine, so we get the horizontal distance to the obstacle. In the case of the front lasers we use the sine instead because we are looking for the vertical distance (being 0 degrees the horizontal reference).
Avoiding collision.
We already know a lot about our surroundings. Now its time to react to this information (hence called reactive-control method). You could say the wall is at about the mean distance of our left lasers output (I've considered 0 to 44 as left). That consideration might seem accurate, but what if the wall is not flat but spiky? What if the obstacle to our left isn't even a wall but some sort of vertical pole? Then the mean would say its far from us and we would crash directly into it. For that reason you have to consider the minimun distance of all your measurements as the obstacle to avoid.
We then set a threshold below which an obstacle is considered too close to our robot. If there's an obstacle at our left which is closer than that threshold, then we must turn right to avoid collision. If the obstacle is at our right, then turn left. If it's in front of us then stop and turn either left or right.
Spiraling start.
Collision avoidance is done and now we are aiming for a better performance overall. Since our robot starts in the middle of the room with plenty of free space around it perhaps its best to try to cover up all that surface by moving in a spiral instead of going in a straight line into a wall. This can easily be done by setting a constant turn speed and increasing its forward speed with every iteration, so that the radius of the circle it describes becomes bigger and bigger. Then, after it reaches a wall for the first time, it will act as usual, avoiding walls and moving in straight lines.
Final model.
For the final version I've tweaked the speeds a little and made the robot go slightly backwards when facing a wall. I've also done some adjustments to try to avoid situations where the robot keeps turning in a loop and gets stuck between close walls.
Here's a video of this final version:
Spiraling start.
Collision avoidance is done and now we are aiming for a better performance overall. Since our robot starts in the middle of the room with plenty of free space around it perhaps its best to try to cover up all that surface by moving in a spiral instead of going in a straight line into a wall. This can easily be done by setting a constant turn speed and increasing its forward speed with every iteration, so that the radius of the circle it describes becomes bigger and bigger. Then, after it reaches a wall for the first time, it will act as usual, avoiding walls and moving in straight lines.
Final model.
For the final version I've tweaked the speeds a little and made the robot go slightly backwards when facing a wall. I've also done some adjustments to try to avoid situations where the robot keeps turning in a loop and gets stuck between close walls.
Here's a video of this final version:
Comments
Post a Comment