# How to track robot position?

Robotics Asked by Michael Coss on January 6, 2022

I’m a software researcher, who in my spare time mentors a robotics team, helping on the software side of things. For years, I keep coming back to the same question: How to determine the robots position, and heading during our competitions? We have tried a number of things with varying degrees of success/failure. Encoders on the drive wheels, accelerometers, gyroscopes, etc. I recently bought an IMU with a 3 axis accelerometer, 3 axis gyro, and 3 axis magnetometer, all preprocessed by an Arduino, and outputting the value to a serial port. I thought surely there must be a way to take all these measurements and get a composite view of position and heading. We are using Mecanum wheels on this particular robot, so wheel encoders are not particularly useful. I’ve looked around and there’s a lot of talk about orientation using quaternion with sensor fusion using similar boards, but it very unclear to me how to take the quaternion and the estimation and come up with x,y distance from the starting position? Now, my time window for these measurements is small, ~15 seconds, but I need it to be pretty accurate within that window. I’m about ready to abandon using the IMU, and try something else. One idea is to use a USB ball mouse to try and track robot motion but I’m certain that the mouse is going to get banged around way too much leading to noise and invalid results. As a side note: The robot is about 2ft x 3ft base weighing in at 120 lbs. Any thoughts or suggestions appreciated.

How to estimate a robot's position depends on how well you'd like to estimate it. If you just need a rough guess, try odometry, it works OK. For better results, you have to incorporate more sensors. That's an incremental process that involves a lot of sensor fusion, and suddenly, you've built an Extended Kalman Filter.

The best way, in my opinion, is to use each sensor to form it's own estimate. Then, take a weighted average of the resulting estimates. The weights correspond to the certainty associated with each estimate. This, in essence is the Kalman Filter. What is missing is how to estimate the certainties. This is the hard part of the KF. Try some ad hoc values as a start. You'd be surprised how well this can work.

This is addressed as a first-principals question in any major robotics textbook and even here, on this site.

On this site, we have addressed many questions related to this problem.

and many more I've missed.

But honestly, these are heavy-handed approaches. You must understand the basics (estimating position from odometry, for example) to understand the rest.

Answered by Josh Vander Hook on January 6, 2022

I am not allowed to comment, so I have to add a reply. By position, do you mean the location in space (so X, Y coordinates), or orientation (tilt, etc)?

If position, you can use the accelerometer values and integrate acceleration to get distance traveled, though this is fairly inaccurate. We have tried to do this for a quadcopter, and the drift due to error is quite large.

You can use an accelerometer with a gyroscope together, and a Kalman filter to get a better idea for how far the robot has moved in each direction. Here is a previous discussion on this topic.

The tilt you can calculate directly from accelerometer values (but filter them, even an FIR filter would work ok).

Heading you can get from the gyroscope and/or the magnetometer. The gyroscope detects rotation, so make sure it is somewhere near the center of your robot (or whereever the axis of rotation is).

I hope that helps. I have to go teach, but I'll come back in an hour and add some more info.

Answered by Mewa on January 6, 2022