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.ButtonCommandSpit;
|
5
|
|
|
import org.usfirst.frc.team3695.robot.commands.ManualCommandDrive;
|
6
|
|
|
import org.usfirst.frc.team3695.robot.commands.ManualCommandGrow;
|
7
|
|
|
import org.usfirst.frc.team3695.robot.enumeration.Direction;
|
8
|
|
|
import org.usfirst.frc.team3695.robot.util.Util;
|
9
|
|
|
import org.usfirst.frc.team3695.robot.util.Xbox;
|
10
|
|
|
|
11
|
|
|
import com.ctre.CANTalon;
|
12
|
|
|
import com.ctre.phoenix.motorcontrol.ControlMode;
|
13
|
|
|
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
|
14
|
|
|
|
15
|
|
|
import edu.wpi.first.wpilibj.DigitalInput;
|
16
|
|
|
import edu.wpi.first.wpilibj.Joystick;
|
17
|
|
|
import edu.wpi.first.wpilibj.command.Subsystem;
|
18
|
|
|
|
19
|
|
|
/** the big, metal pole */
|
20
|
|
|
public class SubsystemMast extends Subsystem {
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
private TalonSRX leftPinion;
|
24
|
|
|
private TalonSRX rightPinion;
|
25
|
|
|
private TalonSRX screw;
|
26
|
|
|
|
27
|
|
|
DigitalInput lowerPinionLimit;
|
28
|
|
|
DigitalInput upperPinionLimit;
|
29
|
|
|
DigitalInput lowerScrewLimit;
|
30
|
|
|
DigitalInput midScrewLimit;
|
31
|
|
|
DigitalInput upperScrewLimit;
|
32
|
|
|
|
33
|
|
|
private Direction screwPos;
|
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** runs at robot boot */
|
37
|
|
|
public void initDefaultCommand() {
|
38
|
|
|
setDefaultCommand(new ManualCommandGrow()); }
|
39
|
|
|
|
40
|
|
|
/** gives birth to the CANTalons */
|
41
|
|
|
public SubsystemMast(){
|
42
|
|
|
lowerPinionLimit = new DigitalInput(1);
|
43
|
|
|
upperPinionLimit = new DigitalInput(2);
|
|
|
|
|
44
|
|
|
lowerScrewLimit = new DigitalInput(3);
|
|
|
|
|
45
|
|
|
midScrewLimit = new DigitalInput(4);
|
|
|
|
|
46
|
|
|
upperScrewLimit = new DigitalInput(5);
|
|
|
|
|
47
|
|
|
|
48
|
|
|
leftPinion = new TalonSRX(Constants.LEFT_PINION_MOTOR);
|
49
|
|
|
rightPinion = new TalonSRX(Constants.RIGHT_PINION_MOTOR);
|
50
|
|
|
screw = new TalonSRX(Constants.SCREW_MOTOR);
|
51
|
|
|
voltage(leftPinion);
|
52
|
|
|
voltage(rightPinion);
|
53
|
|
|
voltage(screw);
|
54
|
|
|
}
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** apply pinion motor invert */
|
58
|
|
|
public static final double leftPinionate(double left) {
|
59
|
|
|
return left * (Constants.LEFT_PINION_MOTOR_INVERT ? -1.0 : 1.0);
|
60
|
|
|
}
|
61
|
|
|
|
62
|
|
|
/** apply screw motor invert */
|
63
|
|
|
public static final double rightPinionate(double right) {
|
64
|
|
|
return right * (Constants.RIGHT_PINION_MOTOR_INVERT ? -1.0 : 1.0);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
public static final double screwify(double screw) {
|
68
|
|
|
return screw * (Constants.SCREW_MOTOR_INVERT ? -1.0 : 1.0);
|
69
|
|
|
}
|
70
|
|
|
|
71
|
|
|
/** raise the mast at RT-LR trigger speed */
|
72
|
|
|
public void moveBySpeed(Joystick joy) {
|
73
|
|
|
double screwSpeed = Xbox.RT(joy) - Xbox.LT(joy);
|
74
|
|
|
double pinionSpeed = Xbox.RT(joy) - Xbox.LT(joy);
|
75
|
|
|
/**
|
76
|
|
|
if (lowerScrewLimit.get() && screwSpeed < 0) { screwSpeed = 0; }
|
77
|
|
|
if (upperScrewLimit.get() && screwSpeed > 1) { screwSpeed = 0; }
|
78
|
|
|
if (lowerPinionLimit.get() && pinionSpeed < 0) { pinionSpeed = 0; }
|
79
|
|
|
if (upperPinionLimit.get() && pinionSpeed > 1) { pinionSpeed = 0; }
|
80
|
|
|
**/
|
81
|
|
|
leftPinion.set(ControlMode.PercentOutput, leftPinionate(screwSpeed));
|
82
|
|
|
rightPinion.set(ControlMode.PercentOutput, rightPinionate(screwSpeed));
|
83
|
|
|
screw.set(ControlMode.PercentOutput, screwify(pinionSpeed));
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
public void goToMiddle() {
|
87
|
|
|
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
/** configures the voltage of each CANTalon */
|
91
|
|
|
private void voltage(TalonSRX talon) {
|
|
|
|
|
92
|
|
|
// talon.configNominalOutputVoltage(0f, 0f);
|
93
|
|
|
// talon.configPeakOutputVoltage(12.0f, -12.0f);
|
94
|
|
|
// talon.enableCurrentLimit(true);
|
95
|
|
|
// talon.configContinuousCurrentLimit(35, 300);
|
96
|
|
|
// configContinuousCurrentLimit spat mean errors
|
97
|
|
|
// commented out for now, but we need to address it
|
98
|
|
|
}
|
99
|
|
|
|
100
|
|
|
|
101
|
|
|
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
|