Tutorial 05: Drive a standard (tank) robot
In the five files, one line in Robot.java sets up a tank drive: A tank drive instead. Build it by hand here with TankDrive to see the two driving styles inside.
You will build: a TeleOp that drives a standard (tank) robot, with a button to switch between two driving styles.
You need: a standard chassis with two motors left_drive and right_drive
(or four: front_left, front_right, back_left, back_right).
Full program: Tut05TankDrive.java
1. How a standard drive moves
Section titled “1. How a standard drive moves”A standard drive (also called tank, differential, or “skid steer”) has normal wheels on a left side and a right side. Both sides forward = drive forward. Left forward, right back = spin right. It cannot move sideways.
2. Set up the drive
Section titled “2. Set up the drive”DriveConfig driveConfig = DriveConfig.tankTwoMotor(); // DriveConfig.tank() for 4 motorsdriveConfig.powerLimit = 0.6;TankDrive drive = new TankDrive(hardwareMap, driveConfig);| Your robot | Config | Motor names |
|---|---|---|
| 2 motors | DriveConfig.tankTwoMotor() |
left_drive, right_drive (same as the FTC samples) |
| 4 motors | DriveConfig.tank() |
front_left, front_right, back_left, back_right |
powerLimit = 0.6 keeps every wheel at 60% or less while you test. With 4 motors, both motors on a side
always get the same power.
The motors on the left face the other way, so the library reverses the left side by default. Check it
with MotorDirectionCheck:
set its config() to DriveConfig.tankTwoMotor() and lift the wheels off the ground. X = left,
Y = right. Both must roll forward.
3. Arcade style
Section titled “3. Arcade style”One stick moves forward and back, and the other turns. For most new drivers, this style is the easiest.
drive.arcade(StickShaping.shape(-gamepad1.left_stick_y, 0.05, 2), StickShaping.shape(gamepad1.right_stick_x, 0.05, 2), speed);The library adds and subtracts for you: left = forward + turn, right = forward - turn. When a side goes past full power, the library scales both sides down together, so the robot keeps the curve you asked for.
4. Tank style
Section titled “4. Tank style”Each stick drives one side, like a bulldozer. It is very direct, and some drivers like it better. BOTH sticks’ Y need the minus.
drive.tank(StickShaping.shape(-gamepad1.left_stick_y, 0.05, 2), StickShaping.shape(-gamepad1.right_stick_y, 0.05, 2), speed);5. Let the driver choose
Section titled “5. Let the driver choose”.bindToggle(Pad.G1, Btn.X, () -> { tankStyle = true; confirm.play(true); }, () -> { tankStyle = false; confirm.play(false); })Let each driver try both styles for a practice session. Keep the one they drive best with.
Slow mode and drive.stop() in finally work the same as on
mecanum.
6. Autonomous on a standard drive
Section titled “6. Autonomous on a standard drive”AutoDrive (Tutorial 09) works on a standard drive too, but only forward/back and turns:
move(24, 0, ...), move(24, 180, ...), turn(...), turnTo(...). A sideways move gives an error that
says “turn first, then move”.
Run it
Section titled “Run it”- With the wheels off the ground, push the stick up: both sides roll forward.
- On the floor, arcade style drives and turns as expected. Right stick right = turn right.
- X (two buzzes): tank style. Both sticks up = forward. Left up, right down = spin right.
If something goes wrong
Section titled “If something goes wrong”| Problem | Fix |
|---|---|
| Spins when both sides should go forward | One side’s direction is wrong: flip frontLeftReversed or frontRightReversed. (With 2 motors, the library stores left_drive and right_drive as the “front” motors.) |
| Turns the wrong way in arcade | Left and right motor names are swapped. |
| “TankDrive needs a TANK DriveConfig” | Use DriveConfig.tank() or tankTwoMotor(). |
| 4-motor robot: one wheel fights the others | That one motor’s direction is wrong. Use MotorDirectionCheck. |
Try this
Section titled “Try this”- Add
ReverseDriveto arcade mode (Tutorial 04). - Make turning gentler than driving: multiply the turn by 0.7.
- With 4 motors: change the config to
DriveConfig.tank()and check all four with MotorDirectionCheck.
Next: Tutorial 06: A fast, clear loop. Look it up: drive.md: TankDrive, gamepad.md.
Something wrong on this page? Tell us with a short GitHub form.