Robot

Hi all, in this article I will try to give you some information about one of the most known algorithm that helps us to solve robot localization problem. First of all, when it comes to robotics, there is uncertainty almost in everywhere. In theory, If we know the exact movement of the robot then we can calculate the position of it based on its first location. But you know, nothing is going well in real world. We can’t know where the robot is exactly located since there is an environmental noise that effects sensor measurements.

Lets say we are using motor encoders to compute robot’s location and we are giving command to robot like “go ahead 30cm and turn 45 degrees to counter clockwise”. In an ideal case, it will do what we exactly command. But like I said before, it wont because life is not ideal. If there is an obstacle on the way of the robot and robot bumps to it then its wheels may spin in air and this may cause the wrong measurements. To solve these problems we can increase the amount of the sensors, maybe we can add accelerometer to detect the movement but sometimes it doesnt matter increasing the numbers. Because every sensor has its own uncertainty, this is why the localization problem is one of the biggest problems in robotics.

There are lots of scientists who are trying to solve this problem. Also I can list some of this solutions for you.

But I will continue with Particle Filter. In Particle Filter, we trying to localize the robot according to its sensor measurements by using particles.

So what are those particles? Actually, particles are representing the possible locations of our robot in map. At first run, our robot can be anywhere in map so the particles should be spread to all map randomly.

Whenever the robot(our badboy) moves, all particles(virtual robots) also moves with the same orientation and distance. After the movement, robot senses its environment and the measurement values are saved. After that, each particle senses the virtual environment based on landmarks, and for the each measurement, new weight is calculated by the similarity to the original one. Then the particles are resampled according to their weights(like most similar first 10). So every next iteration will be more certain about the position of robot.

The most important key in localization is: “Movement increases the uncertainty and sensing decreases the uncertainty and these two operations must follow each other continuously.”

You can find the basic implementation of Particle Filter Localization in below:

###
# /robot.py
###

class Robot(object):
    """
    The class that helps to simulate the robot behaviours
    Sebastian Thrun's Robot implementation used as reference and improved by Talha Havadar.
    """
    world_size = 100.0
    landmarks  = [[20.0, 20.0], [80.0, 80.0], [20.0, 80.0], [80.0, 20.0]]

    def __init__(self):
        self.x = random.random() * Robot.world_size
        self.y = random.random() * Robot.world_size
        self.orientation = random.random() * 2.0 * pi
        self.forward_noise = 0.0
        self.turn_noise = 0.0
        self.sense_noise = 0.0

    @staticmethod
    def set_world_size(size):
        """
        Sets the world size of the robot
        """
        if size < 0:
            raise ValueError("World size must be greater than 0.")
        Robot.world_size = size

To access the full code, please visit my RobotLocalization project on GitHub

Enjoy the life!! See you on next one.