Class DifferentialDrive

All Implemented Interfaces:
Sendable, AutoCloseable

public class DifferentialDrive
extends RobotDriveBase
implements Sendable, AutoCloseable
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 MotorController per side. For four and six motor drivetrains, construct and pass in MotorControllerGroup instances as follows.

Four motor drivetrain:


 public class Robot {
   MotorController m_frontLeft = new PWMVictorSPX(1);
   MotorController m_rearLeft = new PWMVictorSPX(2);
   MotorControllerGroup m_left = new MotorControllerGroup(m_frontLeft, m_rearLeft);

   MotorController m_frontRight = new PWMVictorSPX(3);
   MotorController m_rearRight = new PWMVictorSPX(4);
   MotorControllerGroup m_right = new MotorControllerGroup(m_frontRight, m_rearRight);

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

Six motor drivetrain:


 public class Robot {
   MotorController m_frontLeft = new PWMVictorSPX(1);
   MotorController m_midLeft = new PWMVictorSPX(2);
   MotorController m_rearLeft = new PWMVictorSPX(3);
   MotorControllerGroup m_left = new MotorControllerGroup(m_frontLeft, m_midLeft, m_rearLeft);

   MotorController m_frontRight = new PWMVictorSPX(4);
   MotorController m_midRight = new PWMVictorSPX(5);
   MotorController m_rearRight = new PWMVictorSPX(6);
   MotorControllerGroup m_right = new MotorControllerGroup(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.

This library uses the NED axes convention (North-East-Down as external reference in the world frame): http://www.nuclearprojects.com/ins/images/axis_big.png.

The positive X axis points ahead, the positive Y axis points right, and the positive Z axis points down. Rotations follow the right-hand rule, so clockwise rotation around the Z axis is positive.

Inputs smaller then 0.02 will be set to 0, and larger values will be scaled so that the full range is still used. This deadband value can be changed with RobotDriveBase.setDeadband(double).

  • Constructor Details

  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • arcadeDrive

      public void arcadeDrive​(double xSpeed, double zRotation)
      Arcade drive method for differential drive platform. The calculated values will be squared to decrease sensitivity at low speeds.
      Parameters:
      xSpeed - The robot's speed along the X axis [-1.0..1.0]. Forward is positive.
      zRotation - The robot's rotation rate around the Z axis [-1.0..1.0]. Clockwise is positive.
    • arcadeDrive

      public void arcadeDrive​(double xSpeed, double zRotation, boolean squareInputs)
      Arcade drive method for differential drive platform.
      Parameters:
      xSpeed - The robot's speed along the X axis [-1.0..1.0]. Forward is positive.
      zRotation - The robot's rotation rate around the Z axis [-1.0..1.0]. Clockwise is positive.
      squareInputs - If set, decreases the input sensitivity at low speeds.
    • curvatureDrive

      public void curvatureDrive​(double xSpeed, double zRotation, boolean allowTurnInPlace)
      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.

      Parameters:
      xSpeed - The robot's speed along the X axis [-1.0..1.0]. Forward is positive.
      zRotation - The normalized curvature [-1.0..1.0]. Clockwise is positive.
      allowTurnInPlace - If set, overrides constant-curvature turning for turn-in-place maneuvers. zRotation will control turning rate instead of curvature.
    • tankDrive

      public void tankDrive​(double leftSpeed, double rightSpeed)
      Tank drive method for differential drive platform. The calculated values will be squared to decrease sensitivity at low speeds.
      Parameters:
      leftSpeed - The robot's left side speed along the X axis [-1.0..1.0]. Forward is positive.
      rightSpeed - The robot's right side speed along the X axis [-1.0..1.0]. Forward is positive.
    • tankDrive

      public void tankDrive​(double leftSpeed, double rightSpeed, boolean squareInputs)
      Tank drive method for differential drive platform.
      Parameters:
      leftSpeed - The robot left side's speed along the X axis [-1.0..1.0]. Forward is positive.
      rightSpeed - The robot right side's speed along the X axis [-1.0..1.0]. Forward is positive.
      squareInputs - If set, decreases the input sensitivity at low speeds.
    • arcadeDriveIK

      public static DifferentialDrive.WheelSpeeds arcadeDriveIK​(double xSpeed, double zRotation, boolean squareInputs)
      Arcade drive inverse kinematics for differential drive platform.
      Parameters:
      xSpeed - The robot's speed along the X axis [-1.0..1.0]. Forward is positive.
      zRotation - The robot's rotation rate around the Z axis [-1.0..1.0]. Clockwise is positive.
      squareInputs - If set, decreases the input sensitivity at low speeds.
      Returns:
      Wheel speeds.
    • curvatureDriveIK

      public static DifferentialDrive.WheelSpeeds curvatureDriveIK​(double xSpeed, double zRotation, boolean allowTurnInPlace)
      Curvature drive inverse kinematics 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.

      Parameters:
      xSpeed - The robot's speed along the X axis [-1.0..1.0]. Forward is positive.
      zRotation - The normalized curvature [-1.0..1.0]. Clockwise is positive.
      allowTurnInPlace - If set, overrides constant-curvature turning for turn-in-place maneuvers. zRotation will control rotation rate around the Z axis instead of curvature.
      Returns:
      Wheel speeds.
    • tankDriveIK

      public static DifferentialDrive.WheelSpeeds tankDriveIK​(double leftSpeed, double rightSpeed, boolean squareInputs)
      Tank drive inverse kinematics for differential drive platform.
      Parameters:
      leftSpeed - The robot left side's speed along the X axis [-1.0..1.0]. Forward is positive.
      rightSpeed - The robot right side's speed along the X axis [-1.0..1.0]. Forward is positive.
      squareInputs - If set, decreases the input sensitivity at low speeds.
      Returns:
      Wheel speeds.
    • stopMotor

      public void stopMotor()
      Specified by:
      stopMotor in class RobotDriveBase
    • getDescription

      Specified by:
      getDescription in class RobotDriveBase
    • initSendable

      public void initSendable​(SendableBuilder builder)
      Description copied from interface: Sendable
      Initializes this Sendable object.
      Specified by:
      initSendable in interface Sendable
      Parameters:
      builder - sendable builder