# How to count the units moved with 2 motor encoders

I have a 2 wheel device that both has motor encoders, counting the units moved on both motors is simple if the both motors speed is the same. My problem arises when the device is turning to the left or to the right. Turning causes one motor to speed up and the other to slow down. The count now on each motor is different.

Is there some logic or arithmetic i can apply that takes into accounts turnings? and can calculate the true distance moved of the device. The point of refence now of measuring the distance is now not on the wheel since it is not very reliable but now on the center of both wheels.

What I came up with is just to AVERAGE the left and right motor counts, but i do not know if this is the best solution to approach this problem

Any thoughts?

• Seems reasonable. Why are your counts not whole integers, anyways? Commented Dec 24, 2019 at 5:49
• Average is the only solution with this. Orientation 7.86/90 deg except for slippage Commented Dec 24, 2019 at 5:59
• Average is a very poor solution to your problem. You have to do the math to do dead reckoning. Suggest you start with a simple approach using quadrature encoders ...this is a good starting point: seattlerobotics.org/encoder/200010/dead_reckoning_article.html Commented Dec 24, 2019 at 6:09
• i do suggest reading the first reference in that article rossum.sourceforge.net/papers/DiffSteer/DiffSteer.html Commented Dec 24, 2019 at 6:32
• Just use diffeq to grab up a state space representation for the model/simulation (which you need) and then use a Kalman filter/error covariances observer of the motion. Done. It will just work. Period. There's nothing much good coming from simple averages. But feel free, of course.
– jonk
Commented Dec 24, 2019 at 7:17

## im not sure of my answer:

arc length = $$2\pi r\theta$$

distance between wheels = h

arc1 units = $$2\pi r\theta$$ arc2 units = $$2\pi (r+h)\theta$$

arc_center = $$2\pi (r+(h/2))\theta$$

## average:

$$(arc1 + arc2) / 2 = (\pi\theta)(r+(r+h))$$ $$(arc1 + arc2) / 2 = (\pi\theta)(2r+h))$$ $$(arc1 + arc2) / 2 = (\pi\theta)(2(r+h/2)))$$ $$(arc1 + arc2) / 2 = 2(\pi\theta)((r+h/2)))$$

you can see your method is actually = center arc length

• centre is average of both wheels since they are always parallel Commented Dec 24, 2019 at 7:22
• @TonyStewartSunnyskyguyEE75 yes, this post is deriving that the center arc = average(arc1,arc2) Commented Dec 24, 2019 at 10:55
• There is no other sensor input to determine slippage from lack of parallel wheels or center or difference in centre of radius. Thus no other way to count. Of course one can average for velocity, acceleration etc. or do any complex math you want over any time interval but for position, there is no need. In fact for all servo systems you want 1st order feedback when possible. Commented Dec 24, 2019 at 13:54
• Robotic simulator software sourceforge.net/projects/rossum i.sstatic.net/bkanM.png Commented Dec 24, 2019 at 14:37