Add buttons to move intake arm.
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / subsystems / IntakeArm.java
CommitLineData
7b11350e
KZ
1package org.usfirst.frc.team3501.robot.subsystems;
2
3import org.usfirst.frc.team3501.robot.Constants;
4
6fd4f44e 5import edu.wpi.first.wpilibj.AnalogPotentiometer;
7b11350e
KZ
6import edu.wpi.first.wpilibj.CANTalon;
7import edu.wpi.first.wpilibj.command.Subsystem;
8
add57fee 9/***
1eb84222
SC
10 * The IntakeArm consists of two rollers that are controlled by one motor, with
11 * a potentiometer on it.
add57fee 12 *
dc394eb0
SG
13 * The motor controls the rollers, making them roll forwards and backwards. The
14 * Intake rollers are on the back of the robot. As the rollers run, they intake
15 * the ball.
add57fee
YA
16 *
17 * @author superuser
18 *
19 */
20
7b11350e 21public class IntakeArm extends Subsystem {
4e0d6389
LM
22
23 private CANTalon intakeRoller;
0a179caa
KZ
24 private CANTalon leftIntakeArm;
25 private CANTalon rightIntakeArm;
4e0d6389 26 private AnalogPotentiometer intakePot;
54c588d9
CZ
27 public static double[] potAngles = { 0, 30, 45, 90 }; // TODO: correct angles
28 public static double moveIntakeArmSpeed = 0;
4e0d6389
LM
29
30 public IntakeArm() {
31 intakeRoller = new CANTalon(Constants.IntakeArm.ROLLER_PORT);
0a179caa
KZ
32 leftIntakeArm = new CANTalon(Constants.IntakeArm.LEFT_ARM_PORT);
33 rightIntakeArm = new CANTalon(Constants.IntakeArm.RIGHT_ARM_PORT);
4e0d6389
LM
34 intakePot = new AnalogPotentiometer(Constants.IntakeArm.POT_CHANNEL,
35 Constants.IntakeArm.FULL_RANGE, Constants.IntakeArm.OFFSET);
4e0d6389
LM
36 }
37
38 /***
39 * This method sets the voltage of the motor to intake the ball. The voltage
40 * values are constants in Constants class
41 */
42 public void intakeBall() {
43 intakeRoller.set(Constants.IntakeArm.INTAKE_SPEED);
44 }
45
46 /***
47 * This method sets the voltage of the motor to output the ball. The voltage
48 * values are constants in Constants class
49 */
50 public void outputBall() {
51 intakeRoller.set(Constants.IntakeArm.OUTPUT_SPEED);
52 }
53
2b65c91d 54 public void stopRollers() {
33141cdd 55 intakeRoller.set(0);
2b65c91d
LM
56 }
57
4e0d6389
LM
58 /***
59 * This method gets you the current voltage of the motor that controls the
60 * intake arm roller. The range of voltage is from [-1,1]. A negative voltage
61 * makes the motor run backwards.
62 *
63 * @return Returns the voltage of the motor that controls the roller. The
64 * range of the voltage goes from [-1,1]. A negative voltage indicates
65 * that the motor is running backwards.
66 */
67
68 public double getRollerVoltage() {
69 return intakeRoller.get();
70 }
71
72 /***
0a179caa
KZ
73 * This method sets the voltages of the arm motors. The range is from [-1,1].
74 * A negative voltage makes the direction of the motor go backwards.
4e0d6389
LM
75 *
76 * @param voltage
0a179caa
KZ
77 * The voltage that you set the motors at. The range of the voltage
78 * of the arm motors is from [-1,1]. A negative voltage makes the
79 * direction of the motors go backwards.
4e0d6389
LM
80 */
81
0a179caa 82 public void setArmSpeeds(double voltage) {
4e0d6389
LM
83 if (voltage > 1)
84 voltage = 1;
85 else if (voltage < -1)
86 voltage = -1;
87
0a179caa
KZ
88 leftIntakeArm.set(voltage);
89 rightIntakeArm.set(voltage);
4e0d6389
LM
90 }
91
92 /***
0a179caa
KZ
93 * This method gets you the current voltage of the left motor that controls
94 * the intake arm. The range of voltage is from [-1,1]. A negative voltage
95 * makes the motor run backwards.
96 *
97 * @return Returns the voltage of the left motor that controls the arm. The
98 * range of the voltage goes from [-1,1]. A negative voltage indicates
99 * that the motor is running backwards.
100 */
101
102 public double getLeftArmSpeed() {
103 return leftIntakeArm.get();
104 }
105
106 /***
107 * This method gets you the current voltage of the right motor that controls
108 * the intake arm. The range of voltage is from [-1,1]. A negative voltage
109 * makes the motor run backwards.
4e0d6389 110 *
0a179caa
KZ
111 * @return Returns the voltage of the right motor that controls the arm. The
112 * range of the voltage goes from [-1,1]. A negative voltage indicates
113 * that the motor is running backwards.
4e0d6389 114 */
0a179caa
KZ
115 public double getRightArmSpeed() {
116 return rightIntakeArm.get();
117 }
118
119 public CANTalon getLeftIntakeArmMotor() {
120 return leftIntakeArm;
121 }
4e0d6389 122
0a179caa
KZ
123 public CANTalon getRightIntakeArmMotor() {
124 return rightIntakeArm;
4e0d6389
LM
125 }
126
127 /***
128 * This method checks to see if the presence of the ball inside is true or
129 * false.
130 *
131 * @return Returns whether the ball is inside as true or false
132 */
133
134 public boolean isBallInside() {
135 return true;
136 }
137
138 /***
139 * This method checks to see if the motors controlling the rollers are
140 * currently running.
141 *
142 * @return Returns whether the motors are currently running, and returns the
143 * state of the condition (true or false).
144 *
145 */
146
147 public boolean areRollersRolling() {
42c4c734
LM
148 if (Math.abs(getRollerVoltage()) < 0.02)
149 return false;
4e0d6389
LM
150 return true;
151 }
152
153 /***
154 * This method gets the angle of the potentiometer on the Intake Arm.
155 *
156 * @return angle of potentiometer
157 */
158
159 public double getArmAngle() {
160 return intakePot.get() + Constants.IntakeArm.ZERO_ANGLE;
161 }
162
163 public void stop() {
0a179caa 164 setArmSpeeds(0);
4e0d6389
LM
165 }
166
167 public double getAngleForLevel(double targetLevel) {
168 return potAngles[(int) (targetLevel - 1)];
169 }
170
171 @Override
172 protected void initDefaultCommand() {
173
174 }
7b11350e 175}