Completed
Push — master ( 6b018e...519662 )
by John
33s
created

rightify(double)   A

Complexity

Conditions 2

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
c 0
b 0
f 0
rs 10
cc 2
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
	private TalonSRX left1;
19
	private TalonSRX left2;
20
	private TalonSRX right1;
21
	private TalonSRX right2;
22
23
	
24
	/** runs at robot boot */
25
    public void initDefaultCommand() {
26
    	setDefaultCommand(new ManualCommandDrive()); }
27
    
28
    
29
    /** converts RPM to inches per second */
30
    public static final double rpm2ips(double rpm) {
31
    	return rpm / 60.0 * Constants.WHEEL_DIAMETER * Math.PI; }
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 60.0 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...
32
    
33
    
34
    /** converts an inches per second number to RPM */
35
    public static final double ips2rpm(double ips) {
36
    	return ips * 60.0 / Constants.WHEEL_DIAMETER / Math.PI; }
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 60.0 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...
37
    
38
    
39
    /** converts rotations to distance traveled in inches */
40
    public static final double rot2in(double rot) {
41
    	return rot * Constants.WHEEL_DIAMETER * Math.PI; }
42
    
43
    
44
    /** converts distance traveled in inches to rotations */
45
    public static final double in2rot(double in) {
46
    	return in / Constants.WHEEL_DIAMETER / Math.PI; }
47
    
48
    /** apply left motor invert */
49
    public static final double leftify(double left) {
50
		return left * (Constants.LEFT_MOTOR_INVERT ? -1.0 : 1.0);
51
	}
52
53
    /** apply right motor invert */
54
	public static final double rightify(double right) {
55
		return right * (Constants.RIGHT_MOTOR_INVERT ? -1.0 : 1.0);
56
	}
57
	
58
	/** gives birth to the CANTalons */
59
    public SubsystemDrive(){
60
    	// masters
61
	    	left1 = new TalonSRX(Constants.LEFT_MASTER);
62
	    	right1 = new TalonSRX(Constants.RIGHT_MASTER);
63
    	
64
    	// slaves
65
	    	left2 = new TalonSRX(Constants.LEFT_SLAVE);
66
	    	right2 = new TalonSRX(Constants.RIGHT_SLAVE); 	
67
    }
68
    
69
    /** simple rocket league drive code; independent rotation and acceleration */
70
    public void driveRLTank(Joystick joy) {
71
    	double adder = Xbox.RT(joy) - Xbox.LT(joy);
72
    	double left = adder + (Xbox.LEFT_X(joy) / 1.333333);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 1.333333 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...
73
    	double right = adder - (Xbox.LEFT_X(joy) / 1.333333);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 1.333333 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...
74
    	
75
    	//Quick Truncate
76
    	left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left));
77
    	right = (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right));
78
    	    	
79
    	left1.set(ControlMode.PercentOutput, leftify(left));
80
    		left2.set(ControlMode.PercentOutput, leftify(left));
81
    	right1.set(ControlMode.PercentOutput, rightify(right));
82
    		right2.set(ControlMode.PercentOutput, rightify(right));
83
    	
84
    }
85
    
86
    /** drive code where rotation is dependent on acceleration */
87
    public void driveForza(Joystick joy, double ramp) {
88
    	double left = 0, 
89
    		   right = 0;
0 ignored issues
show
Coding Style introduced by
Declaring several variables on the same line makes your code hard to read. Consider delaring right on a separate line.
Loading history...
90
    	double acceleration = Xbox.RT(joy) - Xbox.LT(joy);
91
    	
92
    	if (Xbox.LEFT_X(joy) < 0) {
93
    		right = acceleration;
94
    		left = acceleration * ((2 * (1 - Math.abs(Xbox.LEFT_X(joy)))) - 1); 
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 2 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...
95
    	} else if (Xbox.LEFT_X(joy) > 0) {
96
    		left = acceleration;
97
    		right = acceleration * ((2 * (1 - Math.abs(Xbox.LEFT_X(joy)))) - 1); 
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 2 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...
98
    	} else {
99
    		left = acceleration;
100
    		right = acceleration;
101
    	}
102
    	
103
    	/// ramps
104
	    	left1.configOpenloopRamp(ramp, 0);
105
	    		left2.configOpenloopRamp(ramp, 0);
106
	    	right1.configOpenloopRamp(ramp, 0);
107
	    		right2.configOpenloopRamp(ramp, 0);
108
    	
109
	    left1.set(ControlMode.PercentOutput, leftify(left));
110
			left2.set(ControlMode.PercentOutput, leftify(left));
111
		right1.set(ControlMode.PercentOutput, rightify(right));
112
			right2.set(ControlMode.PercentOutput, rightify(right));
113
    }
114
    
115
    /** configures the voltage of each CANTalon */
116
    private void voltage(TalonSRX talon) {
0 ignored issues
show
Unused Code introduced by
Your method has more parameters than it evaluates. Consider removing talon.
Loading history...
117
    	// talon.configNominalOutputVoltage(0f, 0f);
118
    	// talon.configPeakOutputVoltage(12.0f, -12.0f);
119
    	// talon.enableCurrentLimit(true);
120
    	// talon.configContinuousCurrentLimit(30, 3000);
121
    }
122
    
123
    
124
125
}
126
127