1
|
|
|
package org.usfirst.frc.team3695.robot.subsystems;
|
2
|
|
|
|
3
|
|
|
import org.usfirst.frc.team3695.robot.Constants;
|
4
|
|
|
import org.usfirst.frc.team3695.robot.commands.ManualCommandDrive;
|
5
|
|
|
import org.usfirst.frc.team3695.robot.util.Xbox;
|
6
|
|
|
|
7
|
|
|
import com.ctre.CANTalon;
|
8
|
|
|
import com.ctre.phoenix.motorcontrol.ControlMode;
|
9
|
|
|
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
|
10
|
|
|
|
11
|
|
|
import edu.wpi.first.wpilibj.Joystick;
|
12
|
|
|
import edu.wpi.first.wpilibj.command.Subsystem;
|
13
|
|
|
|
14
|
|
|
/** VROOM VROOM */
|
15
|
|
|
public class SubsystemDrive extends Subsystem {
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
private TalonSRX left1;
|
20
|
|
|
private TalonSRX left2;
|
21
|
|
|
private TalonSRX right1;
|
22
|
|
|
private TalonSRX right2;
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** runs at robot boot */
|
26
|
|
|
public void initDefaultCommand() {
|
27
|
|
|
setDefaultCommand(new ManualCommandDrive()); }
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** converts RPM to inches per second */
|
31
|
|
|
public static final double rpm2ips(double rpm) {
|
32
|
|
|
return rpm / 60.0 * Constants.WHEEL_DIAMETER * Math.PI; }
|
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** converts an inches per second number to RPM */
|
36
|
|
|
public static final double ips2rpm(double ips) {
|
37
|
|
|
return ips * 60.0 / Constants.WHEEL_DIAMETER / Math.PI; }
|
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** converts rotations to distance traveled in inches */
|
41
|
|
|
public static final double rot2in(double rot) {
|
42
|
|
|
return rot * Constants.WHEEL_DIAMETER * Math.PI; }
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** converts distance traveled in inches to rotations */
|
46
|
|
|
public static final double in2rot(double in) {
|
47
|
|
|
return in / Constants.WHEEL_DIAMETER / Math.PI; }
|
48
|
|
|
|
49
|
|
|
/** gives birth to the CANTalons */
|
50
|
|
|
public SubsystemDrive(){
|
51
|
|
|
//Master Talons
|
52
|
|
|
left1 = new TalonSRX(Constants.LEFT_MASTER);
|
53
|
|
|
right1 = new TalonSRX(Constants.RIGHT_MASTER);
|
54
|
|
|
|
55
|
|
|
//Slave Talons
|
56
|
|
|
left2 = new TalonSRX(Constants.LEFT_SLAVE);
|
57
|
|
|
right2 = new TalonSRX(Constants.RIGHT_SLAVE);
|
58
|
|
|
// call voltage for each instantiated CANTalon
|
59
|
|
|
// EX: voltage(left1);
|
60
|
|
|
// train each CANTalon
|
61
|
|
|
// master EX: left1.setFeedbackDevice(CANTalon.FeedbackDevice.CtreMagEncoder_Relative);
|
62
|
|
|
// left1.setEncPosition(0);
|
63
|
|
|
// left1.reverseSensor(false);
|
64
|
|
|
// slave EX: left2.changeControlMode(CANTalon.TalonControlMode.Follower);
|
65
|
|
|
// left2.set(left1.getDeviceID());
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
public void driveTank(Joystick joy) {
|
69
|
|
|
double adder = Xbox.RT(joy) - Xbox.LT(joy);
|
70
|
|
|
//double left_applied = Xbox.LEFT_X(joy) * (adder / Math.abs(adder));
|
71
|
|
|
double left = adder + (Xbox.LEFT_X(joy) / 1.333333);
|
|
|
|
|
72
|
|
|
double right = adder - (Xbox.LEFT_X(joy) / 1.333333);
|
|
|
|
|
73
|
|
|
|
74
|
|
|
//Quick Truncate
|
75
|
|
|
left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left));
|
76
|
|
|
right = -1 * (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right));
|
77
|
|
|
|
78
|
|
|
left1.set(ControlMode.PercentOutput, left);
|
79
|
|
|
left2.set(ControlMode.PercentOutput, left);
|
80
|
|
|
right1.set(ControlMode.PercentOutput, right);
|
81
|
|
|
right2.set(ControlMode.PercentOutput, right);
|
82
|
|
|
|
83
|
|
|
}
|
84
|
|
|
|
85
|
|
|
/** configures the voltage of each CANTalon */
|
86
|
|
|
private void voltage(TalonSRX talon) {
|
|
|
|
|
87
|
|
|
// talon.configNominalOutputVoltage(0f, 0f);
|
88
|
|
|
// talon.configPeakOutputVoltage(12.0f, -12.0f);
|
89
|
|
|
// talon.enableCurrentLimit(true);
|
90
|
|
|
// talon.configContinuousCurrentLimit(30, 3000);
|
91
|
|
|
}
|
92
|
|
|
|
93
|
|
|
|
94
|
|
|
|
95
|
|
|
}
|
96
|
|
|
|
97
|
|
|
|
Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.