add drive methods in drivetrain subsytem
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / subsystems / DriveTrain.java
1 package org.usfirst.frc.team3501.robot.subsystems;
2
3 import org.usfirst.frc.team3501.robot.Constants;
4
5 import com.ctre.CANTalon;
6
7 import edu.wpi.first.wpilibj.Encoder;
8 import edu.wpi.first.wpilibj.RobotDrive;
9 import edu.wpi.first.wpilibj.command.Subsystem;
10
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;
16
17 private DriveTrain() {
18 // MOTOR CONTROLLERS
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);
23
24 // ENCODERS
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);
29
30 leftEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE);
31 rightEncoder.setDistancePerPulse(Constants.DriveTrain.INCHES_PER_PULSE);
32
33 // ROBOT DRIVE
34 robotDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
35 }
36
37 public static DriveTrain getDriveTrain() {
38 if (driveTrain == null)
39 driveTrain = new DriveTrain();
40 return driveTrain;
41 }
42
43 // DRIVE METHODS
44 public void setMotorValues(double left, double right) {
45 robotDrive.tankDrive(left, right);
46 }
47
48 public void joystickDrive(double left, double right) {
49 robotDrive.tankDrive(left, right);
50 }
51
52 public void stop() {
53 setMotorValues(0, 0);
54 }
55
56 public double getFrontLeftMotorVal() {
57 return frontLeft.get();
58 }
59
60 public double getFrontRightMotorVal() {
61 return frontRight.get();
62 }
63
64 public double getRearLeftMotorVal() {
65 return frontLeft.get();
66 }
67
68 public double getRearRightMotorVal() {
69 return frontLeft.get();
70 }
71
72 public CANTalon getFrontLeft() {
73 return frontLeft;
74 }
75
76 public CANTalon getFrontRight() {
77 return frontRight;
78 }
79
80 public CANTalon getRearLeft() {
81 return rearLeft;
82 }
83
84 public CANTalon getRearRight() {
85 return rearRight;
86 }
87
88 // ENCODER METHODS
89
90 public double getLeftEncoder() {
91 return leftEncoder.getDistance();
92 }
93
94 public double getRightEncoder() {
95 return rightEncoder.getDistance();
96 }
97
98 public double getAvgEncoderDistance() {
99 return (leftEncoder.getDistance() + rightEncoder.getDistance()) / 2;
100 }
101
102 public void resetEncoders() {
103 leftEncoder.reset();
104 rightEncoder.reset();
105 }
106
107 public double getLeftSpeed() {
108 return leftEncoder.getRate();
109 }
110
111 public double getRightSpeed() {
112 return rightEncoder.getRate();
113 }
114
115 public double getSpeed() {
116 return (getLeftSpeed() + getRightSpeed()) / 2.0;
117 }
118
119 @Override
120 protected void initDefaultCommand() {
121 }
122
123 }