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
.ADXRS450_Gyro
;
9 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
;
10 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
.Value
;
11 import edu
.wpi
.first
.wpilibj
.Encoder
;
12 import edu
.wpi
.first
.wpilibj
.RobotDrive
;
13 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
15 public class DriveTrain
extends Subsystem
{
16 public static double driveP
= 0.006, driveI
= 0.001, driveD
= -0.002;
17 public static double turnP
= 0.004, turnI
= 0.0013, turnD
= -0.005;
18 public static double driveStraightGyroP
= 0.01;
20 public static final double WHEEL_DIAMETER
= 6; // inches
21 public static final int ENCODER_PULSES_PER_REVOLUTION
= 256;
22 public static final double INCHES_PER_PULSE
= WHEEL_DIAMETER
* Math
.PI
23 / ENCODER_PULSES_PER_REVOLUTION
;
25 public static final double MAINTAIN_CLIMBED_POSITION
= 0;
26 public static final double TIME_TO_CLIMB_FOR
= 0;
27 public static final double CLIMBER_SPEED
= 0;
29 private static DriveTrain driveTrain
;
31 private final CANTalon frontLeft
, frontRight
, rearLeft
, rearRight
;
32 private final RobotDrive robotDrive
;
33 private final Encoder leftEncoder
, rightEncoder
;
34 private final DoubleSolenoid leftGearPiston
, rightGearPiston
;
36 private ADXRS450_Gyro imu
;
38 public boolean shouldBeClimbing
= false;
40 private DriveTrain() {
42 frontLeft
= new CANTalon(Constants
.DriveTrain
.FRONT_LEFT
);
43 frontRight
= new CANTalon(Constants
.DriveTrain
.FRONT_RIGHT
);
44 rearLeft
= new CANTalon(Constants
.DriveTrain
.REAR_LEFT
);
45 rearRight
= new CANTalon(Constants
.DriveTrain
.REAR_RIGHT
);
48 leftEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_LEFT_A
,
49 Constants
.DriveTrain
.ENCODER_LEFT_B
, false, Encoder
.EncodingType
.k4X
);
50 rightEncoder
= new Encoder(Constants
.DriveTrain
.ENCODER_RIGHT_A
,
51 Constants
.DriveTrain
.ENCODER_RIGHT_B
, false, Encoder
.EncodingType
.k4X
);
53 leftEncoder
.setDistancePerPulse(INCHES_PER_PULSE
);
54 rightEncoder
.setDistancePerPulse(INCHES_PER_PULSE
);
57 robotDrive
= new RobotDrive(frontLeft
, rearLeft
, frontRight
, rearRight
);
59 this.imu
= new ADXRS450_Gyro(Constants
.DriveTrain
.GYRO_PORT
);
61 // TODO: Not sure if MODULE_NUMBER should be the same for both
62 leftGearPiston
= new DoubleSolenoid(Constants
.DriveTrain
.MODULE_NUMBER
,
63 Constants
.DriveTrain
.LEFT_GEAR_PISTON_FORWARD
,
64 Constants
.DriveTrain
.LEFT_GEAR_PISTON_REVERSE
);
65 rightGearPiston
= new DoubleSolenoid(Constants
.DriveTrain
.MODULE_NUMBER
,
66 Constants
.DriveTrain
.RIGHT_GEAR_PISTON_FORWARD
,
67 Constants
.DriveTrain
.RIGHT_GEAR_PISTON_REVERSE
);
70 public static DriveTrain
getDriveTrain() {
71 if (driveTrain
== null) {
72 driveTrain
= new DriveTrain();
78 public void setMotorValues(final double left
, final double right
) {
82 frontRight
.set(-right
);
83 rearRight
.set(-right
);
86 public void joystickDrive(final double thrust
, final double twist
) {
87 robotDrive
.arcadeDrive(thrust
, twist
, true);
94 public double getLeftMotorVal() {
95 return (frontLeft
.get() + rearLeft
.get()) / 2;
98 public double getRightMotorVal() {
99 return (frontRight
.get() + rearRight
.get()) / 2;
104 public double getLeftEncoderDistance() {
105 return leftEncoder
.getDistance();
108 public double getRightEncoderDistance() {
109 return rightEncoder
.getDistance();
112 public void printEncoderOutput() {
113 System
.out
.println("left: " + getLeftEncoderDistance());
114 System
.out
.println("right: " + getRightEncoderDistance());
115 // System.out.println(getAvgEncoderDistance());
118 public double getAvgEncoderDistance() {
119 return (leftEncoder
.getDistance() + rightEncoder
.getDistance()) / 2;
122 public void resetEncoders() {
124 rightEncoder
.reset();
127 public double getLeftSpeed() {
128 return leftEncoder
.getRate();
131 public double getRightSpeed() {
132 return rightEncoder
.getRate();
135 public double getSpeed() {
136 return (getLeftSpeed() + getRightSpeed()) / 2.0;
139 // ------Gyro------//
140 public double getAngle() {
141 return this.imu
.getAngle();
144 public void resetGyro() {
149 * @return a value that is the current setpoint for the piston kReverse or
152 public Value
getLeftGearPistonValue() {
153 return leftGearPiston
.get();
157 * @return a value that is the current setpoint for the piston kReverse or
160 public Value
getRightGearPistonValue() {
161 return rightGearPiston
.get();
165 * Changes the ball shift gear assembly to high
167 public void setHighGear() {
168 changeGear(Constants
.DriveTrain
.HIGH_GEAR
);
172 * Changes the ball shift gear assembly to low
174 public void setLowGear() {
175 changeGear(Constants
.DriveTrain
.LOW_GEAR
);
179 * Changes the gear to a DoubleSolenoid.Value
181 private void changeGear(DoubleSolenoid
.Value gear
) {
182 leftGearPiston
.set(gear
);
183 rightGearPiston
.set(gear
);
187 protected void initDefaultCommand() {
188 setDefaultCommand(new JoystickDrive());