My team recently purchased a set of andymark mecanum wheels for off season testing use. We haven’t managed to build a chassis for them yet, but I want to get started on the programming so we have something to work with when we have the chassis built. I’ve been searching these forums for a few weeks now and I’m pretty sure I’ve read everything ever posted about mecanum wheels…twice. I’ve found a lot of code snippets but no explanation of the algorithms behind them.
Anyway, I’ve come up with this so far: http://img83.imageshack.us/img83/4896/mecanumqx7.jpg
I’m working under the assumption that each wheel will move at a 45 degree angle when powered. Thus, each wheel will attempt to move in the directions indicated by the green arrows. The green arrows show the movement of the wheels when the back two are turned backwards and the front two are turned forwards. They are then combined into the vectors shown by the blue arrows. Because the blue arrows are at 90 degrees from each other, you can orient them on the grid shown by the red lines.
I came up with the following equations, where x is the movement of the left front and back right wheels, and y is the movement of the right front and back left wheels:
y = sin(theta-45)(magnitude of R)
x = cos(theta-45)(magnitude of R)
R and theta being the vector indicated by the joystick you’re using to control the drivetrain.
This should return a value between -1 and +1 that should correspond to a PWM value between 0 and 255. If this function returns 0, the PWM value should be 127, if it returns 1 the PWM value should be 255, etc.
I ran a couple of values through this function and found the following problem. If I want the robot to go straight, theta is 90 and magnitude of R is 1.
Thus,
y = sin(90-45)(1) = .707
x = cos(90-45)(1) = .707
The PWM value for this should be:
.707 * 127 = 90
90 + 127 = 217
The problem with this is that all four wheels will move at the same speed (and therefore in the correct direction) but not at full power. I’m assuming that when the magnitude of R is 1, it indicates full speed, I think my problem lies here but I can’t be sure. Any help would be much appreciated.