c83487325eb75655a9eb6b913c036338e12fbe2b
1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
4 import org
.usfirst
.frc
.team3501
.robot
.commands
.driving
.JoystickDrive
;
6 import com
.ctre
.CANTalon
;
8 import edu
.wpi
.first
.wpilibj
.Encoder
;
9 import edu
.wpi
.first
.wpilibj
.RobotDrive
;
10 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
12 public class DriveTrain
extends Subsystem
{
13 private static DriveTrain driveTrain
;
14 private final CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
15 private final RobotDrive robotDrive
;
16 private final Encoder leftEncoder
, rightEncoder
;
18 private DriveTrain() {
20 frontLeft
= new CANTalon(Constants
.DriveTrain
.FRONT_LEFT
);
21 frontRight
= new CANTalon(Constants
.DriveTrain
.FRONT_RIGHT
);
22 rearLeft
= new CANTalon(Constants
.DriveTrain
.REAR_LEFT
);
23 rearRight
= new CANTalon(Constants
.DriveTrain
.REAR_RIGHT
);
26 leftEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_LEFT_A
, Constants
.DriveTrain
.ENCODER_LEFT_B
);
27 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
, Constants
.DriveTrain
.ENCODER_RIGHT_B
);
29 leftEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
30 rightEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
33 robotDrive
= new RobotDrive(frontLeft
, rearLeft
, frontRight
, rearRight
);
36 public static DriveTrain
getDriveTrain() {
37 if (driveTrain
== null) {
38 driveTrain
= new DriveTrain();
44 public void setMotorValues(final double left
, final double right
) {
45 robotDrive
.tankDrive(left
, right
);
48 public void joystickDrive(final double thrust
, final double twist
) {
49 robotDrive
.arcadeDrive(thrust
, twist
);
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() {
121 setDefaultCommand(new JoystickDrive());