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
,
27 Constants
.DriveTrain
.ENCODER_LEFT_B
);
28 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
,
29 Constants
.DriveTrain
.ENCODER_RIGHT_B
);
31 leftEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
32 rightEncoder
.setDistancePerPulse(Constants
.DriveTrain
.INCHES_PER_PULSE
);
35 robotDrive
= new RobotDrive(frontLeft
, rearLeft
, frontRight
, rearRight
);
38 public static DriveTrain
getDriveTrain() {
39 if (driveTrain
== null) {
40 driveTrain
= new DriveTrain();
46 public void setMotorValues(final double left
, final double right
) {
50 frontRight
.set(right
);
54 public void joystickDrive(final double thrust
, final double twist
) {
55 robotDrive
.arcadeDrive(thrust
, twist
);
62 public double getFrontLeftMotorVal() {
63 return frontLeft
.get();
66 public double getFrontRightMotorVal() {
67 return frontRight
.get();
70 public double getRearLeftMotorVal() {
71 return frontLeft
.get();
74 public double getRearRightMotorVal() {
75 return frontLeft
.get();
78 public CANTalon
getFrontLeft() {
82 public CANTalon
getFrontRight() {
86 public CANTalon
getRearLeft() {
90 public CANTalon
getRearRight() {
96 public double getLeftEncoder() {
97 return leftEncoder
.getDistance();
100 public double getRightEncoder() {
101 return rightEncoder
.getDistance();
104 public double getAvgEncoderDistance() {
105 return (leftEncoder
.getDistance() + rightEncoder
.getDistance()) / 2;
108 public void resetEncoders() {
110 rightEncoder
.reset();
113 public double getLeftSpeed() {
114 return leftEncoder
.getRate();
117 public double getRightSpeed() {
118 return rightEncoder
.getRate();
121 public double getSpeed() {
122 return (getLeftSpeed() + getRightSpeed()) / 2.0;
126 protected void initDefaultCommand() {
127 setDefaultCommand(new JoystickDrive());