Fix diverging conflicts, not sure how this happened but it did
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / subsystems / DriveTrain.java
CommitLineData
38a404b3
KZ
1package org.usfirst.frc.team3501.robot.subsystems;
2
3import org.usfirst.frc.team3501.robot.Constants;
111dc444 4
38a404b3 5import edu.wpi.first.wpilibj.CANTalon;
111dc444
YN
6import edu.wpi.first.wpilibj.CounterBase.EncodingType;
7import edu.wpi.first.wpilibj.Encoder;
38a404b3
KZ
8import edu.wpi.first.wpilibj.command.Subsystem;
9
10public class DriveTrain extends Subsystem {
1884c3cf
KZ
11 // Drivetrain related objects
12 private Encoder leftEncoder, rightEncoder;
d7bf2340 13 private CANTalon frontLeft, frontRight, rearLeft, rearRight;
1884c3cf
KZ
14
15 // Drivetrain specific constants that relate to the inches per pulse value for
16 // the encoders
d7bf2340 17 private final static double WHEEL_DIAMETER = 6.0; // in inches
6833a887
YN
18 private final static double PULSES_PER_ROTATION = 256; // in pulses
19 private final static double OUTPUT_SPROCKET_DIAMETER = 2.0; // in inches
20 private final static double WHEEL_SPROCKET_DIAMETER = 3.5; // in inches
d7bf2340
KZ
21
22 public final static double INCHES_PER_PULSE = (((Math.PI)
23 * OUTPUT_SPROCKET_DIAMETER / PULSES_PER_ROTATION) / WHEEL_SPROCKET_DIAMETER)
24 * WHEEL_DIAMETER;
d7bf2340
KZ
25
26 public DriveTrain() {
27 frontLeft = new CANTalon(Constants.DriveTrain.FRONT_LEFT);
28 frontRight = new CANTalon(Constants.DriveTrain.FRONT_RIGHT);
29 rearLeft = new CANTalon(Constants.DriveTrain.REAR_LEFT);
30 rearRight = new CANTalon(Constants.DriveTrain.REAR_RIGHT);
1884c3cf 31
d7bf2340
KZ
32 leftEncoder = new Encoder(Constants.DriveTrain.ENCODER_LEFT_A,
33 Constants.DriveTrain.ENCODER_LEFT_B, false, EncodingType.k4X);
34 rightEncoder = new Encoder(Constants.DriveTrain.ENCODER_RIGHT_A,
35 Constants.DriveTrain.ENCODER_RIGHT_B, false, EncodingType.k4X);
36 leftEncoder.setDistancePerPulse(INCHES_PER_PULSE);
37 rightEncoder.setDistancePerPulse(INCHES_PER_PULSE);
38 }
39
40 @Override
41 protected void initDefaultCommand() {
42 }
43
44 public void resetEncoders() {
45 leftEncoder.reset();
46 rightEncoder.reset();
47 }
48
d7bf2340 49 public double getRightSpeed() {
6833a887 50 return rightEncoder.getRate(); // in inches per second
d7bf2340
KZ
51 }
52
53 public double getLeftSpeed() {
6833a887 54 return leftEncoder.getRate(); // in inches per second
d7bf2340
KZ
55 }
56
57 public double getSpeed() {
6833a887 58 return (getLeftSpeed() + getRightSpeed()) / 2.0; // in inches per second
d7bf2340
KZ
59 }
60
d7bf2340 61 public double getRightDistance() {
6833a887 62 return rightEncoder.getDistance(); // in inches
d7bf2340
KZ
63 }
64
d7bf2340 65 public double getLeftDistance() {
6833a887 66 return leftEncoder.getDistance(); // in inches
d7bf2340
KZ
67 }
68
69 public double getDistance() {
6833a887 70 return (getRightDistance() + getLeftDistance()) / 2.0; // in inches
d7bf2340
KZ
71 }
72
73 public void stop() {
74 setMotorSpeeds(0, 0);
75 }
76
77 public void setMotorSpeeds(double leftSpeed, double rightSpeed) {
1884c3cf
KZ
78 // speed passed to right motor is negative because right motor rotates in
79 // opposite direction
d7bf2340
KZ
80 this.frontLeft.set(leftSpeed);
81 this.frontRight.set(-rightSpeed);
82 this.rearLeft.set(leftSpeed);
83 this.rearRight.set(-rightSpeed);
d7bf2340 84 }
38a404b3
KZ
85
86}