Commit | Line | Data |
---|---|---|
d6c9c0f4 KZ |
1 | package org.usfirst.frc.team3501.robot.subsystems; |
2 | ||
3 | import org.usfirst.frc.team3501.robot.Constants; | |
4 | ||
5 | import edu.wpi.first.wpilibj.AnalogPotentiometer; | |
6 | import edu.wpi.first.wpilibj.CANTalon; | |
7 | import edu.wpi.first.wpilibj.command.Subsystem; | |
8 | ||
9 | public class DefenseArm extends Subsystem { | |
d6c9c0f4 KZ |
10 | private AnalogPotentiometer defenseArmPotentiometer; |
11 | private AnalogPotentiometer defenseHandPotentiometer; | |
12 | private CANTalon defenseArm; | |
13 | private CANTalon defenseHand; | |
14 | private double hookHeight; | |
15 | private double footHeight; | |
e22f03b2 SC |
16 | private double[] potHandAngles; |
17 | private double[] potArmAngles; | |
43e90395 | 18 | |
1d110d2f | 19 | // angles corresponding to pre-determined heights we will need |
d6c9c0f4 KZ |
20 | |
21 | public DefenseArm() { | |
22 | defenseArmPotentiometer = new AnalogPotentiometer( | |
23 | Constants.DefenseArm.ARM_CHANNEL, | |
24 | Constants.DefenseArm.FULL_RANGE, | |
25 | Constants.DefenseArm.OFFSET); | |
1d110d2f SC |
26 | defenseHandPotentiometer = new AnalogPotentiometer( |
27 | Constants.DefenseArm.HAND_CHANNEL, | |
28 | Constants.DefenseArm.FULL_RANGE, | |
29 | Constants.DefenseArm.OFFSET); | |
d6c9c0f4 KZ |
30 | |
31 | defenseArm = new CANTalon(Constants.DefenseArm.ARM_PORT); | |
32 | defenseHand = new CANTalon(Constants.DefenseArm.HAND_PORT); | |
e22f03b2 SC |
33 | potHandAngles = createHandPotArray(); |
34 | potArmAngles = createArmPotArray(); | |
d6c9c0f4 KZ |
35 | } |
36 | ||
37 | public double getArmPotAngle() { | |
38 | return defenseArmPotentiometer.get(); | |
39 | } | |
40 | ||
41 | public double getHandPotAngle() { | |
42 | return defenseHandPotentiometer.get(); | |
43 | } | |
44 | ||
64f47e4f SC |
45 | /*** |
46 | * This method takes an arm location as input (range of [0,2]) | |
47 | * Returns the angle of the arm corresponding to that arm location | |
48 | * | |
49 | * @param desiredArmLocation | |
50 | * takes an arm location ranging from [0,2] | |
51 | * 0 is the lowest position of arm | |
52 | * 2 is the highest position of arm | |
53 | * @return | |
54 | * the angle of the arm corresponding to that arm location | |
55 | */ | |
e22f03b2 SC |
56 | |
57 | public double getAngleForHandLocation(int desiredArmLocation) { | |
58 | return potHandAngles[desiredArmLocation]; | |
59 | } | |
60 | ||
61 | public double getAngleForArmLocation(int desiredArmLocation) { | |
62 | return potArmAngles[desiredArmLocation]; | |
63 | } | |
64 | ||
65 | public double[] createHandPotArray() { | |
66 | double[] arr = new double[3]; | |
67 | ||
68 | for (int i = 0; i < 3; i++) { | |
69 | arr[i] = 45 * i; | |
70 | } | |
71 | return arr; | |
72 | } | |
73 | ||
74 | public double[] createArmPotArray() { | |
75 | double[] arr = new double[3]; | |
76 | ||
77 | for (int i = 0; i < 3; i++) { | |
78 | arr[i] = 45 * i; | |
79 | } | |
80 | return arr; | |
90784ff2 YN |
81 | } |
82 | ||
d6c9c0f4 KZ |
83 | /*** |
84 | * This method sets the voltage of the arm motor. The range is from [-1,1]. A | |
85 | * negative voltage makes the direction of the motor go backwards. | |
86 | * | |
87 | * @param speed | |
88 | * The voltage that you set the motor at. The range of the voltage of | |
89 | * the arm motor is from [-1,1]. A | |
90 | * negative voltage makes the direction of the motor go backwards. | |
91 | */ | |
92 | ||
93 | public void setArmSpeed(double speed) { | |
94 | if (speed > 1) | |
95 | speed = 1; | |
96 | else if (speed < -1) | |
97 | speed = -1; | |
98 | ||
99 | defenseArm.set(speed); | |
100 | } | |
101 | ||
102 | /*** | |
103 | * This method sets the voltage of the hand motor. The range is from [-1,1]. A | |
104 | * negative voltage makes the direction of the motor go backwards. | |
105 | * | |
106 | * @param speed | |
107 | * The voltage that you set the motor at. The range of the voltage of | |
108 | * the hand motor is from [-1,1]. A | |
109 | * negative voltage makes the direction of the motor go backwards. | |
110 | */ | |
111 | ||
112 | public void setHandSpeed(double speed) { | |
113 | if (speed > 1) | |
114 | speed = 1; | |
115 | else if (speed < -1) | |
116 | speed = -1; | |
117 | ||
118 | defenseHand.set(speed); | |
119 | } | |
120 | ||
287263e6 | 121 | // TODO: figure out if measurements are all in inches |
43e90395 CZ |
122 | public double getArmHorizontalDist() { |
123 | double arm = Constants.DefenseArm.ARM_LENGTH * Math.cos(getArmPotAngle()); | |
124 | double hand = Constants.DefenseArm.HAND_LENGTH | |
125 | * Math.cos(getHandPotAngle()); | |
126 | return (arm + hand); | |
127 | } | |
128 | ||
129 | public double getArmHeight() { | |
130 | double armMounted = Constants.DefenseArm.ARM_MOUNTED_HEIGHT; | |
131 | double arm = Constants.DefenseArm.ARM_LENGTH * Math.sin(getArmPotAngle()); | |
132 | double hand = Constants.DefenseArm.HAND_LENGTH | |
133 | * Math.sin(getHandPotAngle()); | |
134 | return (armMounted + arm + hand); | |
135 | } | |
136 | ||
137 | public boolean isOutsideRange() { | |
138 | if (getArmHorizontalDist() < 15) | |
139 | return false; | |
140 | return true; | |
141 | } | |
142 | ||
d6c9c0f4 KZ |
143 | @Override |
144 | protected void initDefaultCommand() { | |
145 | } | |
146 | } |