| 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 = { 0, 45, 90 }; |
| 17 | |
| 18 | // angles corresponding to pre-determined heights we will need |
| 19 | |
| 20 | public DefenseArm() { |
| 21 | defenseArmPotentiometer = new AnalogPotentiometer( |
| 22 | Constants.DefenseArm.ARM_CHANNEL, |
| 23 | Constants.DefenseArm.FULL_RANGE, |
| 24 | Constants.DefenseArm.OFFSET); |
| 25 | defenseHandPotentiometer = new AnalogPotentiometer( |
| 26 | Constants.DefenseArm.HAND_CHANNEL, |
| 27 | Constants.DefenseArm.FULL_RANGE, |
| 28 | Constants.DefenseArm.OFFSET); |
| 29 | |
| 30 | defenseArm = new CANTalon(Constants.DefenseArm.ARM_PORT); |
| 31 | defenseHand = new CANTalon(Constants.DefenseArm.HAND_PORT); |
| 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 getLevelValue(int level) { |
| 54 | if (level >= potAngles.length) |
| 55 | return potAngles[level]; |
| 56 | else |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /*** |
| 61 | * This method sets the voltage of the arm motor. The range is from [-1,1]. A |
| 62 | * negative voltage makes the direction of the motor go backwards. |
| 63 | * |
| 64 | * @param speed |
| 65 | * The voltage that you set the motor at. The range of the voltage of |
| 66 | * the arm motor is from [-1,1]. A |
| 67 | * negative voltage makes the direction of the motor go backwards. |
| 68 | */ |
| 69 | |
| 70 | public void setArmSpeed(double speed) { |
| 71 | if (speed > 1) |
| 72 | speed = 1; |
| 73 | else if (speed < -1) |
| 74 | speed = -1; |
| 75 | |
| 76 | defenseArm.set(speed); |
| 77 | } |
| 78 | |
| 79 | /*** |
| 80 | * This method sets the voltage of the hand motor. The range is from [-1,1]. A |
| 81 | * negative voltage makes the direction of the motor go backwards. |
| 82 | * |
| 83 | * @param speed |
| 84 | * The voltage that you set the motor at. The range of the voltage of |
| 85 | * the hand motor is from [-1,1]. A |
| 86 | * negative voltage makes the direction of the motor go backwards. |
| 87 | */ |
| 88 | |
| 89 | public void setHandSpeed(double speed) { |
| 90 | if (speed > 1) |
| 91 | speed = 1; |
| 92 | else if (speed < -1) |
| 93 | speed = -1; |
| 94 | |
| 95 | defenseHand.set(speed); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | protected void initDefaultCommand() { |
| 100 | } |
| 101 | } |