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; | |
3fb3f225 SC |
16 | private double[] potHandAngles; |
17 | private double[] potArmAngles; | |
28ad5f35 | 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); | |
3fb3f225 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 | */ | |
3fb3f225 SC |
56 | public double getAngleForHandLocation(int desiredArmLocation) { |
57 | return potHandAngles[desiredArmLocation]; | |
90784ff2 YN |
58 | } |
59 | ||
3fb3f225 SC |
60 | public double getAngleForArmLocation(int desiredArmLocation) { |
61 | return potArmAngles[desiredArmLocation]; | |
62 | } | |
63 | ||
64 | public double[] createHandPotArray() { | |
65 | double[] arr = new double[3]; | |
66 | ||
67 | for (int i = 0; i < 3; i++) { | |
68 | arr[i] = 45 * i; | |
69 | } | |
70 | return arr; | |
71 | } | |
72 | ||
73 | public double[] createArmPotArray() { | |
1d110d2f SC |
74 | double[] arr = new double[3]; |
75 | ||
90784ff2 | 76 | for (int i = 0; i < 3; i++) { |
1d110d2f | 77 | arr[i] = 45 * i; |
90784ff2 | 78 | } |
1d110d2f | 79 | return arr; |
90784ff2 YN |
80 | } |
81 | ||
d6c9c0f4 KZ |
82 | /*** |
83 | * This method sets the voltage of the arm motor. The range is from [-1,1]. A | |
84 | * negative voltage makes the direction of the motor go backwards. | |
85 | * | |
86 | * @param speed | |
87 | * The voltage that you set the motor at. The range of the voltage of | |
88 | * the arm motor is from [-1,1]. A | |
89 | * negative voltage makes the direction of the motor go backwards. | |
90 | */ | |
91 | ||
92 | public void setArmSpeed(double speed) { | |
93 | if (speed > 1) | |
94 | speed = 1; | |
95 | else if (speed < -1) | |
96 | speed = -1; | |
97 | ||
98 | defenseArm.set(speed); | |
99 | } | |
100 | ||
101 | /*** | |
102 | * This method sets the voltage of the hand motor. The range is from [-1,1]. A | |
103 | * negative voltage makes the direction of the motor go backwards. | |
104 | * | |
105 | * @param speed | |
106 | * The voltage that you set the motor at. The range of the voltage of | |
107 | * the hand motor is from [-1,1]. A | |
108 | * negative voltage makes the direction of the motor go backwards. | |
109 | */ | |
110 | ||
111 | public void setHandSpeed(double speed) { | |
112 | if (speed > 1) | |
113 | speed = 1; | |
114 | else if (speed < -1) | |
115 | speed = -1; | |
116 | ||
117 | defenseHand.set(speed); | |
118 | } | |
119 | ||
59a85209 | 120 | // TODO: figure out if measurements are all in inches |
4927eb6c | 121 | public double getArmHorizontalDisplacement() { |
bf83e12d CZ |
122 | double armHorizontalDisplacement = Constants.DefenseArm.ARM_LENGTH |
123 | * Math.cos(getArmPotAngle()); | |
124 | double handHorizontalDisplacement = Constants.DefenseArm.HAND_LENGTH | |
01654890 | 125 | * Math.cos(getHandPotAngle()); |
bf83e12d | 126 | return (armHorizontalDisplacement + handHorizontalDisplacement); |
01654890 CZ |
127 | } |
128 | ||
56c148bd | 129 | public double getArmVerticalDisplacement() { |
01654890 | 130 | double armMounted = Constants.DefenseArm.ARM_MOUNTED_HEIGHT; |
bf83e12d CZ |
131 | double armVerticalDisplacement = Constants.DefenseArm.ARM_LENGTH |
132 | * Math.sin(getArmPotAngle()); | |
133 | double handVerticalDisplacement = Constants.DefenseArm.HAND_LENGTH | |
01654890 | 134 | * Math.sin(getHandPotAngle()); |
bf83e12d | 135 | return (armMounted + armVerticalDisplacement + handVerticalDisplacement); |
01654890 CZ |
136 | } |
137 | ||
138 | public boolean isOutsideRange() { | |
4927eb6c | 139 | if (getArmHorizontalDisplacement() < 15) |
01654890 CZ |
140 | return false; |
141 | return true; | |
142 | } | |
143 | ||
d6c9c0f4 KZ |
144 | @Override |
145 | protected void initDefaultCommand() { | |
146 | } | |
147 | } |