Package com.crossbotics.ftchelper.drive
Class TankDrive
java.lang.Object
com.crossbotics.ftchelper.drive.TankDrive
Drives a standard (tank / differential) chassis with 2 or 4 motors. For TeleOp: call a drive
method every loop.
TankDrive drive = new TankDrive(hardwareMap, DriveConfig.tankTwoMotor());
waitForStart();
while (opModeIsActive()) {
drive.arcade(-gamepad1.left_stick_y, gamepad1.right_stick_x); // or:
// drive.tank(-gamepad1.left_stick_y, -gamepad1.right_stick_y);
}
drive.stop();
Signs: forward +, turn clockwise +. A standard drive cannot move sideways. All the sign rules: docs/conventions.md.
Each drive method only sets the wheel powers and returns at once (it never waits). The math
lives in DifferentialMixer. On a 4-motor drive, both motors on a side always get the same power.
Docs: docs/modules/drive.md. Tutorial 05 drives a standard robot with it, step by step.
-
Constructor Summary
ConstructorsConstructorDescriptionTankDrive(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, DriveConfig config) Gets the motors, sets their directions and brake mode, and sets power to 0. -
Method Summary
Modifier and TypeMethodDescriptionvoidarcade(double forward, double turnClockwise) Arcade drive: one value for forward, one for turning.voidarcade(double forward, double turnClockwise, double speedScale) Arcade drive with a speed multiplier 0 to 1 (for a slow mode).The settings this drive was made with.com.qualcomm.robotcore.hardware.DcMotorEx[]The motors: {left, right} for 2 motors, {front-left, front-right, back-left, back-right} for 4.voidsetBrake(boolean brake) True = hold at 0 power, false = coast.voidsetPowers(double[] leftRight) Sets the left and right powers directly ({left, right}).voidstop()Sets both sides to 0.voidtank(double left, double right) Tank drive: one value for each side.voidtank(double left, double right, double speedScale) Tank drive with a speed multiplier 0 to 1.
-
Constructor Details
-
TankDrive
Gets the motors, sets their directions and brake mode, and sets power to 0. Plain power (RUN_WITHOUT_ENCODER). Encoders are not reset.- Parameters:
config- must havetype = TANK(useDriveConfig.tank()orDriveConfig.tankTwoMotor())- Throws:
IllegalArgumentException- if the config is not TANK, or a motor name is not in the configuration
-
-
Method Details
-
arcade
public void arcade(double forward, double turnClockwise) Arcade drive: one value for forward, one for turning.- Parameters:
forward- -1 to 1, e.g.-gamepad1.left_stick_yturnClockwise- -1 to 1, e.g.gamepad1.right_stick_x
-
arcade
public void arcade(double forward, double turnClockwise, double speedScale) Arcade drive with a speed multiplier 0 to 1 (for a slow mode). -
tank
public void tank(double left, double right) Tank drive: one value for each side.- Parameters:
left- -1 to 1, e.g.-gamepad1.left_stick_yright- -1 to 1, e.g.-gamepad1.right_stick_y
-
tank
public void tank(double left, double right, double speedScale) Tank drive with a speed multiplier 0 to 1. -
stop
public void stop()Sets both sides to 0. Call it at the end of your OpMode, best in afinallyblock so it runs even after an error. -
setPowers
public void setPowers(double[] leftRight) Sets the left and right powers directly ({left, right}). The power limit still applies. -
setBrake
public void setBrake(boolean brake) True = hold at 0 power, false = coast. -
getMotors
public com.qualcomm.robotcore.hardware.DcMotorEx[] getMotors()The motors: {left, right} for 2 motors, {front-left, front-right, back-left, back-right} for 4. -
getConfig
The settings this drive was made with.
-