If you just want some practical help for writing your own mecanum code… you can write your own code, which uses -1 to +1 joystick output values, as follows:
Let x, y, and z be the rev/fwd, slide left/right, and spin CCW/CW joystick commands, respectively, which each vary from -1 to +1.
So:
x= -1 corresponds to full speed reverse, x= +1 corresponds to full speed forward,
y= -1 corresponds to full speed slide left, y= +1 corresponds to full speed slide right,
z= -1 corresponds to full speed spin CCW, z= +1 corresponds to full speed spin CW
If your joystick outputs don’t look like the above (eg the signs are reversed), simply convert them.
Let w1, w2, w3, and w4 be the commands to send to each of the 4 wheels, where w1 is front left, w2 is front right, w3 is rear left, w4 is rear right, as viewed from the top.
set the four wheel speed commands as follows:
w1 = x + y + z
w2 = x - y - z
w3 = x - y + z
w4 = x + y - z
You’re almost done. All that remains is to normalize the above commands so that their range is -1 to +1. Proceed as follows:
- look at the magnitude (absolute value) of each of the four commands, and select the MAXIMUM. for sake of discussion, call this maximum value Wmax
- if Wmax is less than or equal to 1, no scaling is required. Just use the four w commands as-is
- if Wmax is greater than 1, then divide EACH of the four w values by Wmax.
That’s all there is to it. Send each w command to the corresponding wheel.
One note of caution: make sure the polarity of the motors on each side of the bot is wired correctly (each wheel must be spinning in the “forward” direction when it gets a +1 command). The easiest way to observe this is to elevate the bot and push the joystick forward; all four wheels should be spinning forward.
Here’s a way to program tank drive on mecanum bot so that you can tune the joystick sensitivity to all three motions (fwd/rev, turn, stafe) independently:
Let X1 and Y1 represent the joystick outputs for the driver’s left-hand joystick;
Let Y2 represent the joystick outputs for the driver’s right-hand joystick (X2 is not used).
Y1 and Y2 control the bot like a standard tank drive for fwd/rev and spinning. X1 provides the strafe command.
When each joystick is pushed forward, its Y output should be positive. When the joystick is pushed to the right, its X output should be positive. If not, add code to invert the sign if necessary.
Let Kf, Kt, and Ks be the tuning parameters (0 to +1) for the forward/reverse, turn, and strafe motions, respectively.
Let W1, W2, W3, and W4 be the front left, front right, rear left, and rear right wheels, respectively. (“left” and “right” in this context means “port” and “starboard”, respectively)
Calculate the following:
Yf = (Y1 + Y2)/2
Yt = (Y1 - Y2)/2
Now calculate the four wheel speed commands:
W1 = KfYf + KtYt + Ks*X1
W2 = KfYf - KtYt - Ks*X1
W3 = KfYf + KtYt - Ks*X1
W4 = KfYf - KtYt + Ks*X1
Now normalize the wheel speed commands:
Let Wmax be the maximum absolute of the four wheel speed commands. If Wmax is greater than 1, then divide each of the four wheel speed commands by Wmax.
Finally, send each of the four normalized wheel speed commands to the respective wheels.
Adjust the values of Kf, Kt, and Ks (over the range 0 to +1) to adjust the joystick sensitivity for the forward/reverse, turn, and strafe motions, respectively.
If you want to understand the theory of mecanum kinematics and forces, take a look at these papers:
Inverse and Forward Kinematic Equations for 4-wheel mecanum vehicle:
http://www.chiefdelphi.com/media/papers/2390
Force vector analysis of 4-wheel mecanum vehicle:
http://www.chiefdelphi.com/media/papers/2385