03 / TeleOp and Mecanum
Robot-Centric Mecanum Drive
Convert gamepad drive, strafe, and turn into four motor powers.
03 / TeleOp and Mecanum
Convert gamepad drive, strafe, and turn into four motor powers.
You will
This lesson is about the interface between drivers and robot behavior. Good TeleOp code is not just mathematically correct; it is predictable under pressure, easy to recover, and readable enough that the drive team can describe what the robot is supposed to do.
A mecanum drivetrain can drive forward/back, strafe left/right, and rotate. The formulas are simple, but axis signs and motor directions must be tested deliberately.
Combining drive, strafe, and turn can produce values larger than 1.0. Dividing all powers by the same denominator keeps the robot's intended direction while staying in the legal output range.
Test driver code in movement primitives and mechanism primitives instead of full-match chaos. Add deadbands, slow modes, edge detection, and safe states only after students can explain the raw input and final output for each control.
For this specific lesson, students should first restate the goal in robot terms, then identify the value or behavior they expect to observe, then run the smallest test that proves the idea. The lesson should feel like a guided lab: predict, run, observe, explain, and only then extend.
MecanumDrive.java · Java
double y = -gamepad1.left_stick_y; double x = gamepad1.left_stick_x * 1.1; double rx = gamepad1.right_stick_x; double denominator = Math.max(Math.abs(y) + Math.abs(x) + Math.abs(rx), 1.0); double frontLeftPower = (y + x + rx) / denominator; double backLeftPower = (y - x + rx) / denominator; double frontRightPower = (y - x - rx) / denominator; double backRightPower = (y + x - rx) / denominator; robot.frontLeft.setPower(frontLeftPower); robot.backLeft.setPower(backLeftPower); robot.frontRight.setPower(frontRightPower); robot.backRight.setPower(backRightPower);
When TeleOp feels wrong, translate driver feedback into small tests: forward, strafe, rotate, precision mode, button press, held button, and safe recovery. Print raw inputs and final commands so the team can separate driver feel from wiring, math, and mechanism bugs.
Check your understanding
What does mecanum power normalization preserve?
0 of 1 answered
References
Finished reading?
You'll move on to “Field-Centric Driving” next.