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 CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
14 private RobotDrive robotDrive
;
15 private 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();
44 public void setMotorValues(double left
, double right
) {
45 robotDrive
.tankDrive(left
, right
);
48 public void joystickDrive(double left
, double right
) {
49 robotDrive
.tankDrive(left
, right
);
56 public double getFrontLeftMotorVal() {
57 return frontLeft
.get();
60 public double getFrontRightMotorVal() {
61 return frontRight
.get();
64 public double getRearLeftMotorVal() {
65 return frontLeft
.get();
68 public double getRearRightMotorVal() {
69 return frontLeft
.get();
72 public CANTalon
getFrontLeft() {
76 public CANTalon
getFrontRight() {
80 public CANTalon
getRearLeft() {
84 public CANTalon
getRearRight() {
90 public double getLeftEncoder() {
91 return leftEncoder
.getDistance();
94 public double getRightEncoder() {
95 return rightEncoder
.getDistance();
98 public double getAvgEncoderDistance() {
99 return (leftEncoder
.getDistance() + rightEncoder
.getDistance()) / 2;
102 public void resetEncoders() {
104 rightEncoder
.reset();
107 public double getLeftSpeed() {
108 return leftEncoder
.getRate();
111 public double getRightSpeed() {
112 return rightEncoder
.getRate();
115 public double getSpeed() {
116 return (getLeftSpeed() + getRightSpeed()) / 2.0;
120 protected void initDefaultCommand() {