# Measure angular error using front sensors

By | October 13, 2011

The front, or forward-facing, sensors on a micromouse have several uses. Apart from detecting the distance to walls ahead and obstacles on one side or another, properly setup forward sensors can be used to measure an angular error with respect to a wall ahead of the mouse…

If the mouse is positioned facing a wall ahead, perpendicular to the axis of the mouse, both forward sensors should give the same value. Indeed, they are calibrated to do just that. Suppose both face directly ahead of the mouse. If the mouse turns in place so that it is a little off axis, both sensors will now see an increase in distance to the wall. If it rotates left, the left sensor will see a larger increase than the right sensor. The opposite will be true for a rotation to the right.

So it seems a reasonable supposition that the difference in the two sensor readings would be a measure of the angle between the mouse and the wall ahead. By plotting the difference against the actual angle, a simple equation can be derived giving the angle off-perpendicular as a function of the sensor difference. For the particular sensor setup on my mouse, the equation has these values:

angleError = -(379*(sensorDifference)/256-3;  // -16 < sensorDifference < 16

The irritating -3 at the end is because I pointed the sensors straight at the wall and there is a small bias from a little bit of misalignment. If the sensors were angled slightly outwards and better aligned in general, the gain increases and the bias should reduce. on a previous configuration, the gain turned out at almost exactly 1. that is, the sensor difference could be used directly as the angular error. In general, that will not be the case. However, since I have just had to replace the emitters, I will have to live with this for now. Plotting actual results from the mouse can be done by having the mouse rotate in front of a wall and then plot the calculated angular error against the actual angular error as measured form the gyro.

You will see that the error is remarkably linear over a range or errors up to +/- 20 degrees. By whatever means suits the controller in your mouse, you can now use the measured value to help align the mouse while searching.

There is, of course, no real need to calculate the actual angle if all you want to do is reduce the difference to zero. You could simply use the difference as the error in your rotation controller with appropriate care about gains. I find it convenient to know the angle and command a turn of just the right size to counteract it. that way, I dont have to mess with the controller setup.

Note that I would not expect the same calibration to work at other distances. Nor have I bothered to work out the relationship between distance and calibration values. At greater distances from the wall, the change in distance with rotation would be a smaller proportion of the actual distance and so the effect would be much less pronounced. Closer to the wall, the effect would be exaggerated. Feel free to add a comment with your results if you try that.

This site uses Akismet to reduce spam. Learn how your comment data is processed.