# Localization within a map with gyro, accelerometer and magnetometer

My goal is to locate precision within a known map.

If the size of the map is known, a rectangle 4 x 3 m, and I know the initial position and orientation of the robot, after a certain period of time here moved randomly, can you know at what point of the map I am?

I use the MPU 9250 sensor, gyro, accelerometer and magnetometer sensor.

## 2 Answers

From the acceleration relatively to time you can get velocity and distance simply by ingrating ,and by how much you have moved added to your initail position with respect to the orientation you get the position,meaning imagine you moved forward orientation is the same you add the distance to y then moved to right straight you add the distance to x,but when you move in x,y together imagine you are in a triangle with the orientation as your angle

• The measurement samples are discrete and the acceleration is not constant. How can I proceed? Some specific guides for python? Jun 30, 2017 at 9:25

As @Abdul mentioned, and accelerometer measures acceleration which when integrated (adding together successive measurements over time) becomes velocity and when velocity is integrated you get position. So (in theory) you can use the accelerometer to track position.

The challenge with this is that in the real world you have error. As error is integrated over time it gets works and then when that is also integrated it gets WAY worse.

Last year our robotics team made a robot that focused on autonomy (the ability to drive itself). Initially we used the drive encoders to track robot position and orientation; but, when the wheels slipped or the robot was bumped it would go off path. To fix that, we added and accelerometer to correct. The initial results were impressive. You could bump the robot and it would return to the target path. Then one competition we had a several minute delayed start and rather than driving straight it immediately turned right and climbed the ramp. Epic Fail.

There are ways to correct (some) for the accumulated error. One technique is to use a Kalman Filter. Since the robot starts and stops a lot, the average acceleration should be zero. Also, you can compensate for bearing errors by using the magnetometer to detect and compare bearing changes. Another option is to use points where you know your robot's position, velocity, or orientation to correct calculated values.

The bottom line is that yes you can use and accelerometer to track potion; but, you will have to deal with accumulated error. The better you handle that the better your positional accuracy will be.