The Mecanum Drive uses four motors and wheels that have rollers to provide thrust at a 45 degree angle away from the rotation axis. By providing the right combination of signals to the four motors, the robot can move forward or back and left or right and rotate in place.
The left stick on the gamepad controls robot translation in the direction the stick is pushed. The right stick on the gamepad controls rotation.
The variables X1, X2, and Y1 are scaled values based on the stick positions.
The variables LF, RF, LR, RR are calculated from combinations of the XY values and represent each wheel’s desired speed and direction. These values are clipped at +-1 and are then used to set the power levels of the wheel motors.