Class DriveTrain

  • All Implemented Interfaces:
    edu.wpi.first.wpilibj.Sendable, edu.wpi.first.wpilibj2.command.Subsystem, IDifferentialDrivebase, Loggable

    public class DriveTrain
    extends edu.wpi.first.wpilibj2.command.SubsystemBase
    implements Loggable, IDifferentialDrivebase
    The DriveTrain handles all robot movement.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DriveTrain.DriveMode  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean alignmentLost()
      After alignment, check to see if bot loses alignment.
      boolean autoTarget​(LimelightTarget target)
      Automatically get to an optimal scoring position based on a limelight target input
      void drive​(double speed, double rotation)
      Open-loop control the drivebase with a desired speed and rotation factor.
      boolean face​(double error, double eps)  
      boolean face​(edu.wpi.first.wpilibj.geometry.Rotation2d rot, double eps)
      Turn the drivebase to face an angle
      boolean face​(LimelightTarget target, double eps)
      Turn the drivebase to face a Limelihgt target
      static DriveTrain getInstance()
      Get the DriveTrain instance.
      double getLeftMeters()
      Get the left side distance traveled in meters
      edu.wpi.first.wpilibj.geometry.Pose2d getPosition()
      Get the robot's current field-relative position
      double getRightMeters()
      Get the right side distance traveled in meters
      edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds getWheelSpeeds()  
      double getWidthMeters()
      Get track width in meters
      void logStatus()
      Log component status
      void periodic()
      Subsystem-specific tasks that must be run once per 20ms must be placed in this method.
      void setBrakes​(boolean brakesApplied)
      Set the motor brakes.
      void setOldYaw​(double oldYaw)  
      void setOpenLoop​(DriveSignal signal)
      Set the Open loop control signal.
      void setPosition​(edu.wpi.first.wpilibj.geometry.Pose2d pose)
      Force-set the robot's position
      void setRampRate​(double rampRate)
      Set the number of seconds the drivebase should take to get to full power
      void setVoltage​(double left, double right)
      Sets Voltage Signal
      void setVoltage​(DriveSignal signal)
      Set the Open loop control signal.
      void stop()
      Stop the drivetrain
      void updateTelemetry()
      Push telemetry data to NetworkTables
      • Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase

        addChild, getName, getSubsystem, initSendable, setName, setSubsystem
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface edu.wpi.first.wpilibj.Sendable

        addChild, setName, setName, setName
      • Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem

        getCurrentCommand, getDefaultCommand, register, setDefaultCommand
    • Method Detail

      • getInstance

        public static DriveTrain getInstance()
        Get the DriveTrain instance.
        Returns:
        DriveTrain instance
      • periodic

        public void periodic()
        Subsystem-specific tasks that must be run once per 20ms must be placed in this method.
        Specified by:
        periodic in interface edu.wpi.first.wpilibj2.command.Subsystem
      • drive

        public void drive​(double speed,
                          double rotation)
        Open-loop control the drivebase with a desired speed and rotation factor.
        Parameters:
        speed - Desired speed percentage [-1.0-1.0]
        rotation - Desired rotation factor [-1.0-1.0]
      • face

        public boolean face​(LimelightTarget target,
                            double eps)
        Turn the drivebase to face a Limelihgt target
        Parameters:
        target - Target to face
        eps - Acceptable error
        Returns:
        Is facing angle?
      • face

        public boolean face​(edu.wpi.first.wpilibj.geometry.Rotation2d rot,
                            double eps)
        Turn the drivebase to face an angle
        Parameters:
        rot - Desired angle
        eps - Acceptable error
        Returns:
        Is facing angle?
      • face

        public boolean face​(double error,
                            double eps)
      • autoTarget

        public boolean autoTarget​(LimelightTarget target)
        Automatically get to an optimal scoring position based on a limelight target input
        Parameters:
        target - Limelight target
        Returns:
        Is in an optimal scoring position?
      • setOpenLoop

        public void setOpenLoop​(DriveSignal signal)
        Set the Open loop control signal. The values of this signal should be in the rage of [-1.0-1.0]
        Parameters:
        signal - Open loop signal
      • setVoltage

        public void setVoltage​(DriveSignal signal)
        Set the Open loop control signal. The values of this signal should be in the rage of [-12.0-12.0]
        Parameters:
        signal - Voltage signal
      • setVoltage

        public void setVoltage​(double left,
                               double right)
        Sets Voltage Signal
        Parameters:
        left -
        right -
      • setRampRate

        public void setRampRate​(double rampRate)
        Set the number of seconds the drivebase should take to get to full power
        Parameters:
        rampRate - Ramp rate
      • stop

        public void stop()
        Stop the drivetrain
      • setBrakes

        public void setBrakes​(boolean brakesApplied)
        Set the motor brakes. When enabled, the robot will automatically try to stay in place (resisting pushing)
        Parameters:
        brakesApplied - Should the brakes be applied?
      • getLeftMeters

        public double getLeftMeters()
        Get the left side distance traveled in meters
        Specified by:
        getLeftMeters in interface IDifferentialDrivebase
        Returns:
        Left distance
      • getRightMeters

        public double getRightMeters()
        Get the right side distance traveled in meters
        Specified by:
        getRightMeters in interface IDifferentialDrivebase
        Returns:
        Right distance
      • getPosition

        public edu.wpi.first.wpilibj.geometry.Pose2d getPosition()
        Get the robot's current field-relative position
        Returns:
        Robot position
      • alignmentLost

        public boolean alignmentLost()
        After alignment, check to see if bot loses alignment.
        Returns:
        If yaw difference is greater than 3 degrees since last alignment;
      • setOldYaw

        public void setOldYaw​(double oldYaw)
        Parameters:
        oldYaw - the oldYaw to set
      • setPosition

        public void setPosition​(edu.wpi.first.wpilibj.geometry.Pose2d pose)
        Force-set the robot's position
        Parameters:
        pose - Robot pose
      • getWheelSpeeds

        public edu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds getWheelSpeeds()
      • logStatus

        public void logStatus()
        Description copied from interface: Loggable
        Log component status
        Specified by:
        logStatus in interface Loggable
      • updateTelemetry

        public void updateTelemetry()
        Description copied from interface: Loggable
        Push telemetry data to NetworkTables
        Specified by:
        updateTelemetry in interface Loggable