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; | |
1d110d2f | 18 | // angles corresponding to pre-determined heights we will need |
d6c9c0f4 KZ |
19 | |
20 | public DefenseArm() { | |
21 | defenseArmPotentiometer = new AnalogPotentiometer( | |
22 | Constants.DefenseArm.ARM_CHANNEL, | |
23 | Constants.DefenseArm.FULL_RANGE, | |
24 | Constants.DefenseArm.OFFSET); | |
1d110d2f SC |
25 | defenseHandPotentiometer = new AnalogPotentiometer( |
26 | Constants.DefenseArm.HAND_CHANNEL, | |
27 | Constants.DefenseArm.FULL_RANGE, | |
28 | Constants.DefenseArm.OFFSET); | |
d6c9c0f4 KZ |
29 | |
30 | defenseArm = new CANTalon(Constants.DefenseArm.ARM_PORT); | |
31 | defenseHand = new CANTalon(Constants.DefenseArm.HAND_PORT); | |
3fb3f225 SC |
32 | potHandAngles = createHandPotArray(); |
33 | potArmAngles = createArmPotArray(); | |
d6c9c0f4 KZ |
34 | } |
35 | ||
36 | public double getArmPotAngle() { | |
37 | return defenseArmPotentiometer.get(); | |
38 | } | |
39 | ||
40 | public double getHandPotAngle() { | |
41 | return defenseHandPotentiometer.get(); | |
42 | } | |
43 | ||
64f47e4f SC |
44 | /*** |
45 | * This method takes an arm location as input (range of [0,2]) | |
46 | * Returns the angle of the arm corresponding to that arm location | |
47 | * | |
48 | * @param desiredArmLocation | |
49 | * takes an arm location ranging from [0,2] | |
50 | * 0 is the lowest position of arm | |
51 | * 2 is the highest position of arm | |
52 | * @return | |
53 | * the angle of the arm corresponding to that arm location | |
54 | */ | |
3fb3f225 SC |
55 | public double getAngleForHandLocation(int desiredArmLocation) { |
56 | return potHandAngles[desiredArmLocation]; | |
90784ff2 YN |
57 | } |
58 | ||
3fb3f225 SC |
59 | public double getAngleForArmLocation(int desiredArmLocation) { |
60 | return potArmAngles[desiredArmLocation]; | |
61 | } | |
62 | ||
63 | public double[] createHandPotArray() { | |
64 | double[] arr = new double[3]; | |
65 | ||
66 | for (int i = 0; i < 3; i++) { | |
67 | arr[i] = 45 * i; | |
68 | } | |
69 | return arr; | |
70 | } | |
71 | ||
72 | public double[] createArmPotArray() { | |
1d110d2f SC |
73 | double[] arr = new double[3]; |
74 | ||
90784ff2 | 75 | for (int i = 0; i < 3; i++) { |
1d110d2f | 76 | arr[i] = 45 * i; |
90784ff2 | 77 | } |
1d110d2f | 78 | return arr; |
90784ff2 YN |
79 | } |
80 | ||
d6c9c0f4 KZ |
81 | /*** |
82 | * This method sets the voltage of the arm motor. The range is from [-1,1]. A | |
83 | * negative voltage makes the direction of the motor go backwards. | |
84 | * | |
85 | * @param speed | |
86 | * The voltage that you set the motor at. The range of the voltage of | |
87 | * the arm motor is from [-1,1]. A | |
88 | * negative voltage makes the direction of the motor go backwards. | |
89 | */ | |
90 | ||
91 | public void setArmSpeed(double speed) { | |
92 | if (speed > 1) | |
93 | speed = 1; | |
94 | else if (speed < -1) | |
95 | speed = -1; | |
96 | ||
97 | defenseArm.set(speed); | |
98 | } | |
99 | ||
100 | /*** | |
101 | * This method sets the voltage of the hand motor. The range is from [-1,1]. A | |
102 | * negative voltage makes the direction of the motor go backwards. | |
103 | * | |
104 | * @param speed | |
105 | * The voltage that you set the motor at. The range of the voltage of | |
106 | * the hand motor is from [-1,1]. A | |
107 | * negative voltage makes the direction of the motor go backwards. | |
108 | */ | |
109 | ||
110 | public void setHandSpeed(double speed) { | |
111 | if (speed > 1) | |
112 | speed = 1; | |
113 | else if (speed < -1) | |
114 | speed = -1; | |
115 | ||
116 | defenseHand.set(speed); | |
117 | } | |
118 | ||
119 | @Override | |
120 | protected void initDefaultCommand() { | |
121 | } | |
122 | } |