I am working on a project where I need to calculate distance travelled 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 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
-
3Mouse acceleration is part of the OS, not the mouse. Are you really having this problem, or are you just predicting this problem?Gerben– Gerben10/10/2016 11:26:22Commented Oct 10, 2016 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– st200010/10/2016 12:56:49Commented Oct 10, 2016 at 12:56
3 Answers 3
One thing I've noticed while using this mouse is that if my read-rate isn't fast enough the mouse will overflow. It can only read up to a 127 pixel movement in x or y before the buffer gets full (similar to what st2000 said). When you read from the mouse, it flushes the buffer and can start measuring pixels again.
I have my program flag any 127 pixel movements as an overflow event. In your application, you could slow the robot down when they happen and find a good 'top speed'. Or you could increase your read-rate.
...assuming you're still working on this 8 years later.
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 processJay– Jay10/14/2016 22:23:35Commented Oct 14, 2016 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 directionsJay– Jay10/14/2016 22:30:12Commented Oct 14, 2016 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– st200010/15/2016 13:12:26Commented Oct 15, 2016 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