Package frc.robot.subsystems
Class DriveTrain
- java.lang.Object
-
- edu.wpi.first.wpilibj2.command.SubsystemBase
-
- frc.robot.subsystems.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 classDriveTrain.DriveMode
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanalignmentLost()After alignment, check to see if bot loses alignment.booleanautoTarget(LimelightTarget target)Automatically get to an optimal scoring position based on a limelight target inputvoiddrive(double speed, double rotation)Open-loop control the drivebase with a desired speed and rotation factor.booleanface(double error, double eps)booleanface(edu.wpi.first.wpilibj.geometry.Rotation2d rot, double eps)Turn the drivebase to face an anglebooleanface(LimelightTarget target, double eps)Turn the drivebase to face a Limelihgt targetstatic DriveTraingetInstance()Get the DriveTrain instance.doublegetLeftMeters()Get the left side distance traveled in metersedu.wpi.first.wpilibj.geometry.Pose2dgetPosition()Get the robot's current field-relative positiondoublegetRightMeters()Get the right side distance traveled in metersedu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeedsgetWheelSpeeds()doublegetWidthMeters()Get track width in metersvoidlogStatus()Log component statusvoidperiodic()Subsystem-specific tasks that must be run once per 20ms must be placed in this method.voidsetBrakes(boolean brakesApplied)Set the motor brakes.voidsetOldYaw(double oldYaw)voidsetOpenLoop(DriveSignal signal)Set the Open loop control signal.voidsetPosition(edu.wpi.first.wpilibj.geometry.Pose2d pose)Force-set the robot's positionvoidsetRampRate(double rampRate)Set the number of seconds the drivebase should take to get to full powervoidsetVoltage(double left, double right)Sets Voltage SignalvoidsetVoltage(DriveSignal signal)Set the Open loop control signal.voidstop()Stop the drivetrainvoidupdateTelemetry()Push telemetry data to NetworkTables-
Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystem
-
-
-
-
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:
periodicin interfaceedu.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 faceeps- 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 angleeps- 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:
getLeftMetersin interfaceIDifferentialDrivebase- Returns:
- Left distance
-
getRightMeters
public double getRightMeters()
Get the right side distance traveled in meters- Specified by:
getRightMetersin interfaceIDifferentialDrivebase- Returns:
- Right distance
-
getWidthMeters
public double getWidthMeters()
Description copied from interface:IDifferentialDrivebaseGet track width in meters- Specified by:
getWidthMetersin interfaceIDifferentialDrivebase- Returns:
- Track width
-
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:LoggableLog component status
-
updateTelemetry
public void updateTelemetry()
Description copied from interface:LoggablePush telemetry data to NetworkTables- Specified by:
updateTelemetryin interfaceLoggable
-
-