org.usfirst.frc.team3695.robot.subsystems.SubsystemMast   A
last analyzed

Complexity

Total Complexity 37

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 138
rs 9.44
c 0
b 0
f 0
wmc 37

22 Methods

Rating   Name   Duplication   Size   Complexity  
A initDefaultCommand() 0 2 1
adjustScrew 0 8 ?
screwify 0 3 ?
C moveBySpeed(Joystick,double) 0 15 10
A dropIt(double) 0 16 3
dropIt 0 16 ?
A publishSwitches() 0 5 1
rightPinionate 0 3 ?
setOverride 0 2 ?
leftPinionate 0 3 ?
voltage 0 6 ?
A screwify(double) 0 3 3
moveBySpeed 0 15 ?
A SubsystemMast() 0 16 1
A adjustScrew(Position) 0 8 5
A setOverride(Boolean) 0 2 1
A rightPinionate(double) 0 3 3
A voltage(TalonSRX) 0 6 1
publishSwitches 0 5 ?
A adjustPinion(Position) 0 11 5
adjustPinion 0 11 ?
A leftPinionate(double) 0 3 3
1
package org.usfirst.frc.team3695.robot.subsystems;
2
3
import com.ctre.phoenix.motorcontrol.ControlMode;
4
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
5
import edu.wpi.first.wpilibj.DigitalInput;
6
import edu.wpi.first.wpilibj.Joystick;
7
import edu.wpi.first.wpilibj.command.Subsystem;
8
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
9
import org.usfirst.frc.team3695.robot.Constants;
10
import org.usfirst.frc.team3695.robot.Robot;
11
import org.usfirst.frc.team3695.robot.commands.ManualCommandGrow;
12
import org.usfirst.frc.team3695.robot.enumeration.Bot;
13
import org.usfirst.frc.team3695.robot.enumeration.Position;
14
import org.usfirst.frc.team3695.robot.util.Xbox;
15
16
/** the big, metal pole */
17
public class SubsystemMast extends Subsystem {
18
	
19
	
20
	private TalonSRX leftPinion;
21
	private TalonSRX rightPinion;
22
	private TalonSRX screw;
23
	
24
	DigitalInput lowerPinionLimit;
25
    DigitalInput upperPinionLimit;
26
    DigitalInput lowerScrewLimit;
27
    DigitalInput midScrewLimit;
28
    DigitalInput upperScrewLimit;
29
30
    private Boolean override;
31
32
	
33
	/** runs at robot boot */
34
    public void initDefaultCommand() {
35
    	setDefaultCommand(new ManualCommandGrow()); }
36
	
37
	/** gives birth to the CANTalons */
38
    public SubsystemMast(){
39
    	/** Does it make sense to move the limit switch IDs to Constants? **/
40
    	//no because they could be moved due to various electrical reasons-nate
41
    	lowerPinionLimit = new DigitalInput(6);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 6 to a constant.

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.

Loading history...
42
        upperPinionLimit = new DigitalInput(7);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 7 to a constant.

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.

Loading history...
43
        lowerScrewLimit  = new DigitalInput(3);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 3 to a constant.

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.

Loading history...
44
        upperScrewLimit  = new DigitalInput(4);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 4 to a constant.

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.

Loading history...
45
    	
46
    	leftPinion = new TalonSRX(Constants.LEFT_PINION_MOTOR);
47
    	rightPinion = new TalonSRX(Constants.RIGHT_PINION_MOTOR);
48
    	screw = new TalonSRX(Constants.SCREW_MOTOR);
49
    		voltage(leftPinion);
50
    		voltage(rightPinion);
51
    		voltage(screw);
52
    		
53
		override = false;
54
    }
55
    
56
    public void setOverride(Boolean override) {
57
    	this.override = override;
58
    }
59
60
   	/** apply pinion motor invert */
61
   	public static final double leftPinionate(double left) {
62
   		Boolean invert = Robot.bot == Bot.OOF ? Constants.OOF.LEFT_PINION_MOTOR_INVERT : Constants.TEUFELSKIND.LEFT_PINION_MOTOR_INVERT;
63
   		return left * (invert ? -1.0 : 1.0);
64
   	}
65
   	
66
   	/** apply screw motor invert */
67
   	public static final double rightPinionate(double right) {
68
   		Boolean invert = Robot.bot == Bot.OOF ? Constants.OOF.RIGHT_PINION_MOTOR_INVERT : Constants.TEUFELSKIND.RIGHT_PINION_MOTOR_INVERT;
69
   		return right * (invert ? -1.0 : 1.0);
70
   	}
71
   	
72
   	public static final double screwify(double screw) {
73
   		Boolean invert = Robot.bot == Bot.OOF ? Constants.OOF.SCREW_MOTOR_INVERT : Constants.TEUFELSKIND.SCREW_MOTOR_INVERT;
74
   		return screw * (invert ? -1.0 : 1.0);
75
   	}
76
    
77
   	/** raise the mast at RT-LR trigger speed */
78
    public void moveBySpeed(Joystick joy, double inhibitor) {
79
    	double dualAction = Xbox.RT(joy) - Xbox.LT(joy);
80
    	double screwSpeed = Xbox.LEFT_Y(joy) + dualAction;
81
    	double pinionSpeed = Xbox.RIGHT_Y(joy) + dualAction;
82
    	
83
		if (!lowerPinionLimit.get() && pinionSpeed > 0)   { pinionSpeed = 0; }
84
		if (!upperPinionLimit.get() && pinionSpeed < 0)   { pinionSpeed = 0; }
85
		if (!lowerScrewLimit.get()  && screwSpeed  > 0)   { screwSpeed = 0;  }
86
		if (!upperScrewLimit.get()  && screwSpeed  < 0)   { screwSpeed = 0;  }
87
			
88
    	publishSwitches();
89
    	if (!override) {
90
    		leftPinion.set(ControlMode.PercentOutput, leftPinionate(pinionSpeed));
91
        	rightPinion.set(ControlMode.PercentOutput, rightPinionate(pinionSpeed));
92
        	screw.set(ControlMode.PercentOutput, inhibitor * screwify(screwSpeed));
93
    	}
94
    }
95
    
96
    public Boolean dropIt(double speed) {
97
    	if (lowerPinionLimit.get()) {
98
	    	leftPinion.set(ControlMode.PercentOutput, leftPinionate(speed));
99
	    	rightPinion.set(ControlMode.PercentOutput, rightPinionate(speed));
100
    	} else {
101
    		leftPinion.set(ControlMode.PercentOutput, 0);
102
	    	rightPinion.set(ControlMode.PercentOutput, 0);
103
    	}
104
    	
105
    	if (lowerScrewLimit.get()) {
106
    		screw.set(ControlMode.PercentOutput, screwify(speed));
107
    	} else {
108
    		screw.set(ControlMode.PercentOutput, 0);
109
    	}
110
    	
111
    	return (!lowerPinionLimit.get()) && (!lowerScrewLimit.get());
112
    }
113
114
    public void adjustPinion(Position direction){
115
116
    	if (direction == Position.UP) {
117
			while (!upperPinionLimit.get()) {
118
				rightPinion.set(ControlMode.PercentOutput, rightPinionate(1));
119
				leftPinion.set(ControlMode.PercentOutput, leftPinionate(1));
120
			}
121
		} else if (direction == Position.DOWN) {
122
			while (!lowerPinionLimit.get()) {
123
				rightPinion.set(ControlMode.PercentOutput, rightPinionate(-1));
124
				leftPinion.set(ControlMode.PercentOutput, leftPinionate(-1));
125
			}
126
		}
127
	}
128
129
	public void adjustScrew(Position direction){
130
    	if (direction == Position.UP){
131
    		while (!upperScrewLimit.get()){
132
    			screw.set(ControlMode.PercentOutput, screwify(1));
133
			}
134
		} else if (direction == Position.DOWN){
135
    		while (!lowerScrewLimit.get()){
136
    			screw.set(ControlMode.PercentOutput, screwify(-1));
137
			}
138
		}
139
	}
140
    	
141
    public void publishSwitches() {
142
    	SmartDashboard.putBoolean("Lower Screw", !lowerScrewLimit.get());
143
    	SmartDashboard.putBoolean("Upper Screw", !upperScrewLimit.get());
144
    	SmartDashboard.putBoolean("Lower Pinion", !lowerPinionLimit.get());
145
    	SmartDashboard.putBoolean("Upper Pinion", !upperPinionLimit.get());
146
    }
147
    
148
    /** configures the voltage of each CANTalon */
149
    private void voltage(TalonSRX talon) {
150
    	// talon.configNominalOutputVoltage(0f, 0f);
151
    	// talon.configPeakOutputVoltage(12.0f, -12.0f);
152
    	talon.enableCurrentLimit(true);
153
    	talon.configContinuousCurrentLimit(60, 300);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 60 to a constant.

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.

Loading history...
154
    	talon.configPeakCurrentDuration(500, 10);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 10 to a constant.

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.

Loading history...
155
    }
156
}
157
158