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 public static final double WHEEL_DIAMETER
= 6; // inches
14 public static final int ENCODER_PULSES_PER_REVOLUTION
= 256;
15 public static final double INCHES_PER_PULSE
= WHEEL_DIAMETER
* Math
.PI
16 / ENCODER_PULSES_PER_REVOLUTION
;
18 private static DriveTrain driveTrain
;
19 private final CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
20 private final RobotDrive robotDrive
;
21 private final Encoder leftEncoder
, rightEncoder
;
23 private DriveTrain() {
25 frontLeft
= new CANTalon(Constants
.DriveTrain
.FRONT_LEFT
);
26 frontRight
= new CANTalon(Constants
.DriveTrain
.FRONT_RIGHT
);
27 rearLeft
= new CANTalon(Constants
.DriveTrain
.REAR_LEFT
);
28 rearRight
= new CANTalon(Constants
.DriveTrain
.REAR_RIGHT
);
31 leftEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_LEFT_A
,
32 Constants
.DriveTrain
.ENCODER_LEFT_B
, false, Encoder
.EncodingType
.k4X
);
33 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
,
34 Constants
.DriveTrain
.ENCODER_RIGHT_B
, false, Encoder
.EncodingType
.k4X
);
36 leftEncoder
.setDistancePerPulse(INCHES_PER_PULSE
);
37 rightEncoder
.setDistancePerPulse(INCHES_PER_PULSE
);
40 robotDrive
= new RobotDrive(frontLeft
, rearLeft
, frontRight
, rearRight
);
43 public static DriveTrain
getDriveTrain() {
44 if (driveTrain
== null) {
45 driveTrain
= new DriveTrain();
51 public void setMotorValues(final double left
, final double right
) {
55 frontRight
.set(-right
);
56 rearRight
.set(-right
);
59 public void joystickDrive(final double thrust
, final double twist
) {
60 robotDrive
.arcadeDrive(thrust
, twist
, true);
67 public double getFrontLeftMotorVal() {
68 return frontLeft
.get();
71 public double getFrontRightMotorVal() {
72 return frontRight
.get();
75 public double getRearLeftMotorVal() {
76 return frontLeft
.get();
79 public double getRearRightMotorVal() {
80 return frontLeft
.get();
83 public CANTalon
getFrontLeft() {
87 public CANTalon
getFrontRight() {
91 public CANTalon
getRearLeft() {
95 public CANTalon
getRearRight() {
101 public double getLeftEncoder() {
102 return leftEncoder
.getDistance();
105 public double getRightEncoder() {
106 return rightEncoder
.getDistance();
109 public double getAvgEncoderDistance() {
110 return (leftEncoder
.getDistance() + rightEncoder
.getDistance()) / 2;
113 public void resetEncoders() {
115 rightEncoder
.reset();
118 public double getLeftSpeed() {
119 return leftEncoder
.getRate();
122 public double getRightSpeed() {
123 return rightEncoder
.getRate();
126 public double getSpeed() {
127 return (getLeftSpeed() + getRightSpeed()) / 2.0;
131 protected void initDefaultCommand() {
132 setDefaultCommand(new JoystickDrive());