edu.wpi.first.wpilibj.drive

## Class DifferentialDrive

- java.lang.Object
- - edu.wpi.first.wpilibj.drive.RobotDriveBase
  - - edu.wpi.first.wpilibj.drive.DifferentialDrive

- All Implemented Interfaces:
    MotorSafety

      public class DifferentialDrive
      extends RobotDriveBase

  A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive base, "tank drive", or West Coast Drive.

  These drive bases typically have drop-center / skid-steer with two or more wheels per side (e.g., 6WD or 8WD). This class takes a SpeedController per side. For four and six motor drivetrains, construct and pass in `SpeedControllerGroup` instances as follows.

  Four motor drivetrain:

       public class Robot {
         Talon m_frontLeft = new Talon(1);
         Talon m_rearLeft = new Talon(2);
         SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);

         Talon m_frontRight = new Talon(3);
         Talon m_rearRight = new Talon(4);
         SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_rearRight);

         DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);
       }

  Six motor drivetrain:

       public class Robot {
         Talon m_frontLeft = new Talon(1);
         Talon m_midLeft = new Talon(2);
         Talon m_rearLeft = new Talon(3);
         SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_midLeft, m_rearLeft);

         Talon m_frontRight = new Talon(4);
         Talon m_midRight = new Talon(5);
         Talon m_rearRight = new Talon(6);
         SpeedControllerGroup m_right = new SpeedControllerGroup(m_frontRight, m_midRight, m_rearRight);

         DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);
       }

  A differential drive robot has left and right wheels separated by an arbitrary width.

  Drive base diagram:

       |_______|
       | |   | |
         |   |
       |_|___|_|
       |       |

  Each drive() function provides different inverse kinematic relations for a differential drive robot. Motor outputs for the right side are negated, so motor direction inversion by the user is usually unnecessary.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.drive.RobotDriveBase

      `RobotDriveBase.MotorType`

  - ### Field Summary

    - ### Fields inherited from class edu.wpi.first.wpilibj.drive.RobotDriveBase

      `m_deadband, m_maxOutput, m_safetyHelper`

    - ### Fields inherited from interface edu.wpi.first.wpilibj.MotorSafety

      `DEFAULT_SAFETY_EXPIRATION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DifferentialDrive(SpeedController leftMotor, SpeedController rightMotor)` Construct a DifferentialDrive.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `arcadeDrive(double y, double rotation)` Arcade drive method for differential drive platform.
    `void` | `arcadeDrive(double y, double rotation, boolean squaredInputs)` Arcade drive method for differential drive platform.
    `void` | `curvatureDrive(double y, double rotation, boolean isQuickTurn)` Curvature drive method for differential drive platform.
    `java.lang.String` | `getDescription()`
    `void` | `stopMotor()`
    `void` | `tankDrive(double left, double right)` Tank drive method for differential drive platform.
    `void` | `tankDrive(double left, double right, boolean squaredInputs)` Tank drive method for differential drive platform.

    - ### Methods inherited from class edu.wpi.first.wpilibj.drive.RobotDriveBase

      `applyDeadband, getExpiration, isAlive, isSafetyEnabled, limit, normalize, setDeadband, setExpiration, setMaxOutput, setSafetyEnabled`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DifferentialDrive

          public DifferentialDrive(SpeedController leftMotor,
                                   SpeedController rightMotor)

      Construct a DifferentialDrive.

      To pass multiple motors per side, use a `SpeedControllerGroup`. If a motor needs to be inverted, do so before passing it in.

  - ### Method Detail

    - #### arcadeDrive

          public void arcadeDrive(double y,
                                  double rotation)

      Arcade drive method for differential drive platform.
      Parameters:
        `y` - The value to use for forwards/backwards. [-1.0..1.0]
        `rotation` - The value to use for the rotation right/left. [-1.0..1.0]

    - #### arcadeDrive

          public void arcadeDrive(double y,
                                  double rotation,
                                  boolean squaredInputs)

      Arcade drive method for differential drive platform.
      Parameters:
        `y` - The value to use for forwards/backwards. [-1.0..1.0]
        `rotation` - The value to use for the rotation right/left [-1.0..1.0]
        `squaredInputs` - If set, decreases the input sensitivity at low speeds.

    - #### curvatureDrive

          public void curvatureDrive(double y,
                                     double rotation,
                                     boolean isQuickTurn)

      Curvature drive method for differential drive platform.

      The rotation argument controls the curvature of the robot's path rather than its rate of heading change. This makes the robot more controllable at high speeds. Also handles the robot's quick turn functionality - "quick turn" overrides constant-curvature turning for turn-in-place maneuvers.

      Parameters:
        `y` - The value to use for forwards/backwards. [-1.0..1.0]
        `rotation` - The value to use for the rotation right/left. [-1.0..1.0]
        `isQuickTurn` - If set, overrides constant-curvature turning for turn-in-place maneuvers.

    - #### tankDrive

          public void tankDrive(double left,
                                double right)

      Tank drive method for differential drive platform.
      Parameters:
        `left` - The value to use for left side motors. [-1.0..1.0]
        `right` - The value to use for right side motors. [-1.0..1.0]

    - #### tankDrive

          public void tankDrive(double left,
                                double right,
                                boolean squaredInputs)

      Tank drive method for differential drive platform.
      Parameters:
        `left` - The value to use for left side motors. [-1.0..1.0]
        `right` - The value to use for right side motors. [-1.0..1.0]
        `squaredInputs` - If set, decreases the input sensitivity at low speeds.

    - #### stopMotor

          public void stopMotor()

      Specified by:
        `stopMotor` in interface `MotorSafety`
      Specified by:
        `stopMotor` in class `RobotDriveBase`

    - #### getDescription

          public java.lang.String getDescription()

      Specified by:
        `getDescription` in interface `MotorSafety`
      Specified by:
        `getDescription` in class `RobotDriveBase`