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 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 inputvoid
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 angleboolean
face(LimelightTarget target, double eps)
Turn the drivebase to face a Limelihgt targetstatic DriveTrain
getInstance()
Get the DriveTrain instance.double
getLeftMeters()
Get the left side distance traveled in metersedu.wpi.first.wpilibj.geometry.Pose2d
getPosition()
Get the robot's current field-relative positiondouble
getRightMeters()
Get the right side distance traveled in metersedu.wpi.first.wpilibj.kinematics.DifferentialDriveWheelSpeeds
getWheelSpeeds()
double
getWidthMeters()
Get track width in metersvoid
logStatus()
Log component statusvoid
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 positionvoid
setRampRate(double rampRate)
Set the number of seconds the drivebase should take to get to full powervoid
setVoltage(double left, double right)
Sets Voltage Signalvoid
setVoltage(DriveSignal signal)
Set the Open loop control signal.void
stop()
Stop the drivetrainvoid
updateTelemetry()
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:
periodic
in 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:
getLeftMeters
in interfaceIDifferentialDrivebase
- Returns:
- Left distance
-
getRightMeters
public double getRightMeters()
Get the right side distance traveled in meters- Specified by:
getRightMeters
in interfaceIDifferentialDrivebase
- Returns:
- Right distance
-
getWidthMeters
public double getWidthMeters()
Description copied from interface:IDifferentialDrivebase
Get track width in meters- Specified by:
getWidthMeters
in 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:Loggable
Log component status
-
updateTelemetry
public void updateTelemetry()
Description copied from interface:Loggable
Push telemetry data to NetworkTables- Specified by:
updateTelemetry
in interfaceLoggable
-
-