Mecanum Drive Api

I am currently working on my own little robot that has a mecanum drivetrain. Im doing this as a project outside of robotics for fun and for a programming challenge. Looking for imspiration, I looked through WPI’s way of programming mecanum. When I went in and looked at driveCartesian (which is how I want to control my robot) I understand all the code, but dont understand why a piece of its in place.

The code that I dont really fully understand why it was programmed that way and what it actually accomplishes is:

    double[] wheelSpeeds = new double[4];
    wheelSpeeds[MotorType.kFrontLeft.value] = input.x + input.y + zRotation;
    wheelSpeeds[MotorType.kFrontRight.value] = -input.x + input.y - zRotation;
    wheelSpeeds[MotorType.kRearLeft.value] = -input.x + input.y + zRotation;
    wheelSpeeds[MotorType.kRearRight.value] = input.x + input.y - zRotation;

I understand that they are creating a array to (in the end of the program) to normalize and apply the speed to the individual motors. But I don’t understand why they are adding and subtracting different x and y values and rotation. I hope i’m right in assuming that these 4 lines are the core of how this class calculates the speed each wheel must go for control of mecanum.

Why does WPI subtract and add different values for different wheels in the MechanumDrive class in the driveCartesian method?

I was the one who did the latest rewrite circa 2016. Subsection 13.4.2 of has the kinematic derivations for a mecanum drive.

WPILib uses normalized velocities instead of absolute, so some of the constants like r are absorbed. There are unexpected negative signs in WPILib’s implementation because the right side velocities are negated under the assumption that positive voltage makes motors spin clockwise viewed from inside the robot. This is done throughout the drive classes.

If I were to do it again, I’d make positive always be forward and let the user handle any negations. It’s a lot easier for the user to figure out in that case and makes the derivation a bit simpler.

1 Like

@calcmogul, Yes! Thank you so much. This is exactly what I was looking for!

Also is anyone is looking for the pdf he posted, the file is under


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.