Driver Control
Turn gamepad input into predictable mecanum movement.
Turn gamepad input into predictable mecanum movement.
In this lesson, you will:
A driver should not need to understand your math during a match. Good TeleOp code makes common movement predictable and keeps surprises out of competition.
Mecanum formulas can produce values above 1.0. Normalizing keeps the ratio between wheels while staying inside the legal motor power range.
Every wheel gets the drive value because forward needs all four wheels. Strafe is added on one diagonal and subtracted on the other, which makes the rollers push sideways. Turn is added on the left side and subtracted on the right. If one movement misbehaves, check the sign pattern for that one input instead of rewriting all four lines.
A joystick rarely rests at exactly zero. Treat small input values as zero before mixing the axes so the robot stays still when the driver releases the sticks.
MecanumTeleOp.javaJava
double drive = -gamepad1.left_stick_y; double strafe = gamepad1.left_stick_x; double turn = gamepad1.right_stick_x; drive = Math.abs(drive) < 0.05 ? 0.0 : drive; strafe = Math.abs(strafe) < 0.05 ? 0.0 : strafe; turn = Math.abs(turn) < 0.05 ? 0.0 : turn; double fl = drive + strafe + turn; double fr = drive - strafe - turn; double bl = drive - strafe + turn; double br = drive + strafe - turn; double max = Math.max(1.0, Math.max( Math.max(Math.abs(fl), Math.abs(fr)), Math.max(Math.abs(bl), Math.abs(br)) )); frontLeft.setPower(fl / max); frontRight.setPower(fr / max); backLeft.setPower(bl / max); backRight.setPower(br / max);
Check your understanding before moving on.
Why is gamepad1.left_stick_y negated in drive code?
What does dividing every wheel power by the max value accomplish?
0 of 2 answered
Mark this lesson complete — “Field-Centric Driving” is up next.