| 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 { |
| 10 | private AnalogPotentiometer defenseArmPotentiometer; |
| 11 | private AnalogPotentiometer defenseHandPotentiometer; |
| 12 | private CANTalon defenseArm; |
| 13 | private CANTalon defenseHand; |
| 14 | private double hookHeight; |
| 15 | private double footHeight; |
| 16 | private double[] potAngles; |
| 17 | // angles corresponding to pre-determined heights we will need |
| 18 | |
| 19 | public DefenseArm() { |
| 20 | defenseArmPotentiometer = new AnalogPotentiometer( |
| 21 | Constants.DefenseArm.ARM_CHANNEL, |
| 22 | Constants.DefenseArm.FULL_RANGE, |
| 23 | Constants.DefenseArm.OFFSET); |
| 24 | defenseHandPotentiometer = new AnalogPotentiometer( |
| 25 | Constants.DefenseArm.HAND_CHANNEL, |
| 26 | Constants.DefenseArm.FULL_RANGE, |
| 27 | Constants.DefenseArm.OFFSET); |
| 28 | |
| 29 | defenseArm = new CANTalon(Constants.DefenseArm.ARM_PORT); |
| 30 | defenseHand = new CANTalon(Constants.DefenseArm.HAND_PORT); |
| 31 | potAngles = createPotArray(); |
| 32 | } |
| 33 | |
| 34 | public double getArmPotAngle() { |
| 35 | return defenseArmPotentiometer.get(); |
| 36 | } |
| 37 | |
| 38 | public double getHandPotAngle() { |
| 39 | return defenseHandPotentiometer.get(); |
| 40 | } |
| 41 | |
| 42 | /*** |
| 43 | * This method takes an arm location as input (range of [0,2]) |
| 44 | * Returns the angle of the arm corresponding to that arm location |
| 45 | * |
| 46 | * @param desiredArmLocation |
| 47 | * takes an arm location ranging from [0,2] |
| 48 | * 0 is the lowest position of arm |
| 49 | * 2 is the highest position of arm |
| 50 | * @return |
| 51 | * the angle of the arm corresponding to that arm location |
| 52 | */ |
| 53 | public double getAngleForLocation(int desiredArmLocation) { |
| 54 | return potAngles[desiredArmLocation]; |
| 55 | } |
| 56 | |
| 57 | public double[] createPotArray() { |
| 58 | double[] arr = new double[3]; |
| 59 | |
| 60 | for (int i = 0; i < 3; i++) { |
| 61 | arr[i] = 45 * i; |
| 62 | } |
| 63 | return arr; |
| 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 speed |
| 71 | * The voltage that you set the motor at. The range of the voltage of |
| 72 | * the arm motor is from [-1,1]. A |
| 73 | * negative voltage makes the direction of the motor go backwards. |
| 74 | */ |
| 75 | |
| 76 | public void setArmSpeed(double speed) { |
| 77 | if (speed > 1) |
| 78 | speed = 1; |
| 79 | else if (speed < -1) |
| 80 | speed = -1; |
| 81 | |
| 82 | defenseArm.set(speed); |
| 83 | } |
| 84 | |
| 85 | /*** |
| 86 | * This method sets the voltage of the hand motor. The range is from [-1,1]. A |
| 87 | * negative voltage makes the direction of the motor go backwards. |
| 88 | * |
| 89 | * @param speed |
| 90 | * The voltage that you set the motor at. The range of the voltage of |
| 91 | * the hand motor is from [-1,1]. A |
| 92 | * negative voltage makes the direction of the motor go backwards. |
| 93 | */ |
| 94 | |
| 95 | public void setHandSpeed(double speed) { |
| 96 | if (speed > 1) |
| 97 | speed = 1; |
| 98 | else if (speed < -1) |
| 99 | speed = -1; |
| 100 | |
| 101 | defenseHand.set(speed); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | protected void initDefaultCommand() { |
| 106 | } |
| 107 | } |