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();
85 public double getLeftEncoderDistance() {
86 return leftEncoder
.getDistance();
89 public double getRightEncoderDistance() {
90 return rightEncoder
.getDistance();
93 public double getAvgEncoderDistance() {
94 return (leftEncoder
.getDistance() + rightEncoder
.getDistance()) / 2;
97 public void resetEncoders() {
102 public double getLeftSpeed() {
103 return leftEncoder
.getRate();
106 public double getRightSpeed() {
107 return rightEncoder
.getRate();
110 public double getSpeed() {
111 return (getLeftSpeed() + getRightSpeed()) / 2.0;
115 protected void initDefaultCommand() {
116 setDefaultCommand(new JoystickDrive());