edu.wpi.first.wpilibj.drive

## Class MecanumDrive

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

- All Implemented Interfaces:
    MotorSafety

      public class MecanumDrive
      extends RobotDriveBase

  A class for driving Mecanum drive platforms.

  Mecanum drives are rectangular with one wheel on each corner. Each wheel has rollers toed in 45 degrees toward the front or back. When looking at the wheels from the top, the roller axles should form an X across the robot. Each drive() function provides different inverse kinematic relations for a Mecanum drive robot.

  Drive base diagram:

       \\_______/
       \\ |   | /
         |   |
       /_|___|_\\
       /       \\

  Each drive() function provides different inverse kinematic relations for a Mecanum 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
    `MecanumDrive(SpeedController frontLeftMotor, SpeedController rearLeftMotor, SpeedController frontRightMotor, SpeedController rearRightMotor)` Construct a MecanumDrive.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `driveCartesian(double x, double y, double rotation)` Drive method for Mecanum platform.
    `void` | `driveCartesian(double x, double y, double rotation, double gyroAngle)` Drive method for Mecanum platform.
    `void` | `drivePolar(double magnitude, double angle, double rotation)` Drive method for Mecanum platform.
    `java.lang.String` | `getDescription()`
    `void` | `stopMotor()`

    - ### 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

    - #### MecanumDrive

          public MecanumDrive(SpeedController frontLeftMotor,
                              SpeedController rearLeftMotor,
                              SpeedController frontRightMotor,
                              SpeedController rearRightMotor)

      Construct a MecanumDrive.

      If a motor needs to be inverted, do so before passing it in.

  - ### Method Detail

    - #### driveCartesian

          public void driveCartesian(double x,
                                     double y,
                                     double rotation)

      Drive method for Mecanum platform.
      Parameters:
        `x` - The speed that the robot should drive in the X direction. [-1.0..1.0]
        `y` - The speed that the robot should drive in the Y direction. [-1.0..1.0]
        `rotation` - The rate of rotation for the robot that is completely independent of the translation. [-1.0..1.0]

    - #### driveCartesian

          public void driveCartesian(double x,
                                     double y,
                                     double rotation,
                                     double gyroAngle)

      Drive method for Mecanum platform.
      Parameters:
        `x` - The speed that the robot should drive in the X direction. [-1.0..1.0]
        `y` - The speed that the robot should drive in the Y direction. [-1.0..1.0]
        `rotation` - The rate of rotation for the robot that is completely independent of the translation. [-1.0..1.0]
        `gyroAngle` - The current angle reading from the gyro. Use this to implement field-oriented controls.

    - #### drivePolar

          public void drivePolar(double magnitude,
                                 double angle,
                                 double rotation)

      Drive method for Mecanum platform.
      Parameters:
        `magnitude` - The speed that the robot should drive in a given direction. [-1.0..1.0]
        `angle` - The direction the robot should drive in degrees. 0.0 is straight ahead. The direction and maginitude are independent of the rotation rate.
        `rotation` - The rate of rotation for the robot that is completely independent of the magnitude or direction. [-1.0..1.0]

    - #### 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`