5389b235380b3a081a6c9c7b34b4e1b72b93edfe
1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
5 import com
.ctre
.CANTalon
;
7 import edu
.wpi
.first
.wpilibj
.Encoder
;
8 import edu
.wpi
.first
.wpilibj
.RobotDrive
;
9 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
11 public class DriveTrain
extends Subsystem
{
12 private static DriveTrain driveTrain
;
13 private final CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
14 private final RobotDrive robotDrive
;
15 private final Encoder leftEncoder
, rightEncoder
;
17 private DriveTrain() {
19 frontLeft
= new CANTalon(Constants
.DriveTrain
.FRONT_LEFT
);
20 frontRight
= new CANTalon(Constants
.DriveTrain
.FRONT_RIGHT
);
21 rearLeft
= new CANTalon(Constants
.DriveTrain
.REAR_LEFT
);
22 rearRight
= new CANTalon(Constants
.DriveTrain
.REAR_RIGHT
);
25 leftEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_LEFT_A
,
26 Constants
.DriveTrain
.ENCODER_LEFT_B
);
27 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
,
28 Constants
.DriveTrain
.ENCODER_RIGHT_B
);
30 leftEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
31 rightEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
34 robotDrive
= new RobotDrive(frontLeft
, rearLeft
, frontRight
, rearRight
);
37 public static DriveTrain
getDriveTrain() {
38 if (driveTrain
== null) {
39 driveTrain
= new DriveTrain();
45 public void setMotorValues(final double left
, final double right
) {
46 robotDrive
.tankDrive(left
, right
);
49 public void joystickDrive(final double left
, final double right
) {
50 robotDrive
.tankDrive(left
, right
);
57 public double getFrontLeftMotorVal() {
58 return frontLeft
.get();
61 public double getFrontRightMotorVal() {
62 return frontRight
.get();
65 public double getRearLeftMotorVal() {
66 return frontLeft
.get();
69 public double getRearRightMotorVal() {
70 return frontLeft
.get();
73 public CANTalon
getFrontLeft() {
77 public CANTalon
getFrontRight() {
81 public CANTalon
getRearLeft() {
85 public CANTalon
getRearRight() {
91 public double getLeftEncoder() {
92 return leftEncoder
.getDistance();
95 public double getRightEncoder() {
96 return rightEncoder
.getDistance();
99 public double getAvgEncoderDistance() {
100 return (leftEncoder
.getDistance() + rightEncoder
.getDistance()) / 2;
103 public void resetEncoders() {
105 rightEncoder
.reset();
108 public double getLeftSpeed() {
109 return leftEncoder
.getRate();
112 public double getRightSpeed() {
113 return rightEncoder
.getRate();
116 public double getSpeed() {
117 return (getLeftSpeed() + getRightSpeed()) / 2.0;
121 protected void initDefaultCommand() {