add commands to control intake of boulders
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / subsystems / IntakeArm.java
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 /***
10 * The IntakeArm consists of two rollers that are controlled by one motor, with
11 * a potentiometer on it.
12 *
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.
16 *
17 * @author superuser
18 *
19 */
20
21 public class IntakeArm extends Subsystem {
22
23 private CANTalon intakeRoller;
24 private CANTalon intakeArm;
25 private AnalogPotentiometer intakePot;
26 private double[] potAngles = { 0, 45, 90 };
27
28 public IntakeArm() {
29 intakeRoller = new CANTalon(Constants.IntakeArm.ROLLER_PORT);
30 intakeArm = new CANTalon(Constants.IntakeArm.ARM_PORT);
31 intakePot = new AnalogPotentiometer(Constants.IntakeArm.POT_CHANNEL,
32 Constants.IntakeArm.FULL_RANGE, Constants.IntakeArm.OFFSET);
33
34 }
35
36 /***
37 * This method sets the voltage of the motor to intake the ball. The voltage
38 * values are constants in Constants class
39 */
40 public void intakeBall() {
41 intakeRoller.set(Constants.IntakeArm.INTAKE_SPEED);
42 }
43
44 /***
45 * This method sets the voltage of the motor to output the ball. The voltage
46 * values are constants in Constants class
47 */
48 public void outputBall() {
49 intakeRoller.set(Constants.IntakeArm.OUTPUT_SPEED);
50 }
51
52 /***
53 * This method gets you the current voltage of the motor that controls the
54 * intake arm roller. The range of voltage is from [-1,1]. A negative voltage
55 * makes the motor run backwards.
56 *
57 * @return Returns the voltage of the motor that controls the roller. The
58 * range of the voltage goes from [-1,1]. A negative voltage indicates
59 * that the motor is running backwards.
60 */
61
62 public double getRollerVoltage() {
63 return intakeRoller.get();
64 }
65
66 /***
67 * This method sets the voltage of the arm motor. The range is from [-1,1]. A
68 * negative voltage makes the direction of the motor go backwards.
69 *
70 * @param voltage
71 * The voltage that you set the motor at. The range of the voltage of
72 * the arm motor is from [-1,1]. A negative voltage makes the
73 * direction of the motor go backwards.
74 */
75
76 public void setArmSpeed(double voltage) {
77 if (voltage > 1)
78 voltage = 1;
79 else if (voltage < -1)
80 voltage = -1;
81
82 intakeArm.set(voltage);
83 }
84
85 /***
86 * This method gets you the current voltage of the motor that controls the
87 * intake arm. The range of voltage is from [-1,1]. A negative voltage makes
88 * the motor run backwards.
89 *
90 * @return Returns the voltage of the motor that controls the arm. The range
91 * of the voltage goes from [-1,1]. A negative voltage indicates that
92 * the motor is running backwards.
93 */
94
95 public double getArmSpeed() {
96 return intakeArm.get();
97 }
98
99 /***
100 * This method checks to see if the presence of the ball inside is true or
101 * false.
102 *
103 * @return Returns whether the ball is inside as true or false
104 */
105
106 public boolean isBallInside() {
107 return true;
108 }
109
110 /***
111 * This method checks to see if the motors controlling the rollers are
112 * currently running.
113 *
114 * @return Returns whether the motors are currently running, and returns the
115 * state of the condition (true or false).
116 *
117 */
118
119 public boolean areRollersRolling() {
120 return true;
121 }
122
123 /***
124 * This method gets the angle of the potentiometer on the Intake Arm.
125 *
126 * @return angle of potentiometer
127 */
128
129 public double getArmAngle() {
130 return intakePot.get() + Constants.IntakeArm.ZERO_ANGLE;
131 }
132
133 public void stop() {
134 setArmSpeed(0);
135 }
136
137 public double getAngleForLevel(double targetLevel) {
138 return potAngles[(int) (targetLevel - 1)];
139 }
140
141 @Override
142 protected void initDefaultCommand() {
143
144 }
145 }