Skip to main content

Mecanum Kinematics

Easydifficulty

This is one of the easier lessons on the site. It's adding and subtracting, done every loop, and by the end you should be able to write a teleop drive from memory.

Three numbers in, four motors out​

The driver gives you three numbers from two thumbsticks: how much to go forward, how much to strafe (slide sideways), and how much to turn. The robot has four motors. Every loop you turn those three numbers into four wheel powers, and if a sign is wrong the robot strafes when you meant to spin.

The obvious "add the sticks together" code has two more problems. It drives relative to the robot, so once the robot turns around the driver is fighting the controls. And pushing two sticks at once can ask a wheel for more than 100% power, which the motor clips, bending a straight line into a curve. Both are fixed below.

One idea: each wheel pushes along a diagonal​

A mecanum wheel has small rollers around its edge set at 45°. Because of that angle, a spinning wheel doesn't push straight forward like a normal wheel. It pushes along a diagonal. The four wheels are mirrored so their diagonals make an X when you look down at the robot.

One wheel can only push along its diagonal, but add up all four pushes and interesting things happen. The sideways parts can cancel, leaving pure forward motion. The forward parts can cancel, leaving pure sideways motion. Or they can combine into a spin. Getting the motion you want is a matter of choosing the four wheel speeds.

Mixing: add the three things you want​

Work in the robot's own frame first. Call the three parts of the command vxv_x (forward), vyv_y (strafe, positive to the left), and ω\omega (turn, positive counter-clockwise). Each wheel gets a share of all three. For front-left, front-right, back-left, and back-right:

wFL=vx−vy−ωwFR=vx+vy+ωwBL=vx+vy−ωwBR=vx−vy+ω\begin{aligned} w_{FL} &= v_x - v_y - \omega & w_{FR} &= v_x + v_y + \omega \\ w_{BL} &= v_x + v_y - \omega & w_{BR} &= v_x - v_y + \omega \end{aligned}

Check it one input at a time. Push only forward, vx=0.5v_x = 0.5: all four wheels get 0.5 and the robot drives straight. Push only left, vy=0.5v_y = 0.5: FR and BL get +0.5 and FL and BR get −0.5, and the X pattern pushes the robot sideways. Turn only, ω=0.5\omega = 0.5: the right wheels get +0.5 and the left wheels −0.5, and it spins in place.

The same four lines written as one matrix multiplication, which is how the ECAM and gm0 references at the end present it:

[wFLwFRwBLwBR]=[1−1−11−1−11−1−11−1−1][vxvyω]\begin{bmatrix} w_{FL} \\ w_{FR} \\ w_{BL} \\ w_{BR} \end{bmatrix} = \begin{bmatrix} 1 & -1 & -1 \\ 1 & \phantom{-}1 & \phantom{-}1 \\ 1 & \phantom{-}1 & -1 \\ 1 & -1 & \phantom{-}1 \end{bmatrix} \begin{bmatrix} v_x \\ v_y \\ \omega \end{bmatrix}

In the full physical version the ω\omega column is ±(L+W)\pm(L+W), where LL and WW are the distances from the robot's center to the wheels, because wheels farther out have to travel further to turn the robot. For teleop with normalized powers you can fold that into ω\omega and use ±1\pm 1. Push the sticks in the demo and watch each wheel's number come from those sums:

Live demoMecanum drive — command in, four wheel powers out, robot in motion
robot vₓ: —robot v_y: —desaturate ÷: —heading: —FL: —FR: —BL: —BR: —
wheel forwardwheel reversefield travel direction & trail

Field-centric: rotate the command first​

Drivers think in field directions, like "toward the goal," not robot directions. So before mixing, rotate the driver's command from the field frame into the robot's frame using the robot's heading θ\theta from the IMU.

Check with a case you can picture. The robot faces left, θ=90°\theta = 90°, and the driver pushes the stick away from them, toward the far wall. From the robot's point of view, the far wall is to its right, so the robot should strafe right: vx=0v_x = 0, vyv_y negative. The rotation by −θ-\theta does exactly that:

[vxvy]robot=[cos⁡θsin⁡θ−sin⁡θcos⁡θ][vxvy]field\begin{bmatrix} v_x \\ v_y \end{bmatrix}_\text{robot} = \begin{bmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{bmatrix} \begin{bmatrix} v_x \\ v_y \end{bmatrix}_\text{field}

With θ=90°\theta = 90°, cos⁡θ=0\cos\theta = 0 and sin⁡θ=1\sin\theta = 1, so a field command of (1,0)(1, 0) becomes (0,−1)(0, -1) in the robot frame: no forward, full right. Now "push the stick away from you" means the same direction on the field whichever way the robot faces. Turn field-centric on in the demo and spin the heading to feel it.

Desaturation: keep the robot driving straight​

The sums can come out bigger than 1. Full forward plus full turn asks the front-right wheel for 1+0+1=21 + 0 + 1 = 2, and the front-left for 1−0−1=01 - 0 - 1 = 0. Clip the front-right to 1 and leave the rest alone, and the ratio between the wheels changes, so the robot curves away from where you aimed.

Instead, divide all four by the biggest one, but only when it's over 1. Here that's 2, so the wheels become 1 and 0: the same turn-and-drive, just at half speed:

scale=max⁡(1, ∣wFL∣,∣wFR∣,∣wBL∣,∣wBR∣),wi←wiscale\text{scale} = \max\big(1,\ |w_{FL}|, |w_{FR}|, |w_{BL}|, |w_{BR}|\big), \qquad w_i \leftarrow \frac{w_i}{\text{scale}}

Commands that already fit pass through unchanged, because of the 1 in the max. Oversized ones shrink but keep their ratios, so the robot still goes the direction you asked. (gm0's tutorial divides by max⁡(∣vx∣+∣vy∣+∣ω∣, 1)\max(|v_x| + |v_y| + |\omega|,\ 1) instead, which is a slightly more cautious version of the same idea.) In the demo, push forward and turn all the way and watch the "desaturate ÷" readout go above 1.

Scaling the joystick for fine control​

A raw stick is linear: half stick gives half speed. But the moments that need precision, like creeping up to score, are small-stick moments, and a linear response makes them twitchy. Bending the response fixes it: small pushes give very small speeds, and full stick still gives full speed. Raise the stick's magnitude to a power k≥1k \ge 1. (Shape the magnitude rather than each axis separately, or the direction gets distorted.)

mout=min k,min=vx2+vy2m_\text{out} = m_\text{in}^{\,k}, \qquad m_\text{in} = \sqrt{v_x^2 + v_y^2}

k=1k = 1 is linear; k=2k = 2 (squared) is the classic FTC feel — half stick now gives a quarter speed, so slow moves are gentle and the top end is untouched. Some drivers prefer cubic (k=3k = 3).

Dead zone: ignore a stick that won't sit still​

Thumbsticks don't return exactly to zero. Let go and the stick might report 0.03 forever, so the robot creeps on its own. A dead zone fixes that: any value smaller than a threshold dd counts as zero.

A plain dead zone causes a small lurch, though. The moment the stick passes dd, the output jumps from 0 to dd. The fix is to stretch what's left of the range so the output starts at 0 at the edge of the dead zone and reaches 1 at full stick. Combined with the response curve:

shape(s)={0∣s∣≤dsign⁡(s) (∣s∣−d1−d) ⁣k∣s∣>d\text{shape}(s) = \begin{cases} 0 & |s| \le d \\[4pt] \operatorname{sign}(s)\,\left(\dfrac{|s| - d}{1 - d}\right)^{\!k} & |s| > d \end{cases}

Here ss is the raw stick value, dd the dead zone (around 0.06 is typical), and kk the curve exponent. With d=0.06d = 0.06 and k=2k = 2, a stick at 0.53 gives ((0.53−0.06)/0.94)2=0.52=0.25((0.53 - 0.06)/0.94)^2 = 0.5^2 = 0.25.

Drag the input below. The flat red band is the dead zone, and past it the blue curve climbs to full. A dead zone of 0.05 to 0.10 stops the drift without the driver noticing it.

Live demoDead zone + response curve: from raw stick to drive command
raw stick →↑ command outdead zone
raw: 0.30command out: 0.05inside dead zone?: no
shaped commandraw (linear) for comparisondead zone — ignored

A clean field-centric teleop drive​

The whole thing is short as long as you keep the order: shape, rotate, mix, desaturate.

FTCStick shaping: dead zone and response curve
// One stick axis in [-1, 1] -> a shaped command in [-1, 1].
// DEADZONE ~ 0.06, DRIVE_CURVE ~ 2.0.
double shape(double s) {
double a = Math.abs(s);
if (a < DEADZONE) return 0; // ignore stick drift at rest

double scaled = (a - DEADZONE) / (1 - DEADZONE);
return Math.signum(s) * Math.pow(scaled, DRIVE_CURVE);
}

scaled runs from 0 at the edge of the dead zone to 1 at full stick, so the output doesn't jump.

FTCField-centric mecanum drive
// fwd +1 away from the driver, strafe +1 to the driver's left,
// turn +1 counter-clockwise, all [-1, 1]. heading is field-frame radians.
void driveFieldCentric(double fwd, double strafe, double turn, double heading) {
double mag = Math.min(1, Math.hypot(fwd, strafe)); // shape the MAGNITUDE
double dir = Math.atan2(strafe, fwd);
double m = shape(mag);

double fwdC = m * Math.cos(dir);
double strafeC = m * Math.sin(dir);
double w = shape(turn);

double c = Math.cos(heading), s = Math.sin(heading); // rotate by -heading
double vx = fwdC * c + strafeC * s;
double vy = -fwdC * s + strafeC * c;

double fl = vx - vy - w; // mix the wheels
double fr = vx + vy + w;
double bl = vx + vy - w;
double br = vx - vy + w;

double scale = Math.max(1, Math.max(
Math.max(Math.abs(fl), Math.abs(fr)),
Math.max(Math.abs(bl), Math.abs(br))));
setWheelPowers(fl / scale, fr / scale, bl / scale, br / scale);
}
ExerciseWhat the exponent does

Make a table of scaled^1 and scaled^2 at 0.25, 0.5, 0.75, and 1.0. Where does the driver gain fine control, and what do they give up? Then, with DEADZONE = 0.06 and no stretching, how big is the jump when the stick leaves the dead zone?

Show solution

Squaring gives 0.0625, 0.25, 0.5625, and 1.0, so the bottom half of the stick now covers only a quarter of the output range. Slow, precise driving gets most of the stick's travel. The cost is at the top, where the same stick movement changes the speed more, so full-speed driving is a bit twitchier.

Without stretching, the first output past the dead zone is 0.06 instead of 0, a 6% power jump. On a drivetrain that's a visible twitch every time the driver starts moving.

ExerciseWhy the magnitude is shaped, not each axis

Push the stick to exactly 45° and square fwd and strafe separately. What angle does the robot drive at? Now try 60°.

Show solution

At 45° it still drives at 45°, because both parts are equal and get squared the same way. At 60° the parts are 0.5 and 0.866. Squared, they're 0.25 and 0.75, and atan2(0.75, 0.25) is 71.6°, not 60°. Shaping each axis separately bends every direction except straight along an axis or a diagonal. Shaping the magnitude and rebuilding from the angle keeps the direction.

ExerciseDerive the four signs

Each roller turns wheel spin into a push at 45°. Draw all four from above and add up the pushes for "all wheels forward," then "left side forward, right side backward," then one diagonal pair (FL, BR) driven against the other (FR, BL).

Show solution

All four forward: the sideways parts cancel in pairs and the forward parts add, so the robot drives straight. Left side forward, right side backward: the forward and sideways parts both cancel, leaving only a twist, so the robot spins in place. One diagonal against the other: the forward parts and the twist cancel, leaving a sideways push, which is the strafe. Each sign in the mixer just says which of those three a wheel contributes to, and in which direction.

ExerciseWhy desaturate all four by one factor

Why divide every wheel by the same number instead of clipping each one at 1?

Show solution

The ratios between the four wheels are what set the direction and turn rate. Clip one wheel and the robot goes somewhere you didn't ask, usually curving, and it happens exactly when you're pushing hardest. Scaling all four keeps the ratios, so the robot goes the right way, just slower. When you've asked for too much, slower is the right way to fall short.

In an FTC OpMode the sticks map in like this. The gamepad's Y axis is upside down, so negate it:

FTCReading the gamepad
double fwd = -gamepad1.left_stick_y; // up on the stick = forward
double strafe = -gamepad1.left_stick_x; // left on the stick = +left (our convention)
double turn = -gamepad1.right_stick_x; // left = counter-clockwise
double heading = imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS);
driveFieldCentric(fwd, strafe, turn, heading);

In autonomous, the same (vx, vy, omega) command comes from a controller instead of the sticks. Before building one, the next lesson, Angle Wrapping, fixes the one bug every heading controller runs into.

Strafing is weaker than driving forward

The angled rollers lose a little grip sideways, so a mecanum robot strafes slower than it drives forward at the same power. The usual fix, from gm0, is to multiply the strafe command by about 1.1 before mixing. Tune the exact number on your robot.

Mecanum drive encoders slip

You can use mecanum wheel encoders for position tracking, but the rollers slip sideways, so strafing distance and heading drift more than the ideal math suggests, especially when driving hard or pushing. Before an autonomous follower relies on that position, set up your localization library and check it with the Pose Estimation Contract, including how far off it is after returning to the start.

Most mecanum bugs are one reversed motor

If one wheel fights the others, flip that motor's direction in the configuration, not the math. Pick one convention (+x forward, +y left, +ω counter-clockwise), write it in a comment, and make every wheel follow it.

Sources and further reading

This lesson follows three excellent public tutorials, adapted to our curriculum's conventions (+x forward, +y left, +ω CCW):

  • Wheel kinematics and the mixing matrix: ECAM Eurobot, Mecanum wheel kinematics.
  • The FTC wheel-power equations, field-centric rotation, normalization, and the strafe correction — gm0, Mecanum Drive.
  • Joystick direction and magnitude, 45° roller-force intuition, sinusoidal wheel contributions, turn superposition, and common-factor normalization — SEA Monsters 2605, How a Mecanum Drive Works. Its interactive diagrams are a useful second explanation before deriving the four-sign mixer by hand.