I am working on a project where I need to calculate distance traveled by a robot. The mouse is connected to the arduino uno processor and I received some sample code from the arduino website to get started.

The problem is that the mouse gives difference distances depending on how fast or slow the it moves. (The same way you can move your pc mouse from side to side, fast and slow, and watch it cover different distances across the screen). Is there anyway to get get around this mouse setting? If not, is there a more accurate sensor that can be used to accomplish the task? I'm having a hard time finding one.

Here is a link to the datasheet: http://www.alldatasheet.com/datasheet-pdf/pdf/333273/PIXART/PAW3402.html

  • 2
    Mouse acceleration is part of the OS, not the mouse. Are you really having this problem, or are you just predicting this problem?
    – Gerben
    Oct 10 '16 at 11:26
  • If you could point out in the specifications you linked to where the mouse has the feature / ability to tell how fast it is moving I would appreciate it. And will change my answer to accommodate.
    – st2000
    Oct 10 '16 at 12:56

Assuming under normal conditions a relative pointing device such as a optical mouse always reports relative position changes with out regard to speed. If true, then consider that the speed of the robot is faster than the mouse can process. Also, consider that the mouse's optics is out of focus with respect to the surface it is supposedly taking its positioning cues from. Lastly, consider the surface may not be ideal for an optical mouse. Attempt the same experiment using a sheet of paper or a "not-shiny" wood surface.

All surfaces have to be flat. For example, a ceramic tile floor will likely not work as the surface will come in and out of focus during travel. Make sure the elevation of the robot with respect to the surface is constant. Inspect the wheels to make sure they are perfectly round and rotating around their center point.

Check and make sure you are not suffering from a integer calculation or type size problem. Examine your code and make sure you are handling all cases including the expected maximum and minimum values properly. And that your variables are large enough to handle these expected values.

  • It seems that the speed of the robot is faster than the mouse can process
    – Jay
    Oct 14 '16 at 22:23
  • on page 9 of the data sheet, bytes 2 and 3 give the detail of how fast the mouse is moving in the X and Y directions
    – Jay
    Oct 14 '16 at 22:30
  • @Jay, agreed. I knew this was going to be tricky to explain. I believe your Question describes an artifact of the driver, not the mouse. That is, using most drivers, if you move the mouse 1 inch slowly the driver will move the cursor a much shorter distance across the screen then if you moved the mouse the same distance quickly. I suspect, if you sum up all the mouse reports for both actions, the total will be nearly identical.
    – st2000
    Oct 15 '16 at 13:12

What you can do is use a hall effect (magnetic) sensor. If you connect a small magnet yo your shaft and connect the sensor in a way that the magnet will pass the sensor at every rotation, you can count the number of rotation that the shaft doesn thus calculating the distance.

It's a simple math equation:

distance = rotation * circonference of the wheels

For circonference, here is the equation:

circonfernce = diameter * PI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.