1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
5 import edu
.wpi
.first
.wpilibj
.AnalogPotentiometer
;
6 import edu
.wpi
.first
.wpilibj
.CANTalon
;
7 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
9 public class DefenseArm
extends Subsystem
{
10 private AnalogPotentiometer defenseArmPotentiometer
;
11 private AnalogPotentiometer defenseHandPotentiometer
;
12 private CANTalon defenseArm
;
13 private CANTalon defenseHand
;
14 private double hookHeight
;
15 private double footHeight
;
17 private double[] potHandAngles
;
18 private double[] potArmAngles
;
19 private double[] potAngles
;
21 // angles corresponding to pre-determined heights we will need
24 defenseArmPotentiometer
= new AnalogPotentiometer(
25 Constants
.DefenseArm
.ARM_CHANNEL
, Constants
.DefenseArm
.FULL_RANGE
,
26 Constants
.DefenseArm
.OFFSET
);
27 defenseHandPotentiometer
= new AnalogPotentiometer(
28 Constants
.DefenseArm
.HAND_CHANNEL
, Constants
.DefenseArm
.FULL_RANGE
,
29 Constants
.DefenseArm
.OFFSET
);
31 defenseArm
= new CANTalon(Constants
.DefenseArm
.ARM_PORT
);
32 defenseHand
= new CANTalon(Constants
.DefenseArm
.HAND_PORT
);
33 potHandAngles
= createHandPotArray();
34 potArmAngles
= createArmPotArray();
37 public double getArmPotAngle() {
38 return defenseArmPotentiometer
.get();
41 public double getHandPotAngle() {
42 return defenseHandPotentiometer
.get();
46 * This method takes an arm location as input (range of [0,2]) Returns the
47 * angle of the arm corresponding to that arm location
49 * @param desiredArmLocation
50 * takes an arm location ranging from [0,2] 0 is the lowest position
51 * of arm 2 is the highest position of arm
52 * @return the angle of the arm corresponding to that arm location
54 public double getAngleForHandLocation(int desiredArmLocation
) {
55 return potHandAngles
[desiredArmLocation
];
58 public double getAngleForArmLocation(int desiredArmLocation
) {
59 return potArmAngles
[desiredArmLocation
];
62 public double[] createHandPotArray() {
63 double[] arr
= new double[3];
65 for (int i
= 0; i
< 3; i
++) {
71 public double[] createArmPotArray() {
72 double[] arr
= new double[3];
74 for (int i
= 0; i
< 3; i
++) {
81 * This method sets the voltage of the arm motor. The range is from [-1,1]. A
82 * negative voltage makes the direction of the motor go backwards.
85 * The voltage that you set the motor at. The range of the voltage of
86 * the arm motor is from [-1,1]. A negative voltage makes the
87 * direction of the motor go backwards.
90 public void setArmSpeed(double speed
) {
96 defenseArm
.set(speed
);
100 * This method sets the voltage of the hand motor. The range is from [-1,1]. A
101 * negative voltage makes the direction of the motor go backwards.
104 * The voltage that you set the motor at. The range of the voltage of
105 * the hand motor is from [-1,1]. A negative voltage makes the
106 * direction of the motor go backwards.
109 public void setHandSpeed(double speed
) {
115 defenseHand
.set(speed
);
118 // TODO: figure out if measurements are all in inches
119 public double getArmHorizontalDisplacement() {
120 double armHorizontalDisplacement
= Constants
.DefenseArm
.ARM_LENGTH
121 * Math
.cos(getArmPotAngle());
122 double handHorizontalDisplacement
= Constants
.DefenseArm
.HAND_LENGTH
123 * Math
.cos(getHandPotAngle());
124 return (armHorizontalDisplacement
+ handHorizontalDisplacement
);
127 public double getArmVerticalDisplacement() {
128 double armMounted
= Constants
.DefenseArm
.ARM_MOUNTED_HEIGHT
;
129 double armVerticalDisplacement
= Constants
.DefenseArm
.ARM_LENGTH
130 * Math
.sin(getArmPotAngle());
131 double handVerticalDisplacement
= Constants
.DefenseArm
.HAND_LENGTH
132 * Math
.sin(getHandPotAngle());
133 return (armMounted
+ armVerticalDisplacement
+ handVerticalDisplacement
);
136 public double getArmHorizontalDist() {
137 double arm
= Constants
.DefenseArm
.ARM_LENGTH
* Math
.cos(getArmPotAngle());
138 double hand
= Constants
.DefenseArm
.HAND_LENGTH
139 * Math
.cos(getHandPotAngle());
143 public double getArmHeight() {
144 double armMounted
= Constants
.DefenseArm
.ARM_MOUNTED_HEIGHT
;
145 double arm
= Constants
.DefenseArm
.ARM_LENGTH
* Math
.sin(getArmPotAngle());
146 double hand
= Constants
.DefenseArm
.HAND_LENGTH
147 * Math
.sin(getHandPotAngle());
148 return (armMounted
+ arm
+ hand
);
151 public boolean isOutsideRange() {
152 if (getArmHorizontalDist() < 15)
158 protected void initDefaultCommand() {