I have a differential drive robot, using odometery to infer its position.
I am using the standard equations:
WheelBase = 35.5cm;
WheelRadius = 5cm;
WheelCircumference = (WheelRadius * 2 * Math.PI);
WheelCircumferencePerEncoderClick = WheelCircumference / 360;
DistanceLeft = WheelCircumferencePerEncoderClick * EncoderCountLeft
DistanceRight = WheelCircumferencePerEncoderClick * EncoderCountRight
DistanceTravelled = (DistanceRight + DistanceLeft) / 2
AngleChange (Theta) = (DistanceRight - DistanceLeft) / WheelBase
My (DIY) chassis has as a slight feature, where over the course of the wheel base (35.5cm), the wheels are misaligned, in that the left wheel is 6.39mm (I’m a software person not a hardware person!) more ‘forwards’ than the right wheel. (The wheels are the middle of the robot.)
I’m unsure how to calculate what I must add to my formulas to give me the correct values.. It doesn’t affect the robot much, unless it does on the spot turns, and my values are way off, I think this is causing it.
My first thought was to plot the wheel locations on a grid, and calculate the slope of the line of their positions, and use that to multiply… something.
Am I on the right track? Can someone lend a hand? I’ve looked around for this error, and most people seem to ignore it (since they are using professional chassis).
The correction must be made to the formula for AngleChanged, as follows:
Take L and R to be the distances traveled by the left and right wheels, respectively, in one tick.
Let B denote the length of the nominal wheelbase (not the length of your skewed one).
Let E represent the left wheel error. That is, the distance the left wheel is offset forward from its ideal position.
We seek to find θ, the change in the angle of the wheelbase in one tick.
First, (pre)-calculate the angle between the skewed wheelbase and the ideal wheelbase:
Using some elementary geometry (I can post details if you desire), we may calculate theta as follows:
Seeing as this reduces to your previous implementation when E=0, and has intuitively understandable results as E -> +inf., our formula seems correct.
NOTE:
You probably want to do away with that computationally ugly arctangent in your calculation of σ (sigma). In situations as these, it’s common practice (indeed, you used it in your previous formulas) to use the approximation arctan(x) = x, for small x.
The problem here is that while the quantity (L-R)/B is likely to be quite small, the error addition E/B may grow unacceptably large. You can try calculating sigma by just doing away with the arctan and using sigma = (E+L-R)/B, but if you want a better approximation you should use the first-order taylor series for arctan(a+x) around 0:
arctan(a+x) = arctan(a) + x/(1 + a^2)
Applied to the calculation of sigma, the approximation now looks such:
Notice that the arctan(E / B) has already been precalculated as φ. This is a much better approximation for sigma, which should yield more exact calculations for theta.