Class TankDrive

java.lang.Object
com.crossbotics.ftchelper.drive.TankDrive

public class TankDrive extends Object
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

    Constructors
    Constructor
    Description
    TankDrive(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 Type
    Method
    Description
    void
    arcade(double forward, double turnClockwise)
    Arcade drive: one value for forward, one for turning.
    void
    arcade(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.
    void
    setBrake(boolean brake)
    True = hold at 0 power, false = coast.
    void
    setPowers(double[] leftRight)
    Sets the left and right powers directly ({left, right}).
    void
    Sets both sides to 0.
    void
    tank(double left, double right)
    Tank drive: one value for each side.
    void
    tank(double left, double right, double speedScale)
    Tank drive with a speed multiplier 0 to 1.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TankDrive

      public TankDrive(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, DriveConfig config)
      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 have type = TANK (use DriveConfig.tank() or DriveConfig.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_y
      turnClockwise - -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_y
      right - -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 a finally block 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

      public DriveConfig getConfig()
      The settings this drive was made with.